refactor: Simplify getAvconvProcess()

This commit is contained in:
Pierre Rudloff 2018-07-03 20:09:45 +02:00
parent 159ea245a8
commit cb7c21164b

View file

@ -222,6 +222,7 @@ class VideoDownload
{ {
$arguments = []; $arguments = [];
if ($video->protocol == 'rtmp') {
foreach ([ foreach ([
'url' => '-rtmp_tcurl', 'url' => '-rtmp_tcurl',
'webpage_url' => '-rtmp_pageurl', 'webpage_url' => '-rtmp_pageurl',
@ -242,6 +243,7 @@ class VideoDownload
$arguments[] = $conn; $arguments[] = $conn;
} }
} }
}
return $arguments; return $arguments;
} }
@ -289,26 +291,20 @@ class VideoDownload
$durationRegex = '/(\d+:)?(\d+:)?(\d+)/'; $durationRegex = '/(\d+:)?(\d+:)?(\d+)/';
if ($video->protocol == 'rtmp') { $afterArguments = [];
$beforeArguments = $this->getRtmpArguments($video);
} else {
$beforeArguments = [];
}
if ($audioOnly) { if ($audioOnly) {
$afterArguments = ['-vn']; $afterArguments[] = '-vn';
} else {
$afterArguments = [];
} }
if (isset($from) && !empty($from)) { if (!empty($from)) {
if (!preg_match($durationRegex, $from)) { if (!preg_match($durationRegex, $from)) {
throw new Exception(_('Invalid start time: ').$from.'.'); throw new Exception(_('Invalid start time: ').$from.'.');
} }
$afterArguments[] = '-ss'; $afterArguments[] = '-ss';
$afterArguments[] = $from; $afterArguments[] = $from;
} }
if (isset($to) && !empty($to)) { if (!empty($to)) {
if (!preg_match($durationRegex, $to)) { if (!preg_match($durationRegex, $to)) {
throw new Exception(_('Invalid end time: ').$to.'.'); throw new Exception(_('Invalid end time: ').$to.'.');
} }
@ -321,7 +317,7 @@ class VideoDownload
$this->config->avconv, $this->config->avconv,
'-v', $this->config->avconvVerbosity, '-v', $this->config->avconvVerbosity,
], ],
$beforeArguments, $this->getRtmpArguments($video),
[ [
'-i', $video->url, '-i', $video->url,
'-f', $filetype, '-f', $filetype,