Merge pull request #145 from rampage644/features/pomodoro_cmus
Features/pomodoro cmus
This commit is contained in:
commit
9de7640fcc
@ -5,18 +5,42 @@ from i3pystatus.core.util import TimeWrapper
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_artist_title(input):
|
||||||
|
for sep in ('-', ' - '):
|
||||||
|
split = input.split(sep)
|
||||||
|
if len(split) == 2:
|
||||||
|
return split[0], split[1]
|
||||||
|
# fallback
|
||||||
|
return (input.split('-') + [''] * 2)[:2]
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
.. rubric:: Available formatters
|
||||||
|
|
||||||
|
* `{status}` — current status icon (paused/playing/stopped)
|
||||||
|
* `{song_elapsed}` — song elapsed time (mm:ss format)
|
||||||
|
* `{song_length}` — total song duration (mm:ss format)
|
||||||
|
* `{artist}` — artist
|
||||||
|
* `{title}` — title
|
||||||
|
* `{album}` — album
|
||||||
|
* `{tracknumber}` — tracknumber
|
||||||
|
* `{file}` — file or url name
|
||||||
|
* `{stream}` — song name from stream
|
||||||
|
* `{bitrate}` — bitrate
|
||||||
"""
|
"""
|
||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
'format',
|
('format', 'format string, available formatters: status, song_elapsed, '
|
||||||
'color'
|
'song_length, artist, title, album, tracknumber, file, '
|
||||||
|
'stream, bitrate'),
|
||||||
|
'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 = {
|
||||||
@ -34,8 +58,8 @@ class Cmus(IntervalModule):
|
|||||||
def _query_cmus(self):
|
def _query_cmus(self):
|
||||||
status_dict = {}
|
status_dict = {}
|
||||||
status, error = self._cmus_command('query')
|
status, error = self._cmus_command('query')
|
||||||
status = status.decode('utf-8').split('\n')
|
|
||||||
if status != b'cmus-remote: cmus is not running\n':
|
if status != b'cmus-remote: cmus is not running\n':
|
||||||
|
status = status.decode('utf-8').split('\n')
|
||||||
for item in status:
|
for item in status:
|
||||||
split_item = item.split(' ')
|
split_item = item.split(' ')
|
||||||
if split_item[0] in ['tag', 'set']:
|
if split_item[0] in ['tag', 'set']:
|
||||||
@ -48,6 +72,12 @@ class Cmus(IntervalModule):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
status = self._query_cmus()
|
status = self._query_cmus()
|
||||||
|
if not status:
|
||||||
|
self.output = {
|
||||||
|
"full_text": 'Not running',
|
||||||
|
"color": self.color
|
||||||
|
}
|
||||||
|
return
|
||||||
fdict = {
|
fdict = {
|
||||||
'file': status.get('file', ''),
|
'file': status.get('file', ''),
|
||||||
'status': self.status[status["status"]],
|
'status': self.status[status["status"]],
|
||||||
@ -62,14 +92,16 @@ class Cmus(IntervalModule):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fdict['stream']:
|
if fdict['stream']:
|
||||||
fdict['artist'], fdict['title'] = (
|
fdict['artist'], fdict[
|
||||||
fdict['stream'].split('-') + [''] * 2)[:2]
|
'title'] = _extract_artist_title(fdict['stream'])
|
||||||
|
|
||||||
elif not fdict['title']:
|
elif not fdict['title']:
|
||||||
_, filename = os.path.split(fdict['file'])
|
_, filename = os.path.split(fdict['file'])
|
||||||
filebase, _ = os.path.splitext(filename)
|
filebase, _ = os.path.splitext(filename)
|
||||||
fdict['artist'], fdict['title'] = (
|
fdict['artist'], fdict['title'] = _extract_artist_title(filebase)
|
||||||
filebase.split('-') + [''] * 2)[:2]
|
|
||||||
|
fdict['title'] = fdict['title'].strip()
|
||||||
|
fdict['artist'] = fdict['artist'].strip()
|
||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": formatp(self.format, **fdict),
|
"full_text": formatp(self.format, **fdict),
|
||||||
|
@ -24,9 +24,11 @@ class Pomodoro(IntervalModule):
|
|||||||
'Path to sound file to play as alarm. Played by "aplay" utility'),
|
'Path to sound file to play as alarm. Played by "aplay" utility'),
|
||||||
('pomodoro_duration',
|
('pomodoro_duration',
|
||||||
'Working (pomodoro) interval duration in seconds'),
|
'Working (pomodoro) interval duration in seconds'),
|
||||||
('break_duration', 'Short break duration in secods'),
|
('break_duration', 'Short break duration in seconds'),
|
||||||
('long_break_duration', 'Long break duration in secods'),
|
('long_break_duration', 'Long break duration in seconds'),
|
||||||
('short_break_count', 'Short break count before first long break'),
|
('short_break_count', 'Short break count before first long break'),
|
||||||
|
('format', 'format string, available formatters: current_pomodoro, '
|
||||||
|
'total_pomodoro, time')
|
||||||
)
|
)
|
||||||
|
|
||||||
color_stopped = '#2ECCFA'
|
color_stopped = '#2ECCFA'
|
||||||
@ -34,6 +36,7 @@ class Pomodoro(IntervalModule):
|
|||||||
color_break = '#37FF00'
|
color_break = '#37FF00'
|
||||||
interval = 1
|
interval = 1
|
||||||
short_break_count = 3
|
short_break_count = 3
|
||||||
|
format = '☯ {current_pomodoro}/{total_pomodoro} {time}'
|
||||||
|
|
||||||
pomodoro_duration = 25 * 60
|
pomodoro_duration = 25 * 60
|
||||||
break_duration = 5 * 60
|
break_duration = 5 * 60
|
||||||
@ -56,8 +59,8 @@ class Pomodoro(IntervalModule):
|
|||||||
else:
|
else:
|
||||||
self.time = datetime.now() + \
|
self.time = datetime.now() + \
|
||||||
timedelta(seconds=self.break_duration)
|
timedelta(seconds=self.break_duration)
|
||||||
text = 'Go for a break!'
|
|
||||||
self.breaks += 1
|
self.breaks += 1
|
||||||
|
text = 'Go for a break!'
|
||||||
else:
|
else:
|
||||||
self.state = 'running'
|
self.state = 'running'
|
||||||
self.time = datetime.now() + \
|
self.time = datetime.now() + \
|
||||||
@ -70,17 +73,27 @@ class Pomodoro(IntervalModule):
|
|||||||
text = '{:02}:{:02}'.format(int(min), int(sec))
|
text = '{:02}:{:02}'.format(int(min), int(sec))
|
||||||
color = self.color_running if self.state == 'running' else self.color_break
|
color = self.color_running if self.state == 'running' else self.color_break
|
||||||
else:
|
else:
|
||||||
text = 'Stopped'
|
self.output = {
|
||||||
color = self.color_stopped
|
'full_text': 'Stopped',
|
||||||
|
'color': self.color_stopped
|
||||||
|
}
|
||||||
|
return
|
||||||
|
|
||||||
|
sdict = {
|
||||||
|
'time': text,
|
||||||
|
'current_pomodoro': self.breaks,
|
||||||
|
'total_pomodoro': self.short_break_count + 1,
|
||||||
|
}
|
||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
'full_text': text,
|
'full_text': self.format.format(**sdict),
|
||||||
'color': color
|
'color': color
|
||||||
}
|
}
|
||||||
|
|
||||||
def on_leftclick(self):
|
def on_leftclick(self):
|
||||||
self.state = 'running'
|
self.state = 'running'
|
||||||
self.time = datetime.now() + timedelta(seconds=self.pomodoro_duration)
|
self.time = datetime.now() + timedelta(seconds=self.pomodoro_duration)
|
||||||
|
self.breaks = 0
|
||||||
|
|
||||||
def on_rightclick(self):
|
def on_rightclick(self):
|
||||||
self.state = 'stopped'
|
self.state = 'stopped'
|
||||||
|
Loading…
Reference in New Issue
Block a user