From f670629d49906f3238f7f5ff4515186bc783bc5f Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Thu, 17 Dec 2020 22:45:50 +0100 Subject: [PATCH 1/3] Add return types --- classes/Downloader.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/classes/Downloader.php b/classes/Downloader.php index ee810eb..2b0b4f9 100644 --- a/classes/Downloader.php +++ b/classes/Downloader.php @@ -115,7 +115,7 @@ class Downloader * @param string|null $password Password * @return Video */ - public function getVideo(string $webpageUrl, $requestedFormat = 'best/bestvideo', string $password = null) + public function getVideo(string $webpageUrl, $requestedFormat = 'best/bestvideo', string $password = null): Video { return new Video($this, $webpageUrl, $requestedFormat, $password); } @@ -127,7 +127,7 @@ class Downloader * * @return Process */ - private function getProcess(array $arguments) + private function getProcess(array $arguments): Process { return new Process( array_merge( @@ -145,7 +145,7 @@ class Downloader * * @return bool False if the command returns an error, true otherwise */ - public static function checkCommand(array $command) + public static function checkCommand(array $command): bool { $process = new Process($command); $process->run(); @@ -178,7 +178,7 @@ class Downloader $audioOnly = true, string $from = null, string $to = null - ) { + ): Process { if (!$this->checkCommand([$this->avconv, '-version'])) { throw new AvconvException($this->avconv); } @@ -246,7 +246,7 @@ class Downloader * @throws YoutubedlException If youtube-dl returns an error * @throws PasswordException If the video is protected by a password and no password was specified */ - public function callYoutubedl(array $arguments) + public function callYoutubedl(array $arguments): string { $process = $this->getProcess($arguments); //This is needed by the openload extractor because it runs PhantomJS @@ -468,7 +468,7 @@ class Downloader * * @throws AlltubeLibraryException */ - public function getExtractors() + public function getExtractors(): array { return explode("\n", trim($this->callYoutubedl(['--list-extractors']))); } @@ -484,7 +484,7 @@ class Downloader * @throws AlltubeLibraryException * @link https://github.com/guzzle/guzzle/issues/2640 */ - public function getHttpResponse(Video $video, array $headers = []) + public function getHttpResponse(Video $video, array $headers = []): ResponseInterface { // IDN conversion breaks with Google hosts like https://r3---sn-25glene6.googlevideo.com/. $client = new Client(['idn_conversion' => false]); From 4977f997976ed506759d84e74efc0c5726e33217 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Mon, 8 Feb 2021 22:03:09 +0100 Subject: [PATCH 2/3] Use LoggerAwareTrait Instead of implementing setLogger() ourselves --- classes/Downloader.php | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/classes/Downloader.php b/classes/Downloader.php index 2b0b4f9..12b1d7d 100644 --- a/classes/Downloader.php +++ b/classes/Downloader.php @@ -15,15 +15,17 @@ use Alltube\Library\Exception\WrongPasswordException; use Alltube\Library\Exception\YoutubedlException; use GuzzleHttp\Client; use Psr\Http\Message\ResponseInterface; -use Psr\Log\LoggerInterface; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; use Symfony\Component\Process\Process; /** * Class used to call youtube-dl and download videos. */ -class Downloader +class Downloader implements LoggerAwareInterface { + use LoggerAwareTrait; /** * youtube-dl binary path. @@ -68,11 +70,6 @@ class Downloader */ private $params; - /** - * @var LoggerInterface - */ - private $logger; - /** * Downloader constructor. * @param string $youtubedl youtube-dl binary path @@ -100,15 +97,6 @@ class Downloader $this->logger = new NullLogger(); } - /** - * @param LoggerInterface $logger - * @return void - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - /** * @param string $webpageUrl URL of the page containing the video * @param string $requestedFormat Requested video format From a0548ea473748b10f6146ba8f029e2947b332a46 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 5 May 2021 20:56:42 +0200 Subject: [PATCH 3/3] Don't set stream context manually Guzzle already takes care of that --- classes/Downloader.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/classes/Downloader.php b/classes/Downloader.php index 12b1d7d..bae6a19 100644 --- a/classes/Downloader.php +++ b/classes/Downloader.php @@ -477,22 +477,12 @@ class Downloader implements LoggerAwareInterface // IDN conversion breaks with Google hosts like https://r3---sn-25glene6.googlevideo.com/. $client = new Client(['idn_conversion' => false]); $urls = $video->getUrl(); - $stream_context_options = []; - - if (array_key_exists('Referer', (array)$video->http_headers)) { - $stream_context_options = [ - 'http' => [ - 'header' => 'Referer: ' . $video->http_headers->Referer - ] - ]; - } return $client->request( 'GET', $urls[0], [ 'stream' => true, - 'stream_context' => $stream_context_options, 'headers' => array_merge((array)$video->http_headers, $headers) ] );