From c816fbe7a8a52ae5bf5b23537cc1aa6e8676946e Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 15 Aug 2024 09:59:19 +0200 Subject: [PATCH] Use 0 as insert position for empty playlist FIXES: error when adding a new video to an empty playlist FIXES: notifiy boolean and notify function using the same name, making add to playlist unusable --- melon/models/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/melon/models/__init__.py b/melon/models/__init__.py index 1699073..8fb8a88 100644 --- a/melon/models/__init__.py +++ b/melon/models/__init__.py @@ -865,7 +865,7 @@ def get_playlists() -> list[PlaylistWrapper]: return results -def add_to_local_playlist(playlist_id: int, vid, pos=None, notify=True): +def add_to_local_playlist(playlist_id: int, vid, pos=None, broadcast=True): ensure_video(vid) conn = connect_to_db() if pos is None: @@ -877,7 +877,11 @@ def add_to_local_playlist(playlist_id: int, vid, pos=None, notify=True): """, (playlist_id,), ).fetchone() - pos = vids[0] + 1 + if vids[0] is None: + # playlist is empty + pos = 0 + else: + pos = vids[0] + 1 execute_sql( conn, """ @@ -887,7 +891,7 @@ def add_to_local_playlist(playlist_id: int, vid, pos=None, notify=True): (playlist_id, vid.id, vid.server, pos), ) conn.close() - if notify: + if broadcast: notify("playlists_changed") @@ -904,7 +908,7 @@ def set_local_playlist_content(playlist_id: int, videos: list[Resource]): ) # manually add new items for index, entry in enumerate(videos): - add_to_local_playlist(playlist_id, entry, pos=index, notify=False) + add_to_local_playlist(playlist_id, entry, pos=index, broadcast=False) conn.close() notify("playlists_changed") -- 2.38.5