Browse Source

Initial commit

master
Jan-Lukas Else 11 months ago
commit
c593ef5871
5 changed files with 95 additions and 0 deletions
  1. +20
    -0
      .drone.yml
  2. +2
    -0
      .gitignore
  3. +11
    -0
      Dockerfile
  4. +43
    -0
      index.js
  5. +19
    -0
      package.json

+ 20
- 0
.drone.yml View File

@ -0,0 +1,20 @@
kind: pipeline
name: default
steps:
- name: publish
image: plugins/docker
settings:
username:
from_secret: docker_username
password:
from_secret: docker_password
repo: quay.io/jlelse/tiktokjson
registry: quay.io
tags: latest
when:
branch:
- master
event:
exclude:
- pull_request

+ 2
- 0
.gitignore View File

@ -0,0 +1,2 @@
package-lock.json
node_modules

+ 11
- 0
Dockerfile View File

@ -0,0 +1,11 @@
FROM node:14-alpine
WORKDIR /app
COPY package.json ./
RUN npm install
COPY index.js .
EXPOSE 8080
CMD [ "node", "index.js" ]

+ 43
- 0
index.js View File

@ -0,0 +1,43 @@
const express = require('express')
const scraper = require('tiktok-scraper');
const app = express()
const port = 8080
app.get('/user/:user', async (req, res) => {
let user = req.params.user
if (user && user.length != 0) {
try {
let feed = {
"version": "https://jsonfeed.org/version/1",
"title": `TikTok user @${user}`,
"home_page_url": `https://tiktok.com/@${user}`,
"items": []
}
let posts = await scraper.user(user, { number: 10 })
for (const post of posts.collector) {
feed.items.push({
"id": post.id,
"title": post.text,
"content_text": post.text,
"url": post.webVideoUrl,
"date_published": new Date(parseInt(post.createTime, 10) * 1000),
"attachments": [
{
"url": post.videoUrl,
"mime_type": "video/mp4"
}
]
})
}
res.send(feed)
} 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}`))

+ 19
- 0
package.json View File

@ -0,0 +1,19 @@
{
"name": "tiktokrss",
"version": "1.0.0",
"description": "TikTok to JSON Feed",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "https://git.jlel.se/jlelse/TikTokJsonFeed.git"
},
"author": "jlelse",
"license": "MIT",
"dependencies": {
"express": "^4.17.1",
"tiktok-scraper": "^1.1.10"
}
}

Loading…
Cancel
Save