Example #1
0
class Updater(object): #@UndefinedVariable
    """
    Updates various properties
    """
    def __init__(self):
        self._shell=None
        self._db=None
        self.recentlyUpdated=BoundedList(64)
        
        Bus.subscribe(self.__class__, "track_entry",     self.on_track_entry)
        Bus.subscribe(self.__class__, "user_track_info", self.on_user_track_info)
        Bus.subscribe(self.__class__, "rb_shell",        self.on_rb_shell)
        
    def on_rb_shell(self, shell, db, _sp):
        """
        Grab RB objects references (shell, db, player)
        """
        self._shell=shell
        self._db=db
        
    def on_track_entry(self, trackWrapper, artist_name, track_name, dbid):
        """
        Note: track_entry is defined in "Finder"
        """
        if dbid in self.recentlyUpdated:
            print ">>> recently updated: a(%s) t(%s)" % (artist_name, track_name)
            return
        
        track=trackWrapper.track
        dbe=trackWrapper.db_entry
        
        #print "te.details: %s" % te.details
        
        ## If Finder didn't find an entry in the database,
        ## we can't do much at this point
        if dbe is None:
            return
               
        try: playcount=track.details["playcount"]
        except:
            #print "** Playcount not found"
            return
        
        #print "updating: artist(%s) track(%s) playcount(%s)" % (artist_name, track_name, playcount)
        
        try:
            self._db.set(dbe, rhythmdb.PROP_PLAY_COUNT, playcount)
            self._db.commit()
            self.recentlyUpdated.push(dbid)
        except Exception,e:
            print "ERROR: updating 'playcount' for track: %s" % e
        
        Bus.publish(self.__class__, "track_updated", track, artist_name, track_name)
Example #2
0
 def __init__(self):
     self._shell=None
     self._db=None
     self.recentlyUpdated=BoundedList(64)
     
     Bus.subscribe(self.__class__, "track_entry",     self.on_track_entry)
     Bus.subscribe(self.__class__, "user_track_info", self.on_user_track_info)
     Bus.subscribe(self.__class__, "rb_shell",        self.on_rb_shell)