class JamendoManager(Singleton, Client): def __init__(self): Singleton.__init__(self) Client.__init__(self) self.prefs = PluginPrefs("jamendo") self.username = self.get_preference("username", "") self.password = self.get_preference("password", "") def is_logged(self): return self.logged def has_preference(self, name): return self.prefs.has_key(name) def get_preference(self, name, default=None): return self.prefs.get(name, default) def set_preference(self, name, value): self.prefs[name] = value self.prefs.save() def get_username(self): return self.username def set_username(self, value): self.username = value self.set_preference("username", value) def get_password(self): return self.password def set_password(self, value): self.password = value self.set_preference("password", value)
def __init__(self,uname=None,pword=None): self.api = twitter.Api() self.setSourceAsCanola() self.auth = False self.userName = None self.password = None self.prefs = PluginPrefs("twitter")
def get_thumb_path(id=None): prefs = PluginPrefs("twitter") try: path = prefs["twitter_thumbs"] except KeyError: path = os.path.join(os.path.expanduser("~"), ".canola", "twitter", "thumbs") prefs["twitter_thumbs"] = path prefs.save() if not os.path.exists(path): os.makedirs(path) if id is not None: path = os.path.join(path, "%s.jpg" % id) return path
def __init__(self): Singleton.__init__(self) Client.__init__(self) self.prefs = PluginPrefs("jamendo") self.username = self.get_preference("username", "") self.password = self.get_preference("password", "")
def __init__(self, parent=None): ModelFolder.__init__(self, self.title, parent) self.prefs = PluginPrefs('picasa') try: self._state = self.prefs["photocast_sync"] except KeyError: self._state = False self.prefs["photocast_sync"] = self._state self.prefs.save()
def __init__(self): PlayerHook.__init__(self) self._model = None self._timer = None self.start_time = None self._timer_paused = False self.prefs = PluginPrefs("lastfm") self.sending_submits = False self.pending_submits = Queue()
def __init__(self): Singleton.__init__(self) self.gd_client = gdata.photos.service.PhotosService() self.gd_client.email = '' self.gd_client.password = '' self.gd_client.source = 'Picasa plugin for Canola' self.logged = False self.login_error = '' self._user = '' self._password = '' self.albums ='' self.thumbs_path = '' self.outside_terra = False; #used to save the list of current downloading thumbs to avoid multiple #downloads for the same file self.thumbs_in_progress = {}; try: self.prefs = PluginPrefs("picasa") except: print "running outside canola" self.outside_terra = True;
class PhotocastSyncModel(ModelFolder): terra_type = "Model/Options/Folder/Image/Picasa/Album/Photocast" title = "Photocasts" table = "photocast_feeds" stmt_select = "SELECT id, uri, title, desc, author FROM %s" % table stmt_delete = "DELETE FROM %s" % table stmt_insert = "INSERT INTO %s (uri, title, desc, author, epoch) VALUES \ ( ?, ?, ?, ?, ?)" % table def __init__(self, parent=None): ModelFolder.__init__(self, self.title, parent) self.prefs = PluginPrefs('picasa') try: self._state = self.prefs["photocast_sync"] except KeyError: self._state = False self.prefs["photocast_sync"] = self._state self.prefs.save() def _change_state(self): self._state = not self._state self.prefs["photocast_sync"] = self._state self.prefs.save() def _remove_albums(self): cur = db.get_cursor() self.select_cond = r" WHERE uri LIKE '%" + picasa_manager.user + \ r"%' AND title LIKE '%[PICASA]%'" self.query = self.stmt_delete + self.select_cond cur.execute(self.query) db.commit() cur.close() def _insert_albums(self): cur = db.get_cursor() albums = picasa_manager.get_user_albums() for album in albums.entry: if album.access.text == "protected": #TODO: protected albums can't be accessed with authkey continue name = "[PICASA]" + album.title.text try: author = album.author[0].name.text except: author = "" description = album.summary.text epoch = int(time()) url = album.id.text.replace("/entry/api/", "/feed/base/", 1) + \ "?kind=photo&alt=rss&hl=en_GB" #adding authkey in the url for private and proteced albums #authkey seems to be valid for 2 weeks if ( album.access.text != "public"): auth_index = album.link[0].href.rfind("authkey=") auth_key= album.link[0].href[auth_index:] url = url + "&" + auth_key try: db.execute(self.stmt_insert, (url, name, description, \ author, epoch)) except: log.error("Error while adding feed in db") db.commit() cur.close() def do_load(self): PhotocastOnOffModel(self) PhotocastRefreshModel(self)
class Client(object): def __init__(self,uname=None,pword=None): self.api = twitter.Api() self.setSourceAsCanola() self.auth = False self.userName = None self.password = None self.prefs = PluginPrefs("twitter") #self.login(uname,pword) def getPublicTimeline(self): try: statuses = self.api.GetPublicTimeline() lst = utils.getMessageList_from_statuses(statuses) return lst except URLError: raise TwitterError("No network") def getFriendTimeline(self): try: statuses = self.api.GetFriendsTimeline() lst = utils.getMessageList_from_statuses(statuses) return lst except URLError: raise TwitterError("No Network") except HTTPError: raise AuthError("Authentication failed") def getReplies(self): try: statuses = self.api.GetReplies() lst = utils.getMessageList_from_statuses(statuses) return lst except URLError: raise TwitterError("No Network") except HTTPError: raise AuthError("Authentication failed") def getMyUpdates(self): try: statuses = self.api.GetUserTimeline() lst = utils.getMessageList_from_statuses(statuses) return lst except URLError: raise TwitterError("No Network") except HTTPError: raise AuthError("Authentication failed") def deleteStatus(self, id): try: statuses = self.api.DestroyStatus(id) return True except URLError: raise TwitterError("No Network") except HTTPError: raise AuthError("Authentication failed") def sendTweet(self,msg): try: statuses = self.api.PostUpdate(msg) return True except URLError: raise TwitterError("No Network") except HTTPError: raise AuthError("Authentication failed") def login(self,uname=None,pword=None): if not uname and not pword: self.api.ClearCredentials() self.auth = False self.userName = None self.password = None try: self.api.GetPublicTimeline() except URLError: raise TwitterError("No Network") else: self.api.SetCredentials(username=uname,password=pword) try: self.api.GetFriendsTimeline() except HTTPError: raise AuthError("Authentication failed") except URLError: raise TwitterError("No Network") self.auth = True self.userName = uname self.password = pword self.saveSettings(uname,pword) def logout(self): self.api.ClearCredentials() self.auth = False self.userName = None self.password = None self.saveSettings(None,None) def saveSettings(self,uname,pword): self.prefs["twitter_username"] = uname self.prefs["twitter_password"] = pword self.prefs.save() def loadSettings(self): try: uname = self.prefs["twitter_username"] pword = self.prefs["twitter_password"] self.login(uname,pword) except KeyError: return def getUserName(self): return self.userName def getPassWord(self): return self.password def isLogged(self): return self.auth def setSourceAsCanola(self): self.api.SetSource("canola")
class PicasaManager(Singleton): def __init__(self): Singleton.__init__(self) self.gd_client = gdata.photos.service.PhotosService() self.gd_client.email = '' self.gd_client.password = '' self.gd_client.source = 'Picasa plugin for Canola' self.logged = False self.login_error = '' self._user = '' self._password = '' self.albums ='' self.thumbs_path = '' self.outside_terra = False; #used to save the list of current downloading thumbs to avoid multiple #downloads for the same file self.thumbs_in_progress = {}; try: self.prefs = PluginPrefs("picasa") except: print "running outside canola" self.outside_terra = True; def reload_prefs(self): self.user = self.get_preference("username", "") self.password = self.get_preference("password", "") def get_preference(self, name, default=None): return self.prefs.get(name, default) def get_thumbs_path(self): if not self.thumbs_path: try: self.thumbs_path = self.prefs["thumbs_path"] except KeyError: try: download_path = PluginPrefs("settings")["download_path"] except KeyError: download_path = os.path.join(os.path.expanduser("~"), ".canola") self.thumbs_path = os.path.join(download_path, "picasa", "thumbnails") self.set_preference("thumbs_path", self.thumbs_path) if not os.path.exists(self.thumbs_path): os.makedirs(self.thumbs_path) return self.thumbs_path def set_preference(self, name, value): self.prefs[name] = value self.prefs.save() def getPassword(self): return self._password def setPassword(self, password): self._password = self.gd_client.password = password if not self.outside_terra: self.set_preference("password", password) password = property(getPassword, setPassword) def getUser(self): return self._user def setUser(self, email): self._user = self.gd_client.email = email if not self.outside_terra: self.set_preference("username", email) user = property(getUser, setUser) def login(self): if not self.outside_terra: self.reload_prefs() try: self.gd_client.ProgrammaticLogin() self.logged = True self.albums = None except gdata.service.Error, error: log.error("Could not login to Picasa, exception: %s" % error) self.login_error = error self.logged = False
class AudioScrobbler(PlayerHook): terra_type = "Hook/Player/Audio" time_cons = 240 np_time = 5 max_cached = 200 def __init__(self): PlayerHook.__init__(self) self._model = None self._timer = None self.start_time = None self._timer_paused = False self.prefs = PluginPrefs("lastfm") self.sending_submits = False self.pending_submits = Queue() def media_changed(self, model): """Function that is called everytime that the Player's Controller changes the model. """ if self._timer is not None: self._timer.delete() self._timer_paused = False log.warning("media changed to %s" % model.title) self._model = model self._length = 0 self.start_time = None def _validate_cmd(self, submit=False, length=None, name=None, album=None): dsc = bool(submit) and "submit" or "now playing" name = name or self._model.name album = album or self._model.album if length is None: length = self._length if not lastfm_manager.get_username() or \ not lastfm_manager.get_password(): log.warning("%s ignored (user or pass empty): %s - %s" % \ (dsc, name, album)) return False if not lastfm_manager.scrobble_enabled: log.warning("%s ignored (scrobble disabled): %s - %s" % \ (dsc, name, album)) return False if lastfm_manager.session_id and not lastfm_manager.post_session_id: log.warning("%s ignored (no post sessiond id): %s - %s" % \ (dsc, name, album)) return False if submit and not length: log.error("%s ignored (length not specified): %s - %s" % \ (dsc, name, album)) return False log.warning("sending %s: %s - %s" % (dsc, name, album)) return True def _now_playing(self): if self._validate_cmd() and (network and network.status > 0.0): ThreadedFunction(None, lastfm_manager.now_playing, self._model.name, self._model.artist, self._model.album, self._model.trackno, self._length).start() def _cache_submit_send(self): # create offline cache if not exists if not self.prefs.has_key('submit_cache'): self.prefs['submit_cache'] = [] # refresh offline cache from queue while self.pending_submits.qsize() > 0: if len(self.prefs['submit_cache']) >= self.max_cached: self.prefs['submit_cache'] = \ self.prefs['submit_cache'][-self.max_cached + 1:] args = self.pending_submits.get() self.prefs['submit_cache'].append(args) # save to file self.prefs.save() # nothing to do if not self.prefs['submit_cache']: return # send all cached submits for args in self.prefs['submit_cache']: if self._validate_cmd(submit=True, length=args[4], name=args[0], album=args[2]): try: lastfm_manager.submit(*args) except Exception, e: log.error("error on submit %s" % e.message) self.prefs['submit_cache'] = self.prefs['submit_cache'][1:] # save to file self.prefs.save()