Skip to content
This repository was archived by the owner on Oct 12, 2021. It is now read-only.

Commit 5daab15

Browse files
committed
Fixed Youtube download, should fix #249
Now YT's QSelector() will select MP4 @ 720p as default (if available), closes #245
1 parent 2cd0823 commit 5daab15

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

hosts/download/youtube_com.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ protected function retryReCaptchav2() {
123123
return $this->reCAPTCHAv2($_POST['recaptcha2_public_key'], $data);
124124
}
125125

126-
private function queryVideo($alt = 0) {
127-
$this->page = $this->GetPage('https://www.youtube.com/get_video_info?hl=en_US&video_id=' . $this->vid . ($alt ? '&eurl=https%3A%2F%2Fgoogle.com%2F' : '&el=detailpage') . ($this->sts > 0 ? '&sts=' . $this->sts : ''), $this->cookie);
126+
private function queryVideo() {
127+
$this->page = $this->GetPage('https://www.youtube.com/get_video_info?hl=en_US&video_id=' . $this->vid . '&eurl=https%3A%2F%2Fgoogle.com%2F&html5=1' . ($this->sts > 0 ? '&sts=' . $this->sts : ''), $this->cookie);
128128
$this->cookie = GetCookiesArr($this->page, $this->cookie);
129129
$this->response = array_map('urldecode', $this->FormToArr(substr($this->page, strpos($this->page, "\r\n\r\n") + 4)));
130130
if (!empty($this->response['requires_purchase'])) html_error('[Unsupported Video] This Video or Channel Requires a Payment to Watch.');
@@ -133,11 +133,10 @@ private function queryVideo($alt = 0) {
133133

134134
private function getFmtMaps() {
135135
$this->queryVideo();
136-
if (!empty($this->response['errorcode']) && $this->response['errorcode'] == 150 && $this->response['errordetail'] == 1) $this->queryVideo(1);
137136

138137
if (!empty($this->response['reason'])) html_error('['.htmlspecialchars($this->response['errorcode']).'] '.htmlspecialchars($this->response['reason']));
139138

140-
if (!empty($this->response['player_response']['playabilityStatus']['reason'])) html_error('['.htmlspecialchars($this->response['player_response']['playabilityStatus']['reason']).'] '.htmlspecialchars($this->response['player_response']['playabilityStatus']['errorScreen']['playerErrorMessageRenderer']['subreason']['simpleText']));
139+
if (!empty($this->response['player_response']['playabilityStatus']['reason'])) html_error('['.htmlspecialchars($this->response['player_response']['playabilityStatus']['reason']).'] '.htmlspecialchars($this->response['player_response']['playabilityStatus']['errorScreen']['playerErrorMessageRenderer']['subreason']['runs'][0]['text']));
141140

142141
if (!empty($this->response['player_response']['streamingData']['formats'])) {
143142
$this->response['_formats'] = $this->response['player_response']['streamingData']['formats'];
@@ -272,6 +271,8 @@ private function getCipher() {
272271
$savefile = DOWNLOAD_DIR.'YT_lastjs.txt';
273272
if (!preg_match('@(?<=[\"\'])(?:(?:https?:?)?//((?:[\w\-]+\.)+[\w\-]+(?:\:\d+)?))?(/(?:[^\"\'/]+/)+?(?:html5)?player[-_][\w\-\.]+(?:(?:/\w+)?/[\w\-\.]+)?)\.js@i', str_replace('\\/', '/', $page), $this->js)) html_error('YT\'s player javascript not found.');
274273

274+
$this->changeMesg(sprintf('<br />Found player: %s.js', $this->js[2]), 1);
275+
275276
if (@file_exists($savefile) && ($file = file_get_contents($savefile, false, NULL, 0, 822)) && ($saved = @unserialize($file)) && is_array($saved) && !empty($saved['js']) && !empty($saved['sts']) && !empty($saved['steps']) && ((!$this->sts && $saved['js'] == $this->js[2]) || $saved['sts'] == $this->sts) && preg_match('@^\s*([ws]\d+|r)( ([ws]\d+|r))*\s*$@', $saved['steps'])) {
276277
$this->changeMesg(sprintf('<br />Using cached decoder: [%d] %s.', $saved['sts'], $saved['steps']), 1);
277278
$this->encS = explode(' ', trim($saved['steps']));
@@ -348,12 +349,12 @@ private function QSelector() {
348349
$sizes = array();
349350
$opt = array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 5, CURLOPT_NOBODY => true);
350351
foreach ($this->fmtmaps as $itag => $fmt) {
351-
if (empty($this->fmts[$itag])) continue;
352+
if (empty($this->fmts[$itag]) || !empty($fmt['contentLength']) || !empty($fmt['clen'])) continue;
352353
$headers = explode("\r\n\r\n", cURL($fmt['url'], $this->cookie, 0, 0, 0, $opt));
353354
$headers = ((count($headers) > 2) ? $headers[count($headers) - 2] : $headers[0]) . "\r\n\r\n";
354355
if (substr($headers, 9, 3) == '200' && ($CL = cut_str($headers, "\nContent-Length: ", "\n")) && $CL > 1024) $sizes[$itag] = bytesToKbOrMbOrGb(trim($CL));
355356
if (substr($headers, 9, 3) == '403') {
356-
$this->changeMesg('<br />Cannot Ask Video Filesize (Signature Error?)');
357+
$this->changeMesg('<br />Cannot Ask Video Filesize of (' . $itag . ') (Signature Error?)');
357358
break;
358359
}
359360
}
@@ -369,7 +370,7 @@ private function QSelector() {
369370
if (!empty($this->fmts[$itag])) {
370371
// Classic Formats
371372
$size = (!empty($fmt['contentLength']) ? ' ('.bytesToKbOrMbOrGb($fmt['contentLength']).')' : (!empty($fmt['clen']) ? ' ('.bytesToKbOrMbOrGb($fmt['clen']).')' : (!empty($sizes[$itag]) ? ' ('.$sizes[$itag].')' : '')));
372-
if (($I = explode('|', $this->fmts[$itag]))) printf("<option value='%d'>[%1\$d] Video: %s %dp | Audio: %s ~%d Kbps%s</option>\n", $itag, $C['V'][$I[0]], $I[1], $C['A'][$I[2]], $I[3], $size);
373+
if (($I = explode('|', $this->fmts[$itag]))) printf('<option value="%d"' . ($itag == '22' ? ' selected="selected"' : '') . ">[%1\$d] Video: %s %dp | Audio: %s ~%d Kbps%s</option>\n", $itag, $C['V'][$I[0]], $I[1], $C['A'][$I[2]], $I[3], $size);
373374
} else if (!empty($fmt['_codecs'])) {
374375
// DASH Streams
375376
$size = (!empty($fmt['contentLength']) ? ' ('.bytesToKbOrMbOrGb($fmt['contentLength']).')' : (!empty($fmt['clen']) ? ' ('.bytesToKbOrMbOrGb($fmt['clen']).')' : ''));
@@ -431,4 +432,5 @@ private function QSelector() {
431432
// [02-2-2020] Fixed signature search. - Th3-822
432433
// [15-3-2020] Fixed embed JS regex. - Th3-822
433434
// [31-5-2020] Fixed signature search & Rewrote quality selector to parse and show all available formats. - Th3-822
434-
// [17-8-2020] Fixed signature timestamp search. - Th3-822
435+
// [17-8-2020] Fixed signature timestamp search. - Th3-822
436+
// [30-5-2021] Fixed get_video_info & Now MP4 @ 720p is default (if available) on the selector. - Th3-822

0 commit comments

Comments
 (0)