";
} else {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
if ($username === $correct_username && $password === $correct_password) {
$_SESSION['logged_in'] = true;
echo "Login successful. Welcome!";
header("Location: " . $_SERVER['PHP_SELF']);
exit;
} else {
echo "Invalid username or password.
";
}
}
echo '';
exit();
}
?>
...
Manual
$id,
'title' => $title,
'uploader' => $uploader,
'file' => $newName,
'uploaded' => date('c'),
'url' => $fileUrl,
'waybackurl'=> $waybackUrl ?: "https://web.archive.org/web/*/$fileUrl",
];
$list[] = $entry;
file_put_contents(JSON_FILE, json_encode($list, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), LOCK_EX);
echo "OK
Saved as: {$newName}
YouTube ID: {$id}
Title: {$title}
Uploader: {$uploader}
";
echo "URL: {$fileUrl}
";
if ($archiveSuccess) {
echo "Wayback Machine archive triggered successfully.
";
if ($waybackUrl) {
echo "Archived URL: {$waybackUrl}
";
} else {
echo "Waiting for archive to appear. FixLink
";
}
} else {
echo "Could not trigger automatic archiving. FixLink
";
echo "You can archive manually: Save on Wayback Machine
";
}
exit;
}
function handleFileUpload($file): string {
if ($file['size'] > MAX_SIZE) exit('File too large.');
if (mime_content_type($file['tmp_name']) !== 'video/mp4') exit('Not an MP4.');
$safeName = preg_replace('/[^A-Za-z0-9_\-\.]/', '_', $file['name']);
$dst = __DIR__ . DIRECTORY_SEPARATOR . $safeName;
if (!move_uploaded_file($file['tmp_name'], $dst)) exit('Move failed.');
return $dst;
}
function handleUrlDownloadContent(string $content, string $filename): string {
$dst = __DIR__ . DIRECTORY_SEPARATOR . $filename;
if (file_put_contents($dst, $content) === false) exit('Failed to save the downloaded file.');
return $dst;
}
function yt_api(string $url): array {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
]);
$json = curl_exec($ch);
curl_close($ch);
return json_decode($json, true) ?: [];
}
function try_wayback_save(string $url): bool {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
]);
curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return in_array($httpCode, [200, 302]);
}
function get_wayback_timestamped_url(string $url): ?string {
$api = 'https://archive.org/wayback/available?url=' . rawurlencode($url);
$json = file_get_contents($api);
if (!$json) return null;
$data = json_decode($json, true);
if (isset($data['archived_snapshots']['closest']['timestamp'])) {
$ts = $data['archived_snapshots']['closest']['timestamp'];
return "https://web.archive.org/web/{$ts}/{$url}";
}
return null;
}
?>
Upload MP4
Move mp4