From 338470c11fab863d600bb33b7c1b53d3f11c9208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Rafael=20S=C3=A1nchez?= Date: Sun, 30 Jul 2017 01:06:52 -0400 Subject: [PATCH] Adding Music On Console (mocp) support, requires >= 2.3.0 version --- powerline/segments/common/players.py | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/powerline/segments/common/players.py b/powerline/segments/common/players.py index ccbf116b..4cb1769a 100644 --- a/powerline/segments/common/players.py +++ b/powerline/segments/common/players.py @@ -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 don’t 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'))) +