Remove unused code
Unit tests for every function Error handling
This commit is contained in:
parent
de96f30d57
commit
11ff0fa9c4
7 changed files with 159 additions and 138 deletions
131
download.php
131
download.php
|
@ -2,9 +2,9 @@
|
|||
/**
|
||||
* 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 <contact@rudloff.pro>
|
||||
|
@ -15,9 +15,9 @@
|
|||
/**
|
||||
* 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 <contact@rudloff.pro>
|
||||
|
@ -26,53 +26,40 @@
|
|||
* */
|
||||
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
|
||||
$version
|
||||
);
|
||||
return $version[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List all extractors
|
||||
*
|
||||
*
|
||||
* @return array Extractors
|
||||
* */
|
||||
static function listExtractors()
|
||||
{
|
||||
exec(
|
||||
PYTHON.' '.YOUTUBE_DL.' --list-extractors',
|
||||
$extractors, $code
|
||||
$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)
|
||||
|
@ -88,31 +75,13 @@ Class VideoDownload
|
|||
);
|
||||
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)
|
||||
|
@ -123,88 +92,38 @@ Class VideoDownload
|
|||
}
|
||||
$cmd .=' --dump-json '.escapeshellarg($url)." 2>&1";
|
||||
exec(
|
||||
$cmd,
|
||||
$json, $code
|
||||
$cmd, $result, $code
|
||||
);
|
||||
if ($code>0) {
|
||||
return array('success'=>false, 'error'=>$json);
|
||||
throw new Exception(implode(PHP_EOL, $result));
|
||||
} else {
|
||||
return json_decode($json[0]);
|
||||
return json_decode($result[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;
|
||||
$cmd=PYTHON.' '.YOUTUBE_DL.' '.PARAMS;
|
||||
if (isset($format)) {
|
||||
$cmd .= ' -f '.escapeshellarg($format);
|
||||
}
|
||||
$cmd .=' -g '.escapeshellarg($url)." 2>&1";
|
||||
exec(
|
||||
$cmd, $url, $code
|
||||
$cmd, $result, $code
|
||||
);
|
||||
if ($code>0) {
|
||||
return array('success'=>false, 'error'=>$url);
|
||||
throw new Exception(implode(PHP_EOL, $result));
|
||||
} else {
|
||||
return array('success'=>true, 'url'=>end($url));
|
||||
return array('success'=>true, 'url'=>end($result));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue