2014-03-13 19:07:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-10-31 14:42:25 +00:00
|
|
|
* VideoDownload class
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* PHP Version 5.3.10
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* @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-10-29 19:43:43 +00:00
|
|
|
namespace Alltube;
|
2016-03-29 23:49:08 +00:00
|
|
|
|
2014-03-13 19:07:56 +00:00
|
|
|
/**
|
|
|
|
* Main class
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* PHP Version 5.3.10
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* @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
|
|
|
|
* */
|
2016-03-29 23:49:08 +00:00
|
|
|
class VideoDownload
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get the user agent used youtube-dl
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* @return string UA
|
|
|
|
* */
|
2016-03-29 23:49:08 +00:00
|
|
|
public static function getUA()
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
2015-10-31 14:42:25 +00:00
|
|
|
$config = Config::getInstance();
|
2016-02-28 22:04:53 +00:00
|
|
|
$cmd = escapeshellcmd(
|
|
|
|
$config->python.' '.escapeshellarg($config->youtubedl).
|
|
|
|
' '.$config->params
|
|
|
|
);
|
2014-03-13 19:07:56 +00:00
|
|
|
exec(
|
2016-02-28 22:00:33 +00:00
|
|
|
$cmd.' --dump-user-agent',
|
2015-09-04 20:45:55 +00:00
|
|
|
$version
|
2014-03-13 19:07:56 +00:00
|
|
|
);
|
|
|
|
return $version[0];
|
|
|
|
}
|
2015-09-04 20:45:55 +00:00
|
|
|
|
2014-03-13 19:07:56 +00:00
|
|
|
/**
|
|
|
|
* List all extractors
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* @return array Extractors
|
|
|
|
* */
|
2016-03-29 23:49:08 +00:00
|
|
|
public static function listExtractors()
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
2015-10-31 14:42:25 +00:00
|
|
|
$config = Config::getInstance();
|
2016-02-28 22:04:53 +00:00
|
|
|
$cmd = escapeshellcmd(
|
|
|
|
$config->python.' '.escapeshellarg($config->youtubedl).
|
|
|
|
' '.$config->params
|
|
|
|
);
|
2014-03-13 19:07:56 +00:00
|
|
|
exec(
|
2016-02-28 22:00:33 +00:00
|
|
|
$cmd.' --list-extractors',
|
2015-09-04 20:45:55 +00:00
|
|
|
$extractors
|
2014-03-13 19:07:56 +00:00
|
|
|
);
|
|
|
|
return $extractors;
|
|
|
|
}
|
2015-09-04 20:45:55 +00:00
|
|
|
|
2014-03-13 19:07:56 +00:00
|
|
|
/**
|
|
|
|
* Get filename of video
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* @param string $url URL of page
|
|
|
|
* @param string $format Format to use for the video
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* @return string Filename
|
|
|
|
* */
|
2016-03-29 23:49:08 +00:00
|
|
|
public static function getFilename($url, $format = null)
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
2015-10-31 14:42:25 +00:00
|
|
|
$config = Config::getInstance();
|
2016-02-28 22:04:53 +00:00
|
|
|
$cmd = escapeshellcmd(
|
|
|
|
$config->python.' '.escapeshellarg($config->youtubedl).
|
|
|
|
' '.$config->params
|
|
|
|
);
|
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);
|
|
|
|
}
|
2015-09-04 20:45:55 +00:00
|
|
|
|
2014-03-13 19:07:56 +00:00
|
|
|
/**
|
|
|
|
* Get all information about a video
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* @param string $url URL of page
|
|
|
|
* @param string $format Format to use for the video
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* @return string JSON
|
|
|
|
* */
|
2016-03-29 23:49:08 +00:00
|
|
|
public static function getJSON($url, $format = null)
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
2015-10-31 14:42:25 +00:00
|
|
|
$config = Config::getInstance();
|
2016-02-28 22:04:53 +00:00
|
|
|
$cmd = escapeshellcmd(
|
|
|
|
$config->python.' '.escapeshellarg($config->youtubedl).
|
|
|
|
' '.$config->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(
|
2016-03-29 23:49:08 +00:00
|
|
|
$cmd,
|
|
|
|
$result,
|
|
|
|
$code
|
2014-03-13 19:07:56 +00:00
|
|
|
);
|
2014-03-25 18:09:40 +00:00
|
|
|
if ($code>0) {
|
2015-10-29 19:43:43 +00:00
|
|
|
throw new \Exception(implode(PHP_EOL, $result));
|
2014-03-18 14:08:16 +00:00
|
|
|
} else {
|
2015-09-04 20:45:55 +00:00
|
|
|
return json_decode($result[0]);
|
2014-03-18 14:08:16 +00:00
|
|
|
}
|
2014-03-13 19:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get URL of video from URL of page
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* @param string $url URL of page
|
|
|
|
* @param string $format Format to use for the video
|
2015-09-04 20:45:55 +00:00
|
|
|
*
|
2014-03-13 19:07:56 +00:00
|
|
|
* @return string URL of video
|
|
|
|
* */
|
2016-03-29 23:49:08 +00:00
|
|
|
public static function getURL($url, $format = null)
|
2014-03-13 19:07:56 +00:00
|
|
|
{
|
2015-10-31 14:42:25 +00:00
|
|
|
$config = Config::getInstance();
|
2016-02-28 22:04:53 +00:00
|
|
|
$cmd = escapeshellcmd(
|
|
|
|
$config->python.' '.escapeshellarg($config->youtubedl).
|
|
|
|
' '.$config->params
|
|
|
|
);
|
2014-03-13 19:07:56 +00:00
|
|
|
if (isset($format)) {
|
|
|
|
$cmd .= ' -f '.escapeshellarg($format);
|
|
|
|
}
|
|
|
|
$cmd .=' -g '.escapeshellarg($url)." 2>&1";
|
|
|
|
exec(
|
2016-03-29 23:49:08 +00:00
|
|
|
$cmd,
|
|
|
|
$result,
|
|
|
|
$code
|
2014-03-13 19:07:56 +00:00
|
|
|
);
|
|
|
|
if ($code>0) {
|
2015-10-29 19:43:43 +00:00
|
|
|
throw new \Exception(implode(PHP_EOL, $result));
|
2014-03-13 19:07:56 +00:00
|
|
|
} else {
|
2015-09-04 20:45:55 +00:00
|
|
|
return array('success'=>true, 'url'=>end($result));
|
2014-03-13 19:07:56 +00:00
|
|
|
}
|
2015-09-04 20:45:55 +00:00
|
|
|
|
2014-03-13 19:07:56 +00:00
|
|
|
}
|
|
|
|
}
|