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: {
|
||||
options: {
|
||||
standard: 'PSR2'
|
||||
},
|
||||
php: {
|
||||
src: ['*.php', 'classes/*.php', 'controllers/*.php']
|
||||
},
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
* @link http://rudloff.pro
|
||||
* */
|
||||
namespace Alltube;
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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 $python = '/usr/bin/python';
|
||||
|
@ -43,7 +45,7 @@ Class Config
|
|||
if (is_file($yamlfile)) {
|
||||
$yaml = Yaml::parse(file_get_contents($yamlfile));
|
||||
if (isset($yaml) && is_array($yaml)) {
|
||||
foreach ($yaml as $param=>$value) {
|
||||
foreach ($yaml as $param => $value) {
|
||||
if (isset($this->$param)) {
|
||||
$this->$param = $value;
|
||||
}
|
||||
|
@ -62,9 +64,9 @@ Class Config
|
|||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$_instance)) {
|
||||
self::$_instance = new Config();
|
||||
if (is_null(self::$instance)) {
|
||||
self::$instance = new Config();
|
||||
}
|
||||
return self::$_instance;
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
* @link http://rudloff.pro
|
||||
* */
|
||||
namespace Alltube;
|
||||
|
||||
/**
|
||||
* Main class
|
||||
*
|
||||
|
@ -22,14 +23,14 @@ namespace Alltube;
|
|||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://rudloff.pro
|
||||
* */
|
||||
Class VideoDownload
|
||||
class VideoDownload
|
||||
{
|
||||
/**
|
||||
* Get the user agent used youtube-dl
|
||||
*
|
||||
* @return string UA
|
||||
* */
|
||||
static function getUA()
|
||||
public static function getUA()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$cmd = escapeshellcmd(
|
||||
|
@ -48,7 +49,7 @@ Class VideoDownload
|
|||
*
|
||||
* @return array Extractors
|
||||
* */
|
||||
static function listExtractors()
|
||||
public static function listExtractors()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$cmd = escapeshellcmd(
|
||||
|
@ -70,7 +71,7 @@ Class VideoDownload
|
|||
*
|
||||
* @return string Filename
|
||||
* */
|
||||
static function getFilename($url, $format=null)
|
||||
public static function getFilename($url, $format = null)
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$cmd = escapeshellcmd(
|
||||
|
@ -96,7 +97,7 @@ Class VideoDownload
|
|||
*
|
||||
* @return string JSON
|
||||
* */
|
||||
static function getJSON($url, $format=null)
|
||||
public static function getJSON($url, $format = null)
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$cmd = escapeshellcmd(
|
||||
|
@ -108,7 +109,9 @@ Class VideoDownload
|
|||
}
|
||||
$cmd .=' --dump-json '.escapeshellarg($url)." 2>&1";
|
||||
exec(
|
||||
$cmd, $result, $code
|
||||
$cmd,
|
||||
$result,
|
||||
$code
|
||||
);
|
||||
if ($code>0) {
|
||||
throw new \Exception(implode(PHP_EOL, $result));
|
||||
|
@ -125,7 +128,7 @@ Class VideoDownload
|
|||
*
|
||||
* @return string URL of video
|
||||
* */
|
||||
static function getURL($url, $format=null)
|
||||
public static function getURL($url, $format = null)
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$cmd = escapeshellcmd(
|
||||
|
@ -137,7 +140,9 @@ Class VideoDownload
|
|||
}
|
||||
$cmd .=' -g '.escapeshellarg($url)." 2>&1";
|
||||
exec(
|
||||
$cmd, $result, $code
|
||||
$cmd,
|
||||
$result,
|
||||
$code
|
||||
);
|
||||
if ($code>0) {
|
||||
throw new \Exception(implode(PHP_EOL, $result));
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
* @link http://rudloff.pro
|
||||
* */
|
||||
namespace Alltube\Controller;
|
||||
|
||||
use Alltube\VideoDownload;
|
||||
use Alltube\Config;
|
||||
|
||||
/**
|
||||
* Main controller
|
||||
*
|
||||
|
@ -35,7 +37,7 @@ class FrontController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
static function index($request, $response)
|
||||
public static function index($request, $response)
|
||||
{
|
||||
global $container;
|
||||
$config = Config::getInstance();
|
||||
|
@ -68,7 +70,7 @@ class FrontController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
static function extractors($request, $response)
|
||||
public static function extractors($request, $response)
|
||||
{
|
||||
global $container;
|
||||
$container->view->render(
|
||||
|
@ -98,7 +100,7 @@ class FrontController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
static function video($request, $response)
|
||||
public static function video($request, $response)
|
||||
{
|
||||
global $container;
|
||||
$config = Config::getInstance();
|
||||
|
@ -122,8 +124,11 @@ class FrontController
|
|||
pathinfo(
|
||||
VideoDownload::getFilename(
|
||||
$video->webpage_url
|
||||
), PATHINFO_FILENAME
|
||||
).'.mp3', ENT_COMPAT, 'ISO-8859-1'
|
||||
),
|
||||
PATHINFO_FILENAME
|
||||
).'.mp3',
|
||||
ENT_COMPAT,
|
||||
'ISO-8859-1'
|
||||
).'"'
|
||||
);
|
||||
header("Content-Type: audio/mpeg");
|
||||
|
@ -141,8 +146,11 @@ class FrontController
|
|||
pathinfo(
|
||||
VideoDownload::getFilename(
|
||||
$video->webpage_url
|
||||
), PATHINFO_FILENAME
|
||||
).'.mp3', ENT_COMPAT, 'ISO-8859-1'
|
||||
),
|
||||
PATHINFO_FILENAME
|
||||
).'.mp3',
|
||||
ENT_COMPAT,
|
||||
'ISO-8859-1'
|
||||
).'"'
|
||||
);
|
||||
header("Content-Type: audio/mpeg");
|
||||
|
@ -208,7 +216,7 @@ class FrontController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
static function redirect($request, $response)
|
||||
public static function redirect($request, $response)
|
||||
{
|
||||
global $app;
|
||||
if (isset($_GET["url"])) {
|
||||
|
@ -230,7 +238,7 @@ class FrontController
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
static function json($request, $response)
|
||||
public static function json($request, $response)
|
||||
{
|
||||
global $app;
|
||||
if (isset($_GET["url"])) {
|
||||
|
|
39
js/cast.js
39
js/cast.js
|
@ -3,12 +3,14 @@
|
|||
var launchBtn, disabledBtn, stopBtn;
|
||||
var session, currentMedia;
|
||||
|
||||
function receiverListener(e) {
|
||||
function receiverListener(e)
|
||||
{
|
||||
'use strict';
|
||||
console.log('receiverListener', e);
|
||||
}
|
||||
|
||||
function onMediaDiscovered(how, media) {
|
||||
function onMediaDiscovered(how, media)
|
||||
{
|
||||
'use strict';
|
||||
console.log('onMediaDiscovered', how);
|
||||
currentMedia = media;
|
||||
|
@ -18,7 +20,8 @@ function onMediaDiscovered(how, media) {
|
|||
}
|
||||
}
|
||||
|
||||
function sessionListener(e) {
|
||||
function sessionListener(e)
|
||||
{
|
||||
'use strict';
|
||||
session = e;
|
||||
session.addMediaListener(onMediaDiscovered.bind(this, 'addMediaListener'));
|
||||
|
@ -27,41 +30,48 @@ function sessionListener(e) {
|
|||
}
|
||||
}
|
||||
|
||||
function onStopCast() {
|
||||
function onStopCast()
|
||||
{
|
||||
'use strict';
|
||||
stopBtn.classList.add('cast_hidden');
|
||||
launchBtn.classList.remove('cast_hidden');
|
||||
}
|
||||
|
||||
function stopCast() {
|
||||
function stopCast()
|
||||
{
|
||||
'use strict';
|
||||
session.stop(onStopCast);
|
||||
}
|
||||
|
||||
function onMediaError() {
|
||||
function onMediaError()
|
||||
{
|
||||
'use strict';
|
||||
console.log('onMediaError');
|
||||
stopCast();
|
||||
}
|
||||
|
||||
function onRequestSessionSuccess(e) {
|
||||
function onRequestSessionSuccess(e)
|
||||
{
|
||||
'use strict';
|
||||
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);
|
||||
session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError);
|
||||
}
|
||||
|
||||
function onLaunchError(e) {
|
||||
function onLaunchError(e)
|
||||
{
|
||||
'use strict';
|
||||
console.log('onLaunchError', e.description);
|
||||
}
|
||||
|
||||
function launchCast() {
|
||||
function launchCast()
|
||||
{
|
||||
'use strict';
|
||||
chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
|
||||
}
|
||||
|
||||
function onInitSuccess() {
|
||||
function onInitSuccess()
|
||||
{
|
||||
'use strict';
|
||||
launchBtn = document.getElementById('cast_btn_launch');
|
||||
disabledBtn = document.getElementById('cast_disabled');
|
||||
|
@ -74,18 +84,21 @@ function onInitSuccess() {
|
|||
}
|
||||
}
|
||||
|
||||
function onError() {
|
||||
function onError()
|
||||
{
|
||||
'use strict';
|
||||
console.log('onError');
|
||||
}
|
||||
|
||||
function initializeCastApi() {
|
||||
function initializeCastApi()
|
||||
{
|
||||
'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);
|
||||
chrome.cast.initialize(apiConfig, onInitSuccess, onError);
|
||||
}
|
||||
|
||||
function loadCastApi(loaded, errorInfo) {
|
||||
function loadCastApi(loaded, errorInfo)
|
||||
{
|
||||
'use strict';
|
||||
if (loaded) {
|
||||
initializeCastApi();
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://rudloff.pro
|
||||
* */
|
||||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\Config;
|
||||
|
||||
/**
|
||||
|
@ -23,7 +25,7 @@ use Alltube\Config;
|
|||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||
* @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
|
||||
* @link http://rudloff.pro
|
||||
* */
|
||||
namespace Alltube\Test;
|
||||
|
||||
use Alltube\VideoDownload;
|
||||
|
||||
/**
|
||||
|
@ -23,7 +25,7 @@ use Alltube\VideoDownload;
|
|||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://rudloff.pro
|
||||
* */
|
||||
class VideoDownloadTest extends PHPUnit_Framework_TestCase
|
||||
class VideoDownloadTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test getUA function
|
||||
|
|
Loading…
Reference in a new issue