File size: 1,032 Bytes
db675ed d87ce4b a2430c9 7428675 bf1c8f2 d87ce4b bf1c8f2 d87ce4b bf1c8f2 a2430c9 d87ce4b bf1c8f2 d87ce4b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<?php
require __DIR__ . '/vendor/autoload.php';
use YoutubeDl\YoutubeDl;
use YoutubeDl\Process\ProcessBuilder;
use YoutubeDl\Options;
// URLパラメータ確認
if (empty($_GET['url'])) {
exit('URLを指定してください');
}
$url = $_GET['url'];
try {
// yt-dlp のパスに合わせて指定(Dockerfile で /usr/local/bin に入れたなら OK)
$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());
}
|