Example #1
0
 def h_ptrack(self, _source, _ukey, track):
     """
     For each 'mb_track' received, try to find a corresponding
     rb db entry and issue a "track_entry" message.
     
     This should help 'Updater' to do its job.
     """
     artist_name=track.details["artist_name"]
     track_name=track.details["track_name"]
     
     #print "meta_track: %s" % track
     
     s1=(rhythmdb.QUERY_PROP_LIKE, rhythmdb.PROP_ARTIST, str(artist_name))
     s2=(rhythmdb.QUERY_PROP_LIKE, rhythmdb.PROP_TITLE,  str(track_name))
     query = self.db.query_new()
     self.db.query_append(query, s1)
     self.db.query_append(query, s2)
     query_model = self.db.query_model_new_empty() 
     self.db.do_full_query_parsed(query_model, query)
     
     dbe=None
     id=None
     for e in query_model:
         dbe=e[0]
         id=self.db.entry_get(dbe, rhythmdb.PROP_ENTRY_ID)
         #print "++ FOUND: artist(%s) track(%s)" % (artist_name, track_name)            
         break  ## not elegant but it works
         
     #if dbe is None:
     #    print "-- NOT FOUND: artist(%s) track(%s)" % (artist_name, track_name)
         
     te=TrackEntryWrapper(track, dbe)
     Bus.publish(self.__class__, "track_entry", te, artist_name, track_name, id)
Example #2
0
    def sRecordsLatest(self, records):
        """
        Signal Receptor - Records
        
        Fields in each 'record':
         - "id"
         - "created"
         - "updated"
         - "playcount"
         - "track_name"
         - "track_mbid"
         - "artist_name"
         - "artist_mbid"
         - "album_name"
         - "album_mbid"      
        """
      
        for record in records:
            entry={}

            keys=record.keys()
            for key in keys:
                entry[str(key)]=record[str(key)]

            #print "entry: artist(%s) track(%s) playcount(%s)" % (entry["artist_name"], entry["track_name"], entry["playcount"])
            track=Track(entry)
            Bus.publish(self.__class__, "track", track)

        Bus.publish(self.__class__, "lastfm_proxy_detected", True)
Example #3
0
 def _check(self):
     now=time.time()
     delta=now-self.last_libwalk
     start=delta>self.WALKING_TIMEOUT
     if start:
         print "* enabling lib-walking"
         self.enable=True
         
     Bus.publish(self.__class__, "libwalker_start", start)
Example #4
0
    def __init__(self):
        self.freq = 0

        self.tcount = 0
        self.scount = 0
        self.mcount = 0
        self.hcount = 0
        self.dcount = 0

        Bus.subscribe(self.__class__, "tick", self.h_tick)
        Bus.subscribe(self.__class__, "tick_params", self.h_tick_params)
Example #5
0
        def __init__(self):

            Bus.subscribe(self.__class__, "state?", self.hq_state)
            Bus.subscribe(self.__class__, "state", self.h_state)

            Bus.subscribe(self.__class__, "last_libwalk?", self.hq_last_libwalk)
            Bus.subscribe(self.__class__, "libwalker_done", self.h_libwalker_done)

            self.sm = StateManager()
Example #6
0
    def h_msg(self, mtype, *pa):
        
        #if mtype!="tick":
        #    print "to mswitch: mtype(%s) pa:%s" % (mtype, pa)
        mswitch.publish("__bridge__", mtype, *pa)

        if mtype=="tick":
            while True:
                try:   msg=self.iq.get(block=False)
                except Empty:
                    break
                
                (mtype, payload) = msg
                orig, pargs = payload
    
                if orig!="__bridge__":
                    #if mtype != "tick":
                    #    print "!! from mswitch: orig(%s) mtype(%s) pargs(%s)" % (orig, mtype, pargs)
                    Bus.publish("__bridge__", mtype, *pargs)
