Merge branch 'develop' into feature/stream

Conflicts:
	controllers/FrontController.php
This commit is contained in:
Pierre Rudloff 2016-05-01 13:52:45 +02:00
commit 94722841c9
3 changed files with 119 additions and 117 deletions

View file

@ -14,6 +14,10 @@ Addtype font/truetype .ttf
FileETag None FileETag None
RewriteEngine On RewriteEngine On
RewriteCond %{HTTP_HOST} ^alltube\.herokuapp\.com$ [NC]
RewriteRule ^(.*)$ https://www.alltubedownload.net/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L] RewriteRule ^ index.php [QSA,L]

View file

@ -115,134 +115,130 @@ class FrontController
if (isset($params["url"])) { if (isset($params["url"])) {
if (isset($params['audio'])) { if (isset($params['audio'])) {
try { try {
try { return $this->getStream($params["url"], 'bestaudio[protocol^=http]', $response, $request);
return $this->getStream($params["url"], 'bestaudio[protocol^=http]', $response, $request); } catch (\Exception $e) {
} catch (\Exception $e) { $video = $this->download->getJSON($params["url"], 'best');
$video = $this->download->getJSON($params["url"], 'best');
$avconvProc = ProcessBuilder::create( $avconvProc = ProcessBuilder::create(
array(
$this->config->avconv,
'-v', 'quiet',
'-i', '-',
'-f', 'mp3',
'-vn',
'pipe:1'
)
);
//Vimeo needs a correct user-agent
ini_set(
'user_agent',
$video->http_headers->{'User-Agent'}
);
$response = $response->withHeader(
'Content-Disposition',
'attachment; filename="'.
html_entity_decode(
pathinfo(
$video->_filename,
PATHINFO_FILENAME
).'.mp3',
ENT_COMPAT,
'ISO-8859-1'
).'"'
);
$response = $response->withHeader('Content-Type', 'audio/mpeg');
if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') {
$builder = new ProcessBuilder(
array( array(
$this->config->avconv, $this->config->rtmpdump,
'-v', 'quiet', '-q',
'-i', '-', '-r',
'-f', 'mp3', $video->url,
'-vn', '--pageUrl', $video->webpage_url
'pipe:1'
) )
); );
if (isset($video->player_url)) {
//Vimeo needs a correct user-agent $builder->add('--swfVfy');
ini_set( $builder->add($video->player_url);
'user_agent',
$video->http_headers->{'User-Agent'}
);
$response = $response->withHeader(
'Content-Disposition',
'attachment; filename="'.
html_entity_decode(
pathinfo(
$video->_filename,
PATHINFO_FILENAME
).'.mp3',
ENT_COMPAT,
'ISO-8859-1'
).'"'
);
$response = $response->withHeader('Content-Type', 'audio/mpeg');
if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') {
$builder = new ProcessBuilder(
array(
$this->config->rtmpdump,
'-q',
'-r',
$video->url,
'--pageUrl', $video->webpage_url
)
);
if (isset($video->player_url)) {
$builder->add('--swfVfy');
$builder->add($video->player_url);
}
if (isset($video->flash_version)) {
$builder->add('--flashVer');
$builder->add($video->flash_version);
}
if (isset($video->play_path)) {
$builder->add('--playpath');
$builder->add($video->play_path);
}
foreach ($video->rtmp_conn as $conn) {
$builder->add('--conn');
$builder->add($conn);
}
$chain = new Chain($builder->getProcess());
$chain->add('|', $avconvProc);
} else {
$chain = new Chain(
ProcessBuilder::create(
array_merge(
array(
'curl',
'--silent',
'--user-agent', $video->http_headers->{'User-Agent'},
$video->url
),
$this->config->curl_params
)
)
);
$chain->add('|', $avconvProc);
} }
if ($request->isGet()) { if (isset($video->flash_version)) {
$response = $response->withBody(new PopenStream($chain->getProcess()->getCommandLine())); $builder->add('--flashVer');
$builder->add($video->flash_version);
} }
return $response; if (isset($video->play_path)) {
$builder->add('--playpath');
$builder->add($video->play_path);
}
foreach ($video->rtmp_conn as $conn) {
$builder->add('--conn');
$builder->add($conn);
}
$chain = new Chain($builder->getProcess());
$chain->add('|', $avconvProc);
} else {
$chain = new Chain(
ProcessBuilder::create(
array_merge(
array(
'curl',
'--silent',
'--user-agent', $video->http_headers->{'User-Agent'},
$video->url
),
$this->config->curl_params
)
)
);
$chain->add('|', $avconvProc);
} }
} catch (\Exception $e) { if ($request->isGet()) {
$error = $e->getMessage(); $response = $response->withBody(new PopenStream($chain->getProcess()->getCommandLine()));
}
return $response;
} }
} else { } else {
try { $video = $this->download->getJSON($params["url"]);
$video = $this->download->getJSON($params["url"]); $container->view->render(
$container->view->render( $response,
$response, 'head.tpl',
'head.tpl', array(
array( 'class'=>'video'
'class'=>'video' )
) );
); $container->view->render(
$container->view->render( $response,
$response, 'video.tpl',
'video.tpl', array(
array( 'video'=>$video
'video'=>$video )
) );
); $container->view->render($response, 'footer.tpl');
$container->view->render($response, 'footer.tpl');
} catch (\Exception $e) {
$error = $e->getMessage();
}
} }
} }
if (isset($error)) { }
$container->view->render(
$response, public function error($request, $response, $exception)
'head.tpl', {
array( global $container;
'class'=>'video' $container->view->render(
) $response,
); 'head.tpl',
$container->view->render( array(
$response, 'class'=>'video'
'error.tpl', )
array( );
'errors'=>$error $container->view->render(
) $response,
); 'error.tpl',
$container->view->render($response, 'footer.tpl'); array(
} 'errors'=>$exception->getMessage()
)
);
$container->view->render($response, 'footer.tpl');
return $response;
} }
private function getStream($url, $format, $response, $request) private function getStream($url, $format, $response, $request)

View file

@ -30,6 +30,8 @@ $container['view'] = function ($c) {
$controller = new FrontController(); $controller = new FrontController();
$container['errorHandler'] = array($controller, 'error');
$app->get( $app->get(
'/', '/',
array($controller, 'index') array($controller, 'index')