@@ 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")