From a2e46e6aa2980755664803e7d08fabd2c8ea2c1c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 1 Apr 2025 12:28:04 +0200 Subject: [PATCH] #7232 --- src/YoutubeDL.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/YoutubeDL.php b/src/YoutubeDL.php index 4cc0a4e..38fce1e 100644 --- a/src/YoutubeDL.php +++ b/src/YoutubeDL.php @@ -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 -- 2.39.5