From 2c11738d2e2040419c0d914ca9efa30c10551cfa Mon Sep 17 00:00:00 2001 From: "Troll (Hermes Agent)" Date: Mon, 10 Aug 2026 23:13:51 +0000 Subject: [PATCH] Poll MusicGPT for full conversion details when webhook omits audio URLs --- app.py | 17 +++++++++++++---- helpers.py | 5 +++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index cc394aa..ab5aa73 100644 --- a/app.py +++ b/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') diff --git a/helpers.py b/helpers.py index fc29e96..d84dc4b 100644 --- a/helpers.py +++ b/helpers.py @@ -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