UNPKG

tiktok-private-api

Version:

Unofficial TikTok API wrapper for scraping user info and posts.

49 lines 1.93 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SignerService = void 0; const node_fs_1 = __importDefault(require("node:fs")); const node_crypto_1 = require("node:crypto"); const jsdom_1 = require("jsdom"); class SignerService { constructor(client) { this.client = client; this._password = "webapp1.0+202106"; const signature_js = node_fs_1.default.readFileSync(__dirname + "/../sdk/signature.js", "utf-8"); const webmssdk = node_fs_1.default.readFileSync(__dirname + "/../sdk/webmssdk.js", "utf-8"); const resourceLoader = new jsdom_1.ResourceLoader({ userAgent: this.client.state.webUserAgent, }); const { window } = new jsdom_1.JSDOM(``, { url: "https://www.tiktok.com/", referrer: "https://www.tiktok.com/", contentType: "text/html", includeNodeLocations: false, runScripts: "outside-only", pretendToBeVisual: true, resources: resourceLoader, }); this._window = window; this._window.eval(signature_js.toString()); this._window.byted_acrawler.init({ aid: 24, dfp: true, }); this._window.eval(webmssdk); } sign(url) { return this._window.byted_acrawler.sign({ url }); } bogus(params) { return this._window._0x32d649(params); } xttparams(params) { // Encrypt query string using aes-128-cbc const cipher = (0, node_crypto_1.createCipheriv)("aes-128-cbc", this._password, this._password); return Buffer.concat([cipher.update(params), cipher.final()]).toString("base64"); } } exports.SignerService = SignerService; //# sourceMappingURL=signer.service.js.map