From 5370f681bca6dc7fef7c683d96c44324069ae942 Mon Sep 17 00:00:00 2001 From: Zipdox Date: Mon, 4 Jan 2021 02:08:52 +0100 Subject: [PATCH] Fixed watermarkless extraction --- src/core/TikTok.ts | 29 ++++++----------------------- src/types/TikTok.ts | 1 + 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/core/TikTok.ts b/src/core/TikTok.ts index 4e7f0f25..13d82668 100644 --- a/src/core/TikTok.ts +++ b/src/core/TikTok.ts @@ -418,29 +418,10 @@ export class TikTokScraper extends EventEmitter { */ // eslint-disable-next-line class-methods-use-this private async extractVideoId(item: PostCollector): Promise { - // All videos after July 27 2020 do not store unique video id - // it means that we can't extract url to the video without the watermark - if (item.createTime > 1595808000) { - return null; - } - try { - const result = await rp({ - uri: item.videoUrl, - }); - const position = Buffer.from(result).indexOf('vid:'); - if (position !== -1) { - const id = Buffer.from(result) - .slice(position + 4, position + 36) - .toString(); - - return `https://api2-16-h2.musical.ly/aweme/v1/play/?video_id=${id}&vr_type=0&is_play_url=1&source=PackSourceEnum_PUBLISH&media_type=4${ - this.hdVideo ? `&ratio=default&improve_bitrate=1` : '' - }`; - } - } catch { - // continue regardless of error - } - return null; + return `https://api2-16-h2.musical.ly/aweme/v1/play/?video_id=${item.secretID}&vr_type=0&is_play_url=1&source=PackSourceEnum_PUBLISH&media_type=4${ + this.hdVideo ? `&ratio=default&improve_bitrate=1` : '' + }`; + } /** @@ -672,6 +653,7 @@ export class TikTokScraper extends EventEmitter { this.noDuplicates.push(posts[i].id); const item: PostCollector = { id: posts[i].id, + secretID: posts[i].video.id, text: posts[i].desc, createTime: posts[i].createTime, authorMeta: { @@ -1072,6 +1054,7 @@ export class TikTokScraper extends EventEmitter { const videoItem = { id: videoData.id, + secretID: videoData.video.id, text: videoData.desc, createTime: videoData.createTime, authorMeta: { diff --git a/src/types/TikTok.ts b/src/types/TikTok.ts index 6cf6c100..95399a43 100644 --- a/src/types/TikTok.ts +++ b/src/types/TikTok.ts @@ -89,6 +89,7 @@ export interface Hashtags { export interface PostCollector { id: string; + secretID: string; text: string; createTime: number; authorMeta: {