Skip to content

Commit

Permalink
fix: add "." for usernames & ignore query for url
Browse files Browse the repository at this point in the history
  • Loading branch information
okdargy committed Jan 2, 2024
1 parent a2d0c21 commit d4b7351
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/services/tiktok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { TikTokAPIResponse, AwemeList } from "../types/Services"
export async function grabAwemeId(videoId: string): Promise<String | Error> {
// https://vm.tiktok.com/ZMJmVWVpL/
const res = await fetch('https://vm.tiktok.com/' + videoId)

// find where res redirected us to tiktok.com 302 or tiktok.com/@username/video/awemeId with regex
const awemeIdPattern = /\/@[\w\d_]+\/video\/(\d{1,19})/
const match = res.url.match(awemeIdPattern)

const url = new URL(res.url)

const awemeIdPattern = /\/@[\w\d_.]+\/video\/(\d{1,19})/
const match = url.pathname.match(awemeIdPattern)
console.log(url.pathname, match)
if (match) {
return match[1]
} else {
Expand Down

1 comment on commit d4b7351

@okdargy
Copy link
Owner Author

@okdargy okdargy commented on d4b7351 Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug fix that was particularly happening on vm.tiktok urls, in completion to #1

Please sign in to comment.