Use unique albums (concat artist) to handle the album art
authorIvan Frade <ivan.frade@gmail.com>
Sat, 5 Sep 2009 08:54:03 +0000 (11:54 +0300)
committerIvan Frade <ivan.frade@gmail.com>
Sat, 5 Sep 2009 08:54:03 +0000 (11:54 +0300)
This will show only one album for compilations.

src/album_art_panel.py
src/download_dialog.py
src/mussorgsky.py
src/tracker_backend.py

index bbc338d..cf3f9ed 100644 (file)
@@ -14,17 +14,18 @@ class MussorgskyAlbumArtPanel (hildon.StackableWindow):
         self.set_border_width (12)
         self.__create_view ()
         self.downloader = None
+        # Visible string, image, artist, album
         self.model = gtk.ListStore (str, gtk.gdk.Pixbuf, str, str)
 
         for p in album_artists:
-            if (not p[1]):
+            if (not p[0]):
                 continue
-            album_art_path = getCoverArtThumbFileName (p[1])
+            album_art_path = getCoverArtThumbFileName (p[0])
             try:
                 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (album_art_path, 64, 64)
             except gobject.GError:
                 pixbuf = None
-            t = ("<b>%s</b>\n<small>%s</small>" % (escape_html(p[1]), escape_html(p[0])), pixbuf, p[0], p[1])
+            t = ("<b>%s</b>\n<small>%s</small>" % (escape_html(p[0]), escape_html(p[1])), pixbuf, p[1], p[0])
             self.model.append (t)
             
         self.treeview.set_model (self.model)
index d467799..08bbc6e 100644 (file)
@@ -58,8 +58,12 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
 
             artist = artist_albums_model.get_value (it, 2)
             album = artist_albums_model.get_value (it, 3)
-            
-            self.current_label.set_markup ("<small>Trying: %s - %s</small>" % (escape_html(artist),
+
+            if (artist.find ('|') != -1):
+                real_artist = "Various artists"
+            else:
+                real_artist = artist
+            self.current_label.set_markup ("<small>Trying: %s - %s</small>" % (escape_html(real_artist),
                                                                                    escape_html(album)))
             
             try:
@@ -69,7 +73,7 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
                 if (self.cancel):
                     break
                 
-                (image, thumb) = self.downloader.get_album_art (artist, album)
+                (image, thumb) = self.downloader.get_album_art (real_artist, album)
                 if thumb:
                         pixbuf = gtk.gdk.pixbuf_new_from_file_at_size (thumb, 64, 64)
                         artist_albums_model.set_value (it, 1, pixbuf)
@@ -79,7 +83,7 @@ class MussorgskyAlbumArtDownloadDialog (gtk.Dialog):
                 thumb = None
             
             self.set_title ("Downloading album art (%d/%d)" % (current, TOTAL))
-            self.previous_label.set_markup ("<b>%s - %s</b>" % (escape_html(artist), escape_html(album)))
+            self.previous_label.set_markup ("<b>%s - %s</b>" % (escape_html(real_artist), escape_html(album)))
               
             if (thumb):
                 self.album_art.set_from_file (thumb)
index 22275ff..ec29a66 100755 (executable)
@@ -50,8 +50,8 @@ class MussorgskyMainWindow (hildon.StackableWindow):
         self.show_edit_panel (list_songs, list_albums, list_artists)
 
     def album_art_clicked (self, widget):
-        artists_albums = self.tracker.get_all_pairs_artist_album ()
-        panel = MussorgskyAlbumArtPanel (artists_albums)
+        album_artists = self.tracker.get_all_pairs_album_artist ()
+        panel = MussorgskyAlbumArtPanel (album_artists)
         panel.show_all ()
 
     def create_main_view (self):
index 78c8f65..23fa0b4 100755 (executable)
@@ -70,7 +70,7 @@ class TrackerBackend:
                                             "Audio:Album",
                                             "File:Mime"],
                                            "", [], rdf_query, False,
-                                           ["Audio:DateAdded"], False, 0, 32000)
+                                           ["Audio:DateAdded"], True, 0, 32000)
         return results
 
     def get_all_broken_songs (self):
@@ -94,30 +94,43 @@ class TrackerBackend:
                                                     ["Audio:Artist"],
                                                     "", False, 0, 32000)
 
-    def get_all_pairs_artist_album (self):
-        return self.iface_metadata.GetUniqueValues ("Music",
-                                                    ["Audio:Artist", "Audio:Album"],
-                                                    "", False, 0, 32000)
+    def get_all_pairs_album_artist (self):
+        return self.iface_metadata.GetUniqueValuesWithAggregates ("Music",
+                                                                  ["Audio:Album"],
+                                                                  "",
+                                                                  ["CONCAT"],
+                                                                  ["Audio:Artist"],
+                                                                  False, 0, 32000)
 
 # Test
 if __name__ == "__main__":
 
-    tracker = TrackerBackend ()
+    import sys
+    from optparse import OptionParser
+
+    parser = OptionParser()
+    parser.add_option ("-n", "--numbers", dest="print_numbers",
+                       action="store_true", default=True,
+                       help="Print stats about broken files")
+    
+    parser.add_option ("-p", "--pairs", dest="pairs_artist_album",
+                       action="store_true", default=True,
+                       help="Print all pairs (album, artist)")
 
-    print "Songs without artist: " + str(tracker.count_songs_wo_artist ())
+    (options, args) = parser.parse_args ()
 
-    results = tracker.get_songs_without_artist ()
-    for r in results:
-        print "'%s', '%s', '%s', '%s', '%s'" % (r[0], r[2], r[3], r[4], r[5])
+    if (not options.print_numbers and not options.pairs_artist_album):
+        parser.print_help ()
+        sys.exit (-1)
 
-    
-    print "Songs without album " + str(tracker.count_songs_wo_album ())
-    print "Songs without title " + str(tracker.count_songs_wo_title ())
+    tracker = TrackerBackend ()
+    if (options.print_numbers):
+        print tracker.count_songs_wo_artist (), "Songs without artist"
+        print tracker.count_songs_wo_title (), "Songs without title"
+        print tracker.count_songs_wo_album (), "Songs without album"
+
+    if (options.pairs_artist_album):
+        for (album, artist) in tracker.get_all_pairs_artist_album ():
+            print album,"-",artist
 
-    albums = tracker.get_list_of_known_albums ()
-    print "%d different albums" % (len (albums))
-    for a in albums:
-        print a[0]
     
-    print "\nAll songs:"
-    print tracker.get_all_songs ()