Correct endpoint
This commit is contained in:
@@ -459,13 +459,12 @@ async def process_radio_track(video_link, video_id, title):
|
|||||||
"yt-dlp",
|
"yt-dlp",
|
||||||
"--no-cache-dir",
|
"--no-cache-dir",
|
||||||
"--extract-audio",
|
"--extract-audio",
|
||||||
"--output", f"{base_filepath}.%(ext)s",
|
"--output",
|
||||||
video_link
|
f"{base_filepath}.%(ext)s",
|
||||||
|
video_link,
|
||||||
]
|
]
|
||||||
process = await asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
*dl_cmd,
|
*dl_cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
||||||
stdout=asyncio.subprocess.PIPE,
|
|
||||||
stderr=asyncio.subprocess.PIPE
|
|
||||||
)
|
)
|
||||||
stdout, stderr = await process.communicate()
|
stdout, stderr = await process.communicate()
|
||||||
if process.returncode != 0:
|
if process.returncode != 0:
|
||||||
@@ -480,19 +479,22 @@ async def process_radio_track(video_link, video_id, title):
|
|||||||
return
|
return
|
||||||
|
|
||||||
filepath = downloaded_files[0]
|
filepath = downloaded_files[0]
|
||||||
|
filename = os.path.basename(filepath)
|
||||||
|
|
||||||
print(f"📻 Uploading to AzuraCast: {title}")
|
print(f"📻 Uploading to AzuraCast: {title}")
|
||||||
|
|
||||||
# 2. Upload to AzuraCast using curl
|
# 2. Upload to AzuraCast using curl with the correct multipart endpoint
|
||||||
upload_cmd = [
|
upload_cmd = [
|
||||||
"curl",
|
"curl",
|
||||||
"-s",
|
"-s",
|
||||||
"-X",
|
"-X",
|
||||||
"POST",
|
"POST",
|
||||||
f"{AZURACAST_URL}/api/station/{AZURACAST_STATION_ID}/files",
|
f"{AZURACAST_URL}/api/station/{AZURACAST_STATION_ID}/files/upload",
|
||||||
"-H",
|
"-H",
|
||||||
f"X-API-Key: {AZURACAST_API_KEY}",
|
f"X-API-Key: {AZURACAST_API_KEY}",
|
||||||
"-F",
|
"-F",
|
||||||
|
f"path={filename}",
|
||||||
|
"-F",
|
||||||
f"file=@{filepath}",
|
f"file=@{filepath}",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -506,6 +508,35 @@ 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")
|
||||||
|
|
||||||
|
# If the /upload endpoint doesn't return the ID directly, fetch it via search
|
||||||
|
if not unique_id:
|
||||||
|
search_cmd = [
|
||||||
|
"curl",
|
||||||
|
"-s",
|
||||||
|
"-G",
|
||||||
|
f"{AZURACAST_URL}/api/station/{AZURACAST_STATION_ID}/files",
|
||||||
|
"--data-urlencode",
|
||||||
|
f"search={filename}",
|
||||||
|
"-H",
|
||||||
|
f"X-API-Key: {AZURACAST_API_KEY}",
|
||||||
|
]
|
||||||
|
search_proc = await asyncio.create_subprocess_exec(
|
||||||
|
*search_cmd,
|
||||||
|
stdout=asyncio.subprocess.PIPE,
|
||||||
|
stderr=asyncio.subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
search_out, _ = await search_proc.communicate()
|
||||||
|
|
||||||
|
search_data = json.loads(search_out.decode())
|
||||||
|
if (
|
||||||
|
isinstance(search_data, dict)
|
||||||
|
and "rows" in search_data
|
||||||
|
and len(search_data["rows"]) > 0
|
||||||
|
):
|
||||||
|
unique_id = search_data["rows"][0].get("unique_id")
|
||||||
|
elif isinstance(search_data, list) and len(search_data) > 0:
|
||||||
|
unique_id = search_data[0].get("unique_id")
|
||||||
|
|
||||||
if unique_id:
|
if unique_id:
|
||||||
req_cmd = [
|
req_cmd = [
|
||||||
"curl",
|
"curl",
|
||||||
|
|||||||
Reference in New Issue
Block a user