Try to fix playlist assignment and increase rotation freq.

Signed-off-by: Abdulkadir Furkan Şanlı <me@afk.pm>
This commit is contained in:
afk
2026-07-19 02:25:49 +02:00
parent 5515690416
commit b946f649e0
+18 -21
View File
@@ -494,15 +494,15 @@ async def process_radio_track(video_link, video_id, title):
response = json.loads(stdout.decode()) response = json.loads(stdout.decode())
unique_id = response.get("unique_id") unique_id = response.get("unique_id")
azura_path = response.get("path") or response.get("file") 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 = [ search_cmd = [
"curl", "curl",
"-s", "-s",
"-G",
f"{base_url}/api/station/{AZURACAST_STATION_ID}/files", f"{base_url}/api/station/{AZURACAST_STATION_ID}/files",
"--data-urlencode",
f"search={filename}",
"-H", "-H",
f"X-API-Key: {AZURACAST_API_KEY}", 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_out, _ = await search_proc.communicate()
search_data = json.loads(search_out.decode()) search_data = json.loads(search_out.decode())
# Normalize the data list whether it's wrapped in "rows" or is a raw array
file_list = ( file_list = (
search_data.get("rows", []) search_data
if isinstance(search_data, dict) if isinstance(search_data, list)
else (search_data if isinstance(search_data, list) else []) else search_data.get("rows", [])
) )
target_suffix = f"_{video_id}."
for item in file_list: for item in file_list:
item_path = item.get("path", "") item_path = item.get("path", "")
# Match the specific filename we just uploaded if target_suffix.lower() in item_path.lower():
if item_path == filename or item_path.endswith(f"/{filename}"): unique_id = item.get("unique_id")
unique_id = unique_id or item.get("unique_id") azura_path = item.get("path")
azura_path = azura_path or item.get("path")
break break
except json.JSONDecodeError: except Exception as e:
print(f"❌ Failed to parse AzuraCast upload response") print(f"❌ Failed to search for uploaded track on AzuraCast: {e}")
# 1. Add the track to the "Currents" playlist FIRST # 1. Add the track to the "Currents" playlist FIRST
# AzuraCast rejects requests for files that aren't assigned to any active playlist. # 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: except json.JSONDecodeError:
print(f"⚠️ Failed to queue {title}. API returned: {req_stdout.decode()}") print(f"⚠️ Failed to queue {title}. API returned: {req_stdout.decode()}")
else: 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): if os.path.exists(filepath):
os.remove(filepath) os.remove(filepath)
async def automated_playlist_rotation(): 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: while True:
try: try:
if not AZURACAST_API_KEY: if not AZURACAST_API_KEY:
await asyncio.sleep(86400) await asyncio.sleep(3600)
continue continue
base_url = AZURACAST_URL.rstrip("/") base_url = AZURACAST_URL.rstrip("/")
@@ -655,7 +654,7 @@ async def automated_playlist_rotation():
playlists = json.loads(pl_stdout.decode()) playlists = json.loads(pl_stdout.decode())
pl_map = {p.get("name", "").lower(): p.get("id") for p in playlists} pl_map = {p.get("name", "").lower(): p.get("id") for p in playlists}
except json.JSONDecodeError: except json.JSONDecodeError:
await asyncio.sleep(86400) await asyncio.sleep(3600)
continue continue
req_playlists = ["currents", "recurrents", "gold"] req_playlists = ["currents", "recurrents", "gold"]
@@ -663,7 +662,7 @@ async def automated_playlist_rotation():
print( print(
"⚠️ Missing required playlists. Please create 'Currents', 'Recurrents', and 'Gold'." "⚠️ Missing required playlists. Please create 'Currents', 'Recurrents', and 'Gold'."
) )
await asyncio.sleep(86400) await asyncio.sleep(3600)
continue continue
currents_id = pl_map["currents"] currents_id = pl_map["currents"]
@@ -673,8 +672,6 @@ async def automated_playlist_rotation():
files_cmd = [ files_cmd = [
"curl", "curl",
"-s", "-s",
"-X",
"GET",
f"{base_url}/api/station/{AZURACAST_STATION_ID}/files", f"{base_url}/api/station/{AZURACAST_STATION_ID}/files",
"-H", "-H",
f"X-API-Key: {AZURACAST_API_KEY}", f"X-API-Key: {AZURACAST_API_KEY}",
@@ -760,7 +757,7 @@ async def automated_playlist_rotation():
except Exception as e: except Exception as e:
print(f"💥 Error in automated_playlist_rotation: {e}") print(f"💥 Error in automated_playlist_rotation: {e}")
await asyncio.sleep(86400) await asyncio.sleep(3600)
async def main(): async def main():