From f8f10b14e3cf1975312d2259143e3c41e7a7abf8 Mon Sep 17 00:00:00 2001 From: hansputera Date: Sun, 6 Mar 2022 13:40:48 +0700 Subject: [PATCH] chore: add prettier Signed-off-by: hansputera --- package.json | 3 +- packages/config/eslint.js | 2 +- packages/config/package.json | 5 +- packages/config/prettier.js | 8 ++ packages/core/.prettierignore | 1 + packages/core/.prettierrc.js | 1 + packages/core/fetch.ts | 10 +- packages/core/index.ts | 2 +- packages/core/package.json | 6 +- packages/core/src/DLTikProvider.ts | 122 +++++++++---------- packages/core/src/dddTikProvider.ts | 54 ++++----- packages/core/src/downTikProvider.ts | 84 ++++++------- packages/core/src/downloaderOneProvider.ts | 112 ++++++++--------- packages/core/src/getVidTikProvider.ts | 96 +++++++++++++++ packages/core/src/index.ts | 38 +++--- packages/core/src/loveTikProvider.ts | 80 ++++++------- packages/core/src/musicalyDownProvider.ts | 100 ++++++++-------- packages/core/src/nativeProvider.ts | 133 ++++++++++----------- packages/core/src/saveFromProvider.ts | 92 +++++++------- packages/core/src/saveTikProvider.ts | 84 ++++++------- packages/core/src/snaptikProvider.ts | 52 ++++---- packages/core/src/tikDownProvider.ts | 74 ++++++------ packages/core/src/tikmateProvider.ts | 82 ++++++------- packages/core/src/tokupProvider.ts | 118 +++++++++--------- packages/core/src/ttDownloaderProvider.ts | 72 +++++------ packages/core/src/ttSaveProvider.ts | 94 +++++++-------- packages/core/src/utils/extractor.ts | 124 +++++++++---------- packages/core/src/utils/generator.ts | 4 +- turbo.json | 3 +- yarn.lock | 50 ++++++-- 30 files changed, 927 insertions(+), 779 deletions(-) create mode 100644 packages/config/prettier.js create mode 100644 packages/core/.prettierignore create mode 100644 packages/core/.prettierrc.js create mode 100644 packages/core/src/getVidTikProvider.ts diff --git a/package.json b/package.json index 36087c3..ecf9b9a 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "scripts": { "build": "turbo run build", "dev": "turbo run dev --parallel", - "lint": "turbo run lint", + "lint": "turbo run lint --parallel", + "format": "turbo run format --parallel", "prepare": "husky install" }, "packageManager": "yarn@3.2.0" diff --git a/packages/config/eslint.js b/packages/config/eslint.js index e3e8c44..b9e6758 100644 --- a/packages/config/eslint.js +++ b/packages/config/eslint.js @@ -1,5 +1,5 @@ module.exports = { - extends: ['google'], + extends: ['google', 'prettier'], settings: { next: { rootDir: [ diff --git a/packages/config/package.json b/packages/config/package.json index ed7a558..8b1c4a6 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -13,6 +13,9 @@ }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.13.0", - "@typescript-eslint/parser": "^5.13.0" + "@typescript-eslint/parser": "^5.13.0", + "eslint": "^8.10.0", + "eslint-config-prettier": "^8.5.0", + "prettier": "^2.5.1" } } diff --git a/packages/config/prettier.js b/packages/config/prettier.js new file mode 100644 index 0000000..0f1c179 --- /dev/null +++ b/packages/config/prettier.js @@ -0,0 +1,8 @@ +module.exports = { + semi: true, + singleQuote: true, + tabWidth: 4, + trailingComma: 'all', + bracketSpacing: false, +// useTabs: true, +}; diff --git a/packages/core/.prettierignore b/packages/core/.prettierignore new file mode 100644 index 0000000..a6c57f5 --- /dev/null +++ b/packages/core/.prettierignore @@ -0,0 +1 @@ +*.json diff --git a/packages/core/.prettierrc.js b/packages/core/.prettierrc.js new file mode 100644 index 0000000..0ae5e0e --- /dev/null +++ b/packages/core/.prettierrc.js @@ -0,0 +1 @@ +module.exports = require('tiktok-dl-config/prettier'); diff --git a/packages/core/fetch.ts b/packages/core/fetch.ts index 3a842a9..587a2e1 100644 --- a/packages/core/fetch.ts +++ b/packages/core/fetch.ts @@ -1,8 +1,8 @@ import got, {ExtendOptions} from 'got'; export const getFetch = (baseUrl: string, options?: ExtendOptions) => - got.extend({ - prefixUrl: baseUrl, - dnsCache: true, - ...options, - }); + got.extend({ + prefixUrl: baseUrl, + dnsCache: true, + ...options, + }); diff --git a/packages/core/index.ts b/packages/core/index.ts index 6d24778..557ef5b 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -1,3 +1,3 @@ export * from './src'; export * from './fetch'; -export * from './src/utils'; \ No newline at end of file +export * from './src/utils'; diff --git a/packages/core/package.json b/packages/core/package.json index bf6f7d2..89ffad6 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -9,10 +9,12 @@ "vm2": "^3.9.6" }, "scripts": { - "lint": "eslint \"+(src)/**/*.ts\" --fix" + "lint": "eslint \"+(src)/**/*.ts\" --fix", + "format": "prettier . --write" }, "devDependencies": { "@typescript-eslint/parser": "^5.13.0", - "eslint": "^8.10.0" + "eslint": "^8.10.0", + "prettier": "^2.5.1" } } diff --git a/packages/core/src/DLTikProvider.ts b/packages/core/src/DLTikProvider.ts index 5ea1542..7157b25 100644 --- a/packages/core/src/DLTikProvider.ts +++ b/packages/core/src/DLTikProvider.ts @@ -5,85 +5,85 @@ import {BaseProvider, ExtractedInfo} from './base'; * @class DLTikProvider */ export class DLTikProvider extends BaseProvider { - /** + /** * @return {string} */ - public resourceName(): string { - return 'dltik'; - } + public resourceName(): string { + return 'dltik'; + } - public client = getFetch('https://dltik.com'); + public client = getFetch('https://dltik.com'); - public maintenance = { - reason: 'My prediction is that DLTik needs an active session to use.', - }; + public maintenance = { + reason: 'My prediction is that DLTik needs an active session to use.', + }; - /** + /** * @param {string} url - Video TikTok URL * @return {Promise} */ - public async fetch(url: string): Promise { - // getting verification token - const response = await this.client('./#url=' + encodeURIComponent(url)); - const token = ( + public async fetch(url: string): Promise { + // getting verification token + const response = await this.client('./#url=' + encodeURIComponent(url)); + const token = ( response.body.match(/type="hidden" value="([^""]+)"/) as string[] - )[1]; + )[1]; - const dlResponse = await this.client.post('./', { - form: { - m: 'getlink', - url: `https://m.tiktok.com/v/${ - ( + const dlResponse = await this.client.post('./', { + form: { + m: 'getlink', + url: `https://m.tiktok.com/v/${ + ( /predownload\('([0-9]+)'\)/gi.exec( response.body, ) as string[] - )[1] - }.html`, - __RequestVerificationToken: token, - }, - headers: { - 'Origin': this.client.defaults.options.prefixUrl, - 'Referer': response.url, - 'Cookie': response.headers['set-cookie']?.toString(), - 'Content-Type': 'application/x-www-form-urlencoded', - 'x-requested-with': 'XMLHttpRequest', - }, - }); + )[1] + }.html`, + __RequestVerificationToken: token, + }, + headers: { + Origin: this.client.defaults.options.prefixUrl, + Referer: response.url, + Cookie: response.headers['set-cookie']?.toString(), + 'Content-Type': 'application/x-www-form-urlencoded', + 'x-requested-with': 'XMLHttpRequest', + }, + }); - return this.extract(dlResponse.body); - } + return this.extract(dlResponse.body); + } - /** + /** * * @param {string} html - Raw * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const json = JSON.parse(html); - if (!json.status) { - return { - error: json.message, - }; - } else { - // if (json.data.videoId === '7013188037203070234') { - // return { - // 'error': 'Invalid url', - // }; - // } - return { - video: { - id: json.data.videoId, - urls: [ - json.data.watermarkVideoUrl, - json.data.destinationUrl, - ], - thumb: json.data.dynamicCover, - }, - music: { - url: json.data.musicUrl, - }, - caption: json.data.desc, - }; + extract(html: string): ExtractedInfo { + const json = JSON.parse(html); + if (!json.status) { + return { + error: json.message, + }; + } else { + // if (json.data.videoId === '7013188037203070234') { + // return { + // 'error': 'Invalid url', + // }; + // } + return { + video: { + id: json.data.videoId, + urls: [ + json.data.watermarkVideoUrl, + json.data.destinationUrl, + ], + thumb: json.data.dynamicCover, + }, + music: { + url: json.data.musicUrl, + }, + caption: json.data.desc, + }; + } } - } } diff --git a/packages/core/src/dddTikProvider.ts b/packages/core/src/dddTikProvider.ts index 687b543..3f88b2e 100644 --- a/packages/core/src/dddTikProvider.ts +++ b/packages/core/src/dddTikProvider.ts @@ -6,47 +6,47 @@ import {matchLink} from './utils'; * @class DDDTikProvider */ export class DDDTikProvider extends BaseProvider { - /** + /** * Get resource name * * @return {string} */ - public resourceName(): string { - return 'dddtik'; - } + public resourceName(): string { + return 'dddtik'; + } - public client = getFetch('https://dddtik.com'); + public client = getFetch('https://dddtik.com'); - public maintenance = undefined; + public maintenance = undefined; - /** + /** * @param {string} url Tiktok video url * @return {Promise} */ - async fetch(url: string): Promise { - const response = await this.client.post('./down.php', { - form: { - url: url, - }, - }); + async fetch(url: string): Promise { + const response = await this.client.post('./down.php', { + form: { + url: url, + }, + }); - return this.extract(response.body); - } + return this.extract(response.body); + } - /** + /** * @param {string} html * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const urls = matchLink(html) as string[]; - urls.pop(); + extract(html: string): ExtractedInfo { + const urls = matchLink(html) as string[]; + urls.pop(); - const t = urls[1]; - return { - video: { - urls: urls.filter((u) => u !== t), - thumb: t, - }, - }; - } + const t = urls[1]; + return { + video: { + urls: urls.filter((u) => u !== t), + thumb: t, + }, + }; + } } diff --git a/packages/core/src/downTikProvider.ts b/packages/core/src/downTikProvider.ts index 5853fbb..e8a9d4a 100644 --- a/packages/core/src/downTikProvider.ts +++ b/packages/core/src/downTikProvider.ts @@ -6,67 +6,67 @@ import {matchCustomDownload} from './utils'; * @class DownTikProvider */ export class DownTikProvider extends BaseProvider { - /** + /** * Get resource name * * @return {string} */ - public resourceName(): string { - return 'downtik'; - } + public resourceName(): string { + return 'downtik'; + } - public client = getFetch('https://downtik.net'); + public client = getFetch('https://downtik.net'); - public maintenance = undefined; + public maintenance = undefined; - /** + /** * @param {string} url * * @return {Promise} */ - async fetch(url: string): Promise { - const response = await this.client('./'); + async fetch(url: string): Promise { + const response = await this.client('./'); - const token = ( + const token = ( response.body.match(/id="token" value="([^""]+)"/) as string[] - )[1]; + )[1]; - const responseAction = await this.client.post('./action.php', { - form: { - url: url, - token: token, - }, - headers: { - cookie: response.headers['set-cookie']?.toString(), - Referer: 'https://downtik.net/', - Origin: 'https://downtik.net', - }, - }); + const responseAction = await this.client.post('./action.php', { + form: { + url: url, + token: token, + }, + headers: { + cookie: response.headers['set-cookie']?.toString(), + Referer: 'https://downtik.net/', + Origin: 'https://downtik.net', + }, + }); - if (JSON.parse(responseAction.body).error) { - return { - error: JSON.parse(responseAction.body).message, - }; + if (JSON.parse(responseAction.body).error) { + return { + error: JSON.parse(responseAction.body).message, + }; + } + + return this.extract(JSON.parse(responseAction.body).data); } - return this.extract(JSON.parse(responseAction.body).data); - } - - /** + /** * @param {string} html * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const urls = matchCustomDownload('downtik', html); + extract(html: string): ExtractedInfo { + const urls = matchCustomDownload('downtik', html); - return { - music: { - url: urls.pop() as string, - }, - video: { - thumb: urls?.shift(), - urls: urls as string[], - }, - }; - } + return { + music: { + url: urls.pop() as string, + }, + video: { + thumb: urls?.shift(), + urls: urls as string[], + }, + }; + } } diff --git a/packages/core/src/downloaderOneProvider.ts b/packages/core/src/downloaderOneProvider.ts index 520989b..9e7a76e 100644 --- a/packages/core/src/downloaderOneProvider.ts +++ b/packages/core/src/downloaderOneProvider.ts @@ -5,81 +5,81 @@ import {getFetch} from '../fetch'; * @class DownloadOne */ export class DownloadOne extends BaseProvider { - /** + /** * Get provider name * @return {string} */ - public resourceName(): string { - return 'ttdownloaderone'; - } + public resourceName(): string { + return 'ttdownloaderone'; + } - public client = getFetch('http://tiktokdownloader.one'); + public client = getFetch('http://tiktokdownloader.one'); - public maintenance = undefined; + public maintenance = undefined; - /** + /** * Fetch ttdownloader.one * @param {string} url Video TikTok URL * @return {Promise} */ - public async fetch(url: string): Promise { - // getting the token - const response = await this.client('./'); + public async fetch(url: string): Promise { + // getting the token + const response = await this.client('./'); - const token = ( + const token = ( /name="_token_" content="(.*)"/gi.exec(response.body) as string[] - )[1]; + )[1]; - const dlResponse = await this.client('./api/v1/fetch?url=' + url, { - headers: { - TOKEN: token, - Referer: 'http://tiktokdownloader.one/', - Origin: 'http://tiktokdownloader.one', - Accept: 'application/json, text/plain, */*', - }, - }); + const dlResponse = await this.client('./api/v1/fetch?url=' + url, { + headers: { + TOKEN: token, + Referer: 'http://tiktokdownloader.one/', + Origin: 'http://tiktokdownloader.one', + Accept: 'application/json, text/plain, */*', + }, + }); - if (dlResponse.statusCode !== 200) { - return { - error: 'Probably the video doesn\'t exist', - }; + if (dlResponse.statusCode !== 200) { + return { + error: "Probably the video doesn't exist", + }; + } + + return this.extract(dlResponse.body); } - return this.extract(dlResponse.body); - } - - /** + /** * Extract page from ttdownloader.one site * @param {string} html * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const json = JSON.parse(html); + extract(html: string): ExtractedInfo { + const json = JSON.parse(html); - return { - video: { - urls: [json.url, json.url_nwm], - thumb: json.cover, - id: json.video_id, - }, - music: { - url: json.music.url, - title: json.music.title, - cover: json.music.cover, - author: json.music.author, - }, - author: { - id: json.user.name, - username: json.user.username, - thumb: json.user.cover, - }, - caption: json.caption, - updatedAt: json.updatedAt ?? '-', - uploadedAt: json.uploaded_at, - commentsCount: json.stats.comment, - sharesCount: json.stats.shares, - likesCount: json.stats.likes, - playsCount: json.stats.play, - }; - } + return { + video: { + urls: [json.url, json.url_nwm], + thumb: json.cover, + id: json.video_id, + }, + music: { + url: json.music.url, + title: json.music.title, + cover: json.music.cover, + author: json.music.author, + }, + author: { + id: json.user.name, + username: json.user.username, + thumb: json.user.cover, + }, + caption: json.caption, + updatedAt: json.updatedAt ?? '-', + uploadedAt: json.uploaded_at, + commentsCount: json.stats.comment, + sharesCount: json.stats.shares, + likesCount: json.stats.likes, + playsCount: json.stats.play, + }; + } } diff --git a/packages/core/src/getVidTikProvider.ts b/packages/core/src/getVidTikProvider.ts new file mode 100644 index 0000000..4d8f548 --- /dev/null +++ b/packages/core/src/getVidTikProvider.ts @@ -0,0 +1,96 @@ +import {BaseProvider, ExtractedInfo} from './base'; +import {getFetch} from '../fetch'; +import {matchLink} from './utils'; +import {random as randomUA} from 'tiktok-dl-config/useragents'; + +/** + * @class GetVidTikProvider + */ +export class GetVidTikProvider extends BaseProvider { + /** + * Get resource name + * + * @return {string} + */ + public resourceName(): string { + return 'getvidtik'; + } + + public client = getFetch('https://getvidtik.com'); + public maintenance = undefined; + + /** + * @param {string} url TikTok Video URL + * @return {Promise} + */ + async fetch(url: string): Promise { + // getting the token. + const response = await this.client.get('./', { + headers: { + 'User-Agent': randomUA(), + }, + }); + + const matchs = /name="token" type="hidden" value="([^""]+)"/.exec( + response.body, + ); + if (!matchs) { + return { + error: "Couldn't get the token.", + }; + } else { + // download request + const downloadResponse = await this.client.post('./download', { + headers: { + 'User-Agent': randomUA(), + Cookie: response.headers['set-cookie']?.toString(), + Origin: this.client.defaults.options.prefixUrl, + Referer: response.url, + }, + followRedirect: false, + }); + + if (downloadResponse.statusCode === 302) { + return { + error: 'The video is private or removed.', + }; + } else { + return this.extract(downloadResponse.body); + } + } + } + + /** + * Extract getVidTik Response + * @param {string} html - Raw + * @return {ExtractedInfo} + */ + extract(html: string): ExtractedInfo { + const matchs = matchLink(html); + if (matchs) { + const tiktokMatchs = matchs.filter((url) => + /http(s)?:\/\/(.*)\.tiktok(cdn)?\.com/gi.test(url), + ); + + if (tiktokMatchs) { + return { + video: { + thumb: tiktokMatchs[0], + urls: [tiktokMatchs[2], tiktokMatchs[3]], // [0] = no watermark, [1] = watermark + }, + music: { + url: tiktokMatchs[tiktokMatchs.length - 1], // soon, i'll use '.at(-1)' + }, + }; + } else { + return { + error: "Couldn't match tiktok links.", + }; + } + } else { + return { + error: "Couldn't match site links.", + }; + } + } +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 9c09a52..623621b 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -17,29 +17,29 @@ import {DownloadOne} from './downloaderOneProvider'; import {NativeProvider} from './nativeProvider'; export const Providers: BaseProvider[] = [ - new SnaptikProvider(), - new TikmateProvider(), - new MusicalyDown(), - new TTDownloader(), - new TTSave(), // won't work because we coudn't receive the cookie. - new DLTikProvider(), - new SaveFromProvider(), - new SaveTikProvider(), - new TikDownProvider(), - new DownTikProvider(), // SaveTik Mirror - new LoveTikProvider(), - new DDDTikProvider(), - new TokupProvider(), // ttsave alternative - new DownloadOne(), - new NativeProvider(), + new SnaptikProvider(), + new TikmateProvider(), + new MusicalyDown(), + new TTDownloader(), + new TTSave(), // won't work because we coudn't receive the cookie. + new DLTikProvider(), + new SaveFromProvider(), + new SaveTikProvider(), + new TikDownProvider(), + new DownTikProvider(), // SaveTik Mirror + new LoveTikProvider(), + new DDDTikProvider(), + new TokupProvider(), // ttsave alternative + new DownloadOne(), + new NativeProvider(), ]; export const getRandomProvider = () => - Providers[Math.floor(Math.random() * Providers.length)]; + Providers[Math.floor(Math.random() * Providers.length)]; export const getProvider = (name: string) => - name.toLowerCase() !== 'random' ? - Providers.find((p) => p.resourceName() === name.toLowerCase()) : - getRandomProvider(); + name.toLowerCase() !== 'random' + ? Providers.find((p) => p.resourceName() === name.toLowerCase()) + : getRandomProvider(); export {BaseProvider, ExtractedInfo}; diff --git a/packages/core/src/loveTikProvider.ts b/packages/core/src/loveTikProvider.ts index 377e9ff..af39590 100644 --- a/packages/core/src/loveTikProvider.ts +++ b/packages/core/src/loveTikProvider.ts @@ -5,61 +5,61 @@ import {getFetch} from '../fetch'; * @class LoveTikProvider */ export class LoveTikProvider extends BaseProvider { - /** + /** * Get resource name * * @return {string} */ - public resourceName(): string { - return 'lovetik'; - } + public resourceName(): string { + return 'lovetik'; + } - public client = getFetch('https://lovetik.com'); + public client = getFetch('https://lovetik.com'); - public maintenance = undefined; + public maintenance = undefined; - /** + /** * @param {string} url Video TikTok URL * @return {Promise} */ - async fetch(url: string): Promise { - const response = await this.client.post('./api/ajax/search', { - form: { - query: url, - }, - headers: { - Origin: 'https://lovetik.com/', - Referer: 'https://lovetik.com/', - }, - }); + async fetch(url: string): Promise { + const response = await this.client.post('./api/ajax/search', { + form: { + query: url, + }, + headers: { + Origin: 'https://lovetik.com/', + Referer: 'https://lovetik.com/', + }, + }); - return this.extract(response.body); - } + return this.extract(response.body); + } - /** + /** * @param {string} jsonString * @return {ExtractedInfo} */ - extract(jsonString: string): ExtractedInfo { - const json = JSON.parse(jsonString); + extract(jsonString: string): ExtractedInfo { + const json = JSON.parse(jsonString); - if (json.mess) { - return { - error: json.mess, - }; + if (json.mess) { + return { + error: json.mess, + }; + } + + return { + music: { + url: json.links.pop().a, + }, + video: { + thumb: json.cover, + urls: json.links.map((l: Record) => l.a), + }, + author: { + username: json.author.replace(/(<([^>]+)>)/gi, ''), + }, + }; } - - return { - music: { - url: json.links.pop().a, - }, - video: { - thumb: json.cover, - urls: json.links.map((l: Record) => l.a), - }, - author: { - username: json.author.replace(/(<([^>]+)>)/gi, ''), - }, - }; - } } diff --git a/packages/core/src/musicalyDownProvider.ts b/packages/core/src/musicalyDownProvider.ts index 1192f7a..b9d8b94 100644 --- a/packages/core/src/musicalyDownProvider.ts +++ b/packages/core/src/musicalyDownProvider.ts @@ -5,72 +5,72 @@ import {BaseProvider, ExtractedInfo} from './base'; * @class MusicalyDown */ export class MusicalyDown extends BaseProvider { - public client = getFetch('https://musicaldown.com/id'); - /** + public client = getFetch('https://musicaldown.com/id'); + /** * * @return {string} */ - public resourceName(): string { - return 'musicalydown'; - } + public resourceName(): string { + return 'musicalydown'; + } - public maintenance = undefined; + public maintenance = undefined; - /** + /** * * @param {string} url - Video Tiktok URL * @return {Promise} */ - public async fetch(url: string): Promise { - const res = await this.client('./', { - headers: { - Accept: '*/*', - Referer: this.client.defaults.options.prefixUrl, - Origin: this.client.defaults.options.prefixUrl, - }, - }); - const tokens = res.body.match( - /input name="([^""]+)" type="hidden" value="([^""]+)"/, - ) as string[]; - const response = await this.client.post('./download', { - form: { - [(res.body.match(/input name="([^"]+)/) as string[])[1]]: url, - [tokens[1]]: tokens[2], - verify: 1, - }, - headers: { - Cookie: res.headers['set-cookie']?.toString(), - Accept: '*/*', - Referer: this.client.defaults.options.prefixUrl, - Origin: this.client.defaults.options.prefixUrl, - }, - }); + public async fetch(url: string): Promise { + const res = await this.client('./', { + headers: { + Accept: '*/*', + Referer: this.client.defaults.options.prefixUrl, + Origin: this.client.defaults.options.prefixUrl, + }, + }); + const tokens = res.body.match( + /input name="([^""]+)" type="hidden" value="([^""]+)"/, + ) as string[]; + const response = await this.client.post('./download', { + form: { + [(res.body.match(/input name="([^"]+)/) as string[])[1]]: url, + [tokens[1]]: tokens[2], + verify: 1, + }, + headers: { + Cookie: res.headers['set-cookie']?.toString(), + Accept: '*/*', + Referer: this.client.defaults.options.prefixUrl, + Origin: this.client.defaults.options.prefixUrl, + }, + }); - return this.extract(response.body); - } + return this.extract(response.body); + } - /** + /** * * @param {string} html - Raw HTML * @return {ExtractedInfo} */ - public extract(html: string): ExtractedInfo { - const matchUrls = html.match( - //gi, - ) as string[]; - const urls = matchUrls.map( - (url) => + public extract(html: string): ExtractedInfo { + const matchUrls = html.match( + //gi, + ) as string[]; + const urls = matchUrls.map( + (url) => //gi.exec( url, )?.[1] as string, - ); - return { - video: { - urls: urls, - thumb: /img class="responsive-img" src="(.*?)"/gi.exec( - html, - )?.[1], - }, - }; - } + ); + return { + video: { + urls: urls, + thumb: /img class="responsive-img" src="(.*?)"/gi.exec( + html, + )?.[1], + }, + }; + } } diff --git a/packages/core/src/nativeProvider.ts b/packages/core/src/nativeProvider.ts index 34b8554..13669e7 100644 --- a/packages/core/src/nativeProvider.ts +++ b/packages/core/src/nativeProvider.ts @@ -7,85 +7,84 @@ import {matchTikTokData} from './utils'; * @class NativeProvider */ export class NativeProvider extends BaseProvider { - /** + /** * Get resource name. * @return {string} */ - public resourceName(): string { - return 'native'; - } + public resourceName(): string { + return 'native'; + } - public maintenance = undefined; - public client = undefined; + public maintenance = undefined; + public client = undefined; - /** + /** * @param {string} url Tiktok video url * @return {Promise} */ - async fetch(url: string): Promise { - const urlInstance = new URL(url); + async fetch(url: string): Promise { + const urlInstance = new URL(url); + const response = await getFetch(urlInstance.origin).get( + `.${urlInstance.pathname}`, + { + headers: { + Referer: urlInstance.href, + Origin: urlInstance.origin, + 'User-Agent': randomUA(), + }, + timeout: { + socket: 10000, + }, + }, + ); - const response = await getFetch(urlInstance.origin).get( - urlInstance.pathname, - { - headers: { - 'Referer': urlInstance.href, - 'Origin': urlInstance.origin, - 'User-Agent': randomUA(), - }, - timeout: { - socket: 5000, - }, - }, - ); + return this.extract(response.body); + } - return this.extract(response.body); - } - - /** - * @param {string} html + /** + * @param {string} html Raw HTML Data * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const matches = matchTikTokData(html); - if (matches.length) { - const json = Object.values( - JSON.parse(matches).ItemModule, - )[0] as any; + extract(html: string): ExtractedInfo { + const matches = matchTikTokData(html); + if (matches.length) { + const json = Object.values( + JSON.parse(matches).ItemModule, + )[0] as any; - return { - video: { - id: json.id, - urls: [json.video.playAddr, json.video.downloadAddr], - thumb: json.video.cover, - duration: json.video.duration, - }, - music: { - url: json.music.playUrl, - title: json.music.title, - author: json.music.authorName, - id: json.music.id, - cover: json.music.coverLarge, - album: json.music.album, - duration: json.music.duration, - }, - author: { - username: json.author, - id: json.authorId, - thumb: json.avatarThumb, - nick: json.nickname, - }, - caption: json.desc, - playsCount: json.stats.playCount, - sharesCount: json.stats.shareCount, - commentsCount: json.stats.commentCount, - likesCount: json.stats.diggCount, - uploadedAt: json.createTime, - }; - } else { - return { - error: 'Something was wrong!', - }; + return { + video: { + id: json.id, + urls: [json.video.playAddr, json.video.downloadAddr], + thumb: json.video.cover, + duration: json.video.duration, + }, + music: { + url: json.music.playUrl, + title: json.music.title, + author: json.music.authorName, + id: json.music.id, + cover: json.music.coverLarge, + album: json.music.album, + duration: json.music.duration, + }, + author: { + username: json.author, + id: json.authorId, + thumb: json.avatarThumb, + nick: json.nickname, + }, + caption: json.desc, + playsCount: json.stats.playCount, + sharesCount: json.stats.shareCount, + commentsCount: json.stats.commentCount, + likesCount: json.stats.diggCount, + uploadedAt: json.createTime, + }; + } else { + return { + error: 'Something was wrong!', + }; + } } - } } diff --git a/packages/core/src/saveFromProvider.ts b/packages/core/src/saveFromProvider.ts index d88f2ed..a1e0bc1 100644 --- a/packages/core/src/saveFromProvider.ts +++ b/packages/core/src/saveFromProvider.ts @@ -6,66 +6,66 @@ import {deObfuscateSaveFromScript} from './utils'; * @class saveFromProvider */ export class SaveFromProvider extends BaseProvider { - /** + /** * * @return {string} */ - public resourceName(): string { - return 'savefrom'; - } + public resourceName(): string { + return 'savefrom'; + } - public client = getFetch('https://worker-as.sf-tools.com'); + public client = getFetch('https://worker-as.sf-tools.com'); - public maintenance = undefined; + public maintenance = undefined; - /** + /** * * @param {string} url - Video TikTok URL * @return {Promise} */ - public async fetch(url: string): Promise { - const response = await this.client.post('./savefrom.php', { - form: { - 'sf_url': url, - 'sf_submit': '', - 'new': '2', - 'lang': 'id', - 'country': 'id', - 'os': 'Ubuntu', - 'browser': 'Firefox', - 'channel': 'Downloader', - 'sf-nomad': '1', - }, - headers: { - Origin: 'https://id.savefrom.net', - Referer: 'https://id.savefrom.net', - }, - }); + public async fetch(url: string): Promise { + const response = await this.client.post('./savefrom.php', { + form: { + sf_url: url, + sf_submit: '', + new: '2', + lang: 'id', + country: 'id', + os: 'Ubuntu', + browser: 'Firefox', + channel: 'Downloader', + 'sf-nomad': '1', + }, + headers: { + Origin: 'https://id.savefrom.net', + Referer: 'https://id.savefrom.net', + }, + }); - return this.extract(response.body); - } + return this.extract(response.body); + } - /** + /** * * @param {string} html - HTML Raw * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const deobfuscated = deObfuscateSaveFromScript(html); - const json = JSON.parse( - (deobfuscated.match(/\({(.*)}\)/) as string[])[0].replace( - /(\(|\))/g, - '', - ), - ); - return { - video: { - thumb: json.thumb, - id: json.id, - urls: json.url.map((x: {url: string}) => x.url), - duration: json.meta.duration, - title: json.meta.title, - }, - }; - } + extract(html: string): ExtractedInfo { + const deobfuscated = deObfuscateSaveFromScript(html); + const json = JSON.parse( + (deobfuscated.match(/\({(.*)}\)/) as string[])[0].replace( + /(\(|\))/g, + '', + ), + ); + return { + video: { + thumb: json.thumb, + id: json.id, + urls: json.url.map((x: {url: string}) => x.url), + duration: json.meta.duration, + title: json.meta.title, + }, + }; + } } diff --git a/packages/core/src/saveTikProvider.ts b/packages/core/src/saveTikProvider.ts index c7cc0bb..48e30ae 100644 --- a/packages/core/src/saveTikProvider.ts +++ b/packages/core/src/saveTikProvider.ts @@ -6,66 +6,66 @@ import {matchCustomDownload} from './utils'; * @class SaveTikProvider */ export class SaveTikProvider extends BaseProvider { - /** + /** * Get resource name * * @return {string} */ - public resourceName(): string { - return 'savetik'; - } + public resourceName(): string { + return 'savetik'; + } - public client = getFetch('https://savetik.net'); + public client = getFetch('https://savetik.net'); - public maintenance = undefined; + public maintenance = undefined; - /** + /** * @param {string} url Video TikTok URL * @return {Promise} */ - async fetch(url: string): Promise { - const response = await this.client('./'); + async fetch(url: string): Promise { + const response = await this.client('./'); - const token = ( + const token = ( response.body.match(/id="token" value="([^""]+)"/) as string[] - )[1]; + )[1]; - const responseAction = await this.client.post('./action.php', { - form: { - url: url, - token: token, - }, - headers: { - cookie: response.headers['set-cookie']?.toString(), - Referer: 'https://savetik.net/', - Origin: 'https://savetik.net', - }, - }); + const responseAction = await this.client.post('./action.php', { + form: { + url: url, + token: token, + }, + headers: { + cookie: response.headers['set-cookie']?.toString(), + Referer: 'https://savetik.net/', + Origin: 'https://savetik.net', + }, + }); - if (JSON.parse(responseAction.body).error) { - return { - error: JSON.parse(responseAction.body).message, - }; + if (JSON.parse(responseAction.body).error) { + return { + error: JSON.parse(responseAction.body).message, + }; + } + + return this.extract(JSON.parse(responseAction.body).data); } - return this.extract(JSON.parse(responseAction.body).data); - } - - /** + /** * @param {string} html * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const urls = matchCustomDownload('savetik', html); + extract(html: string): ExtractedInfo { + const urls = matchCustomDownload('savetik', html); - return { - music: { - url: urls?.pop() as string, - }, - video: { - thumb: urls?.shift(), - urls: urls as string[], - }, - }; - } + return { + music: { + url: urls?.pop() as string, + }, + video: { + thumb: urls?.shift(), + urls: urls as string[], + }, + }; + } } diff --git a/packages/core/src/snaptikProvider.ts b/packages/core/src/snaptikProvider.ts index c0bc3f0..70833f1 100644 --- a/packages/core/src/snaptikProvider.ts +++ b/packages/core/src/snaptikProvider.ts @@ -6,46 +6,46 @@ import {deObfuscate, matchLink} from './utils'; * @class SnaptikProvider */ export class SnaptikProvider extends BaseProvider { - public client = getFetch('https://snaptik.app/en'); - /** + public client = getFetch('https://snaptik.app/en'); + /** * * @return {string} */ - public resourceName(): string { - return 'snaptik'; - } + public resourceName(): string { + return 'snaptik'; + } - public maintenance = undefined; + public maintenance = undefined; - /** + /** * * @param {string} url - TikTok Video URL * @return {Promise} */ - public async fetch(url: string): Promise { - const response = await this.client('./abc.php', { - searchParams: { - url: url, - }, - }); + public async fetch(url: string): Promise { + const response = await this.client('./abc.php', { + searchParams: { + url: url, + }, + }); - return this.extract(response.body); - } + return this.extract(response.body); + } - /** + /** * Extract information from raw html * @param {string} html - Raw HTML * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const results = matchLink(deObfuscate(html)); - if (!results || !results.length) throw new Error('Broken'); + extract(html: string): ExtractedInfo { + const results = matchLink(deObfuscate(html)); + if (!results || !results.length) throw new Error('Broken'); - return { - video: { - thumb: results?.shift(), - urls: [...new Set(results)], - }, - }; - } + return { + video: { + thumb: results?.shift(), + urls: [...new Set(results)], + }, + }; + } } diff --git a/packages/core/src/tikDownProvider.ts b/packages/core/src/tikDownProvider.ts index ad99238..881902e 100644 --- a/packages/core/src/tikDownProvider.ts +++ b/packages/core/src/tikDownProvider.ts @@ -6,61 +6,61 @@ import {matchLink} from './utils'; * @class TikDownProvider */ export class TikDownProvider extends BaseProvider { - /** + /** * Get resource name. * * @return {string} */ - public resourceName(): string { - return 'tikdown'; - } + public resourceName(): string { + return 'tikdown'; + } - public client = getFetch('https://tikdown.org'); + public client = getFetch('https://tikdown.org'); - public maintenance = undefined; + public maintenance = undefined; - /** + /** * @param {string} url * * @return {Promise} */ - async fetch(url: string): Promise { - const response = await this.client('./'); + async fetch(url: string): Promise { + const response = await this.client('./'); - const token = ( + const token = ( response.body.match(/name="_token" value="([^""]+)"/) as string[] - )[1]; + )[1]; - const responseAjax = await this.client.post('./getAjax', { - form: { - url: url, - _token: token, - }, - headers: { - 'x-csrf-token': token, - 'cookie': response.headers['set-cookie']?.toString(), - }, - }); + const responseAjax = await this.client.post('./getAjax', { + form: { + url: url, + _token: token, + }, + headers: { + 'x-csrf-token': token, + cookie: response.headers['set-cookie']?.toString(), + }, + }); - if (!JSON.parse(responseAjax.body).status) { - return { - error: 'Something was wrong', - }; + if (!JSON.parse(responseAjax.body).status) { + return { + error: 'Something was wrong', + }; + } + return this.extract(JSON.parse(responseAjax.body).html); } - return this.extract(JSON.parse(responseAjax.body).html); - } - /** + /** * @param {string} html * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const urls = matchLink(html) as string[]; - return { - video: { - thumb: urls.shift(), - urls: urls, - }, - }; - } + extract(html: string): ExtractedInfo { + const urls = matchLink(html) as string[]; + return { + video: { + thumb: urls.shift(), + urls: urls, + }, + }; + } } diff --git a/packages/core/src/tikmateProvider.ts b/packages/core/src/tikmateProvider.ts index 34c63db..c3474ed 100644 --- a/packages/core/src/tikmateProvider.ts +++ b/packages/core/src/tikmateProvider.ts @@ -6,63 +6,63 @@ import {deObfuscate, matchCustomDownload} from './utils'; * @class TikmateProvider */ export class TikmateProvider extends BaseProvider { - public client = getFetch('https://tikmate.online'); - /** + public client = getFetch('https://tikmate.online'); + /** * * @return {string} */ - public resourceName(): string { - return 'tikmate'; - } + public resourceName(): string { + return 'tikmate'; + } - public maintenance = undefined; + public maintenance = undefined; - /** + /** * * @param {string} url - Video TikTok URL * @return {Promise} */ - public async fetch(url: string): Promise { - // we need to get the token + public async fetch(url: string): Promise { + // we need to get the token - const response = await this.client('./'); - const matchs = response.body.match( - /id="token" value="(.*)?"/, - ) as string[]; + const response = await this.client('./'); + const matchs = response.body.match( + /id="token" value="(.*)?"/, + ) as string[]; - const cookies = response.headers['cookie']; + const cookies = response.headers['cookie']; - const abcResponse = await this.client.post('./abc.php', { - form: matchs ? - { - url: url, - token: matchs[1], - } : - { - url: url, - }, - headers: { - Origin: this.client.defaults.options.prefixUrl, - Referer: this.client.defaults.options.prefixUrl + '/', - Cookie: cookies, - }, - }); + const abcResponse = await this.client.post('./abc.php', { + form: matchs + ? { + url: url, + token: matchs[1], + } + : { + url: url, + }, + headers: { + Origin: this.client.defaults.options.prefixUrl, + Referer: this.client.defaults.options.prefixUrl + '/', + Cookie: cookies, + }, + }); - return this.extract(abcResponse.body); - } + return this.extract(abcResponse.body); + } - /** + /** * Extract information from raw html * @param {string} html - Raw HTML * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const matchs = matchCustomDownload('tikmate', deObfuscate(html)); - return { - video: { - thumb: matchs.shift(), - urls: matchs, - }, - }; - } + extract(html: string): ExtractedInfo { + const matchs = matchCustomDownload('tikmate', deObfuscate(html)); + return { + video: { + thumb: matchs.shift(), + urls: matchs, + }, + }; + } } diff --git a/packages/core/src/tokupProvider.ts b/packages/core/src/tokupProvider.ts index 821984b..ac3b690 100644 --- a/packages/core/src/tokupProvider.ts +++ b/packages/core/src/tokupProvider.ts @@ -5,87 +5,87 @@ import {getFetch} from '../fetch'; * @class TokupProvider */ export class TokupProvider extends BaseProvider { - /** + /** * Get provider name * @return {string} */ - public resourceName(): string { - return 'tokup'; - } + public resourceName(): string { + return 'tokup'; + } - public client = getFetch('https://tokup.app'); + public client = getFetch('https://tokup.app'); - public maintenance = { - reason: 'Tokup site returned \'Oops! Something went wrong!\'', - }; + public maintenance = { + reason: "Tokup site returned 'Oops! Something went wrong!'", + }; - /** + /** * Fetch tokup * @param {string} url - TikTok Video URL * @return {Promise} */ - public async fetch(url: string): Promise { - const response = await this.client.post('./', { - form: { - url: url, - }, - headers: { - Origin: this.client.defaults.options.prefixUrl, - Referer: this.client.defaults.options.prefixUrl, - }, - timeout: 3000, - }); + public async fetch(url: string): Promise { + const response = await this.client.post('./', { + form: { + url: url, + }, + headers: { + Origin: this.client.defaults.options.prefixUrl, + Referer: this.client.defaults.options.prefixUrl, + }, + timeout: 3000, + }); - if ( - response.statusCode !== 200 || + if ( + response.statusCode !== 200 || /video not found\b/gi.test(response.body) - ) { - return { - error: 'Video Not Found', - }; - } else if (/oops/gi.test(response.body)) { - return { - error: 'Tokup Error', - }; - } else { - return this.extract(response.body); + ) { + return { + error: 'Video Not Found', + }; + } else if (/oops/gi.test(response.body)) { + return { + error: 'Tokup Error', + }; + } else { + return this.extract(response.body); + } } - } - /** + /** * Extract tokup html elements * @param {string} html * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - console.log(html); - const authorProfile = ( + extract(html: string): ExtractedInfo { + console.log(html); + const authorProfile = ( /http(s)?(:\/\/(.*)\.tiktokcdn\.com\/(.*))/gi.exec(html) as string[] - )[0]; - const nums = (html.match(/[0-9]+<\/td>/g) as string[]).map((n) => - n.replace(/<(\/)?[a-zA-Z0-9]+>/gi, ''), - ); - const url = [ - ...new Set( + )[0]; + const nums = (html.match(/[0-9]+<\/td>/g) as string[]).map((n) => + n.replace(/<(\/)?[a-zA-Z0-9]+>/gi, ''), + ); + const url = [ + ...new Set( html.match( // eslint-disable-next-line max-len /http(s)?(:\/\/tikmate\.app\/download\/[A-Za-z0-9\-\_]+\/[0-9]+\.mp4+)/gi, ) as string[], - ), - ][0]; + ), + ][0]; - return { - video: { - urls: [url, url + '?hd=1'], - }, - author: { - username: (/target="_blank"\>(.*)\(.+)<\/p>/) as string[])[1], - likesCount: nums[0] as unknown as number, - commentsCount: nums[1] as unknown as number, - sharesCount: nums[2] as unknown as number, - }; - } + return { + video: { + urls: [url, url + '?hd=1'], + }, + author: { + username: (/target="_blank"\>(.*)\(.+)<\/p>/) as string[])[1], + likesCount: nums[0] as unknown as number, + commentsCount: nums[1] as unknown as number, + sharesCount: nums[2] as unknown as number, + }; + } } diff --git a/packages/core/src/ttDownloaderProvider.ts b/packages/core/src/ttDownloaderProvider.ts index 5a63d0e..e19a690 100644 --- a/packages/core/src/ttDownloaderProvider.ts +++ b/packages/core/src/ttDownloaderProvider.ts @@ -6,56 +6,56 @@ import {matchLink} from './utils'; * @class TTDownloader */ export class TTDownloader extends BaseProvider { - /** + /** * @return {string} */ - public resourceName(): string { - return 'ttdownloader'; - } + public resourceName(): string { + return 'ttdownloader'; + } - public client = getFetch('https://ttdownloader.com'); + public client = getFetch('https://ttdownloader.com'); - public maintenance = undefined; + public maintenance = undefined; - /** + /** * * @param {string} url - Video TikTok URL * @return {Promise} */ - public async fetch(url: string): Promise { - // getting token and cookies - const firstResponse = await this.client('./'); - const token = ( + public async fetch(url: string): Promise { + // getting token and cookies + const firstResponse = await this.client('./'); + const token = ( firstResponse.body.match(/name="token" value="(.*)?"/) as string[] - )[1]; - const videoResponse = await this.client.post('./req', { - form: { - token: token, - format: '', - url: url, - }, - headers: { - Origin: 'https://ttdownloader.com', - Referer: 'https://ttdownloader.com', - Cookie: firstResponse.headers['set-cookie']?.toString(), - }, - }); + )[1]; + const videoResponse = await this.client.post('./req', { + form: { + token: token, + format: '', + url: url, + }, + headers: { + Origin: 'https://ttdownloader.com', + Referer: 'https://ttdownloader.com', + Cookie: firstResponse.headers['set-cookie']?.toString(), + }, + }); - return this.extract(videoResponse.body); - } + return this.extract(videoResponse.body); + } - /** + /** * * @param {string} html - HTML Raw * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const urls = matchLink(html); - urls?.pop(); // remove 'https://snaptik.fans' - return { - video: { - urls: urls as string[], - }, - }; - } + extract(html: string): ExtractedInfo { + const urls = matchLink(html); + urls?.pop(); // remove 'https://snaptik.fans' + return { + video: { + urls: urls as string[], + }, + }; + } } diff --git a/packages/core/src/ttSaveProvider.ts b/packages/core/src/ttSaveProvider.ts index 70cd8de..ab9266f 100644 --- a/packages/core/src/ttSaveProvider.ts +++ b/packages/core/src/ttSaveProvider.ts @@ -6,71 +6,71 @@ import {keyGeneratorTTSave, matchLink} from './utils'; * @class TTSave */ export class TTSave extends BaseProvider { - /** + /** * @return {string} */ - public resourceName(): string { - return 'ttsave'; - } + public resourceName(): string { + return 'ttsave'; + } - public client = getFetch('https://ttsave.app'); + public client = getFetch('https://ttsave.app'); - public maintenance = { - reason: 'TTSave doesn\'t returned cookie to manipulate the session', - }; + public maintenance = { + reason: "TTSave doesn't returned cookie to manipulate the session", + }; - /** + /** * * @param {string} url - TikTok Video URL * @return {Promise} */ - public async fetch(url: string): Promise { - // getting token - const response = await this.client('./'); + public async fetch(url: string): Promise { + // getting token + const response = await this.client('./'); - const token = ( + const token = ( response.body.match(/(m|doDownload)?\(e,"(.*)"\)}/) as string[] ) - .filter((x) => x.length) - .pop() as string; - const key = await keyGeneratorTTSave(token); + .filter((x) => x.length) + .pop() as string; + const key = await keyGeneratorTTSave(token); - const dlResponse = await this.client.post('./download.php', { - json: { - id: url, - token: token, - key: key, - }, - headers: { - Origin: this.client.defaults.options.prefixUrl, - Referer: this.client.defaults.options.prefixUrl, - Cookie: response.headers['set-cookie']?.toString(), // no cookies :( - ...response.headers, - }, - }); + const dlResponse = await this.client.post('./download.php', { + json: { + id: url, + token: token, + key: key, + }, + headers: { + Origin: this.client.defaults.options.prefixUrl, + Referer: this.client.defaults.options.prefixUrl, + Cookie: response.headers['set-cookie']?.toString(), // no cookies :( + ...response.headers, + }, + }); - return this.extract(dlResponse.body); - } + return this.extract(dlResponse.body); + } - /** + /** * * @param {string} html - HTML Raw * @return {ExtractedInfo} */ - extract(html: string): ExtractedInfo { - const tiktokCDNs = (matchLink(html) as string[]).filter((x) => - /http(s)?:\/\/(.*)?.tiktokcdn.com/gi.test(x), - ); - const videoCDNs = tiktokCDNs.filter((x) => !/jpeg/gi.test(x)); + extract(html: string): ExtractedInfo { + const tiktokCDNs = (matchLink(html) as string[]).filter((x) => + /http(s)?:\/\/(.*)?.tiktokcdn.com/gi.test(x), + ); + const videoCDNs = tiktokCDNs.filter((x) => !/jpeg/gi.test(x)); - return { - video: { - thumb: tiktokCDNs.find((x) => /jpeg/gi.test(x)), - urls: videoCDNs.filter((x) => !/music/gi.test(x)), - }, - music: { - url: videoCDNs.find((x) => /music/gi.test(x)) as string, - }, - }; - } + return { + video: { + thumb: tiktokCDNs.find((x) => /jpeg/gi.test(x)), + urls: videoCDNs.filter((x) => !/music/gi.test(x)), + }, + music: { + url: videoCDNs.find((x) => /music/gi.test(x)) as string, + }, + }; + } } diff --git a/packages/core/src/utils/extractor.ts b/packages/core/src/utils/extractor.ts index 26fd1c4..f26d3fc 100644 --- a/packages/core/src/utils/extractor.ts +++ b/packages/core/src/utils/extractor.ts @@ -4,79 +4,79 @@ import type {BaseProvider} from '../base'; import {NodeVM} from 'vm2'; export const matchTikTokData = (html: string): string => { - const data = html.match( - // eslint-disable-next-line max-len - /window\['SIGI_STATE'\]=(.*)<\/script>