Don't use static functions
This commit is contained in:
parent
7eef219128
commit
11e8243443
4 changed files with 64 additions and 52 deletions
|
@ -28,6 +28,11 @@ use Alltube\Config;
|
|||
* */
|
||||
class FrontController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = Config::getInstance();
|
||||
$this->download = new VideoDownload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display index page
|
||||
|
@ -37,10 +42,9 @@ class FrontController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function index($request, $response)
|
||||
public function index($request, $response)
|
||||
{
|
||||
global $container;
|
||||
$config = Config::getInstance();
|
||||
$container->view->render(
|
||||
$response,
|
||||
'head.tpl',
|
||||
|
@ -56,7 +60,7 @@ class FrontController
|
|||
$response,
|
||||
'index.tpl',
|
||||
array(
|
||||
'convert'=>$config->convert
|
||||
'convert'=>$this->config->convert
|
||||
)
|
||||
);
|
||||
$container->view->render($response, 'footer.tpl');
|
||||
|
@ -70,7 +74,7 @@ class FrontController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function extractors($request, $response)
|
||||
public function extractors($request, $response)
|
||||
{
|
||||
global $container;
|
||||
$container->view->render(
|
||||
|
@ -86,7 +90,7 @@ class FrontController
|
|||
$response,
|
||||
'extractors.tpl',
|
||||
array(
|
||||
'extractors'=>VideoDownload::listExtractors()
|
||||
'extractors'=>$this->download->listExtractors()
|
||||
)
|
||||
);
|
||||
$container->view->render($response, 'footer.tpl');
|
||||
|
@ -100,17 +104,17 @@ class FrontController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function video($request, $response)
|
||||
public function video($request, $response)
|
||||
{
|
||||
global $container;
|
||||
$config = Config::getInstance();
|
||||
$this->config = Config::getInstance();
|
||||
if (isset($_GET["url"])) {
|
||||
if (isset($_GET['audio'])) {
|
||||
try {
|
||||
$video = VideoDownload::getJSON($_GET["url"]);
|
||||
$video = $this->download->getJSON($_GET["url"]);
|
||||
|
||||
//Vimeo needs a correct user-agent
|
||||
$UA = VideoDownload::getUA();
|
||||
$UA = $this->download->getUA();
|
||||
ini_set(
|
||||
'user_agent',
|
||||
$UA
|
||||
|
@ -122,7 +126,7 @@ class FrontController
|
|||
'Content-Disposition: attachment; filename="'.
|
||||
html_entity_decode(
|
||||
pathinfo(
|
||||
VideoDownload::getFilename(
|
||||
$this->download->getFilename(
|
||||
$video->webpage_url
|
||||
),
|
||||
PATHINFO_FILENAME
|
||||
|
@ -134,7 +138,7 @@ class FrontController
|
|||
header("Content-Type: audio/mpeg");
|
||||
passthru(
|
||||
'/usr/bin/rtmpdump -q -r '.escapeshellarg($video->url).
|
||||
' | '.$config->avconv.
|
||||
' | '.$this->config->avconv.
|
||||
' -v quiet -i - -f mp3 -vn pipe:1'
|
||||
);
|
||||
exit;
|
||||
|
@ -144,7 +148,7 @@ class FrontController
|
|||
'Content-Disposition: attachment; filename="'.
|
||||
html_entity_decode(
|
||||
pathinfo(
|
||||
VideoDownload::getFilename(
|
||||
$this->download->getFilename(
|
||||
$video->webpage_url
|
||||
),
|
||||
PATHINFO_FILENAME
|
||||
|
@ -155,10 +159,10 @@ class FrontController
|
|||
);
|
||||
header("Content-Type: audio/mpeg");
|
||||
passthru(
|
||||
'curl '.$config->curl_params.
|
||||
'curl '.$this->config->curl_params.
|
||||
' --user-agent '.escapeshellarg($UA).
|
||||
' '.escapeshellarg($video->url).
|
||||
' | '.$config->avconv.
|
||||
' | '.$this->config->avconv.
|
||||
' -v quiet -i - -f mp3 -vn pipe:1'
|
||||
);
|
||||
exit;
|
||||
|
@ -168,7 +172,7 @@ class FrontController
|
|||
}
|
||||
} else {
|
||||
try {
|
||||
$video = VideoDownload::getJSON($_GET["url"]);
|
||||
$video = $this->download->getJSON($_GET["url"]);
|
||||
$container->view->render(
|
||||
$response,
|
||||
'head.tpl',
|
||||
|
@ -216,12 +220,12 @@ class FrontController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function redirect($request, $response)
|
||||
public function redirect($request, $response)
|
||||
{
|
||||
global $app;
|
||||
if (isset($_GET["url"])) {
|
||||
try {
|
||||
$video = VideoDownload::getURL($_GET["url"]);
|
||||
$video = $this->download->getURL($_GET["url"]);
|
||||
return $response->withRedirect($video['url']);
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
|
@ -238,12 +242,12 @@ class FrontController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function json($request, $response)
|
||||
public function json($request, $response)
|
||||
{
|
||||
global $app;
|
||||
if (isset($_GET["url"])) {
|
||||
try {
|
||||
$video = VideoDownload::getJSON($_GET["url"]);
|
||||
$video = $this->download->getJSON($_GET["url"]);
|
||||
return $response->withJson($video);
|
||||
} catch (\Exception $e) {
|
||||
return $response->withJson(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue