diff --git a/.gitignore b/.gitignore index 65a8d60..0fb6d93 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ templates_c/ ffmpeg.tar.xz ffmpeg-*/ alltube-release.zip +coverage/ +bower_components/ +config.yml diff --git a/.htaccess b/.htaccess index 110ffe7..5591820 100644 --- a/.htaccess +++ b/.htaccess @@ -1,8 +1,13 @@ AddType application/x-web-app-manifest+json .webapp -ExpiresActive On -ExpiresByType application/javascript "access plus 1 week" -ExpiresByType text/css "access plus 1 week" -ExpiresByType image/png "access plus 1 week" -ExpiresByType image/jpeg "access plus 1 week" -ExpiresByType image/svg+xml "access plus 1 week" + + ExpiresActive On + ExpiresByType application/javascript "access plus 1 week" + ExpiresByType text/css "access plus 1 week" + ExpiresByType image/png "access plus 1 week" + ExpiresByType image/jpeg "access plus 1 week" + ExpiresByType image/svg+xml "access plus 1 week" + FileETag None +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^ index.php [QSA,L] diff --git a/.travis.yml b/.travis.yml index 924623f..89517de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,4 @@ language: php -php: - - 5.4 - - 5.5 - - 5.6 install: - composer install - npm install -script: phpunit tests/ diff --git a/Gruntfile.js b/Gruntfile.js index bfa43c3..ef153d9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,7 +29,7 @@ module.exports = function (grunt) { }, phpcs: { php: { - src: ['*.php'] + src: ['*.php', 'classes/*.php', 'controllers/*.php'] }, tests: { src: ['tests/*.php'] @@ -45,6 +45,14 @@ module.exports = function (grunt) { classes: { dir: 'tests/' } + }, + compress: { + release: { + options: { + archive: 'alltube-release.zip' + }, + src: ['*.php', '!config.yml', 'dist/**', 'fonts/**', '.htaccess', 'img/**', 'js/**', 'LICENSE', 'README.md', 'robots.txt', 'sitemap.xml', 'templates/**', 'templates_c/', 'vendor/**', 'classes/**', 'controllers/**', 'bower_components/**'] + } } } ); @@ -54,8 +62,10 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-phpcs'); grunt.loadNpmTasks('grunt-phpunit'); + grunt.loadNpmTasks('grunt-contrib-compress'); grunt.registerTask('default', ['uglify', 'cssmin']); grunt.registerTask('lint', ['phpcs']); grunt.registerTask('test', ['phpunit']); + grunt.registerTask('release', ['default', 'compress']); }; diff --git a/README.md b/README.md index 76fd9f9..ea68dbf 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ You should also ensure that the *templates_c* folder has the right permissions: If you want to use a custom config, you need to create a config file: - cp config.example.php config.php + cp config.example.yml config.yml ##License @@ -33,7 +33,7 @@ __Please use a different name and logo if you run it on a public server.__ ##Other dependencies You need [avconv](https://libav.org/avconv.html) and [rtmpdump](http://rtmpdump.mplayerhq.hu/) in order to enable conversions. -If you don't want to enable conversions, you can disable it in *config.php*. +If you don't want to enable conversions, you can disable it in *config.yml*. On Debian-based systems: diff --git a/api.php b/api.php deleted file mode 100644 index cf18c14..0000000 --- a/api.php +++ /dev/null @@ -1,84 +0,0 @@ - - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -require_once 'common.php'; -$smarty->assign('class', 'video'); -require_once 'download.php'; -if (isset($_GET["url"])) { - if (isset($_GET['audio'])) { - $video = VideoDownload::getJSON($_GET["url"]); - - if (isset($video->url)) { - //Vimeo needs a correct user-agent - $UA = VideoDownload::getUA(); - ini_set( - 'user_agent', - $UA - ); - $url_info = parse_url($video->url); - if ($url_info['scheme'] == 'rtmp') { - header( - 'Content-Disposition: attachment; filename="'. - html_entity_decode( - pathinfo( - VideoDownload::getFilename( - $video->webpage_url - ), PATHINFO_FILENAME - ).'.mp3', ENT_COMPAT, 'ISO-8859-1' - ).'"' - ); - header("Content-Type: audio/mpeg"); - passthru( - '/usr/bin/rtmpdump -q -r '.escapeshellarg($video->url). - ' | '.AVCONV.' -v quiet -i - -f mp3 -vn pipe:1' - ); - exit; - } else { - header( - 'Content-Disposition: attachment; filename="'. - html_entity_decode( - pathinfo( - VideoDownload::getFilename( - $video->webpage_url - ), PATHINFO_FILENAME - ).'.mp3', ENT_COMPAT, 'ISO-8859-1' - ).'"' - ); - header("Content-Type: audio/mpeg"); - passthru( - 'curl --user-agent '.escapeshellarg($UA). - ' '.escapeshellarg($video->url). - ' | '.AVCONV.' -v quiet -i - -f mp3 -vn pipe:1' - ); - exit; - } - } else { - $error=true; - } - } else { - $video = VideoDownload::getJSON($_GET["url"]); - if (isset($video->webpage_url)) { - $smarty->display('head.tpl'); - $smarty->assign('video', $video); - $smarty->display('video.tpl'); - $smarty->display('footer.tpl'); - } else { - $error=true; - } - } -} -if (isset($error)) { - $smarty->display('head.tpl'); - $smarty->assign('errors', $video['error']); - $smarty->display('error.tpl'); - $smarty->display('footer.tpl'); -} diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..f367807 --- /dev/null +++ b/bower.json @@ -0,0 +1,6 @@ +{ + "name": "alltube", + "dependencies": { + "opensans-googlefont": "*" + } +} diff --git a/classes/Config.php b/classes/Config.php new file mode 100644 index 0000000..c0c5325 --- /dev/null +++ b/classes/Config.php @@ -0,0 +1,65 @@ + + * @license GNU General Public License http://www.gnu.org/licenses/gpl.html + * @link http://rudloff.pro + * */ +namespace Alltube; +use Symfony\Component\Yaml\Yaml; +/** + * Class to manage config parameters + * + * PHP Version 5.3.10 + * + * @category Youtube-dl + * @package Youtubedl + * @author Pierre Rudloff + * @license GNU General Public License http://www.gnu.org/licenses/gpl.html + * @link http://rudloff.pro + * */ +Class Config +{ + private static $_instance; + + public $youtubedl = 'vendor/rg3/youtube-dl/youtube_dl/__main__.py'; + public $python = '/usr/bin/python'; + public $params = '--no-playlist --no-warnings -f best'; + public $convert = false; + public $avconv = 'ffmpeg/ffmpeg'; + + /** + * Config constructor + */ + private function __construct() + { + $yaml = Yaml::parse(__DIR__.'/../config.yml'); + if (isset($yaml) && is_array($yaml)) { + foreach ($yaml as $param=>$value) { + if (isset($this->$param)) { + $this->$param = $value; + } + } + } + if (getenv('CONVERT')) { + $this->convert = getenv('CONVERT'); + } + } + + /** + * Get singleton instance + * @return Config + */ + public static function getInstance() + { + if (is_null(self::$_instance)) { + self::$_instance = new Config(); + } + return self::$_instance; + } +} diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php new file mode 100644 index 0000000..3d18990 --- /dev/null +++ b/classes/VideoDownload.php @@ -0,0 +1,132 @@ + + * @license GNU General Public License http://www.gnu.org/licenses/gpl.html + * @link http://rudloff.pro + * */ +namespace Alltube; +/** + * Main class + * + * PHP Version 5.3.10 + * + * @category Youtube-dl + * @package Youtubedl + * @author Pierre Rudloff + * @license GNU General Public License http://www.gnu.org/licenses/gpl.html + * @link http://rudloff.pro + * */ +Class VideoDownload +{ + /** + * Get the user agent used youtube-dl + * + * @return string UA + * */ + static function getUA() + { + $config = Config::getInstance(); + exec( + $config->python.' '.$config->youtubedl.' --dump-user-agent', + $version + ); + return $version[0]; + } + + /** + * List all extractors + * + * @return array Extractors + * */ + static function listExtractors() + { + $config = Config::getInstance(); + exec( + $config->python.' '.$config->youtubedl.' --list-extractors', + $extractors + ); + return $extractors; + } + + /** + * Get filename of video + * + * @param string $url URL of page + * @param string $format Format to use for the video + * + * @return string Filename + * */ + static function getFilename($url, $format=null) + { + $config = Config::getInstance(); + $cmd=$config->python.' '.$config->youtubedl; + if (isset($format)) { + $cmd .= ' -f '.escapeshellarg($format); + } + $cmd .=' --get-filename '.escapeshellarg($url)." 2>&1"; + exec( + $cmd, + $filename + ); + return end($filename); + } + + /** + * Get all information about a video + * + * @param string $url URL of page + * @param string $format Format to use for the video + * + * @return string JSON + * */ + static function getJSON($url, $format=null) + { + $config = Config::getInstance(); + $cmd=$config->python.' '.$config->youtubedl.' '.$config->params; + if (isset($format)) { + $cmd .= ' -f '.escapeshellarg($format); + } + $cmd .=' --dump-json '.escapeshellarg($url)." 2>&1"; + exec( + $cmd, $result, $code + ); + if ($code>0) { + throw new \Exception(implode(PHP_EOL, $result)); + } else { + return json_decode($result[0]); + } + } + + /** + * Get URL of video from URL of page + * + * @param string $url URL of page + * @param string $format Format to use for the video + * + * @return string URL of video + * */ + static function getURL($url, $format=null) + { + $config = Config::getInstance(); + $cmd=$config->python.' '.$config->youtubedl.' '.$config->params; + if (isset($format)) { + $cmd .= ' -f '.escapeshellarg($format); + } + $cmd .=' -g '.escapeshellarg($url)." 2>&1"; + exec( + $cmd, $result, $code + ); + if ($code>0) { + throw new \Exception(implode(PHP_EOL, $result)); + } else { + return array('success'=>true, 'url'=>end($result)); + } + + } +} diff --git a/common.php b/common.php deleted file mode 100644 index 4db3064..0000000 --- a/common.php +++ /dev/null @@ -1,33 +0,0 @@ - - * @author Olivier Haquette - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -require_once __DIR__.'/vendor/autoload.php'; -if (is_file('config.php')) { - include_once 'config.php'; -} else { - include_once 'config.example.php'; -} -define('FILENAME', basename($_SERVER["SCRIPT_FILENAME"])); -if (DISABLED && FILENAME != 'disabled.php') { - header('Location: disabled.php'); exit; -} else if (MAINTENANCE && FILENAME != 'maintenance.php') { - header('Location: maintenance.php'); exit; -} -$smarty = new Smarty(); -$smarty->assign( - array( - 'base_url'=>BASE_URL, - 'convert'=>CONVERT - ) -); diff --git a/composer.json b/composer.json index 2f4b7d2..110348e 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,15 @@ "homepage": "http://alltubedownload.net/", "type": "project", "require": { - "smarty/smarty": "~3.1" + "smarty/smarty": "~3.1", + "rg3/youtube-dl": "2015.10.24", + "slim/slim": "~2.6.2", + "slim/views": "~0.1.3", + "rudloff/smarty-plugin-noscheme": "~0.1.0", + "symfony/yaml": "~2.7.6" + }, + "require-dev": { + "symfony/var-dumper": "~2.7.6" }, "extra": { "paas": { @@ -14,6 +22,20 @@ ] } }, + "repositories": [ + { + "type": "package", + "package": { + "name": "rg3/youtube-dl", + "version": "2015.10.24", + "source": { + "url": "https://github.com/rg3/youtube-dl.git", + "type": "git", + "reference": "2015.10.24" + } + } + } + ], "authors": [ { "name": "Pierre Rudloff", @@ -21,5 +43,11 @@ "homepage": "https://rudloff.pro/", "role": "Developer" } - ] + ], + "autoload": { + "psr-4": { + "Alltube\\": "classes/", + "Alltube\\Controller\\": "controllers/" + } + } } diff --git a/composer.lock b/composer.lock index 6fb1c3a..2d0cd81 100644 --- a/composer.lock +++ b/composer.lock @@ -1,11 +1,331 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "1d95265fc34ff6df149985554a8ba0d6", + "hash": "a7e5944a818030d017d39d13b9ec0ffd", + "content-hash": "2d61af9410d3e5f69fa0d6a956210a83", "packages": [ + { + "name": "jeremykendall/php-domain-parser", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/jeremykendall/php-domain-parser.git", + "reference": "896e7e70f02bd4fd77190052799bc61e4d779672" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jeremykendall/php-domain-parser/zipball/896e7e70f02bd4fd77190052799bc61e4d779672", + "reference": "896e7e70f02bd4fd77190052799bc61e4d779672", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-intl": "*", + "ext-mbstring": "*", + "php": ">=5.3.0" + }, + "require-dev": { + "jeremykendall/debug-die": "0.0.1.*", + "mikey179/vfsstream": "~1.4", + "phpunit/phpunit": "~4.4" + }, + "bin": [ + "bin/parse", + "bin/update-psl" + ], + "type": "library", + "autoload": { + "psr-0": { + "Pdp\\": "src/" + }, + "files": [ + "src/pdp-parse-url.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeremy Kendall", + "homepage": "http://about.me/jeremykendall", + "role": "Developer" + }, + { + "name": "Contributors", + "homepage": "https://github.com/jeremykendall/php-domain-parser/graphs/contributors" + } + ], + "description": "Public Suffix List based URL parsing implemented in PHP.", + "homepage": "https://github.com/jeremykendall/php-domain-parser", + "keywords": [ + "Public Suffix List", + "domain parsing", + "url parsing" + ], + "time": "2015-03-30 12:49:45" + }, + { + "name": "league/uri", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri.git", + "reference": "a22120c5937814dbadaffccef32bf11040f46c0b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri/zipball/a22120c5937814dbadaffccef32bf11040f46c0b", + "reference": "a22120c5937814dbadaffccef32bf11040f46c0b", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "ext-intl": "*", + "ext-mbstring": "*", + "jeremykendall/php-domain-parser": "^3.0", + "php": ">=5.5.9", + "psr/http-message": "^1.0" + }, + "require-dev": { + "fabpot/php-cs-fixer": "^1.9", + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://github.com/nyamsprod/", + "role": "Developer" + } + ], + "description": "URI manipulation library", + "homepage": "http://url.thephpleague.com", + "keywords": [ + "ftp", + "http", + "parse_url", + "psr-7", + "rfc3986", + "uri", + "url", + "ws" + ], + "time": "2015-09-23 11:09:45" + }, + { + "name": "psr/http-message", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2015-05-04 20:22:00" + }, + { + "name": "rg3/youtube-dl", + "version": "2015.10.24", + "source": { + "type": "git", + "url": "https://github.com/rg3/youtube-dl.git", + "reference": "2015.10.24" + }, + "type": "library" + }, + { + "name": "rudloff/smarty-plugin-noscheme", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/Rudloff/smarty-plugin-noscheme.git", + "reference": "537bcb2f7576252af70d8f9f817bfe050d873072" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Rudloff/smarty-plugin-noscheme/zipball/537bcb2f7576252af70d8f9f817bfe050d873072", + "reference": "537bcb2f7576252af70d8f9f817bfe050d873072", + "shasum": "" + }, + "require": { + "league/uri": "~4.0" + }, + "require-dev": { + "symfony/var-dumper": "~2.7.6" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0" + ], + "authors": [ + { + "name": "Pierre Rudloff", + "email": "contact@rudloff.pro", + "homepage": "https://rudloff.pro/", + "role": "Developer" + } + ], + "description": "Smarty modifier that removes the scheme in URLs", + "time": "2015-10-31 10:25:47" + }, + { + "name": "slim/slim", + "version": "2.6.2", + "source": { + "type": "git", + "url": "https://github.com/slimphp/Slim.git", + "reference": "20a02782f76830b67ae56a5c08eb1f563c351a37" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slimphp/Slim/zipball/20a02782f76830b67ae56a5c08eb1f563c351a37", + "reference": "20a02782f76830b67ae56a5c08eb1f563c351a37", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "suggest": { + "ext-mcrypt": "Required for HTTP cookie encryption" + }, + "type": "library", + "autoload": { + "psr-0": { + "Slim": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josh Lockhart", + "email": "info@joshlockhart.com", + "homepage": "http://www.joshlockhart.com/" + } + ], + "description": "Slim Framework, a PHP micro framework", + "homepage": "http://github.com/codeguy/Slim", + "keywords": [ + "microframework", + "rest", + "router" + ], + "time": "2015-03-08 18:41:17" + }, + { + "name": "slim/views", + "version": "0.1.3", + "source": { + "type": "git", + "url": "https://github.com/slimphp/Slim-Views.git", + "reference": "8561c785e55a39df6cb6f95c3aba3281a60ed5b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slimphp/Slim-Views/zipball/8561c785e55a39df6cb6f95c3aba3281a60ed5b0", + "reference": "8561c785e55a39df6cb6f95c3aba3281a60ed5b0", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "slim/slim": ">=2.4.0" + }, + "suggest": { + "smarty/smarty": "Smarty templating system", + "twig/twig": "Twig templating system" + }, + "type": "library", + "autoload": { + "psr-4": { + "Slim\\Views\\": "./" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josh Lockhart", + "email": "info@joshlockhart.com", + "homepage": "http://www.joshlockhart.com/" + }, + { + "name": "Andrew Smith", + "email": "a.smith@silentworks.co.uk", + "homepage": "http://thoughts.silentworks.co.uk/" + } + ], + "description": "Smarty and Twig View Parser package for the Slim Framework", + "homepage": "http://github.com/codeguy/Slim-Views", + "keywords": [ + "extensions", + "slimphp", + "templating" + ], + "time": "2014-12-09 23:48:51" + }, { "name": "smarty/smarty", "version": "v3.1.27", @@ -60,9 +380,112 @@ "templating" ], "time": "2015-06-18 00:55:59" + }, + { + "name": "symfony/yaml", + "version": "v2.7.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "eca9019c88fbe250164affd107bc8057771f3f4d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/eca9019c88fbe250164affd107bc8057771f3f4d", + "reference": "eca9019c88fbe250164affd107bc8057771f3f4d", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2015-10-11 09:39:48" + } + ], + "packages-dev": [ + { + "name": "symfony/var-dumper", + "version": "v2.7.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "eb033050050916b6bfa51be71009ef67b16046c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/eb033050050916b6bfa51be71009ef67b16046c9", + "reference": "eb033050050916b6bfa51be71009ef67b16046c9", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "suggest": { + "ext-symfony_debug": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony mechanism for exploring and dumping PHP variables", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "time": "2015-10-25 17:17:38" } ], - "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/config.example.php b/config.example.php deleted file mode 100644 index f410318..0000000 --- a/config.example.php +++ /dev/null @@ -1,25 +0,0 @@ - - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -define('YOUTUBE_DL', './youtube-dl'); -define('PYTHON', '/usr/bin/python'); -define('PARAMS', '--no-playlist --no-warnings -f best'); -if (getenv('CONVERT')) { - define('CONVERT', getenv('CONVERT')); -} else { - define('CONVERT', false); -} -define('AVCONV', __DIR__.'/ffmpeg/ffmpeg'); -define('MAINTENANCE', false); -define('DISABLED', false); -define('BASE_URL', 'http://alltubedownload.net/'); diff --git a/config.example.yml b/config.example.yml new file mode 100644 index 0000000..7dd9940 --- /dev/null +++ b/config.example.yml @@ -0,0 +1,5 @@ +youtubedl: vendor/rg3/youtube-dl/youtube_dl/__main__.py +python: /usr/bin/python +params: --no-playlist --no-warnings -f best +convert: false +avconv: ffmpeg/ffmpeg diff --git a/controllers/FrontController.php b/controllers/FrontController.php new file mode 100644 index 0000000..4f70726 --- /dev/null +++ b/controllers/FrontController.php @@ -0,0 +1,216 @@ + + * @license GNU General Public License http://www.gnu.org/licenses/gpl.html + * @link http://rudloff.pro + * */ +namespace Alltube\Controller; +use Alltube\VideoDownload; +use Alltube\Config; +/** + * Main controller + * + * PHP Version 5.3.10 + * + * @category Youtube-dl + * @package Youtubedl + * @author Pierre Rudloff + * @license GNU General Public License http://www.gnu.org/licenses/gpl.html + * @link http://rudloff.pro + * */ +class FrontController +{ + + /** + * Display index page + * @return void + */ + static function index() + { + global $app; + $config = Config::getInstance(); + $app->render( + 'head.tpl', + array( + 'class'=>'index' + ) + ); + $app->render( + 'header.tpl' + ); + $app->render( + 'index.tpl', + array( + 'convert'=>$config->convert + ) + ); + $app->render('footer.tpl'); + } + + /** + * Display a list of extractors + * @return void + */ + static function extractors() + { + global $app; + $app->render( + 'head.tpl', + array( + 'class'=>'extractors' + ) + ); + $app->render('header.tpl'); + $app->render('logo.tpl'); + $app->render( + 'extractors.tpl', + array( + 'extractors'=>VideoDownload::listExtractors() + ) + ); + $app->render('footer.tpl'); + } + + /** + * Dislay information about the video + * @return void + */ + static function video() + { + global $app; + $config = Config::getInstance(); + if (isset($_GET["url"])) { + if (isset($_GET['audio'])) { + try { + $video = VideoDownload::getJSON($_GET["url"]); + + //Vimeo needs a correct user-agent + $UA = VideoDownload::getUA(); + ini_set( + 'user_agent', + $UA + ); + $url_info = parse_url($video->url); + if ($url_info['scheme'] == 'rtmp') { + ob_end_flush(); + header( + 'Content-Disposition: attachment; filename="'. + html_entity_decode( + pathinfo( + VideoDownload::getFilename( + $video->webpage_url + ), PATHINFO_FILENAME + ).'.mp3', ENT_COMPAT, 'ISO-8859-1' + ).'"' + ); + header("Content-Type: audio/mpeg"); + passthru( + '/usr/bin/rtmpdump -q -r '.escapeshellarg($video->url). + ' | '.$config->avconv. + ' -v quiet -i - -f mp3 -vn pipe:1' + ); + exit; + } else { + ob_end_flush(); + header( + 'Content-Disposition: attachment; filename="'. + html_entity_decode( + pathinfo( + VideoDownload::getFilename( + $video->webpage_url + ), PATHINFO_FILENAME + ).'.mp3', ENT_COMPAT, 'ISO-8859-1' + ).'"' + ); + header("Content-Type: audio/mpeg"); + passthru( + 'curl --user-agent '.escapeshellarg($UA). + ' '.escapeshellarg($video->url). + ' | '.$config->avconv. + ' -v quiet -i - -f mp3 -vn pipe:1' + ); + exit; + } + } catch (\Exception $e) { + $error = $e->getMessage(); + } + } else { + try { + $video = VideoDownload::getJSON($_GET["url"]); + $app->render( + 'head.tpl', + array( + 'class'=>'video' + ) + ); + $app->render( + 'video.tpl', + array( + 'video'=>$video + ) + ); + $app->render('footer.tpl'); + } catch (\Exception $e) { + $error = $e->getMessage(); + } + } + } + if (isset($error)) { + $app->render( + 'head.tpl', + array( + 'class'=>'video' + ) + ); + $app->render( + 'error.tpl', + array( + 'errors'=>$error + ) + ); + $app->render('footer.tpl'); + } + } + + /** + * Redirect to video file + * @return void + */ + static function redirect() + { + global $app; + if (isset($_GET["url"])) { + try { + $video = VideoDownload::getURL($_GET["url"]); + $app->redirect($video['url']); + } catch (\Exception $e) { + $app->response->headers->set('Content-Type', 'text/plain'); + echo $e->getMessage(); + } + } + } + + /** + * Output JSON info about the video + * @return void + */ + static function json() + { + global $app; + if (isset($_GET["url"])) { + $app->response->headers->set('Content-Type', 'application/json'); + try { + $video = VideoDownload::getJSON($_GET["url"]); + echo json_encode($video); + } catch (\Exception $e) { + echo json_encode(array('success'=>false, 'error'=>$e->getMessage())); + } + } + } +} diff --git a/css/fonts.css b/css/fonts.css index eff928c..1eb4f61 100644 --- a/css/fonts.css +++ b/css/fonts.css @@ -2,11 +2,11 @@ font-family: 'Open Sans'; font-style: normal; font-weight: 300; - src: local('Open Sans Light'), local('OpenSans-Light'), url(../fonts/OpenSans-Light.ttf); + src: local('Open Sans Light'), local('OpenSans-Light'), url(../bower_components/opensans-googlefont/OpenSans-Light.ttf); } @font-face { font-family: 'Open Sans'; font-style: normal; font-weight: 400; - src: local('Open Sans'), local('OpenSans'), url(../fonts/OpenSans-Regular.ttf); + src: local('Open Sans'), local('OpenSans'), url(../bower_components/opensans-googlefont/OpenSans-Regular.ttf); } diff --git a/css/style.css b/css/style.css index 4bfdc2a..c456cf5 100644 --- a/css/style.css +++ b/css/style.css @@ -248,7 +248,24 @@ color:#f2084a; -moz-transition: all 0.1s ease-in; -o-transition: all 0.1s ease-in; } - + +#bookmarklet{ +padding:15px; +} + +.bookmarklet{ +position:relative; +font-size:13px; +color:gray; +z-index:10; +text-decoration:none; +padding-left:30px; +padding-right:30px; +padding-top:10px; +padding-bottom:10px; +border: 2px dotted; +} + .mp3 { position:relative; diff --git a/disabled.php b/disabled.php deleted file mode 100644 index d7ee805..0000000 --- a/disabled.php +++ /dev/null @@ -1,22 +0,0 @@ - - * @author Olivier Haquette - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -require_once 'common.php'; -if (!DISABLED) { - header('Location: index.php'); exit; -} -$smarty->display('head.tpl'); -$smarty->display('header.tpl'); -$smarty->display('disabled.tpl'); -$smarty->display('footer.tpl'); diff --git a/download.php b/download.php deleted file mode 100644 index 516fda1..0000000 --- a/download.php +++ /dev/null @@ -1,210 +0,0 @@ - - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ - -/** - * PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/) - * Main class - * - * PHP Version 5.3.10 - * - * @category Youtube-dl - * @package Youtubedl - * @author Pierre Rudloff - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -Class VideoDownload -{ - /** - * Get version of youtube-dl - * - * @return string Version - * */ - static function getVersion() - { - exec( - PYTHON.' '.YOUTUBE_DL.' --version', - $version, $code - ); - return $version[0]; - } - /** - * Get the user agent used youtube-dl - * - * @return string UA - * */ - static function getUA() - { - exec( - PYTHON.' '.YOUTUBE_DL.' --dump-user-agent', - $version, $code - ); - return $version[0]; - } - - /** - * List all extractors - * - * @return array Extractors - * */ - static function listExtractors() - { - exec( - PYTHON.' '.YOUTUBE_DL.' --list-extractors', - $extractors, $code - ); - return $extractors; - } - - /** - * Get filename of video - * - * @param string $url URL of page - * @param string $format Format to use for the video - * - * @return string Filename - * */ - static function getFilename($url, $format=null) - { - $cmd=PYTHON.' youtube-dl'; - if (isset($format)) { - $cmd .= ' -f '.escapeshellarg($format); - } - $cmd .=' --get-filename '.escapeshellarg($url)." 2>&1"; - exec( - $cmd, - $filename - ); - return end($filename); - } - - /** - * Get title of video - * - * @param string $url URL of page - * - * @return string Title - * */ - static function getTitle($url) - { - exec( - PYTHON.' '.YOUTUBE_DL.' --get-title '. - escapeshellarg($url), - $title - ); - $title=$title[0]; - return $title; - } - - /** - * Get all information about a video - * - * @param string $url URL of page - * @param string $format Format to use for the video - * - * @return string JSON - * */ - static function getJSON($url, $format=null) - { - $cmd=PYTHON.' '.YOUTUBE_DL.' '.PARAMS; - if (isset($format)) { - $cmd .= ' -f '.escapeshellarg($format); - } - $cmd .=' --dump-json '.escapeshellarg($url)." 2>&1"; - exec( - $cmd, - $json, $code - ); - if ($code>0) { - return array('success'=>false, 'error'=>$json); - } else { - return json_decode($json[0]); - } - } - - /** - * Get thumbnail of video - * - * @param string $url URL of page - * - * @return string URL of image - * */ - static function getThumbnail($url) - { - exec( - PYTHON.' '.YOUTUBE_DL.' --get-thumbnail '. - escapeshellarg($url), - $thumb - ); - if (isset($thumb[0])) { - return $thumb[0]; - } - } - - /** - * Get a list available formats for this video - * - * @param string $url URL of page - * - * @return string Title - * */ - static function getAvailableFormats($url) - { - exec( - PYTHON.' '.YOUTUBE_DL.' -F '. - escapeshellarg($url), - $formats - ); - $return=array(); - foreach ($formats as $i=>$format) { - if ($i > 4) { - $return[]=(preg_split('/(\s\s+)|(\s+:?\s+)|(\s+\[)|\]/', $format)); - } - } - if (empty($return)) { - foreach ($formats as $i=>$format) { - if ($i > 3) { - $return[]=preg_split('/(\s\s+)|(\s+:?\s+)|(\s+\[)|\]/', $format); - } - } - } - return $return; - } - - /** - * Get URL of video from URL of page - * - * @param string $url URL of page - * @param string $format Format to use for the video - * - * @return string URL of video - * */ - static function getURL($url, $format=null) - { - $cmd=PYTHON.' '.YOUTUBE_DL; - if (isset($format)) { - $cmd .= ' -f '.escapeshellarg($format); - } - $cmd .=' -g '.escapeshellarg($url)." 2>&1"; - exec( - $cmd, $url, $code - ); - if ($code>0) { - return array('success'=>false, 'error'=>$url); - } else { - return array('success'=>true, 'url'=>end($url)); - } - - } -} diff --git a/error.html b/error.html new file mode 100644 index 0000000..81b5d00 --- /dev/null +++ b/error.html @@ -0,0 +1,18 @@ + + + + + + AllTube Download - Maintenance + + + +
+
+

