PlaybooksDownload Your First Video
Poll until the video is ready
Check the job until its download URL is ready.
Check GET /v1/jobs/{id} every few seconds. When status becomes "CompletedJob", result.response holds the file URL. A failed job answers with an HTTP error status.
This code continues the script from Submit the download 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}")