summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUltrabug <ultrabug@gentoo.org>2014-12-21 20:13:38 +0100
committerUltrabug <ultrabug@gentoo.org>2014-12-21 20:13:38 +0100
commitadbf860f6027236d94258e2f86b2596ebd759a74 (patch)
tree50390125ecdff7c33de7836226a5b727cb1b9bf2
parent1658050564607ef0a189af3028e0119fc1561216 (diff)
module clementine QA and config
-rw-r--r--py3status/modules/clementine.py62
1 files changed, 37 insertions, 25 deletions
diff --git a/py3status/modules/clementine.py b/py3status/modules/clementine.py
index 61917b7..fd29153 100644
--- a/py3status/modules/clementine.py
+++ b/py3status/modules/clementine.py
@@ -1,19 +1,21 @@
# -*- coding: utf-8 -*-
-
+"""
+This module displays the current "artist - title" playing in Clementine.
+
+Last modified: 2014-03-23
+Author: Francois LASSERRE <choiz@me.com>
+License: GNU GPL http://www.gnu.org/licenses/gpl.html
+"""
+
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 <choiz@me.com>
- License: GNU GPL http://www.gnu.org/licenses/gpl.html
- """
+
+ # available configuration parameters
+ cache_timeout = 0
+
def _getMetadatas(self):
"""
Get the current song metadatas (artist - title)
@@ -22,26 +24,26 @@ class Py3status:
metadatas = check_output('qdbus org.mpris.clementine /TrackList org.freedesktop.MediaPlayer.GetMetadata {}'.format(track_id.decode()), shell=True)
lines = metadatas.decode('utf-8').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:
@@ -50,16 +52,26 @@ class Py3status:
now_playing = '♫ {}'.format(title)
elif internet_radio:
now_playing = '♫ Internet Radio'
-
+
return now_playing
-
- def clementine(self, i3status_output_json, i3status_config):
+
+ def clementine(self, i3s_output_list, i3s_config):
"""
Get the current "artist - title" and return it.
"""
- response = {'full_text': '', 'name': 'clementine'}
-
- response['cached_until'] = time()
+ response = {'full_text': ''}
+
+ response['cached_until'] = time() + self.cache_timeout
response['full_text'] = self._getMetadatas()
-
- return (0, response)
+
+ return response
+
+if __name__ == "__main__":
+ """
+ Test this module by calling it directly.
+ """
+ from time import sleep
+ x = Py3status()
+ while True:
+ print(x.clementine([], {}))
+ sleep(1)