Example #7
0
    def h_tick(self, count):
        """
        'tick' timebase handler
        """
        if not self.enable:
            return
        
        ## not much we can do with Musicbrainz Proxy
        if not self.mb_detected:
            return
        
        self._doIntegration(count)
        
        
        l=len(self.song_entries)
        
        ## nothing more todo!
        if l==0:
            now=time.time()            
            Bus.publish(self.__class__, "libwalker_done", now)
            self.enable=False
            return
        
        ## not the time to issue requests
        if (count % self.freq)!=0:
            return
            
        jobs_todo=self.JOBS_PARAMS[self.mode]
        #print "jobs_todo(%s)" % jobs_todo

        while jobs_todo:
            self.jobs += 1
            jobs_todo -= 1
            try:    id=self.song_entries.pop(0)
            except: id=None
            if id is None:
                break
            track=self.getTrackByDbId(id)
            
            key="%s=%s" % (self.CACHE_ID_STRING, id)
            Bus.publish(self.__class__, "track", track, False, key, "low")
Example #8
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)
Example #9
0
    def h_tick(self, *_):
        self.tcount += 1
        if self.tcount == self.freq:
            self.tcount = 0
            self.scount += 1
            Bus.publish(self.__class__, "timer_second", self.scount)

        if self.scount == 60:
            self.scount = 0
            self.mcount += 1
            Bus.publish(self.__class__, "timer_minute", self.mcount)

        if self.mcount == 60:
            self.mcount = 0
            self.hcount += 1
            Bus.publish(self.__class__, "timer_hour", self.hcount)

        if self.hcount == 24:
            self.hcount = 0
            self.dcount += 1
            Bus.publish(self.__class__, "timer_day", self.dcount)
Example #10
0
 def __init__(self):
     self.iq=Queue()
     Bus.subscribe("__bridge__", "*", self.h_msg)
Example #11
0
 def __init__(self):
     self.freq=0
     self.count=0
     self.db=None
     self.mb_detected=False
     self.song_entries=[]
     
     self.last_libwalk=0
     self.enable=False
     
     ## Integration
     self.icount=0
     self.mode = self.MODE_LOW
     
     ## stats
     self.jobs=0
     self.hits=0
     self.responses=0
     
     Bus.subscribe(self.__class__, "tick",          self.h_tick)
     Bus.subscribe(self.__class__, "tick_params",   self.h_tick_params)
     Bus.subscribe(self.__class__, "last_libwalk",  self.h_last_libwalk)
     Bus.subscribe(self.__class__, "rb_shell",      self.h_rb_shell)
     Bus.subscribe(self.__class__, "mb_track",      self.h_mb_track)
     Bus.subscribe(self.__class__, "entry_added",   self.h_entry_added)
     Bus.subscribe(self.__class__, "song_entries",  self.h_song_entries)
     Bus.subscribe(self.__class__, "musicbrainz_proxy_detected", self.h_musicbrainz_proxy_detected)
Example #12
0
 def hq_state(self, key):
     value = self.sm.retrieve(key)
     Bus.publish(self.__class__, "state", key, value)
Example #13
0
 def h_timer_hour(self):
     Bus.publish(self.__class__, "last_libwalk?")
     self._check()
Example #14
0
 def _announceChanges(self):
     Bus.publish("User", "lastfm_username_changed", self._username)
     Bus.publish("User", "lastfm_password_changed", self._password)
Example #15
0
 def __init__(self, username=None, password=None):
     self._username=username
     self._password=password
     
     Bus.subscribe("User", "config?", self.hq_config)
Example #16
0
 def hq_last_libwalk(self, *_):
     value = self.sm.retrieve("last_libwalk")
     Bus.publish(self.__class__, "last_libwalk", value)
Example #17
0
    def __init__(self): 
        self.db=None

        Bus.subscribe(self.__class__, "ptrack",       self.h_ptrack)
        Bus.subscribe(self.__class__, "rb_shell",     self.on_rb_shell)