Auto-upload stems to Gokapi on completion, save share link
- New helpers: parse_stems_urls, upload_to_gokapi, process_stems_to_gokapi - Stems webhook handler now downloads stem files from MusicGPT CDN, zips them, uploads to Gokapi with 30-day expiry, saves the Gokapi download URL to stems_link in the DB - Download Stems button uses stems_link (Gokapi URL) when available, falls back to the zip endpoint if not - Config: GOKAPI_URL, GOKAPI_API_KEY, GOKAPI_EXPIRY_DAYS env vars - docker-compose: GOKAPI_* environment variables added
This commit is contained in:
parent
9df4c685a4
commit
ccc93ffb3b
5 changed files with 140 additions and 3 deletions
12
app.py
12
app.py
|
|
@ -66,6 +66,7 @@ from helpers import (
|
|||
musicgpt_generate_request, musicgpt_queue_stems, musicgpt_poll_status,
|
||||
download_musicgpt_outputs, format_musicgpt_cost, get_musicgpt_cost_totals,
|
||||
download_album_cover,
|
||||
process_stems_to_gokapi,
|
||||
get_ntfy_config, send_ntfy,
|
||||
sign_prompt_callback, verify_prompt_callback, build_prompt_callback_url,
|
||||
send_email, build_signature_images,
|
||||
|
|
@ -419,7 +420,6 @@ def musicgpt_webhook():
|
|||
if not stems_url and audio_url_map:
|
||||
stems_url = '; '.join(f"{k}: {v}" for k, v in audio_url_map.items())
|
||||
update_fields['stems_url'] = stems_url
|
||||
update_fields['stems_link'] = stems_url
|
||||
try:
|
||||
sc = float(data.get('conversion_cost') or 0)
|
||||
except (ValueError, TypeError):
|
||||
|
|
@ -429,6 +429,16 @@ def musicgpt_webhook():
|
|||
elif new_status in ('FAILED', 'ERROR'):
|
||||
update_fields['stems_error'] = data.get('reason') or data.get('error') or 'Extraction failed'
|
||||
update_request(req['id'], **update_fields)
|
||||
|
||||
# After stems are complete, upload them to Gokapi for a shareable link.
|
||||
if new_status in ('COMPLETED', 'FINISHED') and Config.GOKAPI_URL and Config.GOKAPI_API_KEY:
|
||||
row = db.execute('SELECT * FROM requests WHERE id = ?', (req['id'],)).fetchone()
|
||||
req = dict(row)
|
||||
gokapi_url, gokapi_err = process_stems_to_gokapi(req)
|
||||
if gokapi_err:
|
||||
app.logger.warning(f'Gokapi upload failed for request {req["id"]}: {gokapi_err}')
|
||||
# Note: process_stems_to_gokapi already saves stems_link to the DB on success.
|
||||
|
||||
return jsonify({'ok': True, 'request_id': req['id']}), 200
|
||||
|
||||
return jsonify({'ok': False, 'reason': 'unknown_conversion_type'}), 400
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue