From efe0b97d7f3c6f5f4933751946671f6cc44de218 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Thu, 20 Oct 2016 23:13:37 +0200 Subject: [PATCH] Support audio conversion of password protected videos --- classes/VideoDownload.php | 18 ++++++++++-------- controllers/FrontController.php | 10 ++++++---- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index fb8db32..e727414 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -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( diff --git a/controllers/FrontController.php b/controllers/FrontController.php index f6d7e02..5a2cdd2 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -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)); }