From 2b316d4e8d429e15ae122ecfe57ec080494c7763 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 1 May 2018 16:28:33 +0200 Subject: [PATCH] fix: Throw an exception when trying to download DASH with ffmpeg Fallback to default format when we can't download bestaudio Fixes #165 --- classes/VideoDownload.php | 2 ++ controllers/FrontController.php | 6 +++++- tests/VideoDownloadTest.php | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index f022c31..636f550 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -327,6 +327,8 @@ class VideoDownload $video = $this->getJSON($url, $format, $password); if (in_array($video->protocol, ['m3u8', 'm3u8_native'])) { throw new Exception(_('Conversion of M3U8 files is not supported.')); + } elseif ($video->protocol == 'http_dash_segments') { + throw new Exception(_('Conversion of DASH segments is not supported.')); } $avconvProc = $this->getAvconvProcess($video, $this->config->audioBitrate); diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 0d8d78e..aa07473 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -228,7 +228,11 @@ class FrontController $response = $response->withHeader('Content-Type', 'audio/mpeg'); if ($request->isGet() || $request->isPost()) { - $process = $this->download->getAudioStream($params['url'], 'bestaudio/best', $password); + try { + $process = $this->download->getAudioStream($params['url'], 'bestaudio/best', $password); + } catch (Exception $e) { + $process = $this->download->getAudioStream($params['url'], $this->defaultFormat, $password); + } $response = $response->withBody(new Stream($process)); } diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index be15afd..2b576ac 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -406,6 +406,17 @@ class VideoDownloadTest extends TestCase $this->download->getAudioStream($url, $format); } + /** + * Test getAudioStream function with a DASH URL. + * + * @return void + * @expectedException Exception + */ + public function testGetAudioStreamDashError() + { + $this->download->getAudioStream('https://vimeo.com/251997032', 'bestaudio/best'); + } + /** * Assert that a stream is valid. *