/* This file is part of Freedom Loader. Copyright (C) 2025 MasterAcnolo Freedom Loader is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License. Freedom Loader is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ function formatDate(dateStr) { if (!dateStr || dateStr.length !== 8) return "Inconnue"; return `${dateStr.slice(6,8)}/${dateStr.slice(4,6)}/${dateStr.slice(0,4)}`; } function formatSize(bytes) { return bytes ? (bytes / (1024*1024)).toFixed(2) + " Mo" : "Inconnue"; } async function fetchVideoInfo(url) { try { const res = await fetch("/info", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ url }), }); if (!res.ok) return { error: `Erreur serveur: ${res.status}` }; const data = await res.json(); if (!data) return { error: "Données manquantes" }; return data; } catch (e) { return { error: "Erreur réseau ou JSON" }; } } document.addEventListener("DOMContentLoaded", () => { const urlInput = document.getElementById("UrlInput"); const infoDiv = document.getElementById("videoInfo"); let lastFetchedUrl = ""; urlInput.addEventListener("input", async () => { const url = urlInput.value.trim(); if (!url || url.length < 5) { infoDiv.innerHTML = ""; infoDiv.classList.remove("visible"); lastFetchedUrl = ""; return; } if (url === lastFetchedUrl) return; lastFetchedUrl = url; const data = await fetchVideoInfo(url); if (data.error) { infoDiv.innerHTML = `❌ ${data.error}`; infoDiv.classList.remove("visible"); return; } // Playlist if (data.type === "playlist") { infoDiv.innerHTML = `

Playlist détectée – ${data.count} vidéos

${data.title}

Channel : ${data.channel || "Inconnu"}

`; const listDiv = document.getElementById("playlistVideos"); data.videos.forEach(v => { const durationStr = `${Math.floor(v.duration/60)}m ${(v.duration%60).toString().padStart(2,"0")}s`; listDiv.innerHTML += `
Thumbnail

${v.title}

Durée : ${durationStr}

URL : ${v.webpage_url}

`; }); infoDiv.classList.add("visible"); return; } // Vidéo normale const durationStr = `${Math.floor(data.duration/60)}m ${(data.duration%60) .toString() .padStart(2,"0")}s`; const sizeStr = formatSize(data.filesize_approx); const readableDate = formatDate(data.upload_date); const categories = data.categories?.join(", ") || "Non spécifiées"; infoDiv.innerHTML = `

${data.title}

Thumbnail `; infoDiv.classList.add("visible"); }); })