-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvidmoly.php
133 lines (112 loc) · 4.47 KB
/
vidmoly.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
<?php
class Vidmoly
{
private $path; // Save As File
private $id; // Vidmoly ID
private $url; // Vidmoly URL
private $master; // Master Url
private $label; // Quality Label
private $qualityURL; // Quality URL
public function download($path='',$id='')
{
$this->id = $id;
$this->url = $this->url($id);
preg_match_all('/file:"(.*?)"/si', $this->connect($this->url), $sources);
if(!empty($sources[1][0])){
$this->master = $sources[1][0];
if(strstr($this->master,'master.m3u8')){
// Get Master M3U8
$result = $this->connect($this->master,$this->url);
$result = array_filter(explode("\n",$result));
array_splice($result, 0, 1); $i=0;
// Master M3U8 Shape
if(!empty($result)){
foreach ($result as $key => $value) {
if(strstr($value,'m3u8')){
$source[$i]['file'] = trim($value); $i++;
}else{
preg_match_all('/RESOLUTION=.*?x(.*?),/si', $value, $quality);
$source[$i]['label'] = trim($quality[1][0]);
}
}
}else return json_encode(array('status' => 'M3U8 File in Source Not Found'));
// Download M3U8
if(!empty($source)){
foreach ($source as $key => $value) {
$this->qualityURL = trim($value['file']);
$this->label = trim($value['label']);
$this->path = $this->pathCreate($path);
$this->downloadM3U8File();
if(!file_exists($this->path.$this->label.'.mp4')) return json_encode(array('status' => 'The video has an access block.'));
$status[] = array('label' => $this->label , 'path' => $this->path.$this->label.'.mp4' );
}
return json_encode($status);
}else return json_encode(array('status' => 'MP4 Url Not Found'));
// Download MP4
}else{
$this->qualityURL = $sources[1][0];
$this->label = '720';
$this->path = $this->pathCreate($path);
$status = $this->downloadMP4File();
return json_encode($status);
}
}else return json_encode(array('status' => 'Source Not Found'));
}
// M3U8 URL to Mp4 (Required FFMPEG)
private function downloadM3U8File(){
exec('ffmpeg -i '.$this->qualityURL.' -c copy -bsf:a aac_adtstoasc '.$this->path.$this->label.'.mp4');
}
// Save As MP4
private function downloadMP4File(){
$file = fopen($this->path.$this->label.'.mp4','a+');
fwrite($file,file_get_contents($this->qualityURL));
fclose($file);
return array('label' => $this->label , 'path' => $this->path.$this->label.'.mp4' );
}
// Return Vidmoly URL
private function url($value='')
{
return 'https://vidmoly.to/embed-'.$value.'.html';
}
// CURL Connection
private function connect($url='',$referer='')
{
if(empty($referer)) $referer = $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Connection: keep-alive';
$headers[] = 'Pragma: no-cache';
$headers[] = 'Cache-Control: no-cache';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36';
$headers[] = 'Accept: */*';
$headers[] = 'Origin: https://vidmoly.to';
$headers[] = 'Sec-Fetch-Site: cross-site';
$headers[] = 'Sec-Fetch-Mode: cors';
$headers[] = 'Sec-Fetch-Dest: empty';
$headers[] = 'Referer: '.$referer;
$headers[] = 'Accept-Language: tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
// Create Save As Path
private function pathCreate($tempPath){
$paths = array_filter(explode('/',$tempPath.'/'.$this->id.'/'));
$realPath = realpath('.').'/';
foreach ($paths as $key => $path) {
$realPath .= $path.'/';
if(!is_dir($realPath)) mkdir($realPath,777);
}
return $realPath;
}
}
?>