From c5aa3392e39efc8c3835c148b4c07f61825a0ec5 Mon Sep 17 00:00:00 2001 From: François LASSERRE Date: Sun, 23 Mar 2014 11:50:49 +0100 Subject: Add nowplaying module. This module display the current "artist - title" playing in Clementine. --- examples/nowplaying.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 examples/nowplaying.py diff --git a/examples/nowplaying.py b/examples/nowplaying.py new file mode 100644 index 0000000..0ab0cf8 --- /dev/null +++ b/examples/nowplaying.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +import subprocess +from time import time + +class Py3status: + """ + nowplaying.py + + This module display the current "artist - title" playing in Clementine. + + Last modified: 2014-03-23 + Author: François LASSERRE + License: GNU GPL http://www.gnu.org/licenses/gpl.html + """ + def getMetadatas(self): + """ + Get the current song metadatas (artist - title) + """ + track_id = subprocess.check_output('qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetCurrentTrack', shell=True) + metadatas = subprocess.check_output('qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetMetadata '+track_id, shell=True) + lines = metadatas.split("\n") + lines = filter(None, lines) + + now_playing = '' + + if len(lines) > 0: + + artist = '' + title = '' + internet_radio = 0 + + for item in lines: + + if item.find('artist:') != -1: + artist = item[8:] + + if item.find('title:') != -1: + title = item[7:] + + if (title.find('.wav') != -1) | (title.find('.mp3') != -1): + title = title[:-4] + if (title.find("http") != -1): + title = "" + internet_radio = 1 + + if (len(artist) != 0) & (len(title) != 0): + now_playing = '♫ '+artist+' - '+title + elif len(artist) != 0: + now_playing = '♫ '+artist + elif len(title) != 0: + now_playing = '♫ '+title + elif internet_radio != 0: + now_playing = '♫ Internet Radio' + + return now_playing + + def setMetadatas(self, json, i3status_config): + """ + Get the current "artist - title" and return it. + """ + response = {'full_text': '', 'name': 'track_info'} + + metadata = self.getMetadatas() + + response['full_text'] = metadata + response['cached_until'] = time() + + return (0, response) -- cgit v1.3 From db4301b3c0fa2040e07f998c8ad6bfcd277c223e Mon Sep 17 00:00:00 2001 From: François LASSERRE Date: Fri, 23 May 2014 19:14:59 +0200 Subject: update code rename nowplaying to clementine --- examples/clementine.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++ examples/nowplaying.py | 69 -------------------------------------------------- 2 files changed, 65 insertions(+), 69 deletions(-) create mode 100644 examples/clementine.py delete mode 100644 examples/nowplaying.py diff --git a/examples/clementine.py b/examples/clementine.py new file mode 100644 index 0000000..1a1c389 --- /dev/null +++ b/examples/clementine.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- + +from time import time +from subprocess import check_output + + +class Py3status: + """ + clementine.py + + This module display the current "artist - title" playing in Clementine. + + Last modified: 2014-03-23 + Author: Francois LASSERRE + License: GNU GPL http://www.gnu.org/licenses/gpl.html + """ + def _getMetadatas(self): + """ + Get the current song metadatas (artist - title) + """ + track_id = check_output('qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetCurrentTrack', shell=True) + metadatas = check_output('qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetMetadata ' + track_id, shell=True) + lines = metadatas.split('\n') + lines = filter(None, lines) + + now_playing = '' + + if lines: + artist = '' + title = '' + internet_radio = False + + for item in lines: + if item.find('artist:') != -1: + artist = item[8:] + if item.find('title:') != -1: + title = item[7:] + + if title.find('.wav') != -1 or title.find('.mp3') != -1: + title = title[:-4] + if title.find('http') != -1: + title = '' + internet_radio = True + + if artist and title: + now_playing = '♫ {} - {}'.format(artist, title) + elif artist: + now_playing = '♫ {}'.format(artist) + elif title: + now_playing = '♫ {}'.format(title) + elif internet_radio: + now_playing = '♫ Internet Radio' + + return now_playing + + def clementine(self, i3status_output_json, i3status_config): + """ + Get the current "artist - title" and return it. + """ + response = {'full_text': '', 'name': 'clementine'} + + response['cached_until'] = time() + response['full_text'] = self._getMetadatas() + + return (0, response) diff --git a/examples/nowplaying.py b/examples/nowplaying.py deleted file mode 100644 index 0ab0cf8..0000000 --- a/examples/nowplaying.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- - -import subprocess -from time import time - -class Py3status: - """ - nowplaying.py - - This module display the current "artist - title" playing in Clementine. - - Last modified: 2014-03-23 - Author: François LASSERRE - License: GNU GPL http://www.gnu.org/licenses/gpl.html - """ - def getMetadatas(self): - """ - Get the current song metadatas (artist - title) - """ - track_id = subprocess.check_output('qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetCurrentTrack', shell=True) - metadatas = subprocess.check_output('qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetMetadata '+track_id, shell=True) - lines = metadatas.split("\n") - lines = filter(None, lines) - - now_playing = '' - - if len(lines) > 0: - - artist = '' - title = '' - internet_radio = 0 - - for item in lines: - - if item.find('artist:') != -1: - artist = item[8:] - - if item.find('title:') != -1: - title = item[7:] - - if (title.find('.wav') != -1) | (title.find('.mp3') != -1): - title = title[:-4] - if (title.find("http") != -1): - title = "" - internet_radio = 1 - - if (len(artist) != 0) & (len(title) != 0): - now_playing = '♫ '+artist+' - '+title - elif len(artist) != 0: - now_playing = '♫ '+artist - elif len(title) != 0: - now_playing = '♫ '+title - elif internet_radio != 0: - now_playing = '♫ Internet Radio' - - return now_playing - - def setMetadatas(self, json, i3status_config): - """ - Get the current "artist - title" and return it. - """ - response = {'full_text': '', 'name': 'track_info'} - - metadata = self.getMetadatas() - - response['full_text'] = metadata - response['cached_until'] = time() - - return (0, response) -- cgit v1.3