const API = "https://api.tubeextract.dev/v1";
const headers = {
"X-API-Key": process.env.TUBEEXTRACT_KEY,
"Content-Type": "application/json"
};
const schema = {
multiple: true,
columns: [
{ name: "restaurant_name",
description: "Name of the restaurant the host visited" },
{ name: "food_ordered",
description: "What the host said he ate there" }
]
};
const created = await fetch(`${API}/jobs`, {
method: "POST", headers,
body: JSON.stringify({ youtube_url: url, schema })
}).then(r => r.json());
while (true) {
await new Promise(r => setTimeout(r, 1500));
const job = await fetch(`${API}/${created.job_id}`,
{ headers }).then(r => r.json());
// null until every video has settled, so polling costs nothing
if (job.results !== null) {
await save(job.results); // persist before anything else
break;
}
}