Esempio n. 1
0
    def __init__(self): 
        gobject.GObject.__init__(self) #@UndefinedVariable

        self._path=os.path.expanduser(self.PATH)
        self.conn=sqlite3.connect(self._path, check_same_thread=False)
        self.c = self.conn.cursor()
        
        self.c.execute("""create table if not exists tracks (id integer primary key,
                            created integer,
                            updated integer,
                            track_name text,  track_mbid text,
                            artist_name text)
                        """)

        Bus.add_emission_hook("track",    self.h_track)
        Bus.add_emission_hook("mb_track", self.h_mb_track)
Esempio n. 2
0
 def h_track(self, _, track):
     """
     Based on on 'track' object, we need to find all
     'meta_tracks' entries in the database.  We do
     this by looking up the 'track' in the database
     in order to retrieve the the 'track_mbid'. With this
     information, we can now fetch all the 'meta tracks'
     that have the same 'track_mbid'.
     
     Be sure to 'merge' the fields from the original 'track'
     object when issuing the resulting 'meta_track' message.
     """
     artist_name=track.details["artist_name"]
     track_name =track.details["track_name"]
     otrack=self._findTrack(artist_name, track_name)
     
     ## Did we find a record at all?
     if len(otrack) == 0:
         return True
     
     track_mbid=otrack.get("track_mbid", "")
     
     ## We can't go very far if we don't have a 'pivot'
     ##  track_mbid to work with...
     if track_mbid == "":
         return True
     
     ## Try and find corresponding 'meta_track' information
     ##  based on the source 'track_mbid'.
     ## Issue all 'meta_track' in messages as to help other
     ##  agents (e.g. Finder).
     mtracks=self._findWithTrackMbid(track_mbid)
     if mtracks is None:
         return True
     
     for mtrack_tuple in mtracks:
         rtrack=makeTrackDict(mtrack_tuple)
         r2track=mergeTrackObjects(rtrack, track.details)
         
         ## pain... need to convert to be compatible with gobject...
         ## I wish I would have bypassed gobject at the beginning...
         gtrack=Track(r2track, lastfm_info=track.lastfm_info)
         Bus.emit("meta_track", gtrack)
     
     return True