Commit 17de0840 authored by Marinus Schraal's avatar Marinus Schraal

Use album-artist if available

Album songs can be tagged with an album-artist tag, which indicates the
main artist of an album. Individual songs on an album can have a
different artist tag: the performer(s) on that track. Using album-artist
for display or sorting is preferrable in most cases.

https://bugzilla.gnome.org/show_bug.cgi?id=754700
parent 11e59404
......@@ -46,13 +46,17 @@ class Grilo(GObject.GObject):
}
METADATA_KEYS = [
Grl.METADATA_KEY_ID, Grl.METADATA_KEY_TITLE,
Grl.METADATA_KEY_ARTIST, Grl.METADATA_KEY_ALBUM,
Grl.METADATA_KEY_DURATION,
Grl.METADATA_KEY_ALBUM,
Grl.METADATA_KEY_ALBUM_ARTIST,
Grl.METADATA_KEY_ARTIST,
Grl.METADATA_KEY_CREATION_DATE,
Grl.METADATA_KEY_URL,
Grl.METADATA_KEY_DURATION,
Grl.METADATA_KEY_ID,
Grl.METADATA_KEY_LYRICS,
Grl.METADATA_KEY_THUMBNAIL]
Grl.METADATA_KEY_THUMBNAIL,
Grl.METADATA_KEY_TITLE,
Grl.METADATA_KEY_URL
]
METADATA_THUMBNAIL_KEYS = [
Grl.METADATA_KEY_ID,
......
......@@ -27,6 +27,7 @@ from gnomemusic.player import PlaybackStatus, RepeatType
from gnomemusic.albumArtCache import AlbumArtCache
from gnomemusic.grilo import grilo
from gnomemusic.playlists import Playlists
import gnomemusic.utils as utils
from gettext import gettext as _
from gi.repository import GLib
......@@ -315,22 +316,9 @@ class MediaPlayer2Service(Server):
finally:
metadata['xesam:album'] = GLib.Variant('s', album)
try:
artist = media.get_artist()
assert artist is not None
except:
try:
artist = media.get_artist()
assert artist is not None
except:
try:
artist = media.get_artist()
assert artist is not None
except (AssertionError, ValueError):
artist = _("Unknown Artist")
finally:
metadata['xesam:artist'] = GLib.Variant('as', [artist])
metadata['xesam:albumArtist'] = GLib.Variant('as', [artist])
artist = utils.get_artist_name(media)
metadata['xesam:artist'] = GLib.Variant('as', [artist])
metadata['xesam:albumArtist'] = GLib.Variant('as', [artist])
try:
genre = media.get_genre()
......
......@@ -44,6 +44,7 @@ from random import randint
from collections import deque
from gnomemusic.albumArtCache import AlbumArtCache
from gnomemusic.playlists import Playlists
import gnomemusic.utils as utils
playlists = Playlists.get_default()
from hashlib import md5
......@@ -595,15 +596,9 @@ class Player(GObject.GObject):
self.playBtn.set_sensitive(True)
self._sync_prev_next()
artist = _("Unknown Artist")
try:
assert media.get_artist() is not None
artist = media.get_artist()
except:
pass
finally:
self.artistLabel.set_label(artist)
self._currentArtist = artist
artist = utils.get_artist_name(media)
self.artistLabel.set_label(artist)
self._currentArtist = artist
album = _("Unknown Album")
try:
......
......@@ -122,7 +122,8 @@ class Query():
SELECT
rdf:type(?album)
tracker:id(?album) AS ?id
nmm:artistName(?albumArtist) AS ?artist
nmm:artistName(?albumArtist) AS ?album_artist
nmm:artistName(?performer) AS ?artist
?title
COUNT(?song) AS ?childcount
YEAR(MAX(nie:contentCreated(?song))) AS ?creation_date
......@@ -156,7 +157,8 @@ class Query():
SELECT
rdf:type(?album)
tracker:id(?album) AS ?id
?artist
nmm:artistName(?performer) AS ?artist
nmm:artistName(?albumArtist) AS ?album_artist
?title
COUNT(?song) AS ?childcount
YEAR(MAX(nie:contentCreated(?song))) AS ?creation_date
......@@ -165,14 +167,12 @@ class Query():
?album a nmm:MusicAlbum ;
nmm:albumArtist ?albumArtist ;
nie:title ?title .
?albumArtist nmm:artistName ?artist .
?song nmm:musicAlbum ?album ;
nmm:performer ?performer .
BIND(LCASE(?artist) AS ?artist_lower) .
BIND(LCASE(nmm:artistName(?albumArtist)) AS ?artist_lower) .
BIND(LCASE(?title) AS ?title_lower) .
BIND((%(artist_order)s) AS ?artist_collation) .
BIND((%(album_order)s) AS ?title_collation) .
FILTER(STRSTARTS(nie:url(?song), '%(music_dir)s/'))
}
GROUP BY ?album
......@@ -194,10 +194,10 @@ class Query():
tracker:id (?song) AS ?id
?url
nie:title(?song) AS ?title
nmm:artistName (nmm:performer(?song)) AS ?artist
nie:title (nmm:musicAlbum (?song)) AS ?album
nfo:duration (?song) AS ?duration
IF (BOUND (?tag), 'b', '') AS ?lyrics
nmm:artistName(nmm:performer(?song)) AS ?artist
nie:title(nmm:musicAlbum(?song)) AS ?album
nfo:duration(?song) AS ?duration
IF (BOUND(?tag), 'b', '') AS ?lyrics
{
%(where_clause)s
?song a nmm:MusicPiece ;
......@@ -209,7 +209,7 @@ class Query():
nie:title ?title .
OPTIONAL { ?song nao:hasTag ?tag .
FILTER (?tag = nao:predefined-tag-favorite) } .
FILTER (STRSTARTS (?url, '%(music_dir)s/'))
FILTER(STRSTARTS(?url, '%(music_dir)s/'))
}
ORDER BY ?artist ?album nmm:setNumber(?disc) nmm:trackNumber(?song)
'''.replace('\n', ' ').strip() % {
......@@ -330,12 +330,12 @@ class Query():
tracker:id(?album) AS ?id
(
SELECT
nmm:artistName(?artist)
nmm:artistName(?album_artist)
WHERE {
?album nmm:albumArtist ?artist
?album nmm:albumArtist ?album_artist
}
LIMIT 1
) AS ?artist
) AS ?album_artist
nie:title(?album) AS ?title
nie:title(?album) AS ?album
WHERE {
......@@ -358,12 +358,12 @@ class Query():
tracker:id(?album) AS ?id
(
SELECT
nmm:artistName(?artist)
nmm:artistName(?album_artist)
WHERE {
?album nmm:albumArtist ?artist
?album nmm:albumArtist ?album_artist
}
LIMIT 1
) AS ?artist
) AS ?album_artist
nie:title(?album) AS ?title
nie:title(?album) AS ?album
WHERE {
......
# Copyright (c) 2016 Marinus Schraal <mschraal@src.gnome.org>
#
# GNOME Music is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# GNOME Music is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with GNOME Music; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# The GNOME Music authors hereby grant permission for non-GPL compatible
# GStreamer plugins to be used and distributed together with GStreamer
# and GNOME Music. This permission is above and beyond the permissions
# granted by the GPL license by which GNOME Music is covered. If you
# modify this code, you may extend this exception to your version of the
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
from gettext import gettext as _
def get_artist_name(item):
"""Returns the preferred artist for a media item.
The artist name for a particular media item can be either
the main artist of the full album (album artist), the
artist of the song (artist) or possibly it is not known at
all. The first is preferred in most cases, because it is
the most accurate in an album setting.
:param item: A Grilo Media object
:return: The artist name
:rtype: string
"""
return (item.get_album_artist()
or item.get_artist()
or _("Unknown Artist"))
......@@ -47,6 +47,7 @@ from gnomemusic.toolbar import ToolbarState
import gnomemusic.widgets as Widgets
from gnomemusic.player import DiscoveryStatus
from gnomemusic.playlists import Playlists, StaticPlaylists
import gnomemusic.utils as utils
from gnomemusic.albumArtCache import AlbumArtCache as albumArtCache
from gnomemusic import log
import logging
......@@ -214,7 +215,7 @@ class ViewContainer(Gtk.Stack):
return
self._offset += 1
artist = item.get_artist() or _("Unknown Artist")
artist = utils.get_artist_name(item)
title = albumArtCache.get_media_title(item)
# item.set_title(title)
......@@ -472,7 +473,7 @@ class Songs(ViewContainer):
return
self._offset += 1
item.set_title(albumArtCache.get_media_title(item))
artist = item.get_artist() or _("Unknown Artist")
artist = utils.get_artist_name(item)
if item.get_url() is None:
return
self.model.insert_with_valuesv(
......@@ -724,7 +725,7 @@ class Artists (ViewContainer):
self.view.show()
return
self._offset += 1
artist = item.get_artist() or _("Unknown Artist")
artist = utils.get_artist_name(item)
if not artist.casefold() in self._artists:
_iter = self.model.insert_with_valuesv(-1, [2], [artist])
self._artists[artist.casefold()] = {'iter': _iter, 'albums': [], 'widget': None}
......@@ -1445,7 +1446,7 @@ class Search(ViewContainer):
if data != self.model:
return
artist = item.get_artist() or _("Unknown Artist")
artist = utils.get_artist_name(item)
album = item.get_album() or _("Unknown Album")
key = '%s-%s' % (artist, album)
......@@ -1494,7 +1495,7 @@ class Search(ViewContainer):
self._offset += 1
title = albumArtCache.get_media_title(item)
item.set_title(title)
artist = item.get_artist() or _("Unknown Artist")
artist = utils.get_artist_name(item)
group = 3
try:
......
......@@ -37,6 +37,7 @@ from gnomemusic.grilo import grilo
from gnomemusic.albumArtCache import AlbumArtCache
from gnomemusic.player import DiscoveryStatus
from gnomemusic.playlists import Playlists, StaticPlaylists
import gnomemusic.utils as utils
from gnomemusic import log
import logging
logger = logging.getLogger(__name__)
......@@ -243,7 +244,7 @@ class AlbumWidget(Gtk.EventBox):
self.selection_toolbar = selection_toolbar
self.header_bar = header_bar
self.album = album
real_artist = item.get_artist() or _("Unknown Artist")
real_artist = utils.get_artist_name(item)
self.ui.get_object('cover').set_from_pixbuf(self.loadingIcon)
ALBUM_ART_CACHE.lookup(item, 256, 256, self._on_look_up, None, real_artist, album)
......@@ -653,10 +654,9 @@ class ArtistAlbumWidget(Gtk.Box):
@log
def _update_album_art(self):
real_artist = self.album.get_artist() or _("Unknown Artist")
ALBUM_ART_CACHE.lookup(
self.album, 128, 128, self._get_album_cover, None,
real_artist, self.album.get_title())
artist = utils.get_artist_name(self.album)
ALBUM_ART_CACHE.lookup(self.album, 128, 128, self._get_album_cover,
None, artist, self.album.get_title())
@log
def _get_album_cover(self, pixbuf, path, data=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment