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') { ?>

YoutubeDownloadModel->curlGet($my_video_info); /* TODO: Check return from curl for status code */ if (empty($my_video_info)) { header("Location: /tools/youtube?error=3"); } $thumbnail_url = $title = $view_count = $author = $length_seconds = $url_encoded_fmt_stream_map = $type = $url = ''; parse_str($my_video_info); $length_seconds = date("i:s", $length_seconds); $view_count = number_format($view_count, 0, ',', '.'); if ($status == 'fail') { header("Location: /tools/youtube?error=3"); exit(); } ?>

:

:

YoutubeDownloadModel->clean($title); if (isset($url_encoded_fmt_stream_map)) { /* Now get the url_encoded_fmt_stream_map, and explode on comma */ $my_formats_array = explode(',', $url_encoded_fmt_stream_map); } else { echo '

No encoded format stream found.

'; echo '

Here is what we got from YouTube:

'; echo $my_video_info; } if (count($my_formats_array) == 0) { echo '

' . lang('ytdl_error_no_downloads') . '

'; exit; } /* create an array of available download formats */ $avail_formats[] = ''; $i = 0; $ipbits = $ip = $itag = $sig = $quality = ''; $expire = time(); foreach ($my_formats_array as $format) { parse_str($format); $avail_formats[$i]['itag'] = $itag; $avail_formats[$i]['quality'] = $quality; $type = explode(';', $type); $avail_formats[$i]['type'] = $type[0]; $avail_formats[$i]['url'] = urldecode($url) . '&signature=' . $sig; parse_str(urldecode($url)); $avail_formats[$i]['expires'] = date("d.m.Y G:i:s", $expire); $avail_formats[$i]['ipbits'] = $ipbits; $avail_formats[$i]['ip'] = $ip; $i++; } if ($my_type == 'Download') { echo '

' . lang('ytdl_available_formats') . ':

'; $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 ' ' . ''; echo ''; echo ''; } echo '
' . lang('ytdl_format') . '' . lang('ytdl_quality') . '' . lang('ytdl_size') . '' . lang('ytdl_download_link') . '' . lang('ytdl_available_until') . '
'; echo '' . $type . ' '; echo '' . $formats[$avail_formats[$i]['itag']] . '' . $this->YoutubeDownloadModel->formatBytes($this->YoutubeDownloadModel->get_size($avail_formats[$i]['url'])) . '' . lang('ytdl_download_link') . '' . $avail_formats[$i]['expires'] . '
' . lang('ytdl_not_related_youtube') . '
' . 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.'; ?>
Target format found, it is '. $avail_formats[$j]['itag'] .'

'; $best_format = $j; break 2; } } } //echo '

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'); } }