Skip to content

Commit

Permalink
Fixed youtube download and also added 720p dash formats and a small t…
Browse files Browse the repository at this point in the history
…weak to the quality selector, closes Th3-822#152
  • Loading branch information
Th3-822 committed Nov 10, 2018
1 parent 415198f commit d6cc544
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions hosts/download/youtube_com.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class youtube_com extends DownloadClass {
private $page, $cookie, $fmtmaps, $vid, $sts = -1, $js, $playerJs, $sigJs, $jsVars, $cookieFile,
$fmts = array(22 => '0|720|0|192', 45 => '1|720|1|192', 44 => '1|480|1|192', 35 => '2|480|0|128', 43 => '1|360|1|128', 34 => '2|360|0|128', 18 => '0|360|0|96', 6 => '2|270|3|64', 5 => '2|240|3|64', 36 => '3|240|0|36', 17 => '3|144|0|24'),
$dashfmts = array(138 => 'V0', 272 => 'V1', 315 => 'V1', 266 => 'V0', 313 => 'V1', 308 => 'V1', 264 => 'V0', 271 => 'V1', 299 => 'V0', 303 => 'V1', 137 => 'V0', 248 => 'V1', 298 => 'V0', 302 => 'V1', 135 => 'V0', 244 => 'V1', 140 => 'A0', 171 => 'A1', 251 => 'A2', 250 => 'A2', 249 => 'A2');
$dashfmts = array(138 => 'V0', 272 => 'V1', 315 => 'V1', 266 => 'V0', 313 => 'V1', 308 => 'V1', 264 => 'V0', 271 => 'V1', 299 => 'V0', 303 => 'V1', 137 => 'V0', 248 => 'V1', 136 => 'V0', 298 => 'V0', 247 => 'V1', 302 => 'V1', 135 => 'V0', 244 => 'V1', 140 => 'A0', 171 => 'A1', 251 => 'A2', 250 => 'A2', 249 => 'A2');

public function Download($link) {
$this->cookieFile = DOWNLOAD_DIR.'YT_cookie.txt';
Expand Down Expand Up @@ -236,7 +236,7 @@ private function getCipher() {
//if (($spos = strpos($this->playerJs, '.sig||')) === false) $this->decError('Not found (".sig||")');
//if (($cut1 = cut_str(substr($this->playerJs, $spos), '{', '}')) == false) $this->decError('Cannot get inner content of "if(X.sig||X.s)"');
$v = '[\$_A-Za-z][\$\w]*';
if (!preg_match("@(?:\.sig\|\||\.set\(\"signature\",|\|\"signature\",|$v\.sp,)($v)(?=\($v\.s\))@", $this->playerJs, $fn)) $this->decError('Cannot get decoder function name');
if (!preg_match("@(?:\.sig\|\||\.set\(\"signature\",|\|\"signature\",|$v\.sp,)(?:\(0,$v(?:\.$v)*\)\()?($v)\((?:\(0,$v(?:\.$v)*\)\()?$v\.s\)@", $this->playerJs, $fn)) $this->decError('Cannot get decoder function name');
$fn = preg_quote($fn[1], '@');
if (!preg_match("@(?:function\s+$fn\s*\(|var\s+$fn\s*=\s*function\s*\(|(?<=(?:{|,|;))\s*$fn\s*=\s*function\s*\()@", $this->playerJs, $fpos, PREG_OFFSET_CAPTURE)) $this->decError('Cannot find decoder function');
$fpos = $fpos[0][1];
Expand Down Expand Up @@ -290,7 +290,7 @@ private function QSelector() {
$sizes = array();
$opt = array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 5, CURLOPT_NOBODY => true);
foreach ($this->fmtmaps as $itag => $fmt) {
if (empty($this->fmts[$itag]) && empty($this->dashfmts[$itag])) continue;
if (empty($this->fmts[$itag])) continue;
$headers = explode("\r\n\r\n", cURL($fmt['url'], $this->cookie, 0, 0, 0, $opt));
$headers = ((count($headers) > 2) ? $headers[count($headers) - 2] : $headers[0]) . "\r\n\r\n";
if (substr($headers, 9, 3) == '200' && ($CL = cut_str($headers, "\nContent-Length: ", "\n")) && $CL > 1024) $sizes[$itag] = bytesToKbOrMbOrGb(trim($CL));
Expand All @@ -304,11 +304,12 @@ private function QSelector() {
echo '<label><input type="checkbox" name="cleanname" checked="checked" value="1" /><small>&nbsp;Remove non-supported characters from filename</small></label><br />';
echo "<select name='yt_fmt' id='QS_fmt'>\n";
foreach ($this->fmtmaps as $itag => $fmt) {
$size = (!empty($sizes[$itag]) ? ' ('.$sizes[$itag].')' : '');
if (!empty($this->fmts[$itag])) {
$size = (!empty($sizes[$itag]) ? ' ('.$sizes[$itag].')' : '');
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);
} else if (!empty($this->dashfmts[$itag])) {
if (($I = str_split($this->dashfmts[$itag]))) {
$size = (!empty($fmt['clen']) ? ' ('.bytesToKbOrMbOrGb($fmt['clen']).')' : '');
if ($I[0] == 'V' || $I[0] == 'v') printf("<option value='%d'>[%1\$d] Video only: %s @ %s%s</option>\n", $itag, $C['V'][$I[1]], $fmt['quality_label'], $size);
else printf("<option value='%d'>[%1\$d] Audio only: %s @ ~%s%s</option>\n", $itag, $C['A'][$I[1]], $this->bitrate2KMG($fmt['bitrate']), $size);
}
Expand Down Expand Up @@ -353,4 +354,4 @@ private function QSelector() {
// [30-8-2016] Fixed slow speed while downloading DASH streams. - Th3-822
// [30-4-2017] Fixed signature decoding functions. - Th3-822
// [25-1-2018] Fixed get_video_info. - Th3-822
// [25-9-2018] Fixed signature decoding functions. - Th3-822
// [09-11-2018] Fixed signature decoding functions. - Th3-822

0 comments on commit d6cc544

Please sign in to comment.