]> _ Git - cubist_util.git/commitdiff
wip #7232 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 16 Dec 2024 14:41:27 +0000 (15:41 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 16 Dec 2024 14:41:27 +0000 (15:41 +0100)
src/YoutubeDL.php

index 181e97275b9e3ebdd3ba307550c6bb7d99d0052c..8770df021df6849b0e6e6e65707ef51ff44ab1d8 100644 (file)
@@ -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;
     }