Guides pratiquesTéléchargements par lots avec des webhooks
Soumettre un lot de tâches avec une URL de webhook
Soumettre plusieurs tâches qui rendent compte à votre URL de webhook.
Passez votre endpoint accessible publiquement comme webhook_url. Chaque tâche est indépendante ; HuntAPI appelle le webhook quand elle se termine.
import os
import requests
API_KEY = os.environ["HUNTAPI_API_KEY"]
def get(path, params):
response = requests.get(f"https://api.huntapi.com{path}", headers={"x-api-key": API_KEY}, params=params)
if not response.ok:
raise SystemExit(f"Error {response.status_code}: {response.text}")
return response.json()
WEBHOOK_URL = "https://yourserver.example.com/webhooks/huntapi"
URLS = [
"https://www.youtube.com/watch?v=VIDEO_ID_1",
"https://www.youtube.com/watch?v=VIDEO_ID_2",
"https://www.youtube.com/watch?v=VIDEO_ID_3",
]
job_ids = []
for video_url in URLS:
params = {"query": video_url, "video_quality": "best", "webhook_url": WEBHOOK_URL}
job_id = get("/v1/video/download", params)["job_id"]
job_ids.append(job_id)
print(f"Submitted: {job_id}")
print(f"{len(job_ids)} jobs submitted. Waiting for webhooks...")