WIP stream

This commit is contained in:
Pierre Rudloff 2016-04-07 02:09:34 +02:00
parent 7eef219128
commit df9f60339d
5 changed files with 216 additions and 35 deletions

View file

@ -12,7 +12,8 @@
"symfony/yaml": "~3.0.0",
"symfony/process": "~3.0.0",
"ffmpeg/ffmpeg": "~2.8.2",
"rudloff/smarty-plugin-noscheme": "~0.1.0"
"rudloff/smarty-plugin-noscheme": "~0.1.0",
"guzzlehttp/guzzle": "~6.2.0"
},
"require-dev": {
"symfony/var-dumper": "~3.0.0"

175
composer.lock generated
View file

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "829ac07cae5bc43ef0ad3f5e5be618c5",
"content-hash": "a7131399bb03f78ba0dcfd8ab7e98d59",
"hash": "6ef0d5dc0640824fef3033cba540c6fb",
"content-hash": "dd3d8be96114267b553f77632c326e2c",
"packages": [
{
"name": "container-interop/container-interop",
@ -48,6 +48,177 @@
],
"type": "library"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "d094e337976dff9d8e2424e8485872194e768662"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/d094e337976dff9d8e2424e8485872194e768662",
"reference": "d094e337976dff9d8e2424e8485872194e768662",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "~1.0",
"guzzlehttp/psr7": "~1.1",
"php": ">=5.5.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "~4.0",
"psr/log": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.2-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2016-03-21 20:02:09"
},
{
"name": "guzzlehttp/promises",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8",
"reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2016-03-08 01:15:46"
},
{
"name": "guzzlehttp/psr7",
"version": "1.2.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/2e89629ff057ebb49492ba08e6995d3a6a80021b",
"reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "PSR-7 message implementation",
"keywords": [
"http",
"message",
"stream",
"uri"
],
"time": "2016-02-18 21:54:00"
},
{
"name": "jeremykendall/php-domain-parser",
"version": "3.0.0",

View file

@ -103,11 +103,12 @@ class FrontController
public static function video($request, $response)
{
global $container;
$params = $request->getQueryParams();
$config = Config::getInstance();
if (isset($_GET["url"])) {
if (isset($_GET['audio'])) {
if (isset($params["url"])) {
if (isset($params['audio'])) {
try {
$video = VideoDownload::getJSON($_GET["url"]);
$video = VideoDownload::getJSON($params["url"]);
//Vimeo needs a correct user-agent
$UA = VideoDownload::getUA();
@ -168,7 +169,7 @@ class FrontController
}
} else {
try {
$video = VideoDownload::getJSON($_GET["url"]);
$video = VideoDownload::getJSON($params["url"]);
$container->view->render(
$response,
'head.tpl',
@ -219,12 +220,22 @@ class FrontController
public static function redirect($request, $response)
{
global $app;
if (isset($_GET["url"])) {
$params = $request->getQueryParams();
if (isset($params["url"])) {
try {
$video = VideoDownload::getURL($_GET["url"]);
return $response->withRedirect($video['url']);
$format = isset($params["format"]) ? $params["format"] : 'best';
$video = VideoDownload::getJSON($params["url"], $format);
$client = new \GuzzleHttp\Client();
$stream = $client->request('GET', $video->url, array('stream'=>true));
$response = $response->withHeader('Content-Disposition', 'inline; filename="'.$video->_filename.'"');
$response = $response->withHeader('Content-Type', $stream->getHeader('Content-Type'));
$response = $response->withHeader('Content-Length', $stream->getHeader('Content-Length'));
if ($request->isGet()) {
$response = $response->withBody($stream->getBody());
}
return $response;
} catch (\Exception $e) {
echo $e->getMessage().PHP_EOL;
$response->getBody()->write($e->getMessage().PHP_EOL);
return $response->withHeader('Content-Type', 'text/plain');
}
}
@ -241,9 +252,10 @@ class FrontController
public static function json($request, $response)
{
global $app;
if (isset($_GET["url"])) {
$params = $request->getQueryParams();
if (isset($params["url"])) {
try {
$video = VideoDownload::getJSON($_GET["url"]);
$video = VideoDownload::getJSON($params["url"]);
return $response->withJson($video);
} catch (\Exception $e) {
return $response->withJson(

View file

@ -22,7 +22,7 @@ $container['view'] = function ($c) {
$view = new \Slim\Views\Smarty(__DIR__.'/templates/');
$view->addSlimPlugins($c['router'], $c['request']->getUri());
$view->registerPlugin('modifier', 'noscheme', 'Smarty_Modifier_noscheme');
$view->registerPlugin('modifier', 'noscheme', 'Smarty_Modifier_noscheme');
return $view;
@ -43,7 +43,7 @@ $app->get(
$app->get(
'/redirect',
array('Alltube\Controller\FrontController', 'redirect')
);
)->setName('redirect');
$app->get(
'/json',
array('Alltube\Controller\FrontController', 'json')

View file

@ -22,27 +22,24 @@
<img itemprop="image" class="thumb" src="{$video->thumbnail}" alt="" />
{/if}
<br/>
<input type="hidden" name="url"
value="{$video->webpage_url}" />
{if isset($video->formats)}
<h3>Available formats:</h3>
<p>(You might have to do a <i>Right click > Save as</i>)</p>
<ul id="format" class="format">
<li class="best" itemprop="encoding" itemscope
itemtype="http://schema.org/VideoObject">
<a download="{$video->_filename}" itemprop="contentUrl"
href="{$video->url|escape}">
<b>Best</b> (<span itemprop="encodingFormat">{$video->ext}</span>)
</a></li>
{foreach $video->formats as $format}
<li itemprop="encoding"
itemscope itemtype="http://schema.org/VideoObject">
<a download="{$video->_filename|replace:$video->ext:$format->ext}" itemprop="contentUrl"
href="{$format->url|escape}">
<span itemprop="videoQuality">{$format->format}</span> (<span itemprop="encodingFormat">{$format->ext}</span>)
</a></li>
{/foreach}
</ul><br/><br/>
<h3><label for="format">Available formats:</label></h3>
<form action="{path_for name="redirect"}">
<input type="hidden" name="url" value="{$video->webpage_url}" />
<select name="format" id="format">
<option value="best">
Best ({$video->ext})
</option>
<optgroup>
{foreach $video->formats as $format}
<option value="{$format->format_id}">
{$format->format} ({$format->ext})
</option>
{/foreach}
</optgroup>
</select><br/><br/>
<input class="downloadBtn" type="submit" value="Download" /><br/>
</form>
{else}
<input type="hidden" name="format" value="best" />
<a class="downloadBtn"