$id, 'title' => $snippet['title'], 'uploader' => $snippet['channelTitle'], 'file' => "{$id}.mp4", 'uploaded' => $ts, 'url' => $url, 'waybackurl' => "https://web.archive.org/web/{$wb}/{$url}" ]; } function appendToJson(array $obj, string $file = 'videos.json'): void { $list = []; if (file_exists($file) && filesize($file) > 0) { $raw = file_get_contents($file); $list = json_decode($raw, true) ?? []; } $list[] = $obj; $json = json_encode($list, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); $fp = fopen($file, 'c+'); if (!$fp) throw new RuntimeException('Cannot open videos.json'); flock($fp, LOCK_EX); ftruncate($fp, 0); fwrite($fp, $json); fflush($fp); flock($fp, LOCK_UN); fclose($fp); } try { $url = $_POST['url'] ?? null; $apikey = $_POST['apikey'] ?? null; $app = isset($_POST['appwend']); if (!$url || !$apikey) throw new Exception('Missing url or apikey'); $id = extractVideoId($url); if (!$id) throw new Exception('Invalid YouTube URL'); $data = buildObject($id, fetchYoutubeData($id, $apikey)); if ($app) appendToJson($data); echo json_encode(['success' => true, 'data' => $data]); } catch (Throwable $e) { echo json_encode(['success' => false, 'error' => $e->getMessage()]); } exit; } ?> YouTube Metadata App

YouTube Metadata Generator



Generated JSON: