[gnome-music/wip/jfelder/musicbrainz-tageditordialog: 8/10] utils: Handle more tags
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/musicbrainz-tageditordialog: 8/10] utils: Handle more tags
- Date: Thu, 1 Nov 2018 10:24:48 +0000 (UTC)
commit 195b121e3cdb4587b59a9c55f38e5076cb7140ab
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 a1701fae..232d323c 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -279,7 +279,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:
@@ -315,7 +315,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 c924b670..190879b7 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 2aa59fde..36220847 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 75bcaaa7..f936f8c0 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]