Merge branch 'develop' of https://github.com/hukoeth/alltube into feature/playlist

Conflicts:
	templates/video.tpl
This commit is contained in:
Pierre Rudloff 2017-04-25 01:14:21 +02:00
commit 3f053d9eed
5 changed files with 117 additions and 104 deletions

View file

@ -113,7 +113,14 @@ class VideoDownload
* */ * */
public function getJSON($url, $format = null, $password = null) 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;
} }
/** /**

View file

@ -213,7 +213,7 @@ class FrontController
private function getVideoResponse(Request $request, Response $response, array $params, $password = null) private function getVideoResponse(Request $request, Response $response, array $params, $password = null)
{ {
try { try {
$video = $this->download->getJSON($params['url'], $this->defaultFormat, $password); $vidarr = $this->download->getJSON($params['url'], $this->defaultFormat, $password);
} catch (PasswordException $e) { } catch (PasswordException $e) {
return $this->password($request, $response); return $this->password($request, $response);
} }
@ -226,10 +226,10 @@ class FrontController
$response, $response,
'video.tpl', 'video.tpl',
[ [
'video' => $video, 'vidarr' => $vidarr,
'class' => 'video', 'class' => 'video',
'title' => $video->title, 'title' => $vidarr[0]->title,
'description' => 'Download "'.$video->title.'" from '.$video->extractor_key, 'description' => 'Download "'.$vidarr[0]->title.'" from '.$vidarr[0]->extractor_key,
'protocol' => $protocol, 'protocol' => $protocol,
'config' => $this->config, 'config' => $this->config,
'canonical' => $this->getCanonicalUrl($request), 'canonical' => $this->getCanonicalUrl($request),

View file

@ -1,5 +1,4 @@
<?php <?php
require_once __DIR__.'/vendor/autoload.php'; require_once __DIR__.'/vendor/autoload.php';
use Alltube\Config; use Alltube\Config;
use Alltube\Controller\FrontController; use Alltube\Controller\FrontController;

View file

@ -2,7 +2,7 @@
/*jslint browser: true, nomen: true */ /*jslint browser: true, nomen: true */
var castModule = (function () { var castModule = (function () {
'use strict'; 'use strict';
var launchBtn, disabledBtn, stopBtn, session; var launchBtn, disabledBtn, stopBtn, session, videoLink;
function receiverListener(e) { function receiverListener(e) {
return (e === chrome.cast.ReceiverAvailability.AVAILABLE); return (e === chrome.cast.ReceiverAvailability.AVAILABLE);
@ -51,7 +51,7 @@ var castModule = (function () {
function onRequestSessionSuccess(e) { function onRequestSessionSuccess(e) {
session = 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); session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError);
} }
@ -59,19 +59,23 @@ var castModule = (function () {
throw e.description; throw e.description;
} }
function launchCast() { function launchCast(event) {
videoLink = event.target || event.srcElement;
chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError); chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
} }
function onInitSuccess() { function onInitSuccess() {
launchBtn = document.getElementById('cast_btn_launch'); launchBtn = document.getElementsByClassName('cast_btn_launch');
disabledBtn = document.getElementById('cast_disabled'); disabledBtn = document.getElementsByClassName('cast_disabled');
stopBtn = document.getElementById('cast_btn_stop'); stopBtn = document.getElementsByClassName('cast_btn_stop');
if (launchBtn) { if (launchBtn.length > 0) {
disabledBtn.classList.add('cast_hidden'); var i;
launchBtn.classList.remove('cast_hidden'); for (i = 0; i < launchBtn.length; i++) {
launchBtn.addEventListener('click', launchCast, false); disabledBtn[i].classList.add('cast_hidden');
stopBtn.addEventListener('click', stopCast, false); 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 { return {
init: function () { init: function () {
var intro = document.getElementById('download_intro'); var intro = document.getElementsByClassName('download_intro'), i;
if (intro) { for (i = 0; i < intro.length; i++) {
intro.insertAdjacentHTML('beforeend', '<img class="cast_icon" id="cast_disabled" src="img/ic_media_route_disabled_holo_light.png" alt="" title="Google Cast is not supported on this browser." /> <img class="cast_btn cast_hidden cast_icon" id="cast_btn_launch" src="img/ic_media_route_off_holo_light.png" title="Cast to ChromeCast" alt="Google Cast™" /> <img src="img/ic_media_route_on_holo_light.png" alt="Casting to ChromeCast…" title="Stop casting" id="cast_btn_stop" class="cast_btn cast_hidden cast_icon" />'); intro[i].insertAdjacentHTML('beforeend', '<img class="cast_disabled cast_icon" id="cast_disabled'+i+'" src="img/ic_media_route_disabled_holo_light.png" alt="" title="Google Cast is not supported on this browser." /> <img class="cast_btn_launch cast_btn cast_hidden cast_icon" id="cast_btn_launch'+i+'" src="img/ic_media_route_off_holo_light.png" title="Cast to ChromeCast" alt="Google Cast™" /> <img src="img/ic_media_route_on_holo_light.png" alt="Casting to ChromeCast…" title="Stop casting" id="cast_btn_stop'+i+'" class="cast_btn_stop cast_btn cast_hidden cast_icon" />');
window.__onGCastApiAvailable = loadCastApi;
} }
window.__onGCastApiAvailable = loadCastApi;
} }
}; };
}()); }());

View file

@ -3,92 +3,95 @@
<div itemscope itemtype="http://schema.org/VideoObject"> <div itemscope itemtype="http://schema.org/VideoObject">
<div class="main"> <div class="main">
{include file="inc/logo.tpl"} {include file="inc/logo.tpl"}
<p id="download_intro">You are going to download<i itemprop="name"> {foreach $vidarr as $video}
<a itemprop="url" id="video_link" <p id="download_intro{$video@index}" class="download_intro">You are going to download<i itemprop="name">
data-ext="{$video->ext}" <a itemprop="url" id="video_link{$video@index}"
data-video="{$video->url|escape}" class="video_link"
href="{$video->webpage_url}"> data-ext="{$video->ext}"
{$video->title}</a></i>. data-video="{$video->url|escape}"
</p> href="{$video->webpage_url}">
{if isset($video->thumbnail)} {$video->title}</a></i>.
<img itemprop="thumbnailUrl" class="thumb" src="{$video->thumbnail}" alt="" /> </p>
{/if} {if isset($video->thumbnail)}
{if isset($video->description)} <img itemprop="thumbnailUrl" class="thumb" src="{$video->thumbnail}" alt="" />
<meta itemprop="description" content="{$video->description|escape}" /> {/if}
{/if} {if isset($video->description)}
{if isset($video->upload_date)} <meta itemprop="description" content="{$video->description|escape}" />
<meta itemprop="uploadDate" content="{$video->upload_date}" /> {/if}
{/if} {if isset($video->upload_date)}
<br/> <meta itemprop="uploadDate" content="{$video->upload_date}" />
{if isset($video->formats)} {/if}
<h3><label for="format">Available formats:</label></h3> <br/>
<form action="{path_for name="redirect"}"> {if isset($video->formats)}
<input type="hidden" name="url" value="{$video->webpage_url}" /> <h3><label for="format{$video@index}">Available formats:</label></h3>
{if $uglyUrls} <form action="{path_for name="redirect"}">
<input type="hidden" name="page" value="redirect" /> <input type="hidden" name="url" value="{$video->webpage_url}" />
{/if} {if uglyUrls}
<select name="format" id="format" class="formats monospace"> <input type="hidden" name="page" value="redirect" />
<optgroup label="Generic formats"> {/if}
<option value="best{$protocol}"> <select name="format" id="format{$video@index}" class="formats monospace">
{strip} <optgroup label="Generic formats">
Best ({$video->ext}) <option value="best{$protocol}">
{/strip}
</option>
{if $remux}
<option value="bestvideo+bestaudio">
Remux best video with best audio
</option>
{/if}
<option value="worst{$protocol}">
Worst
</option>
</optgroup>
<optgroup label="Detailed formats" class="monospace">
{foreach $video->formats as $format}
{if $config->stream || $format->protocol|in_array:array('http', 'https')}
{strip} {strip}
<option value="{$format->format_id}"> Best ({$video->ext})
{$format->ext}
{for $foo=1 to (5 - ($format->ext|strlen))}
&nbsp;
{/for}
{if isset($format->width)}
{$format->width}x{$format->height}
{for $foo=1 to (10 - (("{$format->width}x{$format->height}")|strlen))}
&nbsp;
{/for}
{else}
{for $foo=1 to 10}
&nbsp;
{/for}
{/if}
{if isset($format->filesize)}
{($format->filesize/1000000)|round:2} MB
{for $foo=1 to (7 - (($format->filesize/1000000)|round:2|strlen))}
&nbsp;
{/for}
{else}
{for $foo=1 to 10}
&nbsp;
{/for}
{/if}
{if isset($format->format_note)}
{$format->format_note}
{/if}
&nbsp;({$format->format_id})
</option>
{/strip} {/strip}
</option>
{if $remux}
<option value="bestvideo+bestaudio">
Remux best video with best audio
</option>
{/if} {/if}
{/foreach} <option value="worst{$protocol}">
</optgroup> Worst
</select><br/><br/> </option>
<input class="downloadBtn" type="submit" value="Download" /><br/> </optgroup>
</form> <optgroup label="Detailed formats" class="monospace">
{else} {foreach $video->formats as $format}
<input type="hidden" name="format" value="best{$protocol}" /> {if $config->stream || $format->protocol|in_array:array('http', 'https')}
<a class="downloadBtn" {strip}
href="{$video->url|escape}">Download</a><br/> <option value="{$format->format_id}">
{/if} {$format->ext}
{for $foo=1 to (5 - ($format->ext|strlen))}
&nbsp;
{/for}
{if isset($format->width)}
{$format->width}x{$format->height}
{for $foo=1 to (10 - (("{$format->width}x{$format->height}")|strlen))}
&nbsp;
{/for}
{else}
{for $foo=1 to 10}
&nbsp;
{/for}
{/if}
{if isset($format->filesize)}
{($format->filesize/1000000)|round:2} MB
{for $foo=1 to (7 - (($format->filesize/1000000)|round:2|strlen))}
&nbsp;
{/for}
{else}
{for $foo=1 to 10}
&nbsp;
{/for}
{/if}
{if isset($format->format_note)}
{$format->format_note}
{/if}
&nbsp;({$format->format_id})
</option>
{/strip}
{/if}
{/foreach}
</optgroup>
</select><br/><br/>
<input class="downloadBtn" type="submit" value="Download" /><br/>
</form>
{else}
<input type="hidden" name="format" value="best{$protocol}" />
<a class="downloadBtn" href="{$video->url|escape}">Download</a><br/>
{/if}
<hr />
{/foreach}
</div> </div>
</div> </div>
{include file="inc/footer.tpl"} {include file="inc/footer.tpl"}