From 175be12a7e869da8e0d1299df186ac97dce04198 Mon Sep 17 00:00:00 2001 From: Salman Faris Date: Fri, 17 Jul 2026 20:17:46 +0530 Subject: [PATCH] Fix QC playlist cleanup Unlink each label association with the API-required label and playlist filters so script-created QC playlists can be removed without explicitly deleting their items. --- automated_quality_control.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/automated_quality_control.py b/automated_quality_control.py index 9cadfa8..550c0cb 100644 --- a/automated_quality_control.py +++ b/automated_quality_control.py @@ -125,23 +125,35 @@ def get_qc_playlist_ids(): def delete_playlist(playlist_id): """ - Delete a playlist and its items. In v4.1, label associations and playlist - items must be removed before the playlist itself can be deleted. + Delete a QC playlist. In v4.1, label associations must be removed first, + and DELETE /labels/playlists requires a label_id filter. + Playlist items are left for the API to cascade with the playlist. """ - labels_response = requests.delete( + associations_response = requests.get( f"{SCREENLY_API_BASE_URL}/v4.1/labels/playlists?playlist_id=eq.{playlist_id}", headers=REQUEST_HEADERS, ) - if not labels_response.ok: - print(f"Failed to delete label associations for playlist {playlist_id}: {labels_response.status_code} {labels_response.text}") - return False - items_response = requests.delete( - f"{SCREENLY_API_BASE_URL}/v4.1/playlist-items?playlist_id=eq.{playlist_id}", - headers=REQUEST_HEADERS, - ) - if not items_response.ok: - print(f"Failed to delete items for playlist {playlist_id}: {items_response.status_code} {items_response.text}") + if not associations_response.ok: + print( + f"Failed to fetch label associations for playlist {playlist_id}: " + f"{associations_response.status_code} {associations_response.text}" + ) return False + + for association in associations_response.json(): + label_id = association["label_id"] + labels_response = requests.delete( + f"{SCREENLY_API_BASE_URL}/v4.1/labels/playlists" + f"?label_id=eq.{label_id}&playlist_id=eq.{playlist_id}", + headers=REQUEST_HEADERS, + ) + if not labels_response.ok: + print( + f"Failed to delete label association {label_id} for playlist {playlist_id}: " + f"{labels_response.status_code} {labels_response.text}" + ) + return False + response = requests.delete( f"{SCREENLY_API_BASE_URL}/v4.1/playlists?id=eq.{playlist_id}", headers=REQUEST_HEADERS,