forked from wukes/youtube-php-mirroring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpaly.php
157 lines (148 loc) · 4.58 KB
/
mpaly.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
//本程序为二次开发
@session_start();
@ob_start();
error_reporting(0);
#error_reporting(E_ALL^E_NOTICE^E_WARNING);
@ini_set('date.timezone','Asia/Shanghai');
@ini_set('max_execution_time', '0');
@ini_set('allow_url_fopen', '1');
@ini_set ('memory_limit', '256M');
@set_time_limit(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( 'Cache-Control: post-check=0, pre-check=0', false );
@header("Pragma: no-cache");
$v=$_GET[id];
$parserurl='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
$parserurl=dirname($parserurl);
$geturl= $parserurl.'/parser/index.php?videoid='.$v;
$w=file_get_contents($geturl);
$cv=json_decode($w);
//print_r($cv);
//echo $cv[Download][1][url];
function object_array($array)
{
if(is_object($array))
{
$array = (array)$array;
}
if(is_array($array))
{
foreach($array as $key=>$value)
{
$array[$key] = object_array($value);
}
}
return $array;
}
$rr=object_array($cv);
$aaaks=array_reverse(($rr[Download]));
$furl=$aaaks[3][url];//flv视频地址
$murl=$aaaks[3][url];//mp4视频地址
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){
/*
file_put_contents('TMPB.LOG',"CAUGHT HEADER\r\n******************\r\n{$header}\r\n***************\r\n",FILE_APPEND);
if(preg_match('/(Content-Length|Content-Range|Content-Type|Content-Type|Accept-Ranges|X-Content-Type-Options):(.*)/si',$header,$arr)){
@header($arr[1].": ".trim($arr[2]));
}
*/
if (!strpos($header,"Cache") && !strpos($header,"ocation") )
@header(substr($header,0,strpos($header,"\r")));
return strlen($header);
}
$loadedsize=0;
if (isset($_GET['id'])) {
$vid = $_GET['id'];
include('nglib.php');
loadvideo($vid, isset($_GET['type'])? $_GET['type'] :"" );
$file_path = $_SESSION['vurl_'.$vid][0];
if (isset($_GET['type'])) $file_path = getitembytype($vid, $_GET['type']) ;
if (isset($_GET['q'])) $file_path = getitembyitag($vid, $_GET['q']) ;
$file_path = $murl;
/*file_put_contents('TMPB.LOG',date("\r\nY-m-D H:i:s ").$vid."\r\n",FILE_APPEND);
file_put_contents('TMPB.LOG',$file_path."\r\n",FILE_APPEND);
file_put_contents('TMPB.LOG',$_SERVER['HTTP_RANGE']."<<RANGE\r\n",FILE_APPEND);*/
if (isset($_GET['begin'])) $file_path = $file_path.'&begin='.$_GET['begin'];
//DEBUG:
if (isset($_GET['range'])) $_SERVER['HTTP_RANGE']=$_GET['range'];
if (strlen($file_path)>10) {
@header("Content-Disposition: filename=".$_GET["id"].".ngsy");
$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'];
if (function_exists("curl_init")) {
$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();
$okay = curl_exec($ch);
if (!$okay) {
//file_put_contents('TMPB.LOG',curl_error($ch)."ERROR<<RANGE\r\n",FILE_APPEND);
}
//file_put_contents('TMPB.LOG',$loadedsize."KB WRITTEN<<RANGE\r\n",FILE_APPEND);
@curl_close($ch);
} else {
//set_error_handler("customError");
header("Content-Length: -1");
$freadtimes=0;
$file = fopen($file_path,"rb");
@stream_set_blocking($file, 0);
@ob_clean();
if ($file) {
while((!feof($file)) & (0==connection_status())) {
$tttt=fread($file,"10240");
echo $tttt;
$loadedsize+=(strlen($tttt)/1024);
@ob_flush();
@flush();
@usleep(60);
$freadtimes++;
if ($freadtimes > 30000){
break;
}
}
fclose($file);
}
}
} else {
echo "<b>SERVER[YOUTUBE-INDEX]</b>:URL LENGTH ERR";
echo "<br>URL=<br>";
echo $file_path;
echo "<hr><pre>";
$v= getVInfo($vid);
$vlist = url_encoded_fmt_stream_map($v);
echo $v;
var_dump($vlist);
}
}
?>