Use PSR-2
This commit is contained in:
parent
81f32c3e61
commit
46032e1ee1
7 changed files with 73 additions and 38 deletions
|
@ -28,6 +28,9 @@ module.exports = function (grunt) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
phpcs: {
|
phpcs: {
|
||||||
|
options: {
|
||||||
|
standard: 'PSR2'
|
||||||
|
},
|
||||||
php: {
|
php: {
|
||||||
src: ['*.php', 'classes/*.php', 'controllers/*.php']
|
src: ['*.php', 'classes/*.php', 'controllers/*.php']
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,7 +11,9 @@
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
namespace Alltube;
|
namespace Alltube;
|
||||||
|
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to manage config parameters
|
* Class to manage config parameters
|
||||||
*
|
*
|
||||||
|
@ -23,9 +25,9 @@ use Symfony\Component\Yaml\Yaml;
|
||||||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
Class Config
|
class Config
|
||||||
{
|
{
|
||||||
private static $_instance;
|
private static $instance;
|
||||||
|
|
||||||
public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py';
|
public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py';
|
||||||
public $python = '/usr/bin/python';
|
public $python = '/usr/bin/python';
|
||||||
|
@ -62,9 +64,9 @@ Class Config
|
||||||
*/
|
*/
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
{
|
{
|
||||||
if (is_null(self::$_instance)) {
|
if (is_null(self::$instance)) {
|
||||||
self::$_instance = new Config();
|
self::$instance = new Config();
|
||||||
}
|
}
|
||||||
return self::$_instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
namespace Alltube;
|
namespace Alltube;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main class
|
* Main class
|
||||||
*
|
*
|
||||||
|
@ -22,14 +23,14 @@ namespace Alltube;
|
||||||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
Class VideoDownload
|
class VideoDownload
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get the user agent used youtube-dl
|
* Get the user agent used youtube-dl
|
||||||
*
|
*
|
||||||
* @return string UA
|
* @return string UA
|
||||||
* */
|
* */
|
||||||
static function getUA()
|
public static function getUA()
|
||||||
{
|
{
|
||||||
$config = Config::getInstance();
|
$config = Config::getInstance();
|
||||||
$cmd = escapeshellcmd(
|
$cmd = escapeshellcmd(
|
||||||
|
@ -48,7 +49,7 @@ Class VideoDownload
|
||||||
*
|
*
|
||||||
* @return array Extractors
|
* @return array Extractors
|
||||||
* */
|
* */
|
||||||
static function listExtractors()
|
public static function listExtractors()
|
||||||
{
|
{
|
||||||
$config = Config::getInstance();
|
$config = Config::getInstance();
|
||||||
$cmd = escapeshellcmd(
|
$cmd = escapeshellcmd(
|
||||||
|
@ -70,7 +71,7 @@ Class VideoDownload
|
||||||
*
|
*
|
||||||
* @return string Filename
|
* @return string Filename
|
||||||
* */
|
* */
|
||||||
static function getFilename($url, $format=null)
|
public static function getFilename($url, $format = null)
|
||||||
{
|
{
|
||||||
$config = Config::getInstance();
|
$config = Config::getInstance();
|
||||||
$cmd = escapeshellcmd(
|
$cmd = escapeshellcmd(
|
||||||
|
@ -96,7 +97,7 @@ Class VideoDownload
|
||||||
*
|
*
|
||||||
* @return string JSON
|
* @return string JSON
|
||||||
* */
|
* */
|
||||||
static function getJSON($url, $format=null)
|
public static function getJSON($url, $format = null)
|
||||||
{
|
{
|
||||||
$config = Config::getInstance();
|
$config = Config::getInstance();
|
||||||
$cmd = escapeshellcmd(
|
$cmd = escapeshellcmd(
|
||||||
|
@ -108,7 +109,9 @@ Class VideoDownload
|
||||||
}
|
}
|
||||||
$cmd .=' --dump-json '.escapeshellarg($url)." 2>&1";
|
$cmd .=' --dump-json '.escapeshellarg($url)." 2>&1";
|
||||||
exec(
|
exec(
|
||||||
$cmd, $result, $code
|
$cmd,
|
||||||
|
$result,
|
||||||
|
$code
|
||||||
);
|
);
|
||||||
if ($code>0) {
|
if ($code>0) {
|
||||||
throw new \Exception(implode(PHP_EOL, $result));
|
throw new \Exception(implode(PHP_EOL, $result));
|
||||||
|
@ -125,7 +128,7 @@ Class VideoDownload
|
||||||
*
|
*
|
||||||
* @return string URL of video
|
* @return string URL of video
|
||||||
* */
|
* */
|
||||||
static function getURL($url, $format=null)
|
public static function getURL($url, $format = null)
|
||||||
{
|
{
|
||||||
$config = Config::getInstance();
|
$config = Config::getInstance();
|
||||||
$cmd = escapeshellcmd(
|
$cmd = escapeshellcmd(
|
||||||
|
@ -137,7 +140,9 @@ Class VideoDownload
|
||||||
}
|
}
|
||||||
$cmd .=' -g '.escapeshellarg($url)." 2>&1";
|
$cmd .=' -g '.escapeshellarg($url)." 2>&1";
|
||||||
exec(
|
exec(
|
||||||
$cmd, $result, $code
|
$cmd,
|
||||||
|
$result,
|
||||||
|
$code
|
||||||
);
|
);
|
||||||
if ($code>0) {
|
if ($code>0) {
|
||||||
throw new \Exception(implode(PHP_EOL, $result));
|
throw new \Exception(implode(PHP_EOL, $result));
|
||||||
|
|
|
@ -11,8 +11,10 @@
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
namespace Alltube\Controller;
|
namespace Alltube\Controller;
|
||||||
|
|
||||||
use Alltube\VideoDownload;
|
use Alltube\VideoDownload;
|
||||||
use Alltube\Config;
|
use Alltube\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main controller
|
* Main controller
|
||||||
*
|
*
|
||||||
|
@ -35,7 +37,7 @@ class FrontController
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static function index($request, $response)
|
public static function index($request, $response)
|
||||||
{
|
{
|
||||||
global $container;
|
global $container;
|
||||||
$config = Config::getInstance();
|
$config = Config::getInstance();
|
||||||
|
@ -68,7 +70,7 @@ class FrontController
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static function extractors($request, $response)
|
public static function extractors($request, $response)
|
||||||
{
|
{
|
||||||
global $container;
|
global $container;
|
||||||
$container->view->render(
|
$container->view->render(
|
||||||
|
@ -98,7 +100,7 @@ class FrontController
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static function video($request, $response)
|
public static function video($request, $response)
|
||||||
{
|
{
|
||||||
global $container;
|
global $container;
|
||||||
$config = Config::getInstance();
|
$config = Config::getInstance();
|
||||||
|
@ -122,8 +124,11 @@ class FrontController
|
||||||
pathinfo(
|
pathinfo(
|
||||||
VideoDownload::getFilename(
|
VideoDownload::getFilename(
|
||||||
$video->webpage_url
|
$video->webpage_url
|
||||||
), PATHINFO_FILENAME
|
),
|
||||||
).'.mp3', ENT_COMPAT, 'ISO-8859-1'
|
PATHINFO_FILENAME
|
||||||
|
).'.mp3',
|
||||||
|
ENT_COMPAT,
|
||||||
|
'ISO-8859-1'
|
||||||
).'"'
|
).'"'
|
||||||
);
|
);
|
||||||
header("Content-Type: audio/mpeg");
|
header("Content-Type: audio/mpeg");
|
||||||
|
@ -141,8 +146,11 @@ class FrontController
|
||||||
pathinfo(
|
pathinfo(
|
||||||
VideoDownload::getFilename(
|
VideoDownload::getFilename(
|
||||||
$video->webpage_url
|
$video->webpage_url
|
||||||
), PATHINFO_FILENAME
|
),
|
||||||
).'.mp3', ENT_COMPAT, 'ISO-8859-1'
|
PATHINFO_FILENAME
|
||||||
|
).'.mp3',
|
||||||
|
ENT_COMPAT,
|
||||||
|
'ISO-8859-1'
|
||||||
).'"'
|
).'"'
|
||||||
);
|
);
|
||||||
header("Content-Type: audio/mpeg");
|
header("Content-Type: audio/mpeg");
|
||||||
|
@ -208,7 +216,7 @@ class FrontController
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static function redirect($request, $response)
|
public static function redirect($request, $response)
|
||||||
{
|
{
|
||||||
global $app;
|
global $app;
|
||||||
if (isset($_GET["url"])) {
|
if (isset($_GET["url"])) {
|
||||||
|
@ -230,7 +238,7 @@ class FrontController
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
static function json($request, $response)
|
public static function json($request, $response)
|
||||||
{
|
{
|
||||||
global $app;
|
global $app;
|
||||||
if (isset($_GET["url"])) {
|
if (isset($_GET["url"])) {
|
||||||
|
|
39
js/cast.js
39
js/cast.js
|
@ -3,12 +3,14 @@
|
||||||
var launchBtn, disabledBtn, stopBtn;
|
var launchBtn, disabledBtn, stopBtn;
|
||||||
var session, currentMedia;
|
var session, currentMedia;
|
||||||
|
|
||||||
function receiverListener(e) {
|
function receiverListener(e)
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
console.log('receiverListener', e);
|
console.log('receiverListener', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMediaDiscovered(how, media) {
|
function onMediaDiscovered(how, media)
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
console.log('onMediaDiscovered', how);
|
console.log('onMediaDiscovered', how);
|
||||||
currentMedia = media;
|
currentMedia = media;
|
||||||
|
@ -18,7 +20,8 @@ function onMediaDiscovered(how, media) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sessionListener(e) {
|
function sessionListener(e)
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
session = e;
|
session = e;
|
||||||
session.addMediaListener(onMediaDiscovered.bind(this, 'addMediaListener'));
|
session.addMediaListener(onMediaDiscovered.bind(this, 'addMediaListener'));
|
||||||
|
@ -27,41 +30,48 @@ function sessionListener(e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onStopCast() {
|
function onStopCast()
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
stopBtn.classList.add('cast_hidden');
|
stopBtn.classList.add('cast_hidden');
|
||||||
launchBtn.classList.remove('cast_hidden');
|
launchBtn.classList.remove('cast_hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopCast() {
|
function stopCast()
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
session.stop(onStopCast);
|
session.stop(onStopCast);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMediaError() {
|
function onMediaError()
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
console.log('onMediaError');
|
console.log('onMediaError');
|
||||||
stopCast();
|
stopCast();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onRequestSessionSuccess(e) {
|
function onRequestSessionSuccess(e)
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
session = e;
|
session = e;
|
||||||
var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo);
|
var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo);
|
||||||
session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError);
|
session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onLaunchError(e) {
|
function onLaunchError(e)
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
console.log('onLaunchError', e.description);
|
console.log('onLaunchError', e.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
function launchCast() {
|
function launchCast()
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
|
chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onInitSuccess() {
|
function onInitSuccess()
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
launchBtn = document.getElementById('cast_btn_launch');
|
launchBtn = document.getElementById('cast_btn_launch');
|
||||||
disabledBtn = document.getElementById('cast_disabled');
|
disabledBtn = document.getElementById('cast_disabled');
|
||||||
|
@ -74,18 +84,21 @@ function onInitSuccess() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onError() {
|
function onError()
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
console.log('onError');
|
console.log('onError');
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeCastApi() {
|
function initializeCastApi()
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
var sessionRequest = new chrome.cast.SessionRequest(chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID), apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener, chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED);
|
var sessionRequest = new chrome.cast.SessionRequest(chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID), apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener, chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED);
|
||||||
chrome.cast.initialize(apiConfig, onInitSuccess, onError);
|
chrome.cast.initialize(apiConfig, onInitSuccess, onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadCastApi(loaded, errorInfo) {
|
function loadCastApi(loaded, errorInfo)
|
||||||
|
{
|
||||||
'use strict';
|
'use strict';
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
initializeCastApi();
|
initializeCastApi();
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\Config;
|
use Alltube\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,7 +25,7 @@ use Alltube\Config;
|
||||||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
class ConfigTest extends PHPUnit_Framework_TestCase
|
class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
|
namespace Alltube\Test;
|
||||||
|
|
||||||
use Alltube\VideoDownload;
|
use Alltube\VideoDownload;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,7 +25,7 @@ use Alltube\VideoDownload;
|
||||||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||||
* @link http://rudloff.pro
|
* @link http://rudloff.pro
|
||||||
* */
|
* */
|
||||||
class VideoDownloadTest extends PHPUnit_Framework_TestCase
|
class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Test getUA function
|
* Test getUA function
|
||||||
|
|
Loading…
Reference in a new issue