Repository Public
1import { fetchText } from "../ssrf";23// ARTE (arte.tv). Programmes are watched inside ARTE's own embedded player (https://www.arte.tv/embeds/fr/{id}), only4// when ARTE's player configuration says the programme may be embedded, is available where this server is, and its5// rights are current. Nothing is taken out of the player. The catalogue rotates: every title carries its end date.6const PAGES: [string, string, boolean][] = [["DOR", "Documentaires et reportages", true], ["CIN", "Cinéma", false], ["SES", "Séries", false], ["FLM", "Films", false], ["SCI", "Sciences", true], ["HIS", "Histoire", true], ["DEC", "Voyages et découvertes", true], ["ACT", "Info et société", true], ["CPO", "Culture et pop", true]];7const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));8let last = 0;9async function json<T>(url: string): Promise<T> { const w = last + 350 - Date.now(); if (w > 0) await sleep(w); last = Date.now(); return JSON.parse(await fetchText(url, 8 * 1024 * 1024, 40_000)) as T; }1011export interface ArteItem { programId: string; title: string; subtitle: string | null; duration: number | null; url: string; shortDescription?: string | null; teaserText?: string | null; kind?: { code?: string; isCollection?: boolean }; mainImage?: { url?: string } | null;12 episodeInfo?: { season?: number | null; episode?: number | null } | null; genre?: { label?: string } | null }13interface Page { zones?: { code?: string; content?: { data?: ArteItem[] } | null }[] }14export interface ArtePlay { ok: boolean; reason?: string; end: number | null; begin: number | null; duration: number | null; description: string | null; image: string | null }1516export async function listing(): Promise<{ item: ArteItem; section: string; documentary: boolean }[]> {17 const out = new Map<string, { item: ArteItem; section: string; documentary: boolean }>();18 for (const [code, section, documentary] of PAGES) {19 let page: Page; try { page = await json<Page>(`https://api.arte.tv/api/emac/v4/fr/web/pages/${code}/`); } catch { continue; }20 for (const z of page.zones ?? []) for (const it of z.content?.data ?? []) if (it.programId && it.title && !out.has(it.programId)) out.set(it.programId, { item: it, section, documentary });21 }22 return [...out.values()];23}24export async function collection(id: string): Promise<ArteItem[]> {25 const page = await json<Page>(`https://api.arte.tv/api/emac/v4/fr/web/collections/${encodeURIComponent(id)}/`);26 return (page.zones ?? []).filter((z) => (z.code ?? "").startsWith("collection_videos")).flatMap((z) => z.content?.data ?? []).filter((x) => x.programId && x.kind?.code !== "TV_SERIES" && !x.kind?.isCollection);27}28/** ARTE's own answer to « may this be played, embedded, here, now? ». */29export async function playable(id: string): Promise<ArtePlay> {30 interface Cfg { data?: { attributes?: { error?: unknown; rights?: { begin?: string; end?: string } | null; restriction?: { allowEmbed?: boolean; geoblocking?: { restrictedArea?: boolean } } | null; streams?: unknown[]; metadata?: { description?: string; duration?: { seconds?: number }; images?: { url?: string }[] } } } }31 const a = (await json<Cfg>(`https://api.arte.tv/api/player/v2/config/fr/${encodeURIComponent(id)}`)).data?.attributes;32 const end = a?.rights?.end ? Date.parse(a.rights.end) : null, begin = a?.rights?.begin ? Date.parse(a.rights.begin) : null;33 const base = { end, begin, duration: a?.metadata?.duration?.seconds ?? null, description: a?.metadata?.description ?? null, image: a?.metadata?.images?.[0]?.url ?? null };34 if (!a || a.error) return { ok: false, reason: "indisponible", ...base };35 if (!a.streams?.length) return { ok: false, reason: "aucun flux", ...base };36 if (a.restriction?.allowEmbed === false) return { ok: false, reason: "intégration non autorisée", ...base };37 if (a.restriction?.geoblocking?.restrictedArea) return { ok: false, reason: "non disponible dans ce pays", ...base };38 if ((end && end < Date.now()) || (begin && begin > Date.now())) return { ok: false, reason: "hors période de droits", ...base };39 return { ok: true, ...base };40}41export const embedUrl = (id: string) => `https://www.arte.tv/embeds/fr/${encodeURIComponent(id)}`;42export const img = (url: string | undefined | null, size: string) => (url ? url.replace("__SIZE__", size) : null);43