From 03cf5061328e4714f7c640250bb45685f08da4a2 Mon Sep 17 00:00:00 2001 From: Uli Koeth Date: Tue, 7 Mar 2017 17:24:34 +0100 Subject: [PATCH 1/4] 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 2/4] 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 4/4] 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}