From 51eaf192b1be422352de7afa732cf4922c5f9c7e Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 21 Apr 2019 18:49:05 +0200 Subject: [PATCH] refactor: Don't mix static and dynamic methods --- classes/Video.php | 57 +++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/classes/Video.php b/classes/Video.php index 9c60a4b..f1247e5 100644 --- a/classes/Video.php +++ b/classes/Video.php @@ -42,7 +42,7 @@ class Video /** * Password. * - * @var string + * @var string|null */ private $password; @@ -68,7 +68,7 @@ class Video * * @return Process */ - private function getProcess(array $arguments) + private static function getProcess(array $arguments) { $config = Config::getInstance(); @@ -88,41 +88,24 @@ class Video * */ public static function getExtractors() { - return explode("\n", trim(self::getProp('list-extractors'))); + return explode("\n", trim(self::callYoutubedl(['--list-extractors']))); } /** - * Get a property from youtube-dl. + * Call youtube-dl. * - * @param string $prop Property + * @param array $arguments Arguments * * @throws PasswordException If the video is protected by a password and no password was specified * @throws Exception If the password is wrong * @throws Exception If youtube-dl returns an error * - * @return string + * @return string Result */ - private function getProp($prop = 'dump-json') + private static function callYoutubedl(array $arguments) { $config = Config::getInstance(); - $arguments = ['--'.$prop]; - - // This function can also be called statically. - if (isset($this)) { - if (isset($this->webpageUrl)) { - $arguments[] = $this->webpageUrl; - } - if (isset($this->requestedFormat)) { - $arguments[] = '-f'; - $arguments[] = $this->requestedFormat; - } - if (isset($this->password)) { - $arguments[] = '--video-password'; - $arguments[] = $this->password; - } - } - $process = self::getProcess($arguments); //This is needed by the openload extractor because it runs PhantomJS $process->setEnv(['PATH'=>$config->phantomjsDir]); @@ -143,6 +126,32 @@ class Video } } + /** + * Get a property from youtube-dl. + * + * @param string $prop Property + * + * @return string + */ + private function getProp($prop = 'dump-json') + { + $arguments = ['--'.$prop]; + + if (isset($this->webpageUrl)) { + $arguments[] = $this->webpageUrl; + } + if (isset($this->requestedFormat)) { + $arguments[] = '-f'; + $arguments[] = $this->requestedFormat; + } + if (isset($this->password)) { + $arguments[] = '--video-password'; + $arguments[] = $this->password; + } + + return $this::callYoutubedl($arguments); + } + /** * Get all information about a video. *