[gnome-music/wip/jfelder/musicbrainz-tageditordialog: 52/54] utils: Handle more tags



commit ab5ca0fb83cf4e5b8c476160a9ca094a779aaf53
Author: Jean Felder <jfelder src gnome org>
Date:   Tue Aug 21 00:24:40 2018 +0200

    utils: Handle more tags
    
    Add utils functions to retrieve album_disc_number, composer_name,
    genre and track number.

 gnomemusic/mpris.py                     |  4 +--
 gnomemusic/utils.py                     | 50 +++++++++++++++++++++++++++++++++
 gnomemusic/widgets/albumwidget.py       |  4 +--
 gnomemusic/widgets/artistalbumwidget.py |  2 +-
 gnomemusic/widgets/songwidget.py        |  2 +-
 5 files changed, 56 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index f94f5558..f654eb43 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -281,7 +281,7 @@ class MediaPlayer2Service(Server):
             pass
 
         try:
-            trackNumber = media.get_track_number()
+            trackNumber = utils.get_media_track_nr(media)
             assert trackNumber is not None
             metadata['xesam:trackNumber'] = GLib.Variant('i', trackNumber)
         except:
@@ -317,7 +317,7 @@ class MediaPlayer2Service(Server):
         metadata['xesam:albumArtist'] = GLib.Variant('as', [artist])
 
         try:
-            genre = media.get_genre()
+            genre = utils.get_media_genre(media)
             assert genre is not None
             metadata['xesam:genre'] = GLib.Variant('as', genre)
         except:
diff --git a/gnomemusic/utils.py b/gnomemusic/utils.py
index ec171663..c54d1f48 100644
--- a/gnomemusic/utils.py
+++ b/gnomemusic/utils.py
@@ -56,6 +56,19 @@ def get_album_title(item):
     return album
 
 
+def get_album_disc_nr(item):
+    """Returns the album song number associated with the media item
+
+    :param Grl.Media item: song
+    :return: The album title
+    :rtype: string
+    """
+    track_number = item.get_album_disc_number()
+    if track_number == 0:
+        track_number = ""
+    return str(track_number)
+
+
 def get_artist_name(item):
     """Returns the preferred artist for a media item.
 
@@ -75,6 +88,43 @@ def get_artist_name(item):
             or _("Unknown Artist"))
 
 
+def get_composer_name(item):
+    """Returns the composer for a media item.
+
+    :param Grl.Media item: song
+    :return: The artist name
+    :rtype: string
+    """
+
+    return (item.get_composer()
+            or None)
+
+
+def get_media_genre(item):
+    """Returns the title of the media item.
+
+    :param item: A Grilo Media object
+    :return: The title
+    :rtype:
+    """
+
+    return (item.get_genre()
+            or None)
+
+
+def get_media_track_nr(item):
+    """Returns the title of the media item.
+
+    :param item: A Grilo Media object
+    :return: The title
+    :rtype:
+    """
+    track_number = item.get_track_number()
+    if track_number == 0:
+        return ""
+    return str(track_number)
+
+
 def get_media_title(item):
     """Returns the title of the media item.
 
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index ecdc2c93..828ba990 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -149,7 +149,7 @@ class AlbumWidget(Gtk.EventBox):
 
     @log
     def _set_composer_label(self, album):
-        composer = album.get_composer()
+        composer = utils.get_composer(album)
         show = False
 
         if composer:
@@ -217,7 +217,7 @@ class AlbumWidget(Gtk.EventBox):
         if remaining == 0:
             discs = {}
             for song in self._songs:
-                disc_nr = song.get_album_disc_number()
+                disc_nr = utils.get_album_disc_nr(song)
                 if disc_nr not in discs.keys():
                     discs[disc_nr] = [song]
                 else:
diff --git a/gnomemusic/widgets/artistalbumwidget.py b/gnomemusic/widgets/artistalbumwidget.py
index 8d8fda88..621aef3d 100644
--- a/gnomemusic/widgets/artistalbumwidget.py
+++ b/gnomemusic/widgets/artistalbumwidget.py
@@ -117,7 +117,7 @@ class ArtistAlbumWidget(Gtk.Box):
 
         discs = {}
         for song in self._songs:
-            disc_nr = song.get_album_disc_number()
+            disc_nr = utils.get_album_disc_nr(song)
             if disc_nr not in discs.keys():
                 discs[disc_nr] = [song]
             else:
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 4322f8a8..52ec6386 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -88,7 +88,7 @@ class SongWidget(Gtk.EventBox):
         self._selection_mode = False
         self._state = SongWidget.State.UNPLAYED
 
-        song_number = media.get_track_number()
+        song_number = utils.get_media_track_nr(media)
         if song_number == 0:
             song_number = ""
         self._number_label.set_text(str(song_number))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]