Package screenlets :: Package plugins :: Module Rhythmbox
[hide private]
[frames] | no frames]

Source Code for Module screenlets.plugins.Rhythmbox

  1  # This program is free software: you can redistribute it and/or modify 
  2  # it under the terms of the GNU General Public License as published by 
  3  # the Free Software Foundation, either version 3 of the License, or 
  4  # (at your option) any later version. 
  5  #  
  6  # This program is distributed in the hope that it will be useful, 
  7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  9  # GNU General Public License for more details. 
 10  #  
 11  # You should have received a copy of the GNU General Public License 
 12  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 13  # 
 14  # Rythmbox API  
 15   
 16  import os 
 17  import dbus 
 18  from GenericPlayer import GenericAPI 
 19  import urllib 
 20  from urlparse import urlparse 
 21   
22 -class RhythmboxAPI(GenericAPI):
23 __name__ = 'Rhythmbox' 24 __version__ = '0.0' 25 __author__ = 'vrunner' 26 __desc__ = 'API to the Rhythmbox Music Player' 27 28 ns = "org.gnome.Rhythmbox" 29 playerAPI = None 30 shellAPI = None 31 32 callback_fn = None 33 34 # Extended Functions from the GenericAPI 35
36 - def __init__(self, session_bus):
38
39 - def is_active(self, dbus_iface):
40 if self.ns in dbus_iface.ListNames(): return True 41 else: return False
42
43 - def connect(self):
44 proxy_obj1 = self.session_bus.get_object(self.ns, '/org/gnome/Rhythmbox/Player') 45 proxy_obj2 = self.session_bus.get_object(self.ns, '/org/gnome/Rhythmbox/Shell') 46 self.playerAPI = dbus.Interface(proxy_obj1, self.ns+".Player") 47 self.shellAPI = dbus.Interface(proxy_obj2, self.ns+".Shell")
48
49 - def get_title(self):
50 tmp = self.getProperty('rb:stream-song-title') 51 if tmp: return tmp 52 else: return self.getProperty('title')
53
54 - def get_album(self):
55 tmp = self.getProperty('rb:stream-song-album') 56 if tmp: return tmp 57 else: return self.getProperty('album')
58
59 - def get_artist(self):
60 tmp = self.getProperty('rb:stream-song-artist') 61 if tmp: return tmp 62 else: return self.getProperty('artist')
63 64 # **MUST HAVE** the "COVER ART" Plugin enabled 65 # (or the "Art Display-Awn" Plugin) 66
67 - def get_cover_path(self):
68 # Return the Expected Path (will be ignored by NowPlaying if it doesn't 69 # exist 70 71 coverFile = self.getProperty('rb:coverArt-uri') 72 if coverFile != None: 73 if os.path.isfile(coverFile): 74 return coverFile 75 76 coverFile = os.environ['HOME']+"/.cache/rhythmbox/covers/"+self.get_artist()+" - "+self.get_album()+".jpg" 77 if not os.path.isfile(coverFile): 78 baseURL = urlparse( urllib.url2pathname( self.playerAPI.getPlayingUri() ) ) 79 basePath = os.path.dirname( baseURL.path ) 80 names = ['Album', 'Cover', 'Folde'] 81 for x in os.listdir(basePath): 82 if os.path.splitext(x)[1] in [".jpg", ".png"] and (x.capitalize()[:5] in names): 83 coverFile = basePath + '/' + x 84 return coverFile 85 return coverFile
86 87 88
89 - def is_playing(self):
90 try: 91 test_playing = self.playerAPI.getPlaying() 92 if self.playerAPI.getPlaying() == 1: return True 93 else: return False 94 except DBusException: 95 return False
96
97 - def play_pause(self):
98 if self.is_playing: 99 self.playerAPI.playPause(False) 100 else: 101 self.playerAPI.playPause(True)
102
103 - def next(self):
104 self.playerAPI.next()
105
106 - def previous(self):
107 self.playerAPI.previous()
108
109 - def register_change_callback(self, fn):
110 if(self.callback_fn == None): 111 #print "Registering Callback" 112 self.callback_fn = fn 113 self.playerAPI.connect_to_signal("playingChanged", self.info_changed) 114 self.playerAPI.connect_to_signal("playingUriChanged", self.info_changed) 115 self.playerAPI.connect_to_signal("playingSongPropertyChanged", self.info_changed)
116 117 # Internal Functions
118 - def getProperty(self, name):
119 try: 120 val = self.shellAPI.getSongProperties(self.playerAPI.getPlayingUri())[name] 121 return val 122 except: 123 return None
124
125 - def info_changed(self, *args, **kwargs):
126 self.callback_fn()
127