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,24 +222,26 @@ class VideoDownload
{ {
$arguments = []; $arguments = [];
foreach ([ if ($video->protocol == 'rtmp') {
'url' => '-rtmp_tcurl', foreach ([
'webpage_url' => '-rtmp_pageurl', 'url' => '-rtmp_tcurl',
'player_url' => '-rtmp_swfverify', 'webpage_url' => '-rtmp_pageurl',
'flash_version' => '-rtmp_flashver', 'player_url' => '-rtmp_swfverify',
'play_path' => '-rtmp_playpath', 'flash_version' => '-rtmp_flashver',
'app' => '-rtmp_app', 'play_path' => '-rtmp_playpath',
] as $property => $option) { 'app' => '-rtmp_app',
if (isset($video->{$property})) { ] as $property => $option) {
$arguments[] = $option; if (isset($video->{$property})) {
$arguments[] = $video->{$property}; $arguments[] = $option;
$arguments[] = $video->{$property};
}
} }
}
if (isset($video->rtmp_conn)) { if (isset($video->rtmp_conn)) {
foreach ($video->rtmp_conn as $conn) { foreach ($video->rtmp_conn as $conn) {
$arguments[] = '-rtmp_conn'; $arguments[] = '-rtmp_conn';
$arguments[] = $conn; $arguments[] = $conn;
}
} }
} }
@ -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,