Support audio conversion of password protected videos

This commit is contained in:
Pierre Rudloff 2016-10-20 23:13:37 +02:00
parent 75ddf27a95
commit efe0b97d7f
2 changed files with 16 additions and 12 deletions

View file

@ -154,16 +154,17 @@ class VideoDownload
/**
* Get filename of audio from URL of page.
*
* @param string $url URL of page
* @param string $format Format to use for the video
* @param string $url URL of page
* @param string $format Format to use for the video
* @param string $password Video password
*
* @return string Filename of converted audio file
* */
public function getAudioFilename($url, $format = null)
public function getAudioFilename($url, $format = null, $password = null)
{
return html_entity_decode(
pathinfo(
$this->getFilename($url, $format),
$this->getFilename($url, $format, $password),
PATHINFO_FILENAME
).'.mp3',
ENT_COMPAT,
@ -258,18 +259,19 @@ class VideoDownload
/**
* Get audio stream of converted video.
*
* @param string $url URL of page
* @param string $format Format to use for the video
* @param string $url URL of page
* @param string $format Format to use for the video
* @param string $password Video password
*
* @return resource popen stream
*/
public function getAudioStream($url, $format)
public function getAudioStream($url, $format, $password = null)
{
if (!shell_exec('which '.$this->config->avconv)) {
throw(new \Exception('Can\'t find avconv or ffmpeg'));
}
$video = $this->getJSON($url, $format);
$video = $this->getJSON($url, $format, $password);
//Vimeo needs a correct user-agent
ini_set(

View file

@ -143,19 +143,21 @@ class FrontController
}
if (isset($params['audio'])) {
try {
$url = $this->download->getURL($params['url'], 'mp3[protocol^=http]');
$url = $this->download->getURL($params['url'], 'mp3[protocol^=http]', $password);
return $response->withRedirect($url);
} catch (PasswordException $e) {
return $this->password($request, $response);
} catch (\Exception $e) {
$response = $response->withHeader(
'Content-Disposition',
'attachment; filename="'.
$this->download->getAudioFilename($params['url'], 'bestaudio/best').'"'
$this->download->getAudioFilename($params['url'], 'bestaudio/best', $password).'"'
);
$response = $response->withHeader('Content-Type', 'audio/mpeg');
if ($request->isGet()) {
$process = $this->download->getAudioStream($params['url'], 'bestaudio/best');
if ($request->isGet() || $request->isPost()) {
$process = $this->download->getAudioStream($params['url'], 'bestaudio/best', $password);
$response = $response->withBody(new Stream($process));
}