PlaybooksExtract Audio from a Video
Poll for completion
Check the job every 5 seconds until it is done.
Check GET /v1/jobs/{id} every 5 seconds until status is "CompletedJob"; result.response then holds the file URL.
This code continues the script from Submit an audio extraction job.
import time
def wait_for_job(job_id, interval=5, timeout=3600):
deadline = time.time() + timeout
while time.time() < deadline:
job = get(f"/v1/jobs/{job_id}", {})
print(f" Status: {job['status']} ({job.get('progress') or 0}%)")
if job["status"] == "CompletedJob":
return job
if job["status"] not in ("Queued", "Running"):
raise SystemExit(f"Job failed: {job['status']}")
time.sleep(interval)
raise SystemExit("The job did not finish in time.")
job = wait_for_job(job_id)
download_url = job["result"]["response"]
print(f"Ready! Download URL: {download_url}")