From ca6935643f9341b13e9b3f0eb8e9e473589f2c1d Mon Sep 17 00:00:00 2001 From: CU-Jon <111065910+CU-Jon@users.noreply.github.com> Date: Sat, 24 May 2025 19:00:47 -0400 Subject: [PATCH] Update Downloader.php YouTube doesn't like us anymore. Modify the command to use POT - see: https://github.com/yt-dlp/yt-dlp/wiki/PO-Token-Guide --- class/Downloader.php | 50 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/class/Downloader.php b/class/Downloader.php index 85ed443..3deecfd 100644 --- a/class/Downloader.php +++ b/class/Downloader.php @@ -269,7 +269,7 @@ private function check_outuput_folder() } - private function do_download($audio_only) +/* private function do_download($audio_only) { $cmd = $this->config["bin"]; $cmd .= " --ignore-error -o ".$this->download_path."/"; @@ -302,6 +302,54 @@ private function do_download($audio_only) $cmd .= " & echo $!"; shell_exec($cmd); + } */ + + // Modify the command to use POT + private function do_download($audio_only) + { + $cmd = $this->config["bin"]; + $cmd .= " --ignore-error -o ".$this->download_path."/"; + $cmd .= escapeshellarg($this->outfilename); + + if ($this->vformat) + { + $cmd .= " --format "; + $cmd .= escapeshellarg($this->vformat); + } + if($audio_only) + { + $cmd .= " -x "; + } + $cmd .= " --restrict-filenames"; // --restrict-filenames is for specials chars + + // Prepare generate_once.js path in the same directory as bin + $binPath = $this->config["bin"]; + $binDir = dirname($binPath); + $generateOnceJSPath = $binDir . '/bgutil-ytdlp-pot-provider/server/build/generate_once.js'; + + foreach($this->urls as $url) + { + $cmdForUrl = $cmd; + if (strpos($url, 'youtube.com') !== false || strpos($url, 'youtu.be') !== false) { + $cmdForUrl .= ' --extractor-args '; + $cmdForUrl .= '"youtube:getpot_bgutil_script=' . $generateOnceJSPath . '"'; + } + $cmdForUrl .= " ".escapeshellarg($url); + + if($this->config["log"]) + { + $cmdForUrl = "{ echo Command: ".escapeshellarg($cmdForUrl)."; ".$cmdForUrl." ; }"; + $cmdForUrl .= " > ".$this->log_path."/$(date +\"%Y-%m-%d_%H-%M-%S-%N\").txt"; + } + else + { + $cmdForUrl .= " > /dev/null "; + } + + $cmdForUrl .= " & echo $!"; + + shell_exec($cmdForUrl); + } } private function do_info()