forked from ctrlcctrlv/infinity
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathembed.php
executable file
·107 lines (70 loc) · 2.18 KB
/
embed.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
<?php
header("Content-type: image/jpeg");
if (!isset($_GET['service'], $_GET['id'])) {
exit;
}
if(!preg_match('/^[-_A-Za-z0-9]+$/', $_GET['id']) || strlen($_GET['id']) > 16) {
echo file_get_contents("tmp/nw.jpg");
exit;
}
$path ='tmp/embed/' . $_GET['service'] . '_' . $_GET['id'];
if (file_exists($path)) {
die(file_get_contents($path));
}
$link = null;
switch ($_GET['service']) {
case 'youtube':
$link = "https://img.youtube.com/vi/" . $_GET['id'] . "/0.jpg";
break;
case 'youtube320':
$link = "https://i.ytimg.com/vi/" . $_GET['id'] . "/mqdefault.jpg";
break;
case 'vimeo':
$json = CurlRequest('http://vimeo.com/api/v2/video/' . $_GET['id'] . '.json');
$data = json_decode($json, TRUE);
if(isset($data[0]['thumbnail_large']))
$link = str_replace('.webp', '.jpg', $data[0]['thumbnail_large']);
break;
case 'vlive':
$url = 'https://www.vlive.tv/embed/' . $_GET['id'];
$html = CurlRequest($url);
if(preg_match('/videoThumb = \"([^\"]+)\";/', $html, $thumbLink))
$link = $thumbLink[1];
break;
default:
exit;
break;
}
$image = file_get_contents($link);
if (strlen($image) < 100) {
die('404 not found');
}
file_put_contents($path, $image);
echo $image;
function CurlRequest($request, $timeout_ms=2000)
{
//Проверка на правильность URL
if (!filter_var($request, FILTER_VALIDATE_URL)) {
return null;
}
if (function_exists('curl_version')) {
//Инициализация curl
$ch = curl_init($request);
curl_setopt_array($ch, array(
CURLOPT_CONNECTTIMEOUT_MS => $timeout_ms,
CURLOPT_TIMEOUT_MS => $timeout_ms,
CURLOPT_HEADER => false,
CURLOPT_NOBODY => false,
CURLOPT_RETURNTRANSFER => true
));
$response = curl_exec($ch);
curl_close($ch);
if ($response) {
return $response;
}
} else {
//ini_set('default_socket_timeout', $timeout_ms);
return file_get_contents($request);
}
return null;
}