]> _ Git - cubist_util.git/commitdiff
#7232
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 1 Apr 2025 10:28:04 +0000 (12:28 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 1 Apr 2025 10:28:04 +0000 (12:28 +0200)
src/YoutubeDL.php

index 4cc0a4eae2544dfc07d7c3d27bfad7454fe995d8..38fce1ef1bd890bce55af1bda40e77316e5681e6 100644 (file)
@@ -31,8 +31,7 @@ class YoutubeDL
     {
         $ext = $onlyAudio ? 'mp3' : 'mp4';
 
-        $cli = new CommandLine('/usr/local/bin/yt-dlp');
-        $cli->setArg('cache-dir', storage_path('cache/youtubedl'));
+        $cli = static::_getCli();
         $cli->setArg('format', $format);
         $cli->setArg('extractor-args', 'youtube:player_client=web,default,-ios');
         if ($onlyAudio) {
@@ -40,10 +39,6 @@ class YoutubeDL
             $cli->setArg('audio-format', 'mp3');
             $cli->setArg('audio-quality', '0');
         }
-        if (null !== static::$_cookiesFile) {
-            $cli->setArg('cookies', static::$_cookiesFile);
-        }
-
         $cacheKey = hash('sha256', $url . "-" . $cli->hashArgs());
         $fname = $cacheKey . '.' . $ext;
         $file = Files::mkdir($path) . $fname;
@@ -55,7 +50,28 @@ class YoutubeDL
         }
         if (!file_exists($file)) {
             $cli->debug();
+
+
+            $cli = static::_getCli();
+            $cli->setArg('list-formats');
+            $cli->setArg(null, $url);
+            $cli->execute();
+            $cli->debug();
         }
         return $file;
     }
+
+    /**
+     * @return CommandLine
+     */
+    protected static function _getCli()
+    {
+        $cli = new CommandLine('/usr/local/bin/yt-dlp');
+        $cli->setArg('cache-dir', storage_path('cache/youtubedl'));
+        if (null !== static::$_cookiesFile) {
+            $cli->setArg('cookies', static::$_cookiesFile);
+        }
+        return $cli;
+
+    }
 }
\ No newline at end of file