parent
d96a1e4867
commit
4e1c1ca953
5 changed files with 56 additions and 24 deletions
|
@ -38,12 +38,7 @@ class Config
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $params = [
|
public $params = ['--no-playlist', '--no-warnings', '--playlist-end', 1];
|
||||||
'--no-playlist', '--no-warnings',
|
|
||||||
//We can allow non-HTTP URLs on the feature/stream branch
|
|
||||||
'-f best',
|
|
||||||
'--playlist-end', 1,
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable audio conversion.
|
* Enable audio conversion.
|
||||||
|
@ -87,6 +82,12 @@ class Config
|
||||||
*/
|
*/
|
||||||
public $uglyUrls = false;
|
public $uglyUrls = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stream downloaded files trough server?
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
public $stream = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YAML config file path.
|
* YAML config file path.
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,7 +3,6 @@ python: /usr/bin/python
|
||||||
params:
|
params:
|
||||||
- --no-playlist
|
- --no-playlist
|
||||||
- --no-warnings
|
- --no-warnings
|
||||||
- -f best[protocol^=http]
|
|
||||||
- --playlist-end
|
- --playlist-end
|
||||||
- 1
|
- 1
|
||||||
curl_params:
|
curl_params:
|
||||||
|
@ -12,3 +11,4 @@ avconv: vendor/bin/ffmpeg
|
||||||
rtmpdump: vendor/bin/rtmpdump
|
rtmpdump: vendor/bin/rtmpdump
|
||||||
curl: /usr/bin/curl
|
curl: /usr/bin/curl
|
||||||
uglyUrls: false
|
uglyUrls: false
|
||||||
|
stream: false
|
||||||
|
|
|
@ -68,6 +68,11 @@ class FrontController
|
||||||
$session_factory = new \Aura\Session\SessionFactory();
|
$session_factory = new \Aura\Session\SessionFactory();
|
||||||
$session = $session_factory->newInstance($_COOKIE);
|
$session = $session_factory->newInstance($_COOKIE);
|
||||||
$this->sessionSegment = $session->getSegment('Alltube\Controller\FrontController');
|
$this->sessionSegment = $session->getSegment('Alltube\Controller\FrontController');
|
||||||
|
if ($this->config->stream) {
|
||||||
|
$this->defaultFormat = 'best';
|
||||||
|
} else {
|
||||||
|
$this->defaultFormat = 'best[protocol^=http]';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,7 +161,13 @@ class FrontController
|
||||||
}
|
}
|
||||||
if (isset($params['audio'])) {
|
if (isset($params['audio'])) {
|
||||||
try {
|
try {
|
||||||
|
if ($this->config->stream) {
|
||||||
return $this->getStream($params['url'], 'mp3', $response, $request, $password);
|
return $this->getStream($params['url'], 'mp3', $response, $request, $password);
|
||||||
|
} else {
|
||||||
|
$url = $this->download->getURL($params['url'], 'mp3[protocol^=http]', $password);
|
||||||
|
|
||||||
|
return $response->withRedirect($url);
|
||||||
|
}
|
||||||
} catch (PasswordException $e) {
|
} catch (PasswordException $e) {
|
||||||
return $this->password($request, $response);
|
return $this->password($request, $response);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -176,10 +187,15 @@ class FrontController
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$video = $this->download->getJSON($params['url'], null, $password);
|
$video = $this->download->getJSON($params['url'], $this->defaultFormat, $password);
|
||||||
} catch (PasswordException $e) {
|
} catch (PasswordException $e) {
|
||||||
return $this->password($request, $response);
|
return $this->password($request, $response);
|
||||||
}
|
}
|
||||||
|
if ($this->config->stream) {
|
||||||
|
$protocol = '';
|
||||||
|
} else {
|
||||||
|
$protocol = '[protocol^=http]';
|
||||||
|
}
|
||||||
$this->view->render(
|
$this->view->render(
|
||||||
$response,
|
$response,
|
||||||
'video.tpl',
|
'video.tpl',
|
||||||
|
@ -188,6 +204,8 @@ class FrontController
|
||||||
'class' => 'video',
|
'class' => 'video',
|
||||||
'title' => $video->title,
|
'title' => $video->title,
|
||||||
'description' => 'Download "'.$video->title.'" from '.$video->extractor_key,
|
'description' => 'Download "'.$video->title.'" from '.$video->extractor_key,
|
||||||
|
'protocol' => $protocol,
|
||||||
|
'config' => $this->config,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -270,6 +288,7 @@ class FrontController
|
||||||
$params = $request->getQueryParams();
|
$params = $request->getQueryParams();
|
||||||
if (isset($params['url'])) {
|
if (isset($params['url'])) {
|
||||||
try {
|
try {
|
||||||
|
if ($this->config->stream) {
|
||||||
return $this->getStream(
|
return $this->getStream(
|
||||||
$params['url'],
|
$params['url'],
|
||||||
$request->getParam('format'),
|
$request->getParam('format'),
|
||||||
|
@ -277,6 +296,15 @@ class FrontController
|
||||||
$request,
|
$request,
|
||||||
$this->sessionSegment->getFlash($params['url'])
|
$this->sessionSegment->getFlash($params['url'])
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$url = $this->download->getURL(
|
||||||
|
$params['url'],
|
||||||
|
$request->getParam('format'),
|
||||||
|
$this->sessionSegment->getFlash($params['url'])
|
||||||
|
);
|
||||||
|
|
||||||
|
return $response->withRedirect($url);
|
||||||
|
}
|
||||||
} catch (PasswordException $e) {
|
} catch (PasswordException $e) {
|
||||||
return $response->withRedirect(
|
return $response->withRedirect(
|
||||||
$this->container->get('router')->pathFor('video').'?url='.urlencode($params['url'])
|
$this->container->get('router')->pathFor('video').'?url='.urlencode($params['url'])
|
||||||
|
|
|
@ -29,17 +29,18 @@
|
||||||
{/if}
|
{/if}
|
||||||
<select name="format" id="format" class="formats monospace">
|
<select name="format" id="format" class="formats monospace">
|
||||||
<optgroup label="Generic formats">
|
<optgroup label="Generic formats">
|
||||||
<option value="best">
|
<option value="best{$protocol}">
|
||||||
{strip}
|
{strip}
|
||||||
Best ({$video->ext})
|
Best ({$video->ext})
|
||||||
{/strip}
|
{/strip}
|
||||||
</option>
|
</option>
|
||||||
<option value="worst">
|
<option value="worst{$protocol}">
|
||||||
Worst
|
Worst
|
||||||
</option>
|
</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="Detailed formats" class="monospace">
|
<optgroup label="Detailed formats" class="monospace">
|
||||||
{foreach $video->formats as $format}
|
{foreach $video->formats as $format}
|
||||||
|
{if $config->stream || $format->protocol|in_array:array('http', 'https')}
|
||||||
{strip}
|
{strip}
|
||||||
<option value="{$format->format_id}">
|
<option value="{$format->format_id}">
|
||||||
{$format->ext}
|
{$format->ext}
|
||||||
|
@ -72,13 +73,14 @@
|
||||||
({$format->format_id})
|
({$format->format_id})
|
||||||
</option>
|
</option>
|
||||||
{/strip}
|
{/strip}
|
||||||
|
{/if}
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</optgroup>
|
</optgroup>
|
||||||
</select><br/><br/>
|
</select><br/><br/>
|
||||||
<input class="downloadBtn" type="submit" value="Download" /><br/>
|
<input class="downloadBtn" type="submit" value="Download" /><br/>
|
||||||
</form>
|
</form>
|
||||||
{else}
|
{else}
|
||||||
<input type="hidden" name="format" value="best" />
|
<input type="hidden" name="format" value="best{$protocol}" />
|
||||||
<a class="downloadBtn"
|
<a class="downloadBtn"
|
||||||
href="{$video->url|escape}">Download</a><br/>
|
href="{$video->url|escape}">Download</a><br/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -146,7 +146,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
'https://www.youtube.com/watch?v=M7IpKCZ47pU', null,
|
'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'best[protocol^=http]',
|
||||||
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU",
|
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU",
|
||||||
'mp4',
|
'mp4',
|
||||||
'googlevideo.com',
|
'googlevideo.com',
|
||||||
|
@ -159,7 +159,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
'googlevideo.com',
|
'googlevideo.com',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'https://vimeo.com/24195442', null,
|
'https://vimeo.com/24195442', 'best[protocol^=http]',
|
||||||
'Carving the Mountains-24195442',
|
'Carving the Mountains-24195442',
|
||||||
'mp4',
|
'mp4',
|
||||||
'vimeocdn.com',
|
'vimeocdn.com',
|
||||||
|
@ -188,7 +188,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
'https://twitter.com/verge/status/813055465324056576/video/1', null,
|
'https://twitter.com/verge/status/813055465324056576/video/1', 'best',
|
||||||
'The Verge - This tiny origami robot can self-fold and complete tasks-813055465324056576',
|
'The Verge - This tiny origami robot can self-fold and complete tasks-813055465324056576',
|
||||||
'mp4',
|
'mp4',
|
||||||
'video.twimg.com',
|
'video.twimg.com',
|
||||||
|
@ -225,6 +225,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertObjectHasAttribute('url', $info);
|
$this->assertObjectHasAttribute('url', $info);
|
||||||
$this->assertObjectHasAttribute('ext', $info);
|
$this->assertObjectHasAttribute('ext', $info);
|
||||||
$this->assertObjectHasAttribute('title', $info);
|
$this->assertObjectHasAttribute('title', $info);
|
||||||
|
$this->assertObjectHasAttribute('extractor_key', $info);
|
||||||
$this->assertObjectHasAttribute('formats', $info);
|
$this->assertObjectHasAttribute('formats', $info);
|
||||||
$this->assertObjectHasAttribute('_filename', $info);
|
$this->assertObjectHasAttribute('_filename', $info);
|
||||||
}
|
}
|
||||||
|
@ -322,7 +323,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testGetAudioStreamAvconvError($url, $format)
|
public function testGetAudioStreamAvconvError($url, $format)
|
||||||
{
|
{
|
||||||
$config = \Alltube\Config::getInstance();
|
$config = Config::getInstance();
|
||||||
$config->avconv = 'foobar';
|
$config->avconv = 'foobar';
|
||||||
$this->download->getAudioStream($url, $format);
|
$this->download->getAudioStream($url, $format);
|
||||||
}
|
}
|
||||||
|
@ -339,7 +340,7 @@ class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function testGetAudioStreamCurlError($url, $format)
|
public function testGetAudioStreamCurlError($url, $format)
|
||||||
{
|
{
|
||||||
$config = \Alltube\Config::getInstance();
|
$config = Config::getInstance();
|
||||||
$config->curl = 'foobar';
|
$config->curl = 'foobar';
|
||||||
$config->rtmpdump = 'foobar';
|
$config->rtmpdump = 'foobar';
|
||||||
$this->download->getAudioStream($url, $format);
|
$this->download->getAudioStream($url, $format);
|
||||||
|
|
Loading…
Reference in a new issue