~markjtully/unity-music-lens/music-store

« back to all changes in this revision

Viewing changes to unity-music-daemon.py

  • Committer: Mark Tully
  • Date: 2011-05-04 19:49:36 UTC
  • Revision ID: markjtully@gmail.com-20110504194936-cwx8ybje6qgqkwgp
Attempt to fix album art not appearing by querying the track list grabbed from Banshee at startup rather than trying to figure it out for ourselves. (bug 776750)

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
                # Break open the safe
124
124
                c = conn.cursor()
125
125
                # Go through the safe and grab track names, their uris, the artist name, the album title and the track's mimetypes
126
 
                rows = c.execute('''SELECT coretracks.Title, coretracks.Uri, coreartists.Name, corealbums.Title, coretracks.MimeType
 
126
                rows = c.execute('''SELECT coretracks.Title, coretracks.Uri, coreartists.Name, corealbums.Title, coretracks.MimeType, corealbums.ArtistName
127
127
                                                        FROM coretracks, corealbums, coreartists
128
128
                                                        WHERE coretracks.artistID = coreartists.artistID 
129
129
                                                                AND coretracks.albumID = corealbums.albumID 
251
251
                        album = ""    if track[2] is None else track[2]
252
252
                        artist = ""   if track[3] is None else track[3]
253
253
                        mimetype = "" if track[4] is None else track[4]
254
 
                        
 
254
                        itemtype = "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Audio"
255
255
                        trackname = title + " - " + album + " - " + artist
256
256
                        if not trackname.lower().find(search.lower()) == -1:
257
257
                                if self.i < MAX:
258
 
                                        self.addToModel(trackname, uri, mimetype, group, model)
 
258
                                        self.addToModel(trackname, uri, mimetype, itemtype, group, model)
259
259
                                      
260
260
        def findEventsFromZeitgeist(self, event_template, time, total, sort, group, search, model):
261
261
                try:
269
269
                if sort == "mostpopular": resultType = datamodel.ResultType.MostPopularSubjects
270
270
                if sort == "all": resultType = datamodel.ResultType.LeastPopularSubjects
271
271
                self.i = 0
272
 
                #Search Zeitgeist for audio events
 
272
                #Search Zeitgeist for events
273
273
                events = iface.FindEvents(
274
274
                                time,
275
275
                                [event_template, ],
284
284
                                trackname = subject.text
285
285
                                uri = subject.uri
286
286
                                mimetype = subject.mimetype
 
287
                                itemtype = subject.interpretation
287
288
                                if not trackname.lower().find(search.lower()) == -1:
288
289
                                        if self.i < MAX:
289
 
                                                self.addToModel(trackname, uri, mimetype, group, model)
 
290
                                                self.addToModel(trackname, uri, mimetype, itemtype, group, model)
290
291
 
291
 
        def addToModel(self, trackname, uri, mimetype, group, model):
292
 
                #Try and find album art, or use a generic music icon if we can't
293
 
                if trackname.find(" - ") == -1:
294
 
                        track = trackname
295
 
                        artist = ""
296
 
                        album = ""
 
292
        def addToModel(self, trackname, uri, mimetype, itemtype, group, model):
 
293
                albumart = Gio.ThemedIcon.new ("file").to_string()
 
294
                artdir = os.getenv("HOME") + "/.cache/media-art/album-"
 
295
                artist = ""
 
296
                album = ""
 
297
                tracktitle = trackname
 
298
                if itemtype == "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Audio":
 
299
                        # Look up the uri in the banshee list
 
300
                        for track in self.tracks:
 
301
                                if track[1] == uri:
 
302
                                        tracktitle = track[0]
 
303
                                        artist = track[2]
 
304
                                        album = track[3]
 
305
                                        hashname = track[5] + "\t" + track[3]
 
306
                                        hashname = unicodedata.normalize("NFKD", hashname)
 
307
                                        md5album = hashlib.md5()
 
308
                                        try:
 
309
                                                md5album.update(hashname)
 
310
                                                value = md5album.hexdigest()
 
311
                                        except:
 
312
                                                value = ""
 
313
                                        albumart = artdir + value + ".jpg"
 
314
                else:
297
315
                        albumart = uri
298
 
                else:
299
 
                        index = trackname.split(" - ")
300
 
                        track = index[0]
301
 
                        artist = index[1]
302
 
                        album = index[2]
303
 
                        artdir = os.getenv("HOME") + "/.cache/media-art/album-"
304
 
                        hashname = index[1] + "\t" + index[2]
305
 
                        hashname = unicodedata.normalize("NFKD", hashname)
306
 
                        md5album = hashlib.md5()
307
 
                        try:
308
 
                                md5album.update(hashname)
309
 
                                value = md5album.hexdigest()
310
 
                        except:
311
 
                                value = ""
312
 
        
313
 
                        albumart = artdir + value + ".jpg"
314
 
                        if not os.path.isfile(albumart):
315
 
                                #There's a good chance the album might be by 'Various Artists', so we'll try that
316
 
                                hashname = "Various Artists\t" + index[2]
317
 
                                hashname = unicodedata.normalize("NFKD", hashname)
318
 
                                md5album = hashlib.md5()
319
 
                                try:
320
 
                                        md5album.update(hashname)
321
 
                                        value = md5album.hexdigest()
322
 
                                except:
323
 
                                        value = ""
324
 
                                albumart = artdir + value + ".jpg"
325
 
 
326
 
                                if not os.path.isfile(albumart):
327
 
                                        albumart = uri
328
 
                
 
316
                                
329
317
                model.append (uri,                              # uri
330
318
                                  albumart,                             # string formatted GIcon
331
319
                      group,                            # numeric group id
332
320
                      mimetype,                         # mimetype
333
 
                      track,                            # display name
 
321
                      tracktitle,                               # display name
334
322
                      artist + "\n" + album)# comment
335
323
                      
336
324
            # Increment the number of results which have displayed, so we know when to stop showing more