Commit 9f1a6513 authored by Marinus Schraal's avatar Marinus Schraal

Use correct Grilo key for favorite tracking

Music was using the lyrics key to track favorite status for songs. Use
the favourite key instead, with proper tracker plugin support.

https://bugzilla.gnome.org/show_bug.cgi?id=774754
parent 146e5266
......@@ -57,6 +57,7 @@ class Grilo(GObject.GObject):
Grl.METADATA_KEY_CREATION_DATE,
Grl.METADATA_KEY_COMPOSER,
Grl.METADATA_KEY_DURATION,
Grl.METADATA_KEY_FAVOURITE,
Grl.METADATA_KEY_ID,
Grl.METADATA_KEY_LYRICS,
Grl.METADATA_KEY_THUMBNAIL,
......@@ -290,14 +291,24 @@ class Grilo(GObject.GObject):
@log
def toggle_favorite(self, song_item):
# TODO: change "bool(song_item.get_lyrics())" --> song_item.get_favourite() once query works properly
# TODO: when .set/get_favourite work, set_favourite outside loop: item.set_favourite(!item.get_favourite())
if bool(song_item.get_lyrics()): # is favorite
self.sparqltracker.update(Query.remove_favorite(song_item.get_url()), GLib.PRIORITY_DEFAULT, None)
"""Toggles favorite status for media item
Toggles favorite status and writes it back to the tracker store
:param song_item: A Grilo media item
"""
if song_item.get_favourite():
# For now keep unsetting the lyrics to deal with how
# previous versions dealt with favorites.
song_item.set_lyrics("")
else: # not favorite
self.sparqltracker.update(Query.add_favorite(song_item.get_url()), GLib.PRIORITY_DEFAULT, None)
song_item.set_lyrics("i'm truthy")
song_item.set_favourite(False)
else:
song_item.set_favourite(True)
# FIXME: We assume this is the tracker plugin.
# FIXME: Doing this async crashes
self.tracker.store_metadata_sync(song_item,
[Grl.METADATA_KEY_FAVOURITE],
Grl.WriteFlags.NORMAL)
@log
def set_favorite(self, song_item, favorite):
......@@ -306,7 +317,7 @@ class Grilo(GObject.GObject):
:param song_item: A Grilo media item
:param bool favorite: Set favorite status
"""
if bool(song_item.get_lyrics()) != favorite:
if song_item.get_favourite() != favorite:
self.toggle_favorite(song_item)
@log
......
......@@ -208,13 +208,14 @@ class Query():
query = """
SELECT DISTINCT
rdf:type(?song)
?song AS ?tracker_urn
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
?tag AS ?favourite
{
%(where_clause)s
?song a nmm:MusicPiece ;
......@@ -263,6 +264,7 @@ class Query():
query = """
SELECT DISTINCT
rdf:type(?song)
?song AS ?tracker_urn
tracker:id(?song) AS ?id
nie:url(?song) AS ?url
nie:title(?song) AS ?title
......@@ -271,13 +273,13 @@ class Query():
nfo:duration(?song) AS ?duration
nmm:trackNumber(?song) AS ?track_number
nmm:setNumber(nmm:musicAlbumDisc(?song)) AS ?album_disc_number
IF(bound(?tag), 'truth!', '') AS ?lyrics
?tag AS ?favourite
WHERE {
?song a nmm:MusicPiece ;
a nfo:FileDataObject ;
nmm:musicAlbum ?album .
OPTIONAL { ?song nao:hasTag ?tag .
FILTER( ?tag = nao:predefined-tag-favorite ) } .
FILTER (?tag = nao:predefined-tag-favorite) } .
FILTER (tracker:id(?album) = %(album_id)s &&
(STRSTARTS(nie:url(?song), '%(music_dir)s/')))
}
......@@ -297,13 +299,14 @@ class Query():
query = """
SELECT
rdf:type(?song)
?song AS ?tracker_urn
tracker:id(?entry) AS ?id
nie:url(?song) AS ?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), 'truth!', '') AS ?lyrics
?tag AS ?favourite
WHERE {
?playlist a nmm:Playlist ;
a nfo:MediaList ;
......@@ -1026,39 +1029,6 @@ class Query():
return query
@staticmethod
def add_favorite(song_url):
query = """
INSERT {
?song nao:hasTag nao:predefined-tag-favorite
}
WHERE {
?song a nmm:MusicPiece .
FILTER ( nie:url(?song) = "%(song_url)s" )
}
""".replace("\n", " ").strip() % {
'song_url': song_url
}
return query
@staticmethod
def remove_favorite(song_url):
query = """
DELETE {
?song nao:hasTag nao:predefined-tag-favorite
}
WHERE {
?song a nmm:MusicPiece .
FILTER ( nie:url(?song) = "%(song_url)s" )
}
""".replace("\n", " ").strip() % {
'song_url': song_url
}
return query
@staticmethod
def is_audio(media_id):
query = """
......
......@@ -400,7 +400,7 @@ class PlaylistView(BaseView):
model.insert_with_valuesv(
-1,
[2, 3, 5, 9],
[title, artist, item, bool(item.get_lyrics())])
[title, artist, item, item.get_favourite()])
self.songs_count += 1
@log
......
......@@ -247,7 +247,7 @@ class SearchView(BaseView):
[str(item.get_id()), title, artist,
self._loading_icon, item,
2 if source.get_id() != 'grl-tracker-source' \
else bool(item.get_lyrics()), category, composer])
else item.get_favourite(), category, composer])
self.cache.lookup(item, ArtSize.small, self._on_lookup_ready, _iter)
else:
if not artist.casefold() in self._artists:
......
......@@ -136,9 +136,8 @@ class SongsView(BaseView):
utils.get_media_title(item),
artist,
item,
bool(item.get_lyrics())
item.get_favourite()
])
# TODO: change "bool(item.get_lyrics())" --> item.get_favourite() once query works properly
@log
def _add_list_renderers(self):
......
......@@ -352,7 +352,7 @@ class DiscBox(Gtk.Box):
song_widget.connect('button-release-event', self._track_activated)
song_widget.star_stack = builder.get_object('starstack')
song_widget.star_stack.set_favorite(track.get_lyrics())
song_widget.star_stack.set_favorite(track.get_favourite())
song_widget.star_stack.set_visible(True)
song_widget.starevent = builder.get_object('starevent')
......
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