refactor: Don't mix static and dynamic methods

This commit is contained in:
Pierre Rudloff 2019-04-21 18:49:05 +02:00
parent 06a631c892
commit 51eaf192b1

View file

@ -42,7 +42,7 @@ class Video
/** /**
* Password. * Password.
* *
* @var string * @var string|null
*/ */
private $password; private $password;
@ -68,7 +68,7 @@ class Video
* *
* @return Process * @return Process
*/ */
private function getProcess(array $arguments) private static function getProcess(array $arguments)
{ {
$config = Config::getInstance(); $config = Config::getInstance();
@ -88,41 +88,24 @@ class Video
* */ * */
public static function getExtractors() 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 PasswordException If the video is protected by a password and no password was specified
* @throws Exception If the password is wrong * @throws Exception If the password is wrong
* @throws Exception If youtube-dl returns an error * @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(); $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); $process = self::getProcess($arguments);
//This is needed by the openload extractor because it runs PhantomJS //This is needed by the openload extractor because it runs PhantomJS
$process->setEnv(['PATH'=>$config->phantomjsDir]); $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. * Get all information about a video.
* *