From 03cf5061328e4714f7c640250bb45685f08da4a2 Mon Sep 17 00:00:00 2001 From: Uli Koeth Date: Tue, 7 Mar 2017 17:24:34 +0100 Subject: [PATCH 01/40] Handle download lists part 1 --- classes/VideoDownload.php | 9 ++- index.php | 1 - templates/video.tpl | 160 +++++++++++++++++++------------------- 3 files changed, 89 insertions(+), 81 deletions(-) diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index 345d2eb..8391c7a 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -113,7 +113,14 @@ class VideoDownload * */ public function getJSON($url, $format = null, $password = null) { - return json_decode($this->getProp($url, $format, 'dump-json', $password)); + $jsonArray = preg_split( "/\r|\n/", $this->getProp($url, $format, 'dump-json', $password), -1, + PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + $decodedJson = array(); + foreach ($jsonArray as $oneJson) + { + array_push($decodedJson, json_decode($oneJson)); + } + return $decodedJson; } /** diff --git a/index.php b/index.php index b3b77de..ce07549 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,4 @@
{include file="inc/logo.tpl"} -

You are going to download - . -

-{if isset($video->thumbnail)} - -{/if} -{if isset($video->description)} - -{/if} -{if isset($video->upload_date)} - -{/if} -
-{if isset($video->formats)} -

-
- - {if uglyUrls} - - {/if} - + {if uglyUrls} + + {/if} +

-
-
-{else} - - Download
-{/if} + + + + + {foreach $video->formats as $format} + {if $config->stream || $format->protocol|in_array:array('http', 'https')} + {strip} + + {/strip} + {/if} + {/foreach} + +

+
+ + {else} + + Download
+ {/if} +
+{/foreach}
{include file="inc/footer.tpl"} From 560e8c6a5fe87e5fe0c74d7c7b468fbb6f8e9b40 Mon Sep 17 00:00:00 2001 From: Uli Koeth Date: Wed, 8 Mar 2017 13:23:42 +0100 Subject: [PATCH 02/40] Handle download lists part 2 --- controllers/FrontController.php | 8 ++++---- js/cast.js | 34 ++++++++++++++++++--------------- templates/video.tpl | 5 +++-- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 233be8c..0a49450 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -209,7 +209,7 @@ class FrontController private function getVideoResponse(Request $request, Response $response, array $params, $password = null) { try { - $video = $this->download->getJSON($params['url'], $this->defaultFormat, $password); + $vidarr = $this->download->getJSON($params['url'], $this->defaultFormat, $password); } catch (PasswordException $e) { return $this->password($request, $response); } @@ -222,10 +222,10 @@ class FrontController $response, 'video.tpl', [ - 'video' => $video, + 'vidarr' => $vidarr, 'class' => 'video', - 'title' => $video->title, - 'description' => 'Download "'.$video->title.'" from '.$video->extractor_key, + 'title' => $vidarr[0]->title, + 'description' => 'Download "'.$vidarr[0]->title.'" from '.$vidarr[0]->extractor_key, 'protocol' => $protocol, 'config' => $this->config, 'canonical' => $this->getCanonicalUrl($request), diff --git a/js/cast.js b/js/cast.js index 0cc0bd3..bcadc01 100644 --- a/js/cast.js +++ b/js/cast.js @@ -2,7 +2,7 @@ /*jslint browser: true, nomen: true */ var castModule = (function () { 'use strict'; - var launchBtn, disabledBtn, stopBtn, session; + var launchBtn, disabledBtn, stopBtn, session, videoLink; function receiverListener(e) { return (e === chrome.cast.ReceiverAvailability.AVAILABLE); @@ -51,7 +51,7 @@ var castModule = (function () { function onRequestSessionSuccess(e) { session = e; - var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo); + var videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo); session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError); } @@ -59,19 +59,23 @@ var castModule = (function () { throw e.description; } - function launchCast() { + function launchCast(event) { + videoLink = event.target || event.srcElement; chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError); } function onInitSuccess() { - launchBtn = document.getElementById('cast_btn_launch'); - disabledBtn = document.getElementById('cast_disabled'); - stopBtn = document.getElementById('cast_btn_stop'); - if (launchBtn) { - disabledBtn.classList.add('cast_hidden'); - launchBtn.classList.remove('cast_hidden'); - launchBtn.addEventListener('click', launchCast, false); - stopBtn.addEventListener('click', stopCast, false); + launchBtn = document.getElementsByClassName('cast_btn_launch'); + disabledBtn = document.getElementsByClassName('cast_disabled'); + stopBtn = document.getElementsByClassName('cast_btn_stop'); + if (launchBtn.length > 0) { + var i; + for (i = 0; i < launchBtn.length; i++) { + disabledBtn[i].classList.add('cast_hidden'); + launchBtn[i].classList.remove('cast_hidden'); + launchBtn[i].addEventListener('click', launchCast, false); + stopBtn[i].addEventListener('click', stopCast, false); + } } } @@ -94,11 +98,11 @@ var castModule = (function () { return { init: function () { - var intro = document.getElementById('download_intro'); - if (intro) { - intro.insertAdjacentHTML('beforeend', ' Google Cast™ Casting to ChromeCast…'); - window.__onGCastApiAvailable = loadCastApi; + var intro = document.getElementsByClassName('download_intro'), i; + for (i = 0; i < intro.length; i++) { + intro[i].insertAdjacentHTML('beforeend', ' Google Cast™ Casting to ChromeCast…'); } + window.__onGCastApiAvailable = loadCastApi; } }; }()); diff --git a/templates/video.tpl b/templates/video.tpl index 8ee0c5f..1c3b73d 100644 --- a/templates/video.tpl +++ b/templates/video.tpl @@ -4,8 +4,9 @@
{include file="inc/logo.tpl"} {foreach $vidarr as $video} -

You are going to download -

+
+{include file="inc/footer.tpl"} diff --git a/templates/video.tpl b/templates/video.tpl index 369370f..64ca555 100644 --- a/templates/video.tpl +++ b/templates/video.tpl @@ -3,95 +3,92 @@
{include file="inc/logo.tpl"} -{foreach $vidarr as $video} -

You are going to download - . -

- {if isset($video->thumbnail)} - - {/if} - {if isset($video->description)} - - {/if} - {if isset($video->upload_date)} - - {/if} -
- {if isset($video->formats)} -

-
- - {if uglyUrls} - - {/if} - + {if $uglyUrls} + + {/if} +

-
-
- {else} - - Download
- {/if} -
-{/foreach} + {else} + {for $foo=1 to 10} +   + {/for} + {/if} + {if isset($format->filesize)} + {($format->filesize/1000000)|round:2} MB + {for $foo=1 to (7 - (($format->filesize/1000000)|round:2|strlen))} +   + {/for} + {else} + {for $foo=1 to 10} +   + {/for} + {/if} + {if isset($format->format_note)} + {$format->format_note} + {/if} +  ({$format->format_id}) + + {/strip} + {/if} + {/foreach} + +

+
+ +{else} + + Download
+{/if}
{include file="inc/footer.tpl"} diff --git a/tests/FrontControllerTest.php b/tests/FrontControllerTest.php index d2dce25..7a6d425 100644 --- a/tests/FrontControllerTest.php +++ b/tests/FrontControllerTest.php @@ -264,6 +264,22 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase $this->assertTrue($result->isOk()); } + /** + * Test the video() function with a playlist. + * + * @return void + */ + public function testVideoWithPlaylist() + { + $result = $this->controller->video( + $this->request->withQueryParams( + ['url'=>'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC'] + ), + $this->response + ); + $this->assertTrue($result->isOk()); + } + /** * Test the error() function. * diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index e169c8a..d9bda2c 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -266,7 +266,6 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase $this->assertObjectHasAttribute('title', $info); $this->assertObjectHasAttribute('extractor_key', $info); $this->assertObjectHasAttribute('formats', $info); - $this->assertObjectHasAttribute('_filename', $info); } /** From 950ea16672ce20b4a80bdc682246fde2969b7563 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 10:30:30 +0200 Subject: [PATCH 15/40] Link to video page on playlist page Open links on playlist page in new tab to allow to easily get back to playlist --- templates/playlist.tpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/playlist.tpl b/templates/playlist.tpl index c62ec59..62319d8 100644 --- a/templates/playlist.tpl +++ b/templates/playlist.tpl @@ -10,7 +10,8 @@

{$video->title}

- webpage_url}">Download + webpage_url}">Download + webpage_url}">More options
{/foreach} From 7428b334de7a9b114bdf425cfcdea5123f683fae Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 11:05:49 +0200 Subject: [PATCH 16/40] Smal fixes with playlists --- controllers/FrontController.php | 11 +++++++++-- css/style.css | 11 +++++++++++ templates/playlist.tpl | 10 ++++++---- tests/FrontControllerTest.php | 14 ++++++++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 83b2db8..36c7d30 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -227,14 +227,21 @@ class FrontController } else { $template = 'video.tpl'; } + if (isset($video->title)) { + $title = $video->title; + $description = 'Download "'.$video->title.'" from '.$video->extractor_key; + } else { + $title = 'Video download'; + $description = 'Download video from '.$video->extractor_key; + } $this->view->render( $response, $template, [ 'video' => $video, 'class' => 'video', - 'title' => $video->title, - 'description' => 'Download "'.$video->title.'" from '.$video->extractor_key, + 'title' => $title, + 'description' => $description, 'protocol' => $protocol, 'config' => $this->config, 'canonical' => $this->getCanonicalUrl($request), diff --git a/css/style.css b/css/style.css index 4ec7276..a055a97 100644 --- a/css/style.css +++ b/css/style.css @@ -407,6 +407,7 @@ padding:3px; clear: both; padding-top: 2em; text-align: left; + width: 600px; } .playlist-entry h3 { @@ -682,6 +683,16 @@ h1 { text-align:left; } + .playlist-entry { + text-align: center; + width: auto; + } + + .playlist-entry .thumb { + float: none; + margin-right: 0; + } + } @media all and (display-mode: standalone) { diff --git a/templates/playlist.tpl b/templates/playlist.tpl index 62319d8..cab5c4a 100644 --- a/templates/playlist.tpl +++ b/templates/playlist.tpl @@ -2,16 +2,18 @@
{include file="inc/logo.tpl"} -

Videos extracted from the +

Videos extracted from the {if isset($video->title)} -{$video->title} playlist: +{$video->title}{/if} playlist:

{foreach $video->entries as $video}
-

{$video->title}

+

{$video->title}

webpage_url}">Download - webpage_url}">More options + {if count($video->formats) > 1} + webpage_url}">More options + {/if}
{/foreach} diff --git a/tests/FrontControllerTest.php b/tests/FrontControllerTest.php index 7a6d425..3ba8884 100644 --- a/tests/FrontControllerTest.php +++ b/tests/FrontControllerTest.php @@ -179,6 +179,20 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase $this->assertTrue($result->isOk()); } + /** + * Test the video() function with a video that does not have a title. + * + * @return void + */ + public function testVideoWithoutTitle() + { + $result = $this->controller->video( + $this->request->withQueryParams(['url'=>'http://html5demos.com/video']), + $this->response + ); + $this->assertTrue($result->isOk()); + } + /** * Test the video() function with audio conversion. * From e9e0f6ca816b947e1370d33711d69e9748c0a336 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 11:08:34 +0200 Subject: [PATCH 17/40] Remove useless comment --- classes/VideoDownload.php | 1 - 1 file changed, 1 deletion(-) diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index a838303..373ac38 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -291,7 +291,6 @@ class VideoDownload return popen($chain->getProcess()->getCommandLine(), 'r'); } else { $avconvProc = $this->getAvconvMp3Process($video->url); - //dump($avconvProc->getProcess()); die; return popen($avconvProc->getProcess()->getCommandLine(), 'r'); } From 1a7444eb66e944d0e2e09288efec924bcdab2244 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 13:49:46 +0200 Subject: [PATCH 18/40] Remove stray end tag in playlist template (fixes #107) --- templates/playlist.tpl | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/playlist.tpl b/templates/playlist.tpl index cab5c4a..670bc36 100644 --- a/templates/playlist.tpl +++ b/templates/playlist.tpl @@ -17,6 +17,5 @@
{/foreach} -
{include file="inc/footer.tpl"} From 5180577b99d571395225db8ed7706afb23a5811f Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 14:08:29 +0200 Subject: [PATCH 19/40] Ignore errors in playlists (see https://github.com/rg3/youtube-dl/issues/12835) --- classes/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Config.php b/classes/Config.php index b90a6ca..1f73e6b 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -38,7 +38,7 @@ class Config * * @var array */ - public $params = ['--no-warnings']; + public $params = ['--no-warnings', '--ignore-errors']; /** * Enable audio conversion. From 453bf6e4c548316135b93cefa137c39cdf31d623 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 14:55:21 +0200 Subject: [PATCH 20/40] More precise doc for getURL() --- classes/VideoDownload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index 373ac38..0d42a97 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -127,7 +127,7 @@ class VideoDownload * @param string $format Format to use for the video * @param string $password Video password * - * @return array URLs of video + * @return string[] URLs of video * */ public function getURL($url, $format = null, $password = null) { From 71978e54e271df8513779c4a609fb1619f5c10d1 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 21:49:19 +0200 Subject: [PATCH 21/40] Unused variable --- tests/ConfigTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 63675af..f0ba659 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -70,7 +70,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase */ public function testGetInstanceWithEmptyFile() { - $config = Config::getInstance(''); + Config::getInstance(''); } /** From 8d65cf44e3fcb28635a77daca26243a438c64dd1 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 22:12:11 +0200 Subject: [PATCH 22/40] Refactor remux logic in controller --- controllers/FrontController.php | 70 ++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 36c7d30..e1359ce 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -348,6 +348,39 @@ class FrontController return $response; } + /** + * Get a remuxed stream piped through the server. + * + * @param string $urls URLs of the video and audio files + * @param string $webpageUrl URL of the webpage containing the video + * @param Response $response PSR-7 response + * @param Request $request PSR-7 request + * + * @return Response HTTP response + */ + private function getRemuxStream(array $urls, $format, Response $response, Request $request) + { + if (!$this->config->remux) { + throw new \Exception('You need to enable remux mode to merge two formats.'); + } + $stream = $this->download->getRemuxStream($urls); + $response = $response->withHeader('Content-Type', 'video/x-matroska'); + if ($request->isGet()) { + $response = $response->withBody(new Stream($stream)); + } + $webpageUrl = $request->getQueryParam('url'); + + return $response->withHeader('Content-Disposition', 'attachment; filename="'.pathinfo( + $this->download->getFileNameWithExtension( + 'mkv', + $webpageUrl, + $format, + $this->sessionSegment->getFlash($webpageUrl) + ), + PATHINFO_FILENAME + ).'.mkv"'); + } + /** * Redirect to video file. * @@ -366,7 +399,14 @@ class FrontController } if (isset($params['url'])) { try { - if ($this->config->stream) { + $urls = $this->download->getURL( + $params['url'], + $format, + $this->sessionSegment->getFlash($params['url']) + ); + if (count($urls) > 1) { + return $this->getRemuxStream($urls, $format, $response, $request); + } elseif ($this->config->stream) { return $this->getStream( $params['url'], $format, @@ -375,33 +415,7 @@ class FrontController $this->sessionSegment->getFlash($params['url']) ); } else { - $urls = $this->download->getURL( - $params['url'], - $format, - $this->sessionSegment->getFlash($params['url']) - ); - if (count($urls) > 1) { - if (!$this->config->remux) { - throw new \Exception('You need to enable remux mode to merge two formats.'); - } - $stream = $this->download->getRemuxStream($urls); - $response = $response->withHeader('Content-Type', 'video/x-matroska'); - if ($request->isGet()) { - $response = $response->withBody(new Stream($stream)); - } - - return $response->withHeader('Content-Disposition', 'attachment; filename="'.pathinfo( - $this->download->getFileNameWithExtension( - 'mkv', - $params['url'], - $format, - $this->sessionSegment->getFlash($params['url']) - ), - PATHINFO_FILENAME - ).'.mkv"'); - } else { - return $response->withRedirect($urls[0]); - } + return $response->withRedirect($urls[0]); } } catch (PasswordException $e) { return $response->withRedirect( From 60bd5dad6b6c4a614ef8c9ef84b55dc2fa192828 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 22:13:38 +0200 Subject: [PATCH 23/40] Remove obsolete Firefox OS manifest --- manifest.webapp | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 manifest.webapp diff --git a/manifest.webapp b/manifest.webapp deleted file mode 100644 index 91435b8..0000000 --- a/manifest.webapp +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "AllTube", - "description": "Easily download videos from Youtube, Dailymotion, Vimeo and other websites", - "developer": { - "name": "Pierre Rudloff", - "url": "https://rudloff.pro/" - }, - "icons": { - "32": "/img/favicon.png", - "60": "/img/logo_60.png", - "90": "/img/logo_90.png", - "243": "/img/logo_app.png", - "250": "/img/logo_250.png" - }, - "default_locale": "en", - "launch_path": "/index.php" -} From 89991802849efe4b64cb03e9cf94ea1a3b533dcb Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 22:23:18 +0200 Subject: [PATCH 24/40] Missing param types --- controllers/FrontController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index e1359ce..96f2f6e 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -315,7 +315,7 @@ class FrontController * * @return Response HTTP response */ - private function getStream($url, $format, $response, $request, $password = null) + private function getStream($url, $format, Response $response, Request $request, $password = null) { $video = $this->download->getJSON($url, $format, $password); if ($video->protocol == 'rtmp') { From cbcf58c5fbefea2f955dbbea5ad120b386d1d19b Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 22:24:44 +0200 Subject: [PATCH 25/40] Accept any PSR container --- controllers/FrontController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 96f2f6e..07169c6 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -8,7 +8,7 @@ namespace Alltube\Controller; use Alltube\Config; use Alltube\PasswordException; use Alltube\VideoDownload; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; use Slim\Container; use Slim\Http\Request; use Slim\Http\Response; From df7bc9a088823a3467b0dfd84f3010ca48f5cf3d Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 22:47:52 +0200 Subject: [PATCH 26/40] Refactor redirect() function --- controllers/FrontController.php | 85 ++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 07169c6..ab12593 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -351,8 +351,8 @@ class FrontController /** * Get a remuxed stream piped through the server. * - * @param string $urls URLs of the video and audio files - * @param string $webpageUrl URL of the webpage containing the video + * @param array $urls URLs of the video and audio files + * @param string $format Requested format * @param Response $response PSR-7 response * @param Request $request PSR-7 request * @@ -381,6 +381,56 @@ class FrontController ).'.mkv"'); } + /** + * Get video format from request parameters or default format if none is specified + * + * @param Request $request PSR-7 request + * + * @return string format + */ + private function getFormat(Request $request) + { + $format = $request->getQueryParam('format'); + if (!isset($format)) { + $format = $this->defaultFormat; + } + + return $format; + } + + /** + * Get approriate HTTP response to redirect query + * Depends on whether we want to stream, remux or simply redirect + * + * @param string $url URL of the video + * @param string $format Requested format + * @param Response $response PSR-7 response + * @param Request $request PSR-7 request + * + * @return Response HTTP response + */ + private function getRedirectResponse($url, $format, Response $response, Request $request) + { + $videoUrls = $this->download->getURL( + $url, + $format, + $this->sessionSegment->getFlash($url) + ); + if (count($videoUrls) > 1) { + return $this->getRemuxStream($videoUrls, $format, $response, $request); + } elseif ($this->config->stream) { + return $this->getStream( + $url, + $format, + $response, + $request, + $this->sessionSegment->getFlash($url) + ); + } else { + return $response->withRedirect($videoUrls[0]); + } + } + /** * Redirect to video file. * @@ -391,35 +441,14 @@ class FrontController */ public function redirect(Request $request, Response $response) { - $params = $request->getQueryParams(); - if (isset($params['format'])) { - $format = $params['format']; - } else { - $format = $this->defaultFormat; - } - if (isset($params['url'])) { + $url = $request->getQueryParam('url'); + $format = $this->getFormat($request); + if (isset($url)) { try { - $urls = $this->download->getURL( - $params['url'], - $format, - $this->sessionSegment->getFlash($params['url']) - ); - if (count($urls) > 1) { - return $this->getRemuxStream($urls, $format, $response, $request); - } elseif ($this->config->stream) { - return $this->getStream( - $params['url'], - $format, - $response, - $request, - $this->sessionSegment->getFlash($params['url']) - ); - } else { - return $response->withRedirect($urls[0]); - } + return $this->getRedirectResponse($url, $format, $response, $request); } catch (PasswordException $e) { return $response->withRedirect( - $this->container->get('router')->pathFor('video').'?url='.urlencode($params['url']) + $this->container->get('router')->pathFor('video').'?url='.urlencode($url) ); } catch (\Exception $e) { $response->getBody()->write($e->getMessage()); From 5e31767140580a2a90d936c2b4c6706b78b6a55c Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 22:49:28 +0200 Subject: [PATCH 27/40] Lint --- controllers/FrontController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index ab12593..813dcd4 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -351,10 +351,10 @@ class FrontController /** * Get a remuxed stream piped through the server. * - * @param array $urls URLs of the video and audio files - * @param string $format Requested format - * @param Response $response PSR-7 response - * @param Request $request PSR-7 request + * @param array $urls URLs of the video and audio files + * @param string $format Requested format + * @param Response $response PSR-7 response + * @param Request $request PSR-7 request * * @return Response HTTP response */ @@ -382,7 +382,7 @@ class FrontController } /** - * Get video format from request parameters or default format if none is specified + * Get video format from request parameters or default format if none is specified. * * @param Request $request PSR-7 request * @@ -400,7 +400,7 @@ class FrontController /** * Get approriate HTTP response to redirect query - * Depends on whether we want to stream, remux or simply redirect + * Depends on whether we want to stream, remux or simply redirect. * * @param string $url URL of the video * @param string $format Requested format From 8aee9054a8875037f6f3c6b66cc2b8d4e7934136 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 23:04:59 +0200 Subject: [PATCH 28/40] Allow custom cookie array in controller --- controllers/FrontController.php | 6 ++++-- index.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 813dcd4..16d22ee 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -65,8 +65,10 @@ class FrontController * FrontController constructor. * * @param Container $container Slim dependency container + * @param Config $config Config instance + * @param array $cookies Cookie array */ - public function __construct(ContainerInterface $container, Config $config = null) + public function __construct(ContainerInterface $container, Config $config = null, array $cookies = []) { if (isset($config)) { $this->config = $config; @@ -77,7 +79,7 @@ class FrontController $this->container = $container; $this->view = $this->container->get('view'); $session_factory = new \Aura\Session\SessionFactory(); - $session = $session_factory->newInstance($_COOKIE); + $session = $session_factory->newInstance($cookies); $this->sessionSegment = $session->getSegment('Alltube\Controller\FrontController'); if ($this->config->stream) { $this->defaultFormat = 'best'; diff --git a/index.php b/index.php index b3b77de..313b505 100644 --- a/index.php +++ b/index.php @@ -28,7 +28,7 @@ $container['view'] = function ($c) { return $view; }; -$controller = new FrontController($container); +$controller = new FrontController($container, null, $_COOKIE); $container['errorHandler'] = [$controller, 'error']; From a5252393deff26e8ed1543e217389177696bf6fa Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 25 Apr 2017 23:49:13 +0200 Subject: [PATCH 29/40] Refactor FrontControllerTest --- tests/FrontControllerTest.php | 230 +++++++++++++++++----------------- 1 file changed, 117 insertions(+), 113 deletions(-) diff --git a/tests/FrontControllerTest.php b/tests/FrontControllerTest.php index 3ba8884..d0f05f6 100644 --- a/tests/FrontControllerTest.php +++ b/tests/FrontControllerTest.php @@ -83,6 +83,70 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase Config::destroyInstance(); } + /** + * Run controller function with custom query parameters and return the result + * + * @param string $request Controller function to call + * @param array $params Query parameters + * @param Config $config Custom config + * + * @return Response HTTP response + */ + private function getRequestResult($request, array $params, Config $config = null) + { + if (isset($config)) { + $controller = new FrontController($this->container, $config); + } else { + $controller= $this->controller; + } + return $controller->$request( + $this->request->withQueryParams($params), + $this->response + ); + } + + /** + * Assert that calling controller function with these parameters returns a 200 HTTP response + * + * @param string $request Controller function to call + * @param array $params Query parameters + * @param Config $config Custom config + * + * @return void + */ + private function assertRequestIsOk($request, array $params = [], Config $config = null) + { + $this->assertTrue($this->getRequestResult($request, $params, $config)->isOk()); + } + + /** + * Assert that calling controller function with these parameters returns an HTTP redirect + * + * @param string $request Controller function to call + * @param array $params Query parameters + * @param Config $config Custom config + * + * @return void + */ + private function assertRequestIsRedirect($request, array $params = [], Config $config = null) + { + $this->assertTrue($this->getRequestResult($request, $params, $config)->isRedirect()); + } + + /** + * Assert that calling controller function with these parameters returns an HTTP redirect + * + * @param string $request Controller function to call + * @param array $params Query parameters + * @param Config $config Custom config + * + * @return void + */ + private function assertRequestIsServerError($request, array $params = [], Config $config = null) + { + $this->assertTrue($this->getRequestResult($request, $params, $config)->isServerError()); + } + /** * Test the constructor. * @@ -112,8 +176,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testIndex() { - $result = $this->controller->index($this->request, $this->response); - $this->assertTrue($result->isOk()); + $this->assertRequestIsOk('index'); } /** @@ -139,8 +202,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testExtractors() { - $result = $this->controller->extractors($this->request, $this->response); - $this->assertTrue($result->isOk()); + $this->assertRequestIsOk('extractors'); } /** @@ -150,8 +212,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testPassword() { - $result = $this->controller->password($this->request, $this->response); - $this->assertTrue($result->isOk()); + $this->assertRequestIsOk('password'); } /** @@ -161,8 +222,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testVideoWithoutUrl() { - $result = $this->controller->video($this->request, $this->response); - $this->assertTrue($result->isRedirect()); + $this->assertRequestIsRedirect('video'); } /** @@ -172,11 +232,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testVideo() { - $result = $this->controller->video( - $this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU']), - $this->response - ); - $this->assertTrue($result->isOk()); + $this->assertRequestIsOk('video', ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU']); } /** @@ -186,11 +242,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testVideoWithoutTitle() { - $result = $this->controller->video( - $this->request->withQueryParams(['url'=>'http://html5demos.com/video']), - $this->response - ); - $this->assertTrue($result->isOk()); + $this->assertRequestIsOk('video', ['url'=>'http://html5demos.com/video']); } /** @@ -200,11 +252,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testVideoWithAudio() { - $result = $this->controller->video( - $this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio'=>true]), - $this->response - ); - $this->assertTrue($result->isOk()); + $this->assertRequestIsOk('video', ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio'=>true]); } /** @@ -214,14 +262,10 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testVideoWithUnconvertedAudio() { - $result = $this->controller->video( - $this->request->withQueryParams( - ['url' => 'https://2080.bandcamp.com/track/cygnus-x-the-orange-theme-2080-faulty-chip-cover', - 'audio'=> true, ] - ), - $this->response + $this->assertRequestIsRedirect( + 'video', + ['url'=>'https://2080.bandcamp.com/track/cygnus-x-the-orange-theme-2080-faulty-chip-cover', 'audio'=>true] ); - $this->assertTrue($result->isRedirect()); } /** @@ -246,16 +290,8 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testVideoWithMissingPassword() { - $result = $this->controller->video( - $this->request->withQueryParams(['url'=>'http://vimeo.com/68375962']), - $this->response - ); - $this->assertTrue($result->isOk()); - $result = $this->controller->video( - $this->request->withQueryParams(['url'=>'http://vimeo.com/68375962', 'audio'=>true]), - $this->response - ); - $this->assertTrue($result->isOk()); + $this->assertRequestIsOk('video', ['url'=>'http://vimeo.com/68375962']); + $this->assertRequestIsOk('video', ['url'=>'http://vimeo.com/68375962', 'audio'=>true]); } /** @@ -265,17 +301,13 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testVideoWithStream() { - $controller = new FrontController($this->container, new Config(['stream'=>true])); - $result = $controller->video( - $this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU']), - $this->response + $config = new Config(['stream'=>true]); + $this->assertRequestIsOk('video', ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU'], $config); + $this->assertRequestIsOk( + 'video', + ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio'=>true], + $config ); - $this->assertTrue($result->isOk()); - $result = $controller->video( - $this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio'=>true]), - $this->response - ); - $this->assertTrue($result->isOk()); } /** @@ -285,13 +317,10 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testVideoWithPlaylist() { - $result = $this->controller->video( - $this->request->withQueryParams( - ['url'=>'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC'] - ), - $this->response + $this->assertRequestIsOk( + 'video', + ['url'=>'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC'] ); - $this->assertTrue($result->isOk()); } /** @@ -312,8 +341,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testRedirectWithoutUrl() { - $result = $this->controller->redirect($this->request, $this->response); - $this->assertTrue($result->isRedirect()); + $this->assertRequestIsRedirect('redirect'); } /** @@ -323,11 +351,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testRedirect() { - $result = $this->controller->redirect( - $this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU']), - $this->response - ); - $this->assertTrue($result->isRedirect()); + $this->assertRequestIsRedirect('redirect', ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU']); } /** @@ -337,11 +361,10 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testRedirectWithFormat() { - $result = $this->controller->redirect( - $this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'format'=>'worst']), - $this->response + $this->assertRequestIsRedirect( + 'redirect', + ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'format'=>'worst'] ); - $this->assertTrue($result->isRedirect()); } /** @@ -351,12 +374,11 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testRedirectWithStream() { - $controller = new FrontController($this->container, new Config(['stream'=>true])); - $result = $controller->redirect( - $this->request->withQueryParams(['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU']), - $this->response + $this->assertRequestIsOk( + 'redirect', + ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU'], + new Config(['stream'=>true]) ); - $this->assertTrue($result->isOk()); } /** @@ -366,12 +388,11 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testRedirectWithM3uStream() { - $controller = new FrontController($this->container, new Config(['stream'=>true])); - $result = $controller->redirect( - $this->request->withQueryParams(['url'=>'https://twitter.com/verge/status/813055465324056576/video/1']), - $this->response + $this->assertRequestIsOk( + 'redirect', + ['url'=>'https://twitter.com/verge/status/813055465324056576/video/1'], + new Config(['stream'=>true]) ); - $this->assertTrue($result->isOk()); } /** @@ -381,14 +402,11 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testRedirectWithRtmpStream() { - $controller = new FrontController($this->container, new Config(['stream'=>true])); - $result = $controller->redirect( - $this->request->withQueryParams( - ['url'=>'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0'] - ), - $this->response + $this->assertRequestIsOk( + 'redirect', + ['url'=>'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0'], + new Config(['stream'=>true]) ); - $this->assertTrue($result->isOk()); } /** @@ -398,17 +416,14 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testRedirectWithRemux() { - $controller = new FrontController($this->container, new Config(['remux'=>true])); - $result = $controller->redirect( - $this->request->withQueryParams( - [ - 'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', - 'format'=> 'bestvideo+bestaudio', - ] - ), - $this->response + $this->assertRequestIsOk( + 'redirect', + [ + 'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', + 'format'=> 'bestvideo+bestaudio', + ], + new Config(['remux'=>true]) ); - $this->assertTrue($result->isOk()); } /** @@ -418,16 +433,13 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testRedirectWithRemuxDisabled() { - $result = $this->controller->redirect( - $this->request->withQueryParams( - [ - 'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', - 'format'=> 'bestvideo+bestaudio', - ] - ), - $this->response + $this->assertRequestIsServerError( + 'redirect', + [ + 'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', + 'format'=> 'bestvideo+bestaudio', + ] ); - $this->assertTrue($result->isServerError()); } /** @@ -437,11 +449,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testRedirectWithMissingPassword() { - $result = $this->controller->redirect( - $this->request->withQueryParams(['url'=>'http://vimeo.com/68375962']), - $this->response - ); - $this->assertTrue($result->isRedirect()); + $this->assertRequestIsRedirect('redirect', ['url'=>'http://vimeo.com/68375962']); } /** @@ -451,10 +459,6 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase */ public function testRedirectWithError() { - $result = $this->controller->redirect( - $this->request->withQueryParams(['url'=>'http://example.com/foo']), - $this->response - ); - $this->assertTrue($result->isServerError()); + $this->assertRequestIsServerError('redirect', ['url'=>'http://example.com/foo']); } } From db5f653e2d07851422fee3ad8c346068f58af207 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 26 Apr 2017 00:08:35 +0200 Subject: [PATCH 30/40] Refactor stream tests --- tests/VideoDownloadTest.php | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index d9bda2c..48e094d 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -398,6 +398,19 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase $this->download->getAudioStream($url, $format); } + /** + * Assert that a stream is valid + * + * @param resource $stream Stream + * + * @return void + */ + private function assertStream($stream) + { + $this->assertInternalType('resource', $stream); + $this->assertFalse(feof($stream)); + } + /** * Test getM3uStream function. * @@ -409,10 +422,11 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase */ public function testGetM3uStream($url, $format) { - $video = $this->download->getJSON($url, $format); - $stream = $this->download->getM3uStream($video); - $this->assertInternalType('resource', $stream); - $this->assertFalse(feof($stream)); + $this->assertStream( + $this->download->getM3uStream( + $this->download->getJSON($url, $format) + ) + ); } /** @@ -428,9 +442,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase { $urls = $this->download->getURL($url, $format); if (count($urls) > 1) { - $stream = $this->download->getRemuxStream($urls); - $this->assertInternalType('resource', $stream); - $this->assertFalse(feof($stream)); + $this->assertStream($this->download->getRemuxStream($urls)); } } @@ -445,10 +457,11 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase */ public function testGetRtmpStream($url, $format) { - $video = $this->download->getJSON($url, $format); - $stream = $this->download->getRtmpStream($video); - $this->assertInternalType('resource', $stream); - $this->assertFalse(feof($stream)); + $this->assertStream( + $this->download->getRtmpStream( + $this->download->getJSON($url, $format) + ) + ); } /** From 4d104c852fa73343a3da36bd5c44e1b5d869b2d9 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 26 Apr 2017 00:10:00 +0200 Subject: [PATCH 31/40] Lint --- tests/FrontControllerTest.php | 25 +++++++++++++------------ tests/VideoDownloadTest.php | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/FrontControllerTest.php b/tests/FrontControllerTest.php index d0f05f6..f73e1d7 100644 --- a/tests/FrontControllerTest.php +++ b/tests/FrontControllerTest.php @@ -84,7 +84,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase } /** - * Run controller function with custom query parameters and return the result + * Run controller function with custom query parameters and return the result. * * @param string $request Controller function to call * @param array $params Query parameters @@ -97,8 +97,9 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase if (isset($config)) { $controller = new FrontController($this->container, $config); } else { - $controller= $this->controller; + $controller = $this->controller; } + return $controller->$request( $this->request->withQueryParams($params), $this->response @@ -106,7 +107,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase } /** - * Assert that calling controller function with these parameters returns a 200 HTTP response + * Assert that calling controller function with these parameters returns a 200 HTTP response. * * @param string $request Controller function to call * @param array $params Query parameters @@ -120,7 +121,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase } /** - * Assert that calling controller function with these parameters returns an HTTP redirect + * Assert that calling controller function with these parameters returns an HTTP redirect. * * @param string $request Controller function to call * @param array $params Query parameters @@ -134,7 +135,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase } /** - * Assert that calling controller function with these parameters returns an HTTP redirect + * Assert that calling controller function with these parameters returns an HTTP redirect. * * @param string $request Controller function to call * @param array $params Query parameters @@ -264,7 +265,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase { $this->assertRequestIsRedirect( 'video', - ['url'=>'https://2080.bandcamp.com/track/cygnus-x-the-orange-theme-2080-faulty-chip-cover', 'audio'=>true] + ['url'=> 'https://2080.bandcamp.com/track/cygnus-x-the-orange-theme-2080-faulty-chip-cover', 'audio'=>true] ); } @@ -305,7 +306,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase $this->assertRequestIsOk('video', ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU'], $config); $this->assertRequestIsOk( 'video', - ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio'=>true], + ['url'=> 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio'=>true], $config ); } @@ -319,7 +320,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase { $this->assertRequestIsOk( 'video', - ['url'=>'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC'] + ['url'=> 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC'] ); } @@ -363,7 +364,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase { $this->assertRequestIsRedirect( 'redirect', - ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'format'=>'worst'] + ['url'=> 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'format'=>'worst'] ); } @@ -376,7 +377,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase { $this->assertRequestIsOk( 'redirect', - ['url'=>'https://www.youtube.com/watch?v=M7IpKCZ47pU'], + ['url'=> 'https://www.youtube.com/watch?v=M7IpKCZ47pU'], new Config(['stream'=>true]) ); } @@ -390,7 +391,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase { $this->assertRequestIsOk( 'redirect', - ['url'=>'https://twitter.com/verge/status/813055465324056576/video/1'], + ['url'=> 'https://twitter.com/verge/status/813055465324056576/video/1'], new Config(['stream'=>true]) ); } @@ -404,7 +405,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase { $this->assertRequestIsOk( 'redirect', - ['url'=>'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0'], + ['url'=> 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0'], new Config(['stream'=>true]) ); } diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index 48e094d..aab0205 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -399,7 +399,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase } /** - * Assert that a stream is valid + * Assert that a stream is valid. * * @param resource $stream Stream * From 0e7aaea9fc0f57ec15649a61881dbea7da835551 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 26 Apr 2017 00:50:19 +0200 Subject: [PATCH 32/40] Move Smarty view creation to ViewFactory class --- classes/ViewFactory.php | 41 +++++++++++++++++++++++++++++++++++ index.php | 16 ++++---------- tests/FrontControllerTest.php | 13 ++--------- 3 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 classes/ViewFactory.php diff --git a/classes/ViewFactory.php b/classes/ViewFactory.php new file mode 100644 index 0000000..8c3f102 --- /dev/null +++ b/classes/ViewFactory.php @@ -0,0 +1,41 @@ +getUri()); + $view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']); + $view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']); + + $view->registerPlugin('modifier', 'noscheme', 'Smarty_Modifier_noscheme'); + + return $view; + } +} diff --git a/index.php b/index.php index 313b505..0bb2c6e 100644 --- a/index.php +++ b/index.php @@ -4,29 +4,21 @@ require_once __DIR__.'/vendor/autoload.php'; use Alltube\Config; use Alltube\Controller\FrontController; use Alltube\UglyRouter; +use Alltube\ViewFactory; +use Slim\App; if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) { header('Location: '.str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI'])); die; } -$app = new \Slim\App(); +$app = new App(); $container = $app->getContainer(); $config = Config::getInstance(); if ($config->uglyUrls) { $container['router'] = new UglyRouter(); } -$container['view'] = function ($c) { - $view = new \Slim\Views\Smarty(__DIR__.'/templates/'); - - $smartyPlugins = new \Slim\Views\SmartyPlugins($c['router'], $c['request']->getUri()); - $view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']); - $view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']); - - $view->registerPlugin('modifier', 'noscheme', 'Smarty_Modifier_noscheme'); - - return $view; -}; +$container['view'] = ViewFactory::create($container); $controller = new FrontController($container, null, $_COOKIE); diff --git a/tests/FrontControllerTest.php b/tests/FrontControllerTest.php index f73e1d7..859f7de 100644 --- a/tests/FrontControllerTest.php +++ b/tests/FrontControllerTest.php @@ -7,6 +7,7 @@ namespace Alltube\Test; use Alltube\Config; use Alltube\Controller\FrontController; +use Alltube\ViewFactory; use Slim\Container; use Slim\Http\Environment; use Slim\Http\Request; @@ -53,17 +54,7 @@ class FrontControllerTest extends \PHPUnit_Framework_TestCase $this->container = new Container(); $this->request = Request::createFromEnvironment(Environment::mock()); $this->response = new Response(); - $this->container['view'] = function ($c) { - $view = new \Slim\Views\Smarty(__DIR__.'/../templates/'); - - $smartyPlugins = new \Slim\Views\SmartyPlugins($c['router'], $this->request->getUri()); - $view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']); - $view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']); - - $view->registerPlugin('modifier', 'noscheme', 'Smarty_Modifier_noscheme'); - - return $view; - }; + $this->container['view'] = ViewFactory::create($this->container, $this->request); $this->controller = new FrontController($this->container, Config::getInstance('config_test.yml')); $this->container['router']->map(['GET'], '/', [$this->controller, 'index']) ->setName('index'); From 00407a2f6096e6936416d6b4049424042e60e5f5 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 26 Apr 2017 00:52:05 +0200 Subject: [PATCH 33/40] Lint --- classes/ViewFactory.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/classes/ViewFactory.php b/classes/ViewFactory.php index 8c3f102..a2f1087 100644 --- a/classes/ViewFactory.php +++ b/classes/ViewFactory.php @@ -2,6 +2,7 @@ /** * ViewFactory class. */ + namespace Alltube; use Slim\Container; @@ -17,8 +18,8 @@ class ViewFactory /** * Create Smarty view object. * - * @param Container $container Slim dependency container - * @param Request $request PSR-7 request + * @param Container $container Slim dependency container + * @param Request $request PSR-7 request * * @return Smarty */ From ea8e26c649c272fda881aa5ca9d204a966e6f0c4 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 26 Apr 2017 00:59:30 +0200 Subject: [PATCH 34/40] Tests for ViewFactory --- tests/ViewFactoryTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/ViewFactoryTest.php diff --git a/tests/ViewFactoryTest.php b/tests/ViewFactoryTest.php new file mode 100644 index 0000000..589b8d3 --- /dev/null +++ b/tests/ViewFactoryTest.php @@ -0,0 +1,28 @@ +assertInstanceOf(Smarty::class, $view); + } +} From 29c432c1592e62f7e778a11c5e86f00d1161604c Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 26 Apr 2017 01:00:07 +0200 Subject: [PATCH 35/40] Lint --- tests/ViewFactoryTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ViewFactoryTest.php b/tests/ViewFactoryTest.php index 589b8d3..9155faa 100644 --- a/tests/ViewFactoryTest.php +++ b/tests/ViewFactoryTest.php @@ -14,7 +14,6 @@ use Slim\Views\Smarty; */ class ViewFactoryTest extends \PHPUnit_Framework_TestCase { - /** * Test the create() function. * From df2de166cbe3aff17c5e34d89f9aba923f6c7f04 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Wed, 26 Apr 2017 01:08:42 +0200 Subject: [PATCH 36/40] Accept any PSR container in ViewFactory --- classes/ViewFactory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/ViewFactory.php b/classes/ViewFactory.php index a2f1087..a046c3e 100644 --- a/classes/ViewFactory.php +++ b/classes/ViewFactory.php @@ -5,7 +5,7 @@ namespace Alltube; -use Slim\Container; +use Psr\Container\ContainerInterface; use Slim\Http\Request; use Slim\Views\Smarty; use Slim\Views\SmartyPlugins; @@ -23,7 +23,7 @@ class ViewFactory * * @return Smarty */ - public static function create(Container $container, Request $request = null) + public static function create(ContainerInterface $container, Request $request = null) { if (!isset($request)) { $request = $container['request']; From 6651b45545ce3d2700635e2941f087b69288a509 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 28 Apr 2017 14:43:20 +0200 Subject: [PATCH 37/40] Use --flat-playlist to get playlists more efficiently --- classes/Config.php | 2 +- templates/playlist.tpl | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/classes/Config.php b/classes/Config.php index 1f73e6b..be22a3e 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -38,7 +38,7 @@ class Config * * @var array */ - public $params = ['--no-warnings', '--ignore-errors']; + public $params = ['--no-warnings', '--ignore-errors', '--flat-playlist']; /** * Enable audio conversion. diff --git a/templates/playlist.tpl b/templates/playlist.tpl index 670bc36..f6c9f22 100644 --- a/templates/playlist.tpl +++ b/templates/playlist.tpl @@ -8,12 +8,20 @@

{foreach $video->entries as $video}
- -

{$video->title}

- webpage_url}">Download - {if count($video->formats) > 1} - webpage_url}">More options - {/if} +

+ {if !isset($video->title) and $video->ie_key == YoutubePlaylist} + Playlist + {else} + {$video->title} + {/if} +

+ url}">Download + url}">More options
{/foreach} From a356af4b9c9f7b22b6c998d5a642ed40eab1608e Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 28 Apr 2017 14:49:41 +0200 Subject: [PATCH 38/40] Update youtube-dl to 2017.04.28 --- composer.json | 6 +++--- composer.lock | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 0dd115d..870d923 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "squizlabs/php_codesniffer": "~2.8.0", "phpunit/phpunit": "~5.7.2", "ffmpeg/ffmpeg": "dev-release", - "rg3/youtube-dl": "~2017.04.17", + "rg3/youtube-dl": "~2017.04.28", "rudloff/rtmpdump-bin": "~2.3", "heroku/heroku-buildpack-php": "*" }, @@ -37,10 +37,10 @@ "type": "package", "package": { "name": "rg3/youtube-dl", - "version": "2017.04.17", + "version": "2017.04.28", "dist": { "type": "zip", - "url": "https://github.com/rg3/youtube-dl/archive/2017.04.17.zip" + "url": "https://github.com/rg3/youtube-dl/archive/2017.04.28.zip" } } }, diff --git a/composer.lock b/composer.lock index 2903ba6..5d2f04b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "05ee38e7300fb500b266722aab1b441c", + "content-hash": "6fda75dec4d72b9620ca68697278dc7e", "packages": [ { "name": "aura/session", @@ -1735,10 +1735,10 @@ }, { "name": "rg3/youtube-dl", - "version": "2017.04.17", + "version": "2017.04.28", "dist": { "type": "zip", - "url": "https://github.com/rg3/youtube-dl/archive/2017.04.17.zip", + "url": "https://github.com/rg3/youtube-dl/archive/2017.04.28.zip", "reference": null, "shasum": null }, From 0d5bde9f224c9bdd992f7c62aff63bce4ab44ebe Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 28 Apr 2017 16:13:39 +0200 Subject: [PATCH 39/40] Add info about remux mode in FAQ --- FAQ.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/FAQ.md b/FAQ.md index 4ef649b..90e10c7 100644 --- a/FAQ.md +++ b/FAQ.md @@ -18,6 +18,7 @@ Here are the parameters that you can set: * `convert`: true to enable audio conversion * `avconv`: path to your avconv or ffmpeg binary * `rtmpdump`: path to your rtmpdump binary +* `remux`: enable remux mode (experimental) See [`config.example.yml`](config.example.yml) for default values. @@ -128,3 +129,12 @@ And you probably need to run this in another terminal after `heroku local` has f ```bash chmod 0667 /tmp/heroku.fcgi.5000.sock ``` + +## How can I download 1080p videos from Youtube? + +Youtube distributes HD content in two separate video and audio files. +So Alltube will offer you video-only and audio-only formats in the format list. + +You then need to merge them together with a tool like ffmpeg. + +You can also enable the experimental remux mode that will merge the best video and the best audio format on the fly. From f08b7ad1fb48d7ba119582d2be43a3b69c936eb3 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 28 Apr 2017 16:27:12 +0200 Subject: [PATCH 40/40] 0.9.0 release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9469e74..2c3b8e0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "alltube", "description": "HTML GUI for youtube-dl", - "version": "0.8.1-beta", + "version": "0.9.0", "author": "Pierre Rudloff", "bugs": "https://github.com/Rudloff/alltube/issues", "dependencies": {