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)
Exemple #2
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)
Exemple #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)
Exemple #4
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)
Exemple #5
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")
Exemple #6
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)
Exemple #7
0
 def h_timer_hour(self):
     Bus.publish(self.__class__, "last_libwalk?")
     self._check()
Exemple #8
0
 def _announceChanges(self):
     Bus.publish("User", "lastfm_username_changed", self._username)
     Bus.publish("User", "lastfm_password_changed", self._password)
Exemple #9
0
 def hq_state(self, key):
     value = self.sm.retrieve(key)
     Bus.publish(self.__class__, "state", key, value)
Exemple #10
0
 def hq_last_libwalk(self, *_):
     value = self.sm.retrieve("last_libwalk")
     Bus.publish(self.__class__, "last_libwalk", value)