Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import subprocess
- import sys
- try:
- import ansicodes # local module
- except ImportError:
- class ansicodes(object):
- @staticmethod
- def mapColors(strn, fgMap, bgMap=None, *, fCols=None, bCols=None, hardReset=False):
- return "".join(strn)
- def main():
- mpcFormat = "%artist% - %track%:%title% - %album%"
- mpcLines = subprocess.check_output(["mpc", "--format", mpcFormat])
- mpcLines = mpcLines.decode().splitlines()
- mpcStatus = mpcLines[0]
- if mpcStatus.startswith("volume:"):
- return "Not playing"
- mpcTimeLine = mpcLines[1].split()
- mpcTime = mpcTimeLine[2]
- mpcMode = mpcTimeLine[0][1:-1]
- if mpcMode.lower() == "paused":
- modeColor = "1"
- else:
- modeColor = "2"
- ret = ["<{}> ".format(mpcMode), mpcStatus, " [{}]".format(mpcTime)]
- return ansicodes.mapColors(ret, modeColor + " 3", hardReset=True)
- # specific to running directly
- def strExit(ret):
- print(ret)
- def intExit(ret):
- return ret
- mainAction = {str: strExit, int: intExit, None: int}
- if __name__ == "__main__":
- ret = main()
- if ret:
- sys.exit(mainAction[ret.__class__](ret) or 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement