From b946f649e071eef17722a5d29584a7cb5ec4ede4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdulkadir=20Furkan=20=C5=9Eanl=C4=B1?= Date: Sun, 19 Jul 2026 02:25:49 +0200 Subject: [PATCH] Try to fix playlist assignment and increase rotation freq. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Abdulkadir Furkan Şanlı --- main.py | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/main.py b/main.py index 1084db6..48b8493 100755 --- a/main.py +++ b/main.py @@ -494,15 +494,15 @@ async def process_radio_track(video_link, video_id, title): response = json.loads(stdout.decode()) unique_id = response.get("unique_id") azura_path = response.get("path") or response.get("file") + except json.JSONDecodeError: + print("❌ Failed to parse AzuraCast upload response") - if not unique_id or not azura_path: + if not unique_id or not azura_path: + try: search_cmd = [ "curl", "-s", - "-G", f"{base_url}/api/station/{AZURACAST_STATION_ID}/files", - "--data-urlencode", - f"search={filename}", "-H", f"X-API-Key: {AZURACAST_API_KEY}", ] @@ -513,21 +513,20 @@ async def process_radio_track(video_link, video_id, title): ) search_out, _ = await search_proc.communicate() search_data = json.loads(search_out.decode()) - # Normalize the data list whether it's wrapped in "rows" or is a raw array file_list = ( - search_data.get("rows", []) - if isinstance(search_data, dict) - else (search_data if isinstance(search_data, list) else []) + search_data + if isinstance(search_data, list) + else search_data.get("rows", []) ) + target_suffix = f"_{video_id}." for item in file_list: item_path = item.get("path", "") - # Match the specific filename we just uploaded - if item_path == filename or item_path.endswith(f"/{filename}"): - unique_id = unique_id or item.get("unique_id") - azura_path = azura_path or item.get("path") + if target_suffix.lower() in item_path.lower(): + unique_id = item.get("unique_id") + azura_path = item.get("path") break - except json.JSONDecodeError: - print(f"❌ Failed to parse AzuraCast upload response") + except Exception as e: + print(f"❌ Failed to search for uploaded track on AzuraCast: {e}") # 1. Add the track to the "Currents" playlist FIRST # AzuraCast rejects requests for files that aren't assigned to any active playlist. @@ -619,18 +618,18 @@ async def process_radio_track(video_link, video_id, title): except json.JSONDecodeError: print(f"⚠️ Failed to queue {title}. API returned: {req_stdout.decode()}") else: - print(f"⚠️ Uploaded, but no unique_id returned to make the request.") + print("⚠️ Uploaded, but no unique_id returned to make the request.") if os.path.exists(filepath): os.remove(filepath) async def automated_playlist_rotation(): - """Runs continuously, sorting AzuraCast files by age once a day.""" + """Runs continuously, sorting AzuraCast files by age once an hour.""" while True: try: if not AZURACAST_API_KEY: - await asyncio.sleep(86400) + await asyncio.sleep(3600) continue base_url = AZURACAST_URL.rstrip("/") @@ -655,7 +654,7 @@ async def automated_playlist_rotation(): playlists = json.loads(pl_stdout.decode()) pl_map = {p.get("name", "").lower(): p.get("id") for p in playlists} except json.JSONDecodeError: - await asyncio.sleep(86400) + await asyncio.sleep(3600) continue req_playlists = ["currents", "recurrents", "gold"] @@ -663,7 +662,7 @@ async def automated_playlist_rotation(): print( "⚠️ Missing required playlists. Please create 'Currents', 'Recurrents', and 'Gold'." ) - await asyncio.sleep(86400) + await asyncio.sleep(3600) continue currents_id = pl_map["currents"] @@ -673,8 +672,6 @@ async def automated_playlist_rotation(): files_cmd = [ "curl", "-s", - "-X", - "GET", f"{base_url}/api/station/{AZURACAST_STATION_ID}/files", "-H", f"X-API-Key: {AZURACAST_API_KEY}", @@ -760,7 +757,7 @@ async def automated_playlist_rotation(): except Exception as e: print(f"💥 Error in automated_playlist_rotation: {e}") - await asyncio.sleep(86400) + await asyncio.sleep(3600) async def main():