[gnome-music] grltrackerplaylists: Fix duplicated song removal
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] grltrackerplaylists: Fix duplicated song removal
- Date: Sat, 4 Sep 2021 21:52:11 +0000 (UTC)
commit 38f8661700e365b953dd1823c398f03d5c596da2
Author: Mpho Jele <mphokjele gmail com>
Date: Tue Aug 31 14:28:28 2021 +0200
grltrackerplaylists: Fix duplicated song removal
A playlist song that is duplicated gets removed with its duplicates.
For example, if you add an album twice and remove the first the other
song that is identical to it will also get removed, but this won't be
reflected in the view. To fix this we retrieve the song to be removed by
its position in the playlist rather than song_id since all songs that
are the same have the same song_id.
Closes: #469
gnomemusic/grilowrappers/grltrackerplaylists.py | 28 +++++++------------------
gnomemusic/widgets/notificationspopup.py | 2 +-
2 files changed, 8 insertions(+), 22 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerplaylists.py b/gnomemusic/grilowrappers/grltrackerplaylists.py
index a129ba78c..695ee7e14 100644
--- a/gnomemusic/grilowrappers/grltrackerplaylists.py
+++ b/gnomemusic/grilowrappers/grltrackerplaylists.py
@@ -509,10 +509,12 @@ class Playlist(GObject.GObject):
self._model.insert(position, coresong)
self.props.count += 1
- def finish_song_deletion(self, coresong):
+ def finish_song_deletion(self, coresong: CoreSong, position: int) -> None:
"""Removes a song from the playlist
:param CoreSong coresong: song to remove
+ :param int position: Song position in the playlist, starts from
+ zero
"""
def update_cb(conn, res):
try:
@@ -597,7 +599,6 @@ class Playlist(GObject.GObject):
self._tracker.update_async(update_query, None, update_cb)
- song_id = coresong.props.media.get_id()
entry_query = """
SELECT
%(media_type)s AS ?type
@@ -606,31 +607,16 @@ class Playlist(GObject.GObject):
?playlist a nmm:Playlist ;
a nfo:MediaList ;
nfo:hasMediaFileListEntry ?entry .
- ?entry a nfo:MediaFileListEntry ;
- nfo:entryUrl ?url .
- SERVICE <dbus:%(miner_fs_busname)s> {
- GRAPH tracker:Audio {
- SELECT
- ?song
- ?url
- WHERE {
- ?song a nmm:MusicPiece ;
- nie:isStoredAs ?url .
- FILTER (
- %(filter_clause_song)s
- )
- }
- }
- }
+ ?entry a nfo:MediaFileListEntry .
FILTER (
- %(filter_clause_pl)s
+ %(filter_clause_pl)s &&
+ nfo:listPosition(?entry) = %(position)s
)
}
""".replace("\n", " ").strip() % {
"media_type": int(Grl.MediaType.AUDIO),
- "filter_clause_song": "tracker:id(?song) = " + song_id,
+ "position": position + 1,
"filter_clause_pl": "tracker:id(?playlist) = " + self.props.pl_id,
- "miner_fs_busname": self._tracker_wrapper.props.miner_fs_busname
}
self._source.query(
diff --git a/gnomemusic/widgets/notificationspopup.py b/gnomemusic/widgets/notificationspopup.py
index 5d78f98e9..3ba9c55ca 100644
--- a/gnomemusic/widgets/notificationspopup.py
+++ b/gnomemusic/widgets/notificationspopup.py
@@ -249,4 +249,4 @@ class PlaylistNotification(Gtk.Grid):
if self.type_ == PlaylistNotification.Type.PLAYLIST:
self._coregrilo.finish_playlist_deletion(self._playlist, True)
else:
- self._playlist.finish_song_deletion(self._coresong)
+ self._playlist.finish_song_deletion(self._coresong, self._position)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]