2014-03-13 19:07:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
|
|
|
|
* Main class
|
|
|
|
*
|
|
|
|
* PHP Version 5.3.10
|
|
|
|
*
|
|
|
|
* @category Youtube-dl
|
|
|
|
* @package Youtubedl
|
2015-01-07 09:47:46 +00:00
|
|
|
* @author Pierre Rudloff <contact@rudloff.pro>
|
2014-03-13 19:07:56 +00:00
|
|
|
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
|
|
|
* @link http://rudloff.pro
|
|
|
|
* */
|
2015-04-11 20:08:24 +00:00
|
|
|
|
2014-03-13 19:07:56 +00:00
|
|
|
/**
|
|
|
|
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
|
|
|
|
* Main class
|
|
|
|
*
|
|
|
|
* PHP Version 5.3.10
|
|
|
|
*
|
|
|
|
* @category Youtube-dl
|
|
|
|
* @package Youtubedl
|
2015-01-07 09:47:46 +00:00
|
|
|
* @author Pierre Rudloff <contact@rudloff.pro>
|
2014-03-13 19:07:56 +00:00
|
|
|
* @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
|
|
|
|
* */
|
2015-04-12 22:49:50 +00:00
|
|
|
static function getVersion()
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
|
|
|
exec(
|
2014-07-05 10:45:24 +00:00
|
|
|
PYTHON.' '.YOUTUBE_DL.' --version',
|
2014-03-13 19:07:56 +00:00
|
|
|
$version, $code
|
|
|
|
);
|
|
|
|
return $version[0];
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Get the user agent used youtube-dl
|
|
|
|
*
|
|
|
|
* @return string UA
|
|
|
|
* */
|
2015-04-12 22:49:50 +00:00
|
|
|
static function getUA()
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
|
|
|
exec(
|
2014-07-05 10:45:24 +00:00
|
|
|
PYTHON.' '.YOUTUBE_DL.' --dump-user-agent',
|
2014-03-13 19:07:56 +00:00
|
|
|
$version, $code
|
|
|
|
);
|
|
|
|
return $version[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List all extractors
|
|
|
|
*
|
|
|
|
* @return array Extractors
|
|
|
|
* */
|
2015-04-12 22:49:50 +00:00
|
|
|
static function listExtractors()
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
|
|
|
exec(
|
2014-07-05 10:45:24 +00:00
|
|
|
PYTHON.' '.YOUTUBE_DL.' --list-extractors',
|
2014-03-13 19:07:56 +00:00
|
|
|
$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
|
|
|
|
* */
|
2015-04-12 22:49:50 +00:00
|
|
|
static function getFilename($url, $format=null)
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
2014-07-05 10:45:24 +00:00
|
|
|
$cmd=PYTHON.' youtube-dl';
|
2014-03-13 19:07:56 +00:00
|
|
|
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
|
|
|
|
* */
|
2015-04-12 22:49:50 +00:00
|
|
|
static function getTitle($url)
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
|
|
|
exec(
|
2014-07-05 10:45:24 +00:00
|
|
|
PYTHON.' '.YOUTUBE_DL.' --get-title '.
|
2014-03-13 19:07:56 +00:00
|
|
|
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
|
|
|
|
* */
|
2015-04-12 22:49:50 +00:00
|
|
|
static function getJSON($url, $format=null)
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
2014-07-05 10:45:24 +00:00
|
|
|
$cmd=PYTHON.' '.YOUTUBE_DL.' '.PARAMS;
|
2014-03-13 19:07:56 +00:00
|
|
|
if (isset($format)) {
|
|
|
|
$cmd .= ' -f '.escapeshellarg($format);
|
|
|
|
}
|
2014-07-05 10:45:24 +00:00
|
|
|
$cmd .=' --dump-json '.escapeshellarg($url)." 2>&1";
|
2014-03-13 19:07:56 +00:00
|
|
|
exec(
|
|
|
|
$cmd,
|
2014-03-18 14:08:16 +00:00
|
|
|
$json, $code
|
2014-03-13 19:07:56 +00:00
|
|
|
);
|
2014-03-25 18:09:40 +00:00
|
|
|
if ($code>0) {
|
2014-03-18 14:08:16 +00:00
|
|
|
return array('success'=>false, 'error'=>$json);
|
|
|
|
} else {
|
|
|
|
return json_decode($json[0]);
|
|
|
|
}
|
2014-03-13 19:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get thumbnail of video
|
|
|
|
*
|
|
|
|
* @param string $url URL of page
|
|
|
|
*
|
|
|
|
* @return string URL of image
|
|
|
|
* */
|
2015-04-12 22:49:50 +00:00
|
|
|
static function getThumbnail($url)
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
|
|
|
exec(
|
2014-07-05 10:45:24 +00:00
|
|
|
PYTHON.' '.YOUTUBE_DL.' --get-thumbnail '.
|
2014-03-13 19:07:56 +00:00
|
|
|
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
|
|
|
|
* */
|
2015-04-12 22:49:50 +00:00
|
|
|
static function getAvailableFormats($url)
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
|
|
|
exec(
|
2014-07-05 10:45:24 +00:00
|
|
|
PYTHON.' '.YOUTUBE_DL.' -F '.
|
2014-03-13 19:07:56 +00:00
|
|
|
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
|
|
|
|
* */
|
2015-04-12 22:49:50 +00:00
|
|
|
static function getURL($url, $format=null)
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
2014-07-05 10:45:24 +00:00
|
|
|
$cmd=PYTHON.' '.YOUTUBE_DL;
|
2014-03-13 19:07:56 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|