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
9
app.py
9
app.py
|
|
@ -324,6 +324,12 @@ def musicgpt_webhook():
|
||||||
if data.get('is_flagged'):
|
if data.get('is_flagged'):
|
||||||
update_fields['musicgpt_error'] = data.get('reason') or 'Flagged by MusicGPT'
|
update_fields['musicgpt_error'] = data.get('reason') or 'Flagged by MusicGPT'
|
||||||
if new_status in ('COMPLETED', 'FINISHED'):
|
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)
|
download_musicgpt_outputs(req, data, version=version)
|
||||||
# Re-fetch to get updated paths.
|
# Re-fetch to get updated paths.
|
||||||
row = db.execute('SELECT * FROM requests WHERE id = ?', (req['id'],)).fetchone()
|
row = db.execute('SELECT * FROM requests WHERE id = ?', (req['id'],)).fetchone()
|
||||||
|
|
@ -398,6 +404,9 @@ def admin_musicgpt_refresh():
|
||||||
continue
|
continue
|
||||||
if status in ('COMPLETED', 'FINISHED'):
|
if status in ('COMPLETED', 'FINISHED'):
|
||||||
download_musicgpt_outputs(req, conversion)
|
download_musicgpt_outputs(req, conversion)
|
||||||
|
# Re-fetch so we can see the newly saved paths.
|
||||||
|
req = get_request_by_id(row['id'])
|
||||||
|
if req:
|
||||||
fields = {'musicgpt_status': 'COMPLETED'}
|
fields = {'musicgpt_status': 'COMPLETED'}
|
||||||
if req.get('song_a_path') and req.get('song_b_path'):
|
if req.get('song_a_path') and req.get('song_b_path'):
|
||||||
fields['status'] = 'songs_uploaded'
|
fields['status'] = 'songs_uploaded'
|
||||||
|
|
|
||||||
|
|
@ -695,6 +695,11 @@ def download_musicgpt_outputs(req, data, version=None):
|
||||||
|
|
||||||
if saved:
|
if saved:
|
||||||
update_request(request_id, **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
|
return saved
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue