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

Source Code for Module screenlets.plugins.Exaile

  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   
 15  # Exaile API by vrunner 
 16   
 17  import os 
 18  import dbus 
 19  import string 
 20  import gobject 
 21  from GenericPlayer import GenericAPI 
 22   
 23  #EXAILE = {'DBUS_NAME':'org.exaile.DBusInterface','DBUS_OBJECT':'/DBusInterfaceObject', \ 
 24  #                       'DBUS_TITLE':'get_title()','DBUS_ALBUM':'get_album()', \ 
 25  #                       'DBUS_ARTIST':'get_artist()','DBUS_ART':'get_cover_path()',\ 
 26  #                       'DBUS_PLAYING':'query()','PLAY_WORD':'playing'} 
 27   
28 -class ExaileAPI(GenericAPI):
29 __name__ = 'Exaile API' 30 __version__ = '0.0' 31 __author__ = 'vrunner' 32 __desc__ = 'API to the Exaile Music Player' 33 34 ns = "org.exaile.DBusInterface" 35 iroot = "/DBusInterfaceObject" 36 iface = "org.exaile.DBusInterface" 37 38 playerAPI = None 39 40 __timeout = None 41 __interval = 2 42 43 callbackFn = None 44 __curplaying = None 45 46 # Extended Functions from the GenericAPI 47
48 - def __init__(self, session_bus):
50
51 - def is_active(self, dbus_iface):
52 if self.ns in dbus_iface.ListNames(): return True 53 else: return False
54
55 - def connect(self):
56 proxy_obj = self.session_bus.get_object(self.ns, self.iroot) 57 self.playerAPI = dbus.Interface(proxy_obj, self.iface)
58
59 - def get_title(self):
60 return self.playerAPI.get_title()
61
62 - def get_album(self):
63 return self.playerAPI.get_album()
64
65 - def get_artist(self):
66 return self.playerAPI.get_artist()
67
68 - def get_cover_path(self):
69 return self.playerAPI.get_cover_path()
70
71 - def is_playing(self):
72 if self.now_playing() == "": return False 73 else: return True
74
75 - def play_pause(self):
76 self.playerAPI.play()
77
78 - def next(self):
79 self.playerAPI.next_track()
80
81 - def previous(self):
82 self.playerAPI.prev_track()
83
84 - def register_change_callback(self, fn):
85 self.callback_fn = fn 86 # Could not find a callback signal for Banshee, so just calling after some time interval 87 if self.__timeout: 88 gobject.source_remove(self.__timeout) 89 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
90
91 - def info_changed(self, signal=None):
92 if self.__timeout: 93 gobject.source_remove(self.__timeout) 94 95 try: 96 # Only call the callback function if Data has changed 97 if self.__curplaying != None and not self.is_playing(): 98 self.__curplaying = None 99 self.callback_fn() 100 101 nowplaying = self.now_playing() 102 if self.is_playing() and self.__curplaying != nowplaying: 103 self.__curplaying = nowplaying 104 self.callback_fn() 105 self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed) 106 except: 107 # The player exited ? call callback function 108 self.callback_fn() 109 pass
110 111
112 - def now_playing(self):
113 return self.get_artist()+self.get_title()
114