Fix and add video redirects
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5c4bf7a0ea
commit
c3fb40ea02
24
index.js
24
index.js
|
@ -3,7 +3,9 @@ const scraper = require('tiktok-scraper')
|
||||||
const he = require('he')
|
const he = require('he')
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
const port = 8080
|
|
||||||
|
const port = process.env.PORT || 8080
|
||||||
|
const host = process.env.HOST || `http://localhost:${port}`
|
||||||
|
|
||||||
app.get('/user/:user', async (req, res) => {
|
app.get('/user/:user', async (req, res) => {
|
||||||
let user = req.params.user
|
let user = req.params.user
|
||||||
|
@ -15,7 +17,7 @@ app.get('/user/:user', async (req, res) => {
|
||||||
"home_page_url": `https://tiktok.com/@${user}`,
|
"home_page_url": `https://tiktok.com/@${user}`,
|
||||||
"items": []
|
"items": []
|
||||||
}
|
}
|
||||||
let posts = await scraper.user(user, { number: 5, randomUa: true, noWaterMark: true })
|
let posts = await scraper.user(user, { number: 5, randomUa: true, noWaterMark: false })
|
||||||
for (const post of posts.collector) {
|
for (const post of posts.collector) {
|
||||||
feed.items.push({
|
feed.items.push({
|
||||||
"id": post.id,
|
"id": post.id,
|
||||||
|
@ -25,7 +27,7 @@ app.get('/user/:user', async (req, res) => {
|
||||||
"date_published": new Date(parseInt(post.createTime, 10) * 1000),
|
"date_published": new Date(parseInt(post.createTime, 10) * 1000),
|
||||||
"attachments": [
|
"attachments": [
|
||||||
{
|
{
|
||||||
"url": post.videoUrlNoWaterMark,
|
"url": `${host}/video/${user}/${post.id}`,
|
||||||
"mime_type": "video/mp4"
|
"mime_type": "video/mp4"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -41,4 +43,20 @@ app.get('/user/:user', async (req, res) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.get('/video/:user/:video', async (req, res) => {
|
||||||
|
let user = req.params.user
|
||||||
|
let video = req.params.video
|
||||||
|
if (user && user.length != 0 && video && video.length != 0) {
|
||||||
|
try {
|
||||||
|
let videoMeta = await scraper.getVideoMeta(`https://www.tiktok.com/@${user}/video/${video}`, { noWaterMark: false })
|
||||||
|
res.redirect(302, videoMeta.videoUrl)
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
res.status(500).send(JSON.stringify(error))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.status(403)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
app.listen(port, () => console.log(`Listening at http://localhost:${port}`))
|
app.listen(port, () => console.log(`Listening at http://localhost:${port}`))
|
Reference in New Issue
Block a user