From: Vincent Vanwaelscappel Date: Mon, 16 Dec 2024 14:41:27 +0000 (+0100) Subject: wip #7232 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=e7a5220ef0267b34c6794ce637a0f317f59c207b;p=cubist_util.git wip #7232 @1.5 --- diff --git a/src/YoutubeDL.php b/src/YoutubeDL.php index 181e972..8770df0 100644 --- a/src/YoutubeDL.php +++ b/src/YoutubeDL.php @@ -8,6 +8,13 @@ use YoutubeDl\Options; class YoutubeDL { + protected static $_cookiesFile = null; + + public static function setCookiesFile($cookieFile) + { + static::$_cookiesFile = $cookieFile; + } + public static function downloadVideo($url, $path) { return self::_download($url, $path); @@ -28,6 +35,10 @@ class YoutubeDL ->format('bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4') ->url($url); + if (null !== static::$_cookiesFile) { + $options = $options->cookies(static::$_cookiesFile); + } + if ($onlyAudio) { $ext = 'mp3'; $options = $options->extractAudio(true) @@ -43,7 +54,16 @@ class YoutubeDL if (!file_exists($file)) { $yt = new \YoutubeDl\YoutubeDl(); $yt->setBinPath('/usr/local/bin/yt-dlp'); - $yt->download($options); + $collection = $yt->download($options); + + foreach ($collection->getVideos() as $video) { + if ($video->getError() !== null) { + Log::debug("Error downloading video: {$video->getError()}."); + } else { + $video->getFile(); + } + } + } return $file; }