diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | kch_awn_cover.rb-plugin | 7 | ||||
-rw-r--r-- | kch_awn_cover/__init__.py | 66 |
3 files changed, 75 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..52e4e61 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*.pyo diff --git a/kch_awn_cover.rb-plugin b/kch_awn_cover.rb-plugin new file mode 100644 index 0000000..1a10513 --- /dev/null +++ b/kch_awn_cover.rb-plugin @@ -0,0 +1,7 @@ +[RB Plugin] +Loader=python +Module=kch_awn_cover +IAge=1 +Name=Awn Cover artwork +Description=Changes Rhythmbox' icon in Awn to the cover artwork of the current song. +Authors=Kevin Chabowski <kevin@kch42.de> 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) + |