Skip to content

Commit

Permalink
Merge pull request drawrowfly#415 from Zipdox/master
Browse files Browse the repository at this point in the history
Fixed watermarkless extraction
  • Loading branch information
drawrowfly authored Jan 6, 2021
2 parents a4e83bc + 5370f68 commit 0a036b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
29 changes: 6 additions & 23 deletions src/core/TikTok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,29 +418,10 @@ export class TikTokScraper extends EventEmitter {
*/
// eslint-disable-next-line class-methods-use-this
private async extractVideoId(item: PostCollector): Promise<string | null> {
// 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` : ''
}`;

}

/**
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions src/types/TikTok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface DuetInfo {

export interface PostCollector {
id: string;
secretID: string;
text: string;
createTime: number;
authorMeta: {
Expand Down

0 comments on commit 0a036b4

Please sign in to comment.