+
An error occurred in the application and your page could not be served. Please try again in a few moments.
+
+
+ + diff --git a/extractors.php b/extractors.php deleted file mode 100644 index f265363..0000000 --- a/extractors.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @author Olivier Haquette - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -require_once 'common.php'; -$smarty->assign('class', 'extractors'); -require_once 'download.php'; -$smarty->display('head.tpl'); -$smarty->display('header.tpl'); -$smarty->display('logo.tpl'); -$smarty->assign('extractors', VideoDownload::listExtractors()); -$smarty->display('extractors.tpl'); -$smarty->display('footer.tpl'); diff --git a/fonts/OpenSans-Light.ttf b/fonts/OpenSans-Light.ttf deleted file mode 100644 index 0d38189..0000000 Binary files a/fonts/OpenSans-Light.ttf and /dev/null differ diff --git a/fonts/OpenSans-Regular.ttf b/fonts/OpenSans-Regular.ttf deleted file mode 100644 index db43334..0000000 Binary files a/fonts/OpenSans-Regular.ttf and /dev/null differ diff --git a/index.php b/index.php index 6be74ec..181ffa0 100644 --- a/index.php +++ b/index.php @@ -2,9 +2,9 @@ /** * PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/) * Index page - * + * * PHP Version 5.3.10 - * + * * @category Youtube-dl * @package Youtubedl * @author Pierre Rudloff @@ -12,9 +12,37 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -require_once 'common.php'; -$smarty->assign('class', 'index'); -$smarty->display('head.tpl'); -$smarty->display('header.tpl'); -$smarty->display('index.tpl'); -$smarty->display('footer.tpl'); +require_once __DIR__.'/vendor/autoload.php'; +use Alltube\VideoDownload; + +$app = new \Slim\Slim( + array( + 'view' => new \Slim\Views\Smarty() + ) +); +$view = $app->view(); +$view->parserExtensions = array( + __DIR__.'/vendor/slim/views/SmartyPlugins', + __DIR__.'/vendor/rudloff/smarty-plugin-noscheme/' +); +$app->get( + '/', + array('Alltube\Controller\FrontController', 'index') +); +$app->get( + '/extractors', + array('Alltube\Controller\FrontController', 'extractors') +)->name('extractors'); +$app->get( + '/video', + array('Alltube\Controller\FrontController', 'video') +)->name('video'); +$app->get( + '/redirect', + array('Alltube\Controller\FrontController', 'redirect') +); +$app->get( + '/json', + array('Alltube\Controller\FrontController', 'json') +); +$app->run(); diff --git a/json.php b/json.php deleted file mode 100644 index 9131fde..0000000 --- a/json.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -require_once 'common.php'; -require_once 'download.php'; -if (isset($_GET["url"])) { - header('Content-Type: application/json'); - $video = VideoDownload::getJSON($_GET["url"]); - echo json_encode($video); -} diff --git a/maintenance.html b/maintenance.html new file mode 100644 index 0000000..f7ba7a5 --- /dev/null +++ b/maintenance.html @@ -0,0 +1,18 @@ + + + + + + AllTube Download - Maintenance + + + +
+
+

+
This application is undergoing maintenance right now. Please check back later.
+
+
+ + diff --git a/maintenance.php b/maintenance.php deleted file mode 100644 index fc64fec..0000000 --- a/maintenance.php +++ /dev/null @@ -1,22 +0,0 @@ - - * @author Olivier Haquette - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -require_once 'common.php'; -if (!MAINTENANCE) { - header('Location: index.php'); exit; -} -$smarty->display('head.tpl'); -$smarty->display('header.tpl'); -$smarty->display('maintenance.tpl'); -$smarty->display('footer.tpl'); diff --git a/package.json b/package.json index bf94bc7..18c0e7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "alltube", - "version": "0.3.2", + "version": "0.4.0", "dependencies": { "grunt": "~0.4.5", "grunt-cli": "~0.1.13", @@ -8,7 +8,9 @@ "grunt-contrib-uglify": "~0.6.0", "grunt-contrib-watch": "~0.6.1", "grunt-phpcs": "~0.4.0", - "grunt-phpunit": "~0.3.6" + "grunt-phpunit": "~0.3.6", + "grunt-contrib-compress": "~0.13.0", + "bower": "~1.6.3" }, "engines": { "node": "~0.10.29" @@ -18,6 +20,6 @@ "url": "https://github.com/Rudloff/alltube.git" }, "scripts": { - "postinstall": "./node_modules/grunt-cli/bin/grunt; curl -L https://yt-dl.org/downloads/latest/youtube-dl -o youtube-dl; curl http://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xz -o ffmpeg.tar.xz; tar xJf ffmpeg.tar.xz -C ffmpeg --strip-components=1" + "postinstall": "./node_modules/bower/bin/bower install; ./node_modules/grunt-cli/bin/grunt; curl http://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xz -o ffmpeg.tar.xz; tar xJf ffmpeg.tar.xz -C ffmpeg --strip-components=1" } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..0288925 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,15 @@ + + + + classes/ + + + + + tests/ + + + + + + diff --git a/redirect.php b/redirect.php deleted file mode 100644 index de9a40d..0000000 --- a/redirect.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -require_once 'common.php'; -require_once 'download.php'; -if (isset($_GET["url"])) { - $video = VideoDownload::getURL($_GET["url"]); - if (isset($video['url'])) { - header('Location: '.$video['url']); - } else { - echo "Can't find video"; - } -} diff --git a/release.sh b/release.sh deleted file mode 100755 index 7e45ed9..0000000 --- a/release.sh +++ /dev/null @@ -1,2 +0,0 @@ -rm alltube-release.zip -zip -r alltube-release.zip *.php dist/ fonts/ .htaccess img/ js/ LICENSE README.md robots.txt sitemap.xml templates/ templates_c/ vendor/ youtube-dl -x config.php diff --git a/sitemap.xml b/sitemap.xml index b7b9248..9d3433b 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -6,7 +6,7 @@ 1 - http://alltubedownload.net/extractors.php + http://alltubedownload.net/extractors weekly diff --git a/templates/disabled.tpl b/templates/disabled.tpl deleted file mode 100644 index 34dce16..0000000 --- a/templates/disabled.tpl +++ /dev/null @@ -1,15 +0,0 @@ -
-
-

-
- Due to various technical reasons, - we can no longer host an online version of AllTube.
- However, you are free to - - download the code - and run it on your own server. -
-
-
diff --git a/templates/footer.tpl b/templates/footer.tpl index 2a5e4fd..ae9c9be 100644 --- a/templates/footer.tpl +++ b/templates/footer.tpl @@ -15,7 +15,6 @@ · Based on youtube-dl · - Bookmarklet diff --git a/templates/head.tpl b/templates/head.tpl index a32c850..42ffa1e 100644 --- a/templates/head.tpl +++ b/templates/head.tpl @@ -4,24 +4,25 @@ - + AllTube Download - - - + + + + - + - + - + diff --git a/templates/header.tpl b/templates/header.tpl index 4e10afe..dfa1df2 100644 --- a/templates/header.tpl +++ b/templates/header.tpl @@ -1,8 +1,8 @@
diff --git a/templates/index.tpl b/templates/index.tpl index 31a7114..ce0964d 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -1,7 +1,7 @@
-
-
+ @@ -20,5 +20,10 @@ {/if}
- See all supported websites + See all supported websites +
+

Drag this to your bookmarks bar:

+ Bookmarklet +
+
diff --git a/templates/logo.tpl b/templates/logo.tpl index 15d3c3f..517fb3d 100644 --- a/templates/logo.tpl +++ b/templates/logo.tpl @@ -1,4 +1,4 @@

- -AllTube Download + +AllTube Download

diff --git a/templates/maintenance.tpl b/templates/maintenance.tpl deleted file mode 100644 index 18ff6ca..0000000 --- a/templates/maintenance.tpl +++ /dev/null @@ -1,9 +0,0 @@ -
-
-

-
Due to some issues with our server, - we have to disable AllTube for a few days. - Sorry for the inconvenience.
-
-
diff --git a/templates/video.tpl b/templates/video.tpl index a4d3e78..c899966 100644 --- a/templates/video.tpl +++ b/templates/video.tpl @@ -9,16 +9,18 @@ href="{$video->webpage_url}"> {$video->title}. Google Cast™ is disabled Google Cast™ -Casting to ChromeCast…

- +{if isset($video->thumbnail)} + +{/if}
diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php new file mode 100644 index 0000000..75b59e9 --- /dev/null +++ b/tests/ConfigTest.php @@ -0,0 +1,39 @@ + + * @license GNU General Public License http://www.gnu.org/licenses/gpl.html + * @link http://rudloff.pro + * */ +use Alltube\Config; + +/** + * Unit tests for the Config class + * + * PHP Version 5.3.10 + * + * @category Youtube-dl + * @package Youtubedl + * @author Pierre Rudloff + * @license GNU General Public License http://www.gnu.org/licenses/gpl.html + * @link http://rudloff.pro + * */ +class ConfigTest extends PHPUnit_Framework_TestCase +{ + + /** + * Test the getInstance function + * @return void + */ + public function testGetInstance() + { + putenv('CONVERT=1'); + $config = Config::getInstance(); + $this->assertEquals($config->convert, true); + } +} diff --git a/tests/VideoDownloadTest.php b/tests/VideoDownloadTest.php index 7e01706..fc84cf7 100644 --- a/tests/VideoDownloadTest.php +++ b/tests/VideoDownloadTest.php @@ -10,9 +10,7 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ - -require_once __DIR__.'/../common.php'; -require_once __DIR__.'/../download.php'; +use Alltube\VideoDownload; /** * Unit tests for the VideoDownload class @@ -27,19 +25,9 @@ require_once __DIR__.'/../download.php'; * */ class VideoDownloadTest extends PHPUnit_Framework_TestCase { - static private $_testVideoURL = 'https://www.youtube.com/watch?v=RJJ6FCAXvKg'; - - /** - * Test getVersion function - * @return void - */ - public function testGetVersion() - { - $this->assertStringMatchesFormat('%i.%i.%i', VideoDownload::getVersion()); - } - /** * Test getUA function + * * @return void */ public function testGetUA() @@ -49,23 +37,128 @@ class VideoDownloadTest extends PHPUnit_Framework_TestCase /** * Test listExtractors funtion + * * @return void */ public function testListExtractors() { $extractors = VideoDownload::listExtractors(); - $this->assertNotEmpty($extractors); - $this->assertInternalType('array', $extractors); + $this->assertContains('youtube', $extractors); } /** * Test getURL function - * @return void + * + * @param string $url URL + * @param string $format Format + * + * @return void + * @dataProvider urlProvider */ - public function testGetURL() + public function testGetURL($url, $format) { - $url = VideoDownload::getURL(self::$_testVideoURL); - $this->assertArrayHasKey('success', $url); - $this->assertArrayHasKey('url', $url); + $videoURL = VideoDownload::getURL($url, $format); + $this->assertArrayHasKey('success', $videoURL); + $this->assertArrayHasKey('url', $videoURL); + } + + /** + * Test getURL function errors + * + * @param string $url URL + * + * @return void + * @expectedException Exception + * @dataProvider ErrorUrlProvider + */ + public function testGetURLError($url) + { + $videoURL = VideoDownload::getURL($url); + } + + /** + * Provides URLs for tests + * + * @return array + */ + public function urlProvider() + { + return array( + array( + 'https://www.youtube.com/watch?v=M7IpKCZ47pU', null, + "It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp4" + ), + array( + 'https://www.youtube.com/watch?v=RJJ6FCAXvKg', 22, + "'Heart Attack' - Demi Lovato ". + "(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp4" + ), + array( + 'https://vimeo.com/24195442', null, + "Carving the Mountains-24195442.mp4" + ), + ); + } + + /** + * Provides incorrect URLs for tests + * + * @return array + */ + public function errorUrlProvider() + { + return array( + array('http://example.com/video') + ); + } + + /** + * Test getFilename function + * + * @param string $url URL + * @param string $format Format + * @param string $result Expected filename + * + * @return void + * @dataProvider URLProvider + */ + public function testGetFilename($url, $format, $result) + { + $filename = VideoDownload::getFilename($url, $format); + $this->assertEquals($filename, $result); + } + + /** + * Test getJSON function + * + * @param string $url URL + * @param string $format Format + * + * @return void + * @dataProvider URLProvider + */ + public function testGetJSON($url, $format) + { + $info = VideoDownload::getJSON($url, $format); + $this->assertObjectHasAttribute('webpage_url', $info); + $this->assertObjectHasAttribute('url', $info); + $this->assertObjectHasAttribute('ext', $info); + $this->assertObjectHasAttribute('title', $info); + $this->assertObjectHasAttribute('formats', $info); + $this->assertObjectHasAttribute('_filename', $info); + } + + /** + * Test getJSON function errors + * + * @param string $url URL + * + * @return void + * @expectedException Exception + * @dataProvider ErrorURLProvider + */ + public function testGetJSONError($url) + { + $videoURL = VideoDownload::getJSON($url); } } diff --git a/youtoubeur.php b/youtoubeur.php deleted file mode 100644 index f43478c..0000000 --- a/youtoubeur.php +++ /dev/null @@ -1,14 +0,0 @@ - - * @license GNU General Public License http://www.gnu.org/licenses/gpl.html - * @link http://rudloff.pro - * */ -header('Location: index.php');