forked from PRNDA/you2php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stream.php
61 lines (56 loc) · 1.81 KB
/
stream.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
@session_start();
@ob_start();
error_reporting(0);
@header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' );
@header( 'Date: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
@header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
@header( 'Cache-Control: private, max-age=1' );
@header("Pragma: no-cache");
@header("Content-Disposition: filename=".$_GET["id"].".mp4");
include('./YouTubeDownloader.php');
$yt = new YouTubeDownloader();
$u="https://www.youtube.com/watch?v=".$_GET['vv'];
$links = $yt->getDownloadLinks($u);
$file_path=$links['22']['url'];
function read_body(&$ch,&$string){
global $loadedsize;
$rtn=strlen($string);
$loadedsize+=($rtn/1024);
print($string);
@ob_flush();
@flush();
if (0!=connection_status()) {
curl_close($ch);
exit();
}
@$string = NULL;
//@unset($string);
return $rtn;
}
function read_head(&$ch,&$header){
if (!strpos($header,"Cache") && !strpos($header,"ocation") )
@header(substr($header,0,strpos($header,"\r")));
return strlen($header);
}
$header1 = array('Expect: ','Accept: */*');
//$_SERVER['HTTP_RANGE'] = 'bytes=3902905-';
if (isset($_SERVER['HTTP_RANGE'])) {
$header1[] = 'Range: '.$_SERVER['HTTP_RANGE'];
$header1[] = 'Referer: '.$file_path;
}
$header1[] = 'User-Agent: '.$_SERVER['HTTP_USER_AGENT'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file_path);
curl_setopt($ch, CURLOPT_TIMEOUT, 600);
@curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION , true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "read_head"); //
curl_setopt($ch, CURLOPT_WRITEFUNCTION, "read_body"); //
//set_error_handler("customError");
@ob_clean();
curl_exec($ch);
?>