Use bestaudio if available

This commit is contained in:
Pierre Rudloff 2016-04-10 19:41:25 +02:00
parent 39205ebe45
commit 442e2ec87c

View file

@ -112,60 +112,65 @@ class FrontController
if (isset($params["url"])) { if (isset($params["url"])) {
if (isset($params['audio'])) { if (isset($params['audio'])) {
try { try {
$video = $this->download->getJSON($params["url"]); try {
$url = $this->download->getURL($params["url"], 'bestaudio');
return $response->withRedirect($url);
} catch (\Exception $e) {
$video = $this->download->getJSON($params["url"]);
//Vimeo needs a correct user-agent //Vimeo needs a correct user-agent
ini_set( ini_set(
'user_agent', 'user_agent',
$video->http_headers->{'User-Agent'} $video->http_headers->{'User-Agent'}
);
$url_info = parse_url($video->url);
if ($url_info['scheme'] == 'rtmp') {
ob_end_flush();
header(
'Content-Disposition: attachment; filename="'.
html_entity_decode(
pathinfo(
$this->download->getFilename(
$video->webpage_url
),
PATHINFO_FILENAME
).'.mp3',
ENT_COMPAT,
'ISO-8859-1'
).'"'
); );
header("Content-Type: audio/mpeg"); $url_info = parse_url($video->url);
passthru( if ($url_info['scheme'] == 'rtmp') {
'/usr/bin/rtmpdump -q -r '.escapeshellarg($video->url). ob_end_flush();
' | '.$this->config->avconv. header(
' -v quiet -i - -f mp3 -vn pipe:1' 'Content-Disposition: attachment; filename="'.
); html_entity_decode(
exit; pathinfo(
} else { $this->download->getFilename(
ob_end_flush(); $video->webpage_url
header( ),
'Content-Disposition: attachment; filename="'. PATHINFO_FILENAME
html_entity_decode( ).'.mp3',
pathinfo( ENT_COMPAT,
$this->download->getFilename( 'ISO-8859-1'
$video->webpage_url ).'"'
), );
PATHINFO_FILENAME header("Content-Type: audio/mpeg");
).'.mp3', passthru(
ENT_COMPAT, '/usr/bin/rtmpdump -q -r '.escapeshellarg($video->url).
'ISO-8859-1' ' | '.$this->config->avconv.
).'"' ' -v quiet -i - -f mp3 -vn pipe:1'
); );
header("Content-Type: audio/mpeg"); exit;
passthru( } else {
'curl '.$this->config->curl_params. ob_end_flush();
' --user-agent '.escapeshellarg($video->http_headers->{'User-Agent'}). header(
' '.escapeshellarg($video->url). 'Content-Disposition: attachment; filename="'.
' | '.$this->config->avconv. html_entity_decode(
' -v quiet -i - -f mp3 -vn pipe:1' pathinfo(
); $this->download->getFilename(
exit; $video->webpage_url
),
PATHINFO_FILENAME
).'.mp3',
ENT_COMPAT,
'ISO-8859-1'
).'"'
);
header("Content-Type: audio/mpeg");
passthru(
'curl '.$this->config->curl_params.
' --user-agent '.escapeshellarg($video->http_headers->{'User-Agent'}).
' '.escapeshellarg($video->url).
' | '.$this->config->avconv.
' -v quiet -i - -f mp3 -vn pipe:1'
);
exit;
}
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$error = $e->getMessage(); $error = $e->getMessage();