summaryrefslogtreecommitdiff
path: root/kch_awn_cover
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2011-07-20 16:07:04 +0200
committerKevin Chabowski <kevin@kch42.de>2011-07-20 16:07:04 +0200
commitb4a827da07169f94ca616be681fd1c40653ffbe4 (patch)
treefb4c4f2c170485e414eb7bc1eedd8aeba82bae64 /kch_awn_cover
downloadrhythmbox_awn_cover-b4a827da07169f94ca616be681fd1c40653ffbe4.tar.gz
rhythmbox_awn_cover-b4a827da07169f94ca616be681fd1c40653ffbe4.tar.bz2
rhythmbox_awn_cover-b4a827da07169f94ca616be681fd1c40653ffbe4.zip
Initial commit
Diffstat (limited to 'kch_awn_cover')
-rw-r--r--kch_awn_cover/__init__.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/kch_awn_cover/__init__.py b/kch_awn_cover/__init__.py
new file mode 100644
index 0000000..2cc7752
--- /dev/null
+++ b/kch_awn_cover/__init__.py
@@ -0,0 +1,66 @@
+# -*-coding: utf-8 -*-
+
+import rhythmdb, rb
+import dbus
+from glob import glob
+
+def awn_icon_change(iconfile):
+ """Changes Rhythmbox' icon in Awn to iconfile. If iconfile is None, unset icon"""
+ bus = dbus.SessionBus()
+ obj = bus.get_object("com.google.code.Awn", "/com/google/code/Awn")
+
+ if iconfile is None:
+ obj.UnsetTaskIconByName("rhythmbox")
+ else:
+ obj.SetTaskIconByName("rhythmbox", iconfile)
+
+
+class kch_awn_coverPlugin(rb.Plugin):
+ def __init__(self):
+ rb.Plugin.__init__ (self)
+
+ def activate(self, shell):
+ self.shell = shell
+ self.sp = shell.get_player()
+ self.pec_id = self.sp.connect('playing-song-changed', self.playing_entry_changed)
+ self.pc_id = self.sp.connect('playing-changed', self.playing_changed)
+ self.current_pixbuf = None
+ self.current_entry = None
+ entry = sp.get_playing_entry()
+ self.playing_entry_changed(sp, entry)
+
+ def deactivate(self, shell):
+ awn_icon_change(None)
+ self.shell = None
+ self.sp.disconnect(self.pec_id)
+ self.sp.disconnect(self.pc_id)
+ self.sp = None
+
+ def playing_changed(self, sp, playing):
+ self.set_entry(sp.get_playing_entry())
+
+ def playing_entry_changed(self, sp, entry):
+ self.set_entry(entry)
+
+ def set_entry (self, entry):
+ if entry != self.current_entry:
+ if entry is None:
+ awn_icon_change(None)
+ db = self.shell.get_property("db")
+ self.current_entry = entry
+
+ xtns = ["png", "jpg", "jpeg"]
+ try:
+ artwork = [
+ filename
+ for filename in glob("{directory}/covers/{artist} - {album}*".format(
+ directory=rb.user_cache_dir(),
+ artist=db.entry_get(entry, rhythmdb.PROP_ARTIST),
+ album=db.entry_get(entry, rhythmdb.PROP_ALBUM)
+ ))
+ if filename.split(".")[-1].lower() in xtns
+ ][0]
+ awn_icon_change(artwork)
+ except:
+ awn_icon_change(None)
+