Poll MusicGPT for full conversion details when webhook omits audio URLs
This commit is contained in:
parent
5443c464bd
commit
2c11738d2e
2 changed files with 18 additions and 4 deletions
17
app.py
17
app.py
|
|
@ -324,6 +324,12 @@ 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()
|
||||
|
|
@ -398,10 +404,13 @@ def admin_musicgpt_refresh():
|
|||
continue
|
||||
if status in ('COMPLETED', 'FINISHED'):
|
||||
download_musicgpt_outputs(req, conversion)
|
||||
fields = {'musicgpt_status': 'COMPLETED'}
|
||||
if req.get('song_a_path') and req.get('song_b_path'):
|
||||
fields['status'] = 'songs_uploaded'
|
||||
update_request(row['id'], **fields)
|
||||
# Re-fetch so we can see the newly saved paths.
|
||||
req = get_request_by_id(row['id'])
|
||||
if req:
|
||||
fields = {'musicgpt_status': 'COMPLETED'}
|
||||
if req.get('song_a_path') and req.get('song_b_path'):
|
||||
fields['status'] = 'songs_uploaded'
|
||||
update_request(row['id'], **fields)
|
||||
updated += 1
|
||||
elif status in ('FAILED', 'ERROR'):
|
||||
update_request(row['id'], musicgpt_status='FAILED', musicgpt_error=conversion.get('status_msg') or 'Polling reported failure')
|
||||
|
|
|
|||
|
|
@ -695,6 +695,11 @@ def download_musicgpt_outputs(req, data, version=None):
|
|||
|
||||
if saved:
|
||||
update_request(request_id, **saved)
|
||||
# If both song versions have been downloaded, advance request status.
|
||||
from models import get_request_by_id
|
||||
req = get_request_by_id(request_id)
|
||||
if req and req.get('song_a_path') and req.get('song_b_path') and req.get('status') not in ('songs_uploaded', 'delivered', 'cancelled'):
|
||||
update_request(request_id, status='songs_uploaded')
|
||||
return saved
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue