Adding Music On Console (mocp) support, requires >= 2.3.0 version

This commit is contained in:
Jesús Rafael Sánchez 2017-07-30 01:06:52 -04:00
parent f35c401b0f
commit 338470c11f

View File

@ -528,3 +528,60 @@ Requires ``osascript``.
{0}
''').format(_common_args.format('itunes')))
class MocPlayerSegment(PlayerSegment):
def get_player_status(self, pl):
'''Return Music On Console (mocp) player information.
mocp -i returns current information i.e.
File: filename.format
Title: full title
Artist: artist name
SongTitle: song title
Album: album name
TotalTime: 00:00
TimeLeft: 00:00
TotalSec: 000
CurrentTime: 00:00
CurrentSec: 000
Bitrate: 000kbps
AvgBitrate: 000kbps
Rate: 00kHz
For the information we are looking for we dont really care if
we have extra-timing information or bit rate level. The
dictionary comprehension in this method takes anything in
ignore_info and brings the key inside that to the right info of
the dictionary.
'''
now_playing_str = run_cmd(pl, ['mocp', '-i'])
if not now_playing_str:
return
ignore_info = (
'File', 'TimeLeft', 'TotalSec', 'Title',
'Bitrate', 'AvgBitrate', 'Rate'
)
now_playing = dict(
[line.split(': ')
for line in now_playing_str.split('\n')[:-1]]
)
state = _convert_state(now_playing.get('State'))
return {
'state': state,
'album': now_playing.get('Album'),
'artist': now_playing.get('Artist'),
'title': now_playing.get('Title'),
'elapsed': _convert_seconds(now_playing.get('CurrentTime', 0)),
'total': _convert_seconds(now_playing.get('TotalTime', 0)),
}
mocp = with_docstring(MocPlayerSegment(),
('''Return MOC (Music On Console) player information
Requires mocp command be acessible from $PATH.
{0}
''').format(_common_args.format('mocp')))