Refactor getter classes
This commit is contained in:
parent
5de8e9d8cc
commit
9ad024888a
1 changed files with 29 additions and 54 deletions
|
@ -48,47 +48,11 @@ class VideoDownload
|
||||||
return explode(PHP_EOL, trim($process->getOutput()));
|
return explode(PHP_EOL, trim($process->getOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function getProp($url, $format = null, $prop = 'dump-json')
|
||||||
* Get all information about a video.
|
|
||||||
*
|
|
||||||
* @param string $url URL of page
|
|
||||||
* @param string $format Format to use for the video
|
|
||||||
*
|
|
||||||
* @return object Decoded JSON
|
|
||||||
* */
|
|
||||||
public function getJSON($url, $format = null)
|
|
||||||
{
|
{
|
||||||
$this->procBuilder->setArguments(
|
$this->procBuilder->setArguments(
|
||||||
[
|
[
|
||||||
'--dump-json',
|
'--'.$prop,
|
||||||
$url,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
if (isset($format)) {
|
|
||||||
$this->procBuilder->add('-f '.$format);
|
|
||||||
}
|
|
||||||
$process = $this->procBuilder->getProcess();
|
|
||||||
$process->run();
|
|
||||||
if (!$process->isSuccessful()) {
|
|
||||||
throw new \Exception($process->getErrorOutput());
|
|
||||||
} else {
|
|
||||||
return json_decode($process->getOutput());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get URL of video from URL of page.
|
|
||||||
*
|
|
||||||
* @param string $url URL of page
|
|
||||||
* @param string $format Format to use for the video
|
|
||||||
*
|
|
||||||
* @return string URL of video
|
|
||||||
* */
|
|
||||||
public function getURL($url, $format = null)
|
|
||||||
{
|
|
||||||
$this->procBuilder->setArguments(
|
|
||||||
[
|
|
||||||
'--get-url',
|
|
||||||
$url,
|
$url,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -104,6 +68,32 @@ class VideoDownload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all information about a video.
|
||||||
|
*
|
||||||
|
* @param string $url URL of page
|
||||||
|
* @param string $format Format to use for the video
|
||||||
|
*
|
||||||
|
* @return object Decoded JSON
|
||||||
|
* */
|
||||||
|
public function getJSON($url, $format = null)
|
||||||
|
{
|
||||||
|
return json_decode($this->getProp($url, $format, 'dump-json'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get URL of video from URL of page.
|
||||||
|
*
|
||||||
|
* @param string $url URL of page
|
||||||
|
* @param string $format Format to use for the video
|
||||||
|
*
|
||||||
|
* @return string URL of video
|
||||||
|
* */
|
||||||
|
public function getURL($url, $format = null)
|
||||||
|
{
|
||||||
|
return $this->getProp($url, $format, 'get-url');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get filename of video file from URL of page.
|
* Get filename of video file from URL of page.
|
||||||
*
|
*
|
||||||
|
@ -114,22 +104,7 @@ class VideoDownload
|
||||||
* */
|
* */
|
||||||
public function getFilename($url, $format = null)
|
public function getFilename($url, $format = null)
|
||||||
{
|
{
|
||||||
$this->procBuilder->setArguments(
|
return trim($this->getProp($url, $format, 'get-filename'));
|
||||||
[
|
|
||||||
'--get-filename',
|
|
||||||
$url,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
if (isset($format)) {
|
|
||||||
$this->procBuilder->add('-f '.$format);
|
|
||||||
}
|
|
||||||
$process = $this->procBuilder->getProcess();
|
|
||||||
$process->run();
|
|
||||||
if (!$process->isSuccessful()) {
|
|
||||||
throw new \Exception($process->getErrorOutput());
|
|
||||||
} else {
|
|
||||||
return trim($process->getOutput());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue