~comcloudway/melon

c816fbe7a8a52ae5bf5b23537cc1aa6e8676946e — Jakob Meier a month ago 78a5bbc
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
1 files changed, 8 insertions(+), 4 deletions(-)

M melon/models/__init__.py
M melon/models/__init__.py => melon/models/__init__.py +8 -4
@@ 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")