From edf4d4644dcb53c542809ff7330a2fa16e2978c9 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 23 May 2018 22:38:15 +0200 Subject: [PATCH] fix: Fix downloading a playlist as a TAR archive This is the only time where youtube-dl returning an empty URL is not a problem. --- classes/EmptyUrlException.php | 15 +++++++++++++++ classes/VideoDownload.php | 2 +- controllers/FrontController.php | 19 ++++++++++++++----- 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 classes/EmptyUrlException.php diff --git a/classes/EmptyUrlException.php b/classes/EmptyUrlException.php new file mode 100644 index 0000000..663501c --- /dev/null +++ b/classes/EmptyUrlException.php @@ -0,0 +1,15 @@ +getProp($url, $format, 'get-url', $password)); if (empty($urls[0])) { - throw new Exception(_('youtube-dl returned an empty URL.')); + throw new EmptyUrlException(_('youtube-dl returned an empty URL.')); } return $urls; diff --git a/controllers/FrontController.php b/controllers/FrontController.php index aa07473..1c9dba2 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -6,6 +6,7 @@ namespace Alltube\Controller; use Alltube\Config; +use Alltube\EmptyUrlException; use Alltube\Locale; use Alltube\LocaleManager; use Alltube\PasswordException; @@ -456,11 +457,19 @@ class FrontController */ private function getRedirectResponse($url, $format, Response $response, Request $request) { - $videoUrls = $this->download->getURL( - $url, - $format, - $this->sessionSegment->getFlash($url) - ); + try { + $videoUrls = $this->download->getURL( + $url, + $format, + $this->sessionSegment->getFlash($url) + ); + } catch (EmptyUrlException $e) { + /* + If this happens it is probably a playlist + so it will either be handle by getStream() or throw an exception anyway. + */ + $videoUrls = []; + } if (count($videoUrls) > 1) { return $this->getRemuxStream($videoUrls, $format, $response, $request); } elseif ($this->config->stream) {