-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
266 lines (258 loc) · 9.3 KB
/
index.php
File metadata and controls
266 lines (258 loc) · 9.3 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
$store_locally = true; /* change to false if you don't want to host videos locally */
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function downloadVideo($video_url, $geturl = false)
{
$ch = curl_init();
$headers = array(
'Range: bytes=0-',
);
$options = array(
CURLOPT_URL => $video_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_FOLLOWLOCATION => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_USERAGENT => 'okhttp',
CURLOPT_ENCODING => "utf-8",
CURLOPT_AUTOREFERER => true,
CURLOPT_COOKIEJAR => 'cookie.txt',
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_REFERER => 'https://www.tiktok.com/',
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_TIMEOUT => 30,
CURLOPT_MAXREDIRS => 10,
);
curl_setopt_array( $ch, $options );
if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($geturl === true)
{
return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
}
curl_close($ch);
$filename = "user_videos/" . generateRandomString() . ".mp4";
$d = fopen($filename, "w");
fwrite($d, $data);
fclose($d);
return $filename;
}
if (isset($_GET['url']) && !empty($_GET['url'])) {
if ($_SERVER['HTTP_REFERER'] != "") {
$url = $_GET['url'];
$name = downloadVideo($url);
echo $name;
exit();
}
else
{
echo "";
exit();
}
}
function getContent($url, $geturl = false)
{
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Mobile Safari/537.36',
CURLOPT_ENCODING => "utf-8",
CURLOPT_AUTOREFERER => false,
CURLOPT_COOKIEJAR => 'cookie.txt',
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_REFERER => 'https://www.tiktok.com/',
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_TIMEOUT => 30,
CURLOPT_MAXREDIRS => 10,
);
curl_setopt_array( $ch, $options );
if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($geturl === true)
{
return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
}
curl_close($ch);
return strval($data);
}
function getKey($playable)
{
$ch = curl_init();
$headers = [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding: gzip, deflate, br',
'Accept-Language: en-US,en;q=0.9',
'Range: bytes=0-200000'
];
$options = array(
CURLOPT_URL => $playable,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0',
CURLOPT_ENCODING => "utf-8",
CURLOPT_AUTOREFERER => false,
CURLOPT_COOKIEJAR => 'cookie.txt',
CURLOPT_COOKIEFILE => 'cookie.txt',
CURLOPT_REFERER => 'https://www.tiktok.com/',
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_TIMEOUT => 30,
CURLOPT_MAXREDIRS => 10,
);
curl_setopt_array( $ch, $options );
if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$tmp = explode("vid:", $data);
if(count($tmp) > 1){
$key = trim(explode("%", $tmp[1])[0]);
}
else
{
$key = "";
}
return $key;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>TikTok Download</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css2?family=Gotu&display=swap" rel="stylesheet">
<style type="text/css">
html, body
{
font-family: "Gotu"
}
input
{
padding: 5px;
border-radius: 10px;
border-style: solid;
border-color: blue;
transition-duration: 0.5s;
width: 80%;
}
input:focus
{
border-color: skyblue;
transition-duration: 0.5s;
}
</style>
</head>
<body class="bg-light">
<div class="text-center">
<form method="POST" class="mt-2">
<input type="text" placeholder="https://www.tiktok.com/@username/video/1234567890123456789" class="mb-3" name="tiktok-url"><br><br>
<button class="btn btn-success" type="submit" >Download Video</button>
</form>
</div>
<div class="text-center">
<button id="wmarked_link" disabled="disabled" class="btn btn-primary" align="center" onclick="window.location.href='<?php if ($store_locally){ echo $filename;} else { echo $contentURL; } ?>'">:)</button>
</div>
<?php
if (isset($_POST['tiktok-url']) && !empty($_POST['tiktok-url'])) {
$url = trim($_POST['tiktok-url']);
$resp = getContent($url);
//echo "$resp";
$check = explode('"downloadAddr":"', $resp);
if (count($check) > 1){
$contentURL = explode("\"",$check[1])[0];
$contentURL = str_replace("\\u0026", "&", $contentURL);
$thumb = explode("\"",explode('og:image" content="', $resp)[1])[0];
$username = explode('/',explode('"$pageUrl":"/@', $resp)[1])[0];
$create_time = explode(',', explode('"createTime":', $resp)[1])[0];
$dt = new DateTime("@$create_time");
$create_time = $dt->format("d M Y H:i:s A");
$videoKey = getKey($contentURL);
$cleanVideo = "https://api2-16-h2.musical.ly/aweme/v1/play/?video_id=$videoKey&vr_type=0&is_play_url=1&source=PackSourceEnum_PUBLISH&media_type=4";
$cleanVideo = getContent($cleanVideo, true);
if (!file_exists("user_videos") && $store_locally){
mkdir("user_videos");
}
if ($store_locally){
?>
<script type="text/javascript">
$(document).ready(function(){
$('#wmarked_link').text("Please wait ...");
$.get('./<?php echo basename($_SERVER['PHP_SELF']); ?>?url=<?php echo urlencode($contentURL); ?>').done(function(data)
{
$('#wmarked_link').removeAttr('disabled');
$('#wmarked_link').attr('onclick', 'window.location.href="' + data + '"');
$('#wmarked_link').text("Video Downloaded Click to View mp4");
});
});
</script>
<?php
}
?>
<script>
$(document).ready(function(){
$('html, body').animate({
scrollTop: ($('#result').offset().top)
},1000);
});
</script>
</div>
<?php
}
else
{
?>
<script>
$(document).ready(function(){
$('html, body').animate({
scrollTop: ($('#result').offset().top)
},1000);
});
</script>
<?php
}
}
?>
<script type="text/javascript">
window.setInterval(function(){
if ($("input[name='tiktok-url']").attr("placeholder") == "https://www.tiktok.com/@username/video/1234567890123456789") {
$("input[name='tiktok-url']").attr("placeholder", "https://vm.tiktok.com/a1b2c3/");
}
else
{
$("input[name='tiktok-url']").attr("placeholder", "https://www.tiktok.com/@username/video/1234567890123456789");
}
}, 3000);
</script>
</body>
</html>