jlelse
/
TikTokJsonFeed
Archived
1
Fork 0

Fix and add video redirects
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Jan-Lukas Else 2020-06-22 16:25:18 +02:00
parent 5c4bf7a0ea
commit c3fb40ea02
1 changed files with 21 additions and 3 deletions

View File

@ -3,7 +3,9 @@ const scraper = require('tiktok-scraper')
const he = require('he')
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) => {
let user = req.params.user
@ -15,7 +17,7 @@ app.get('/user/:user', async (req, res) => {
"home_page_url": `https://tiktok.com/@${user}`,
"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) {
feed.items.push({
"id": post.id,
@ -25,7 +27,7 @@ app.get('/user/:user', async (req, res) => {
"date_published": new Date(parseInt(post.createTime, 10) * 1000),
"attachments": [
{
"url": post.videoUrlNoWaterMark,
"url": `${host}/video/${user}/${post.id}`,
"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}`))