/
dl.php
111 lines (85 loc) · 3.06 KB
/
dl.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
<?php
class VidClearDownloader
{
private $headers_sent = false;
private $debug = false;
protected function sendHeader($header)
{
if ($this->debug) {
var_dump($header);
} else {
header($header);
}
}
public function decode($pData)
{
$encryption_key = 'themeluxurydotcom';
$decryption_iv = '9999999999999999';
$ciphering = "AES-256-CTR";
$pData = str_replace(' ','+', $pData);
$decryption = openssl_decrypt($pData, $ciphering, $encryption_key, 0, $decryption_iv);
return $decryption;
}
public function headerCallback($ch, $data)
{
if (preg_match('/HTTP\/[\d.]+\s*(\d+)/', $data, $matches)) {
$status_code = $matches[1];
if ($status_code == 200 || $status_code == 206 || $status_code == 403 || $status_code == 404) {
$this->headers_sent = true;
$this->sendHeader(rtrim($data));
}
} else {
$forward = array('content-type', 'content-length', 'accept-ranges', 'content-range');
$parts = explode(':', $data, 2);
if ($this->headers_sent && count($parts) == 2 && in_array(strtolower(trim($parts[0])), $forward)) {
$this->sendHeader(rtrim($data));
}
}
return strlen($data);
}
public function bodyCallback($ch, $data)
{
if (true) {
echo $data;
flush();
}
return strlen($data);
}
public function stream($url)
{
$ch = curl_init();
$headers = array();
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0';
if (isset($_SERVER['HTTP_RANGE'])) {
$headers[] = 'Range: ' . $_SERVER['HTTP_RANGE'];
}
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, [$this, 'headerCallback']);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, [$this, 'bodyCallback']);
$ret = curl_exec($ch);
$error = ($ret === false) ? sprintf('curl error: %s, num: %s', curl_error($ch), curl_errno($ch)) : null;
curl_close($ch);
if ($error) {
echo $error;
exit;
}
}
}
if ( !empty($_GET['token']) ) {
$video = new VidClearDownloader();
$token = $video->decode($_GET['token']);
$deJson = json_decode($token);
header('Content-Disposition: attachment; filename="'.rawurlencode($deJson->filename).'-'.time().'.'.$deJson->type.'"');
\set_time_limit(1800);
$video->stream($deJson->url);
} else {
echo 'Silence is Golden!';
}