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