1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)
|