alltube/api.php

85 lines
2.8 KiB
PHP
Raw Normal View History

2014-03-13 19:07:56 +00:00
<?php
/**
* PHP web interface for youtube-dl (http://rg3.github.com/youtube-dl/)
2014-04-04 14:38:36 +00:00
*
2014-03-13 19:07:56 +00:00
* PHP Version 5.3.10
2014-04-04 14:38:36 +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
use Alltube\VideoDownload;
2015-01-07 09:42:44 +00:00
require_once 'common.php';
2015-04-11 20:08:24 +00:00
$smarty->assign('class', 'video');
2014-03-13 19:07:56 +00:00
if (isset($_GET["url"])) {
2015-01-07 09:23:48 +00:00
if (isset($_GET['audio'])) {
try {
$video = VideoDownload::getJSON($_GET["url"]);
2014-04-04 14:38:36 +00:00
//Vimeo needs a correct user-agent
$UA = VideoDownload::getUA();
ini_set(
'user_agent',
$UA
);
$url_info = parse_url($video->url);
if ($url_info['scheme'] == 'rtmp') {
2015-01-07 09:23:48 +00:00
header(
'Content-Disposition: attachment; filename="'.
html_entity_decode(
pathinfo(
VideoDownload::getFilename(
2015-01-07 09:23:48 +00:00
$video->webpage_url
), PATHINFO_FILENAME
).'.mp3', ENT_COMPAT, 'ISO-8859-1'
).'"'
);
header("Content-Type: audio/mpeg");
passthru(
'/usr/bin/rtmpdump -q -r '.escapeshellarg($video->url).
2015-05-16 01:23:55 +00:00
' | '.AVCONV.' -v quiet -i - -f mp3 -vn pipe:1'
2015-01-07 09:23:48 +00:00
);
exit;
} else {
2015-01-07 09:23:48 +00:00
header(
'Content-Disposition: attachment; filename="'.
html_entity_decode(
pathinfo(
VideoDownload::getFilename(
2015-01-07 09:23:48 +00:00
$video->webpage_url
), PATHINFO_FILENAME
).'.mp3', ENT_COMPAT, 'ISO-8859-1'
).'"'
);
header("Content-Type: audio/mpeg");
passthru(
2015-05-16 01:34:13 +00:00
'curl --user-agent '.escapeshellarg($UA).
' '.escapeshellarg($video->url).
2015-05-16 01:23:55 +00:00
' | '.AVCONV.' -v quiet -i - -f mp3 -vn pipe:1'
2015-01-07 09:23:48 +00:00
);
exit;
}
} catch (Exception $e) {
$error = $e->getMessage();
2014-03-13 19:07:56 +00:00
}
} else {
try {
$video = VideoDownload::getJSON($_GET["url"]);
2015-04-11 20:08:24 +00:00
$smarty->display('head.tpl');
$smarty->assign('video', $video);
$smarty->display('video.tpl');
$smarty->display('footer.tpl');
} catch (Exception $e) {
$error = $e->getMessage();
2014-03-13 19:07:56 +00:00
}
}
2014-04-04 14:38:36 +00:00
}
2014-03-13 19:07:56 +00:00
if (isset($error)) {
2015-04-11 20:08:24 +00:00
$smarty->display('head.tpl');
$smarty->assign('errors', $error);
2015-04-11 20:08:24 +00:00
$smarty->display('error.tpl');
$smarty->display('footer.tpl');
2014-03-13 19:07:56 +00:00
}