From 8825ff2117a8269d4cc7de0c067be90c1497ee9c Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 5 Jul 2014 12:45:24 +0200 Subject: [PATCH] Config in a separate file (fixes #2 and fixes #3) --- api.php | 1 - config.php | 17 +++++++++++++++++ download.php | 25 +++++++++++-------------- json.php | 14 ++++++++++++-- 4 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 config.php diff --git a/api.php b/api.php index 3b233b1..2a36a27 100644 --- a/api.php +++ b/api.php @@ -10,7 +10,6 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ -$python="/usr/bin/python"; require_once 'download.php'; if (isset($_GET["url"])) { if (isset($_GET["format"]) || isset($_GET['audio'])) { diff --git a/config.php b/config.php new file mode 100644 index 0000000..0249c03 --- /dev/null +++ b/config.php @@ -0,0 +1,17 @@ + + * @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'); +?> diff --git a/download.php b/download.php index ab2f177..746c229 100644 --- a/download.php +++ b/download.php @@ -11,7 +11,7 @@ * @license GNU General Public License http://www.gnu.org/licenses/gpl.html * @link http://rudloff.pro * */ - +require_once 'config.php'; /** * PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/) * Main class @@ -26,9 +26,6 @@ * */ Class VideoDownload { - static private $_python="/usr/bin/python"; - static private $_params="--no-playlist"; - /** * Get version of youtube-dl * @@ -37,7 +34,7 @@ Class VideoDownload function getVersion () { exec( - VideoDownload::$_python.' youtube-dl --version', + PYTHON.' '.YOUTUBE_DL.' --version', $version, $code ); return $version[0]; @@ -50,7 +47,7 @@ Class VideoDownload function getUA () { exec( - VideoDownload::$_python.' youtube-dl --dump-user-agent', + PYTHON.' '.YOUTUBE_DL.' --dump-user-agent', $version, $code ); return $version[0]; @@ -64,7 +61,7 @@ Class VideoDownload function listExtractors () { exec( - VideoDownload::$_python.' youtube-dl --list-extractors', + PYTHON.' '.YOUTUBE_DL.' --list-extractors', $extractors, $code ); return $extractors; @@ -80,7 +77,7 @@ Class VideoDownload * */ function getFilename ($url, $format=null) { - $cmd=VideoDownload::$_python.' youtube-dl'; + $cmd=PYTHON.' youtube-dl'; if (isset($format)) { $cmd .= ' -f '.escapeshellarg($format); } @@ -102,7 +99,7 @@ Class VideoDownload function getTitle ($url) { exec( - VideoDownload::$_python.' youtube-dl --get-title '. + PYTHON.' '.YOUTUBE_DL.' --get-title '. escapeshellarg($url), $title ); @@ -120,11 +117,11 @@ Class VideoDownload * */ function getJSON ($url, $format=null) { - $cmd=VideoDownload::$_python.' youtube-dl '.VideoDownload::$_params; + $cmd=PYTHON.' '.YOUTUBE_DL.' '.PARAMS; if (isset($format)) { $cmd .= ' -f '.escapeshellarg($format); } - $cmd .=' --no-warnings --dump-json '.escapeshellarg($url)." 2>&1"; + $cmd .=' --dump-json '.escapeshellarg($url)." 2>&1"; exec( $cmd, $json, $code @@ -146,7 +143,7 @@ Class VideoDownload function getThumbnail ($url) { exec( - VideoDownload::$_python.' youtube-dl --get-thumbnail '. + PYTHON.' '.YOUTUBE_DL.' --get-thumbnail '. escapeshellarg($url), $thumb ); @@ -165,7 +162,7 @@ Class VideoDownload function getAvailableFormats ($url) { exec( - VideoDownload::$_python.' youtube-dl -F '. + PYTHON.' '.YOUTUBE_DL.' -F '. escapeshellarg($url), $formats ); @@ -195,7 +192,7 @@ Class VideoDownload * */ function getURL ($url, $format=null) { - $cmd=VideoDownload::$_python.' youtube-dl'; + $cmd=PYTHON.' '.YOUTUBE_DL; if (isset($format)) { $cmd .= ' -f '.escapeshellarg($format); } diff --git a/json.php b/json.php index 36e1617..fd81816 100644 --- a/json.php +++ b/json.php @@ -1,6 +1,16 @@ + * @license GNU General Public License http://www.gnu.org/licenses/gpl.html + * @link http://rudloff.pro + * */ require_once 'download.php'; if (isset($_GET["url"])) { header('Content-Type: application/json');