Make MusicGPT webhook robust: store cover/cost, download when URLs available
This commit is contained in:
parent
2c11738d2e
commit
57bdf69942
1 changed files with 11 additions and 12 deletions
23
app.py
23
app.py
|
|
@ -324,22 +324,21 @@ def musicgpt_webhook():
|
|||
if data.get('is_flagged'):
|
||||
update_fields['musicgpt_error'] = data.get('reason') or 'Flagged by MusicGPT'
|
||||
if new_status in ('COMPLETED', 'FINISHED'):
|
||||
# Real webhooks may omit audio URLs; fetch full conversion details if needed.
|
||||
if not (data.get('conversion_path') or data.get('conversion_path_1') or data.get('conversion_path_2')):
|
||||
poll_result = musicgpt_poll_status(task_id)
|
||||
conversion = poll_result.get('conversion') or {}
|
||||
if conversion and isinstance(conversion, dict):
|
||||
data.update(conversion)
|
||||
download_musicgpt_outputs(req, data, version=version)
|
||||
# Re-fetch to get updated paths.
|
||||
row = db.execute('SELECT * FROM requests WHERE id = ?', (req['id'],)).fetchone()
|
||||
req = dict(row)
|
||||
if req.get('song_a_path') and req.get('song_b_path'):
|
||||
update_fields['status'] = 'songs_uploaded'
|
||||
# Webhooks often fire before audio URLs are ready. Store whatever the
|
||||
# webhook gives us, then rely on the dashboard manual refresh to
|
||||
# download files once the API reports them fully available.
|
||||
if data.get('album_cover_path'):
|
||||
update_fields['album_cover_url'] = data.get('album_cover_path')
|
||||
try:
|
||||
update_fields['musicgpt_cost'] = float(data.get('conversion_cost') or 0)
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
# Still attempt download in case the webhook is the rare complete one.
|
||||
download_musicgpt_outputs(req, data, version=version)
|
||||
row = db.execute('SELECT * FROM requests WHERE id = ?', (req['id'],)).fetchone()
|
||||
req = dict(row)
|
||||
if req.get('song_a_path') and req.get('song_b_path'):
|
||||
update_fields['status'] = 'songs_uploaded'
|
||||
elif new_status in ('FAILED', 'ERROR'):
|
||||
update_fields['musicgpt_error'] = data.get('reason') or data.get('error') or 'MusicGPT reported failure'
|
||||
update_request(req['id'], **update_fields)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue