This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
66 lines (59 loc) · 1.73 KB
/
index.js
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
const urlRegex = require("url-regex");
const fetch = require("node-fetch");
const express = require('express')
const app = express()
const port = process.env.PORT || 3210;
const fs = require('fs')
const util = require('util');
let counter;
counter = require('./counter.json').count
app.get('/https://vm.tiktok.com/:id', (req, res) => {
let url = 'https://vm.tiktok.com/' + req.params.id;
if (url <= 2) {
console.log('Missing or Invalid URL');
res.json({
'found': 'no',
'reason': 'Missing or Invalid URL'
})
}else{
if (url.endsWith('/')) url = url.substring(0, url.length - 1);
const urlParts = url.split("/");
let id = urlParts[urlParts.length - 1];
if(id.includes("?")) id = id.split("?")[0];
var outputFolder = './';
if (process.argv.length >= 4) outputFolder = process.argv[3];
if (!outputFolder.endsWith('/')) outputFolder += '/';
fetch(url)
.then(res => {
return res.text();
})
.then(body => {
const urls = body.match(urlRegex());
const mediaUrl = urls.find(url => url.includes("muscdn.com") && url.includes("https://v"));
if (mediaUrl) {
console.log(`Found Media URL: ${mediaUrl}`);
res.status(200).send({
status: 200,
message: 'OK',
found: 'yes',
url: mediaUrl
})
} else {
console.log('Missing or Invalid URL');
res.status(400).send({
status: 400,
message: 'BAD REQUEST',
found: 'no',
reason: 'Missing or Invalid URL',
})
}
});
}
fs.writeFile('./counter.json', JSON.stringify({"count": counter + 1}), 'utf8', function (err) {
if (err) return console.log(err);
counter++
})
})
app.listen(port, () => {
console.log(`listening on port ${port}`);
});