Initial import
This commit is contained in:
parent
c082725c80
commit
0651377e93
35 changed files with 1296 additions and 0 deletions
211
download.php
Normal file
211
download.php
Normal file
|
@ -0,0 +1,211 @@
|
|||
<?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
|
||||
* @author Pierre Rudloff <rudloff@strasweb.fr>
|
||||
* @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 <rudloff@strasweb.fr>
|
||||
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
|
||||
* @link http://rudloff.pro
|
||||
* */
|
||||
Class VideoDownload
|
||||
{
|
||||
static private $_python="/usr/bin/python";
|
||||
static private $_params="--no-playlist";
|
||||
|
||||
/**
|
||||
* Get version of youtube-dl
|
||||
*
|
||||
* @return string Version
|
||||
* */
|
||||
function getVersion ()
|
||||
{
|
||||
exec(
|
||||
VideoDownload::$_python.' youtube-dl --version',
|
||||
$version, $code
|
||||
);
|
||||
return $version[0];
|
||||
}
|
||||
/**
|
||||
* Get the user agent used youtube-dl
|
||||
*
|
||||
* @return string UA
|
||||
* */
|
||||
function getUA ()
|
||||
{
|
||||
exec(
|
||||
VideoDownload::$_python.' youtube-dl --dump-user-agent',
|
||||
$version, $code
|
||||
);
|
||||
return $version[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* List all extractors
|
||||
*
|
||||
* @return array Extractors
|
||||
* */
|
||||
function listExtractors ()
|
||||
{
|
||||
exec(
|
||||
VideoDownload::$_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
|
||||
* */
|
||||
function getFilename ($url, $format=null)
|
||||
{
|
||||
$cmd=VideoDownload::$_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
|
||||
* */
|
||||
function getTitle ($url)
|
||||
{
|
||||
exec(
|
||||
VideoDownload::$_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
|
||||
* */
|
||||
function getJSON ($url, $format=null)
|
||||
{
|
||||
$cmd=VideoDownload::$_python.' youtube-dl '.VideoDownload::$_params;
|
||||
if (isset($format)) {
|
||||
$cmd .= ' -f '.escapeshellarg($format);
|
||||
}
|
||||
$cmd .=' --dump-json '.escapeshellarg($url);
|
||||
exec(
|
||||
$cmd,
|
||||
$json
|
||||
);
|
||||
return $json[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get thumbnail of video
|
||||
*
|
||||
* @param string $url URL of page
|
||||
*
|
||||
* @return string URL of image
|
||||
* */
|
||||
function getThumbnail ($url)
|
||||
{
|
||||
exec(
|
||||
VideoDownload::$_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
|
||||
* */
|
||||
function getAvailabeFormats ($url)
|
||||
{
|
||||
exec(
|
||||
VideoDownload::$_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
|
||||
* */
|
||||
function getURL ($url, $format=null)
|
||||
{
|
||||
$cmd=VideoDownload::$_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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue