load->model('YoutubeDownloadModel', '', TRUE);
$this->load->model('RedirectModel', '', TRUE);
}
public function index()
{
$this->load->view('header', ['active' => 'youtube-downloader', 'title' => lang('ytdl_site_title')]);
$this->load->view('youtube_downloader');
$this->load->view('footer');
}
public function download()
{
if (empty($_GET['mime']) OR empty($_GET['token'])) {
header("Location: /youtube");
}
$mime = filter_var($_GET['mime']);
$ext = str_replace(array('/', 'x-'), '', strstr($mime, '/'));
$url = base64_decode(filter_var($_GET['token']));
$name = urldecode($_GET['title']) . '.' . $ext;
echo $url;
if ($url) {
$size = $this->YoutubeDownloadModel->get_size($url);
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $name . '"');
header('Expires: 0');
header('Content-Length: ' . $size);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
} else {
header('Content-Type: "' . $mime . '"');
header('Content-Disposition: attachment; filename="' . $name . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Content-Length: ' . $size);
header('Pragma: no-cache');
}
readfile($url);
exit;
}
}
public function video()
{
echo $this->load->view('header', ['title' => lang('ytdl_site_title'), 'active' => 'youtube-downloader'], true);
if (isset($_REQUEST['videoid'])) {
$my_id = $_REQUEST['videoid'];
if (preg_match('/^https:\/\/w{3}?.youtube.com\//', $my_id)) {
$url = parse_url($my_id);
$my_id = NULL;
if (is_array($url) && count($url) > 0 && isset($url['query']) && !empty($url['query'])) {
$parts = explode('&', $url['query']);
if (is_array($parts) && count($parts) > 0) {
foreach ($parts as $p) {
$pattern = '/^v\=/';
if (preg_match($pattern, $p)) {
$my_id = preg_replace($pattern, '', $p);
break;
}
}
}
if (!$my_id) {
header("Location: /tools/youtube?error=1");
exit;
}
} else {
header("Location: /tools/youtube?error=2");
exit;
}
} elseif (preg_match('/^https?:\/\/youtu.be/', $my_id)) {
$url = parse_url($my_id);
$my_id = NULL;
$my_id = preg_replace('/^\//', '', $url['path']);
}
} else {
header("Location: /tools/youtube?error=1");
exit;
}
if (isset($_REQUEST['type'])) {
$my_type = $_REQUEST['type'];
} else {
$my_type = 'redirect';
}
if ($my_type == 'Download') {
?>
= lang('ytdl_description'); ?> No encoded format stream found. Here is what we got from YouTube: ' . lang('ytdl_error_no_downloads') . ' ' . lang('ytdl_available_formats') . ':= lang('ytdl_title'); ?>
= $title; ?>
= lang('ytdl_views'); ?>: = $view_count; ?>
= lang('ytdl_length') . ': ' . $length_seconds . ' ' . lang('ytdl_minutes'); ?>
= lang('ytdl_author') ?>:
= $author; ?>
= lang('ytdl_watch'); ?>
';
$formats = [
'22' => '720p',
'18' => '360p',
'43' => '360p',
'5' => '240p',
'36' => '240p',
'17' => '144p'
];
/* now that we have the array, print the options */
for ($i = 0; $i < count($avail_formats); $i++) {
$type = explode('/', $avail_formats[$i]['type'])[1];
$thisurl = base_url('tools/youtube/download?mime=' . $avail_formats[$i]['type'] . '&title=' . urlencode(htmlspecialchars($my_title)) . '&token=' . base64_encode($avail_formats[$i]['url']));
$url = base_url('r/' . $this->RedirectModel->addRandomItem($thisurl, true, 6));
echo '' . lang('ytdl_format') . ' ' . lang('ytdl_quality') . ' ' . lang('ytdl_size') . ' ' . lang('ytdl_download_link') . ' ' . lang('ytdl_available_until') . ' ';
}
echo '';
echo '' . $type . ' ';
echo ' ' .
'' . $formats[$avail_formats[$i]['itag']] . ' ' . $this->YoutubeDownloadModel->formatBytes($this->YoutubeDownloadModel->get_size($avail_formats[$i]['url'])) . ' ';
echo '' . lang('ytdl_download_link') . ' ' . $avail_formats[$i]['expires'] . ' ';
echo '
' . lang('ytdl_no_haftung') . '
Der Betreiber nimmt Abstand von jeglichen urheberrechtsverletzenden Handlungen, die mit dem YouTube-Downloader durchgeführt werden könnten und unterstützt diese keinesfalls.';
?>
Out of loop, best_format is '. $best_format .'
'; if ((isset($best_format)) && (isset($avail_formats[$best_format]['url'])) && (isset($avail_formats[$best_format]['type'])) ) { $redirect_url = $avail_formats[$best_format]['url'] . '&title=' . $cleanedtitle; $content_type = $avail_formats[$best_format]['type']; } if (isset($redirect_url)) { header("Location: $redirect_url"); } } $this->load->view('footer'); } }