Pep8 formatting
This commit is contained in:
parent
2ae45ec1e7
commit
1ca35c238e
@ -4,88 +4,92 @@ from i3pystatus import IntervalModule, formatp
|
|||||||
from i3pystatus.core.util import TimeWrapper
|
from i3pystatus.core.util import TimeWrapper
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
class Cmus(IntervalModule):
|
class Cmus(IntervalModule):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
gets the status and current song info using cmus-remote
|
gets the status and current song info using cmus-remote
|
||||||
"""
|
"""
|
||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
'format',
|
'format',
|
||||||
'color'
|
'color'
|
||||||
)
|
)
|
||||||
color = "#909090"
|
color = "#909090"
|
||||||
format = "{status} {song_elapsed}/{song_length} {artist}-{title}"
|
format = "{status} {song_elapsed}/{song_length} {artist}-{title}"
|
||||||
status_text = ''
|
status_text = ''
|
||||||
interval = 1
|
interval = 1
|
||||||
status = {
|
status = {
|
||||||
"paused": "▷",
|
"paused": "▷",
|
||||||
"playing": "▶",
|
"playing": "▶",
|
||||||
"stopped": "◾",
|
"stopped": "◾",
|
||||||
}
|
|
||||||
def _cmus_command(self,command):
|
|
||||||
p = subprocess.Popen('cmus-remote --{command}'.format(command=command), shell=True,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.STDOUT)
|
|
||||||
return p.communicate()
|
|
||||||
|
|
||||||
def _query_cmus(self):
|
|
||||||
status_dict = {}
|
|
||||||
status, error = self._cmus_command('query')
|
|
||||||
status = status.decode('utf-8').split('\n')
|
|
||||||
if status != b'cmus-remote: cmus is not running\n':
|
|
||||||
for item in status:
|
|
||||||
split_item = item.split(' ')
|
|
||||||
if split_item[0] in ['tag', 'set']:
|
|
||||||
key = '_'.join(split_item[:2])
|
|
||||||
val = ' '.join([x for x in split_item[2:]])
|
|
||||||
status_dict[key] = val
|
|
||||||
else:
|
|
||||||
status_dict[split_item[0]] = ' '.join(split_item[1:])
|
|
||||||
return status_dict
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
status = self._query_cmus()
|
|
||||||
fdict = {
|
|
||||||
'file': status.get('file', ''),
|
|
||||||
'status': self.status[status["status"]],
|
|
||||||
'title': status.get('tag_title', ''),
|
|
||||||
'stream': status.get('stream', ''),
|
|
||||||
'album': status.get('tag_album', ''),
|
|
||||||
'artist': status.get('tag_artist', ''),
|
|
||||||
'tracknumber': status.get('tag_tracknumber', 0),
|
|
||||||
'song_length': TimeWrapper(status.get('duration', 0)),
|
|
||||||
'song_elapsed': TimeWrapper(status.get('position', 0)),
|
|
||||||
'bitrate': int(status.get("bitrate", 0)),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if fdict['stream']:
|
def _cmus_command(self, command):
|
||||||
fdict['artist'], fdict['title'] = (fdict['stream'].split('-') + [''] * 2)[:2]
|
p = subprocess.Popen('cmus-remote --{command}'.format(command=command), shell=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT)
|
||||||
|
return p.communicate()
|
||||||
|
|
||||||
elif not fdict['title']:
|
def _query_cmus(self):
|
||||||
_, filename = os.path.split(fdict['file'])
|
status_dict = {}
|
||||||
filebase, _ = os.path.splitext(filename)
|
status, error = self._cmus_command('query')
|
||||||
fdict['artist'], fdict['title'] = (filebase.split('-') + [''] * 2)[:2]
|
status = status.decode('utf-8').split('\n')
|
||||||
|
if status != b'cmus-remote: cmus is not running\n':
|
||||||
|
for item in status:
|
||||||
|
split_item = item.split(' ')
|
||||||
|
if split_item[0] in ['tag', 'set']:
|
||||||
|
key = '_'.join(split_item[:2])
|
||||||
|
val = ' '.join([x for x in split_item[2:]])
|
||||||
|
status_dict[key] = val
|
||||||
|
else:
|
||||||
|
status_dict[split_item[0]] = ' '.join(split_item[1:])
|
||||||
|
return status_dict
|
||||||
|
|
||||||
self.output = {
|
def run(self):
|
||||||
"full_text": formatp(self.format, **fdict),
|
status = self._query_cmus()
|
||||||
"color": self.color
|
fdict = {
|
||||||
}
|
'file': status.get('file', ''),
|
||||||
|
'status': self.status[status["status"]],
|
||||||
|
'title': status.get('tag_title', ''),
|
||||||
|
'stream': status.get('stream', ''),
|
||||||
|
'album': status.get('tag_album', ''),
|
||||||
|
'artist': status.get('tag_artist', ''),
|
||||||
|
'tracknumber': status.get('tag_tracknumber', 0),
|
||||||
|
'song_length': TimeWrapper(status.get('duration', 0)),
|
||||||
|
'song_elapsed': TimeWrapper(status.get('position', 0)),
|
||||||
|
'bitrate': int(status.get("bitrate", 0)),
|
||||||
|
}
|
||||||
|
|
||||||
def on_leftclick(self):
|
if fdict['stream']:
|
||||||
status = self._query_cmus().get('status', '')
|
fdict['artist'], fdict['title'] = (
|
||||||
if status == 'playing':
|
fdict['stream'].split('-') + [''] * 2)[:2]
|
||||||
self._cmus_command('pause')
|
|
||||||
if status == 'paused':
|
|
||||||
self._cmus_command('play')
|
|
||||||
if status == 'stopped':
|
|
||||||
self._cmus_command('play')
|
|
||||||
|
|
||||||
def on_rightclick(self):
|
elif not fdict['title']:
|
||||||
self._cmus_command("next")
|
_, filename = os.path.split(fdict['file'])
|
||||||
|
filebase, _ = os.path.splitext(filename)
|
||||||
|
fdict['artist'], fdict['title'] = (
|
||||||
|
filebase.split('-') + [''] * 2)[:2]
|
||||||
|
|
||||||
def on_upscroll(self):
|
self.output = {
|
||||||
self._cmus_command("next")
|
"full_text": formatp(self.format, **fdict),
|
||||||
|
"color": self.color
|
||||||
|
}
|
||||||
|
|
||||||
def on_downscroll(self):
|
def on_leftclick(self):
|
||||||
self._cmus_command("prev")
|
status = self._query_cmus().get('status', '')
|
||||||
|
if status == 'playing':
|
||||||
|
self._cmus_command('pause')
|
||||||
|
if status == 'paused':
|
||||||
|
self._cmus_command('play')
|
||||||
|
if status == 'stopped':
|
||||||
|
self._cmus_command('play')
|
||||||
|
|
||||||
|
def on_rightclick(self):
|
||||||
|
self._cmus_command("next")
|
||||||
|
|
||||||
|
def on_upscroll(self):
|
||||||
|
self._cmus_command("next")
|
||||||
|
|
||||||
|
def on_downscroll(self):
|
||||||
|
self._cmus_command("prev")
|
||||||
|
Loading…
Reference in New Issue
Block a user