Skip to content

Commit

Permalink
Moved to JS, using JSDOM and added Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
pablouser1 committed Apr 17, 2022
1 parent 912e098 commit 6980abb
Show file tree
Hide file tree
Showing 20 changed files with 1,274 additions and 198 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ trim_trailing_whitespace = true
charset = utf-8

# 4 space indentation
[*.py]
[*.js]
indent_style = space
indent_size = 4
indent_size = 2
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/.venv
/.vscode
__pycache__
/node_modules
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:17

WORKDIR /usr/src/app

COPY package.json ./
RUN yarn install
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
# SignTok
Sign your TikTok urls easily.
This is a port of [tiktok-signature](https://github.com/carcabot/tiktok-signature) to Python using Selenium and Selenium Stealth

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
This is a port of [tiktok-signature](https://github.com/carcabot/tiktok-signature) using JSDOM

## Installation
```
pip install -r requirements.txt
yarn install
```
You also need to have Chrome installed

## Usage
For webserver:
```
python web.py
node server.py
```
Then you can send a POST request to localhost:8080 with a raw/plain body containing the url

For cli usage:
```
python cli.py
node index.js 'YOUR_URL_HERE'
```

## TODO
* Docker
89 changes: 0 additions & 89 deletions TikTokSigner/Signer.py

This file was deleted.

9 changes: 0 additions & 9 deletions TikTokSigner/Utils.py

This file was deleted.

Empty file removed TikTokSigner/__init__.py
Empty file.
10 changes: 2 additions & 8 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
"keywords": [
"tiktok",
"api",
"python"
"node"
],
"website": "https://github.com/pablouser1/SignTok",
"repository": "https://github.com/pablouser1/SignTok",
"buildpacks": [
{
"url": "https://github.com/heroku/heroku-buildpack-google-chrome"
},
{
"url": "https://github.com/heroku/heroku-buildpack-chromedriver"
},
{
"url": "heroku/python"
"url": "heroku/nodejs"
}
]
}
20 changes: 0 additions & 20 deletions cli.py

This file was deleted.

9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Signer = require("./src/Signer")

if (process.argv.length > 2) {
const signer = new Signer()
const url = process.argv[2]

const data = signer.sign(url)
console.log(data)
}
2 changes: 1 addition & 1 deletion js/signature.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions js/xttparams.js

This file was deleted.

18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "signtok",
"version": "1.0.0",
"description": "Sign your TikTok requests easily",
"repository": "https://github.com/pablouser1/SignTok",
"author": "Pablo Ferreiro",
"license": "MIT",
"private": true,
"scripts": {
"start": "node server.js"
},
"dependencies": {
"canvas": "^2.9.1",
"crypto-js": "^4.1.1",
"express": "^4.17.3",
"jsdom": "^19.0.0"
}
}
19 changes: 0 additions & 19 deletions requirements.txt

This file was deleted.

30 changes: 30 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const Signer = require("./src/Signer")
const bodyParser = require("body-parser")
const express = require("express")

const port = process.env.PORT || 8080
const app = express()
app.use(bodyParser.text())

const signer = new Signer()

app.get('/', (req, res) => {
res.redirect('https://github.com/pablouser1/SignTok')
})

app.post("/signature", (req, res) => {
const url = req.body
const data = signer.sign(url)
console.log("Sent data from request with url: " + url)
res.send({
status: "ok",
data: {
...data,
navigator: signer.navigator()
}
})
})

app.listen(port, () => {
console.log(`App listening on port ${port}`)
})
78 changes: 78 additions & 0 deletions src/Signer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const fs = require("fs")
const Utils = require("./Utils")
const { JSDOM, ResourceLoader } = require("jsdom")
const CryptoJS = require("crypto-js")

class Signer {
static DEFAULT_USERAGENT =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36"
static PASSWORD = CryptoJS.enc.Utf8.parse('webapp1.0+202106')
/**
* @type Window
*/
window = null

constructor(userAgent = Signer.DEFAULT_USERAGENT) {
const signature_js = fs.readFileSync(__dirname + "/../js/signature.js", "utf-8")
const resourceLoader = new ResourceLoader({
userAgent
})

const { window } = new JSDOM(``, {
url: "https://www.tiktok.com",
referrer: "https://www.tiktok.com",
contentType: "text/html",
includeNodeLocations: true,
runScripts: "outside-only",
resources: resourceLoader
})
this.window = window
this.window.eval(signature_js.toString())
this.window.byted_acrawler.init({
"aid":24,
"dfp":true
})
}

navigator() {
return {
deviceScaleFactor: this.window.devicePixelRatio,
user_agent: this.window.navigator.userAgent,
browser_language: this.window.navigator.language,
browser_platform: this.window.navigator.platform,
browser_name: this.window.navigator.appCodeName,
browser_version: this.window.navigator.appVersion
}
}

signature(url) {
return this.window.byted_acrawler.sign({ url })
}

xttparams(params) {
params += "&is_encryption=1"
const crypt = CryptoJS.AES.encrypt(params, Signer.PASSWORD, {
iv: Signer.PASSWORD,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
}).toString()
return crypt
}

sign(url) {
const verifyFp = Utils.verify_fp()
url += "&verifyFp=" + verifyFp
const signature = this.signature(url)
const signed_url = url + "&_signature=" + signature
const params = new URL(url).searchParams.toString()
const xttparams = this.xttparams(params)
return {
signature: signature,
verify_fp: verifyFp,
signed_url: signed_url,
"x-tt-params": xttparams
}
}
}

module.exports = Signer
8 changes: 8 additions & 0 deletions src/Utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Utils {
static verify_fp() {
// TODO, add proper verify fp method
return "verify_68b8ccfa65726db8b3db0cc07821d696"
}
}

module.exports = Utils
Loading

0 comments on commit 6980abb

Please sign in to comment.