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.
This commit is contained in:
Pierre Rudloff 2018-05-23 22:38:15 +02:00
parent 17b9185e53
commit edf4d4644d
3 changed files with 30 additions and 6 deletions

View file

@ -0,0 +1,15 @@
<?php
/**
* EmptyUrlException class.
*/
namespace Alltube;
use Exception;
/**
* Exception thrown when youtube-dl returns an empty URL.
*/
class EmptyUrlException extends Exception
{
}

View file

@ -155,7 +155,7 @@ class VideoDownload
$urls = explode("\n", $this->getProp($url, $format, 'get-url', $password)); $urls = explode("\n", $this->getProp($url, $format, 'get-url', $password));
if (empty($urls[0])) { if (empty($urls[0])) {
throw new Exception(_('youtube-dl returned an empty URL.')); throw new EmptyUrlException(_('youtube-dl returned an empty URL.'));
} }
return $urls; return $urls;

View file

@ -6,6 +6,7 @@
namespace Alltube\Controller; namespace Alltube\Controller;
use Alltube\Config; use Alltube\Config;
use Alltube\EmptyUrlException;
use Alltube\Locale; use Alltube\Locale;
use Alltube\LocaleManager; use Alltube\LocaleManager;
use Alltube\PasswordException; use Alltube\PasswordException;
@ -456,11 +457,19 @@ class FrontController
*/ */
private function getRedirectResponse($url, $format, Response $response, Request $request) private function getRedirectResponse($url, $format, Response $response, Request $request)
{ {
try {
$videoUrls = $this->download->getURL( $videoUrls = $this->download->getURL(
$url, $url,
$format, $format,
$this->sessionSegment->getFlash($url) $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) { if (count($videoUrls) > 1) {
return $this->getRemuxStream($videoUrls, $format, $response, $request); return $this->getRemuxStream($videoUrls, $format, $response, $request);
} elseif ($this->config->stream) { } elseif ($this->config->stream) {