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
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:
258
self.addToModel(trackname, uri, mimetype, group, model)
258
self.addToModel(trackname, uri, mimetype, itemtype, group, model)
260
260
def findEventsFromZeitgeist(self, event_template, time, total, sort, group, search, model):
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:
289
self.addToModel(trackname, uri, mimetype, group, model)
290
self.addToModel(trackname, uri, mimetype, itemtype, group, model)
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:
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-"
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:
302
tracktitle = track[0]
305
hashname = track[5] + "\t" + track[3]
306
hashname = unicodedata.normalize("NFKD", hashname)
307
md5album = hashlib.md5()
309
md5album.update(hashname)
310
value = md5album.hexdigest()
313
albumart = artdir + value + ".jpg"
299
index = trackname.split(" - ")
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()
308
md5album.update(hashname)
309
value = md5album.hexdigest()
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()
320
md5album.update(hashname)
321
value = md5album.hexdigest()
324
albumart = artdir + value + ".jpg"
326
if not os.path.isfile(albumart):
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
336
324
# Increment the number of results which have displayed, so we know when to stop showing more