|
<?php |
|
require __DIR__ . '/vendor/autoload.php'; |
|
|
|
|
|
use YoutubeDl\YoutubeDl; |
|
use YoutubeDl\Process\ProcessBuilder; |
|
use YoutubeDl\Options; |
|
|
|
|
|
if (empty($_GET['url'])) { |
|
exit('URLを指定してください'); |
|
} |
|
|
|
$url = $_GET['url']; |
|
|
|
try { |
|
|
|
$yt = new YoutubeDl(new ProcessBuilder('/usr/local/bin/yt-dlp')); |
|
|
|
$collection = $yt->download( |
|
Options::create() |
|
->url($url) |
|
->noPlaylist() // プレイリスト無効化 |
|
->extractAudio(false) |
|
); |
|
|
|
$video = $collection->getVideos()[0]; |
|
if ($video->getError()) { |
|
throw new \Exception($video->getError()); |
|
} |
|
|
|
$filename = basename($video->getTitle()) . '.mp4'; |
|
|
|
header('Content-Type: video/mp4'); |
|
header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
|
|
readfile($video->getFile()); |
|
|
|
} catch (Exception $e) { |
|
exit('エラー: ' . $e->getMessage()); |
|
} |
|
|