v0.8.8: Fix stems extraction — upload MP3 file instead of audio_url

The MusicGPT Extraction API's audio_url field only accepts YouTube URLs,
not direct MP3 links. Sending our /api/audio-source/ endpoint URL resulted
in 'Error fetching audio length from YouTube' because MusicGPT tried to
parse it as a YouTube video.

Switch to the audio_file upload option: open the local MP3 and upload it
directly as multipart/form-data to the Extraction API.

Bumped timeout from 30s to 60s for file upload.
This commit is contained in:
Troll (Hermes Agent) 2026-08-12 03:37:43 +00:00
parent 8df735d88c
commit 9575464be2
4 changed files with 15 additions and 10 deletions

View file

@ -619,21 +619,26 @@ def musicgpt_poll_status(task_id):
return {"error": str(e)}
def musicgpt_queue_stems(rid, audio_url, stems=None):
def musicgpt_queue_stems(rid, audio_file_path, stems=None):
"""
Queue a stem extraction job for a generated audio URL.
Queue a stem extraction job by uploading the MP3 file directly.
The MusicGPT Extraction API's audio_url field only accepts YouTube URLs,
not direct MP3 URLs. We use the audio_file upload option instead.
Returns (task_id, conversion_id, credit_estimate, error_message).
"""
url = f"{MUSICGPT_API_BASE}/v2/Extraction"
if stems is None:
stems = ["vocals", "instrumental"]
payload = {
"audio_url": audio_url,
"stems": json.dumps(stems),
"webhook_url": build_musicgpt_webhook_url(),
}
try:
resp = requests.post(url, data=payload, headers={"Authorization": get_musicgpt_api_key()}, timeout=30)
with open(audio_file_path, "rb") as f:
files = {"audio_file": f}
resp = requests.post(url, data=payload, files=files, headers={"Authorization": get_musicgpt_api_key()}, timeout=60)
try:
data = resp.json()
except Exception: