Skip to content

Commit

Permalink
minor: switch from /generate/video to tiktok api /v1/play
Browse files Browse the repository at this point in the history
not removing /generate/video from index.ts to ensure that old urls stay working
  • Loading branch information
okdargy committed Mar 15, 2024
1 parent 7156155 commit 5cea1cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ app.get('/generate/alternate', (c) => {
})
})

function getExpiry(url: URL) {
const hex = new URL(url).pathname.split('/')[2];
return new Date(parseInt(hex, 16) * 1000);
}

app.get(
'/generate/*',
cache({
Expand Down
17 changes: 16 additions & 1 deletion src/templates/pages/VideoResponse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ import { AwemeList } from '../../types/Services';
import MetaHelper from '../../util/MetaHelper';

export function VideoResponse(data: AwemeList): JSX.Element {
let videoUrl = 'https://fxtiktok-rewrite.dargy.workers.dev/generate/video/' + data.aweme_id

if(data.video.duration > 0) {
const awemeVideo = data.video.download_addr.url_list.find((url) => url.includes('/aweme/v1/play'))

if (awemeVideo) {
const url = new URL(awemeVideo)

const videoId = url.searchParams.get('video_id')
const fileId = url.searchParams.get('file_id')

videoUrl = `https://${url.hostname}/aweme/v1/play/?video_id=${videoId}&file_id=${fileId}&item_id=${data.aweme_id}`
}
}

return (
<>
{
Expand Down Expand Up @@ -40,7 +55,7 @@ export function VideoResponse(data: AwemeList): JSX.Element {
},
{
name: `og:${data.video.duration !== 0 ? 'video' : 'image'}`,
content: `https://fxtiktok-rewrite.dargy.workers.dev/generate/${data.video.duration !== 0 ? 'video' : 'image'}/` + data.aweme_id
content: `${data.video.duration !== 0 ? videoUrl : 'https://fxtiktok-rewrite.dargy.workers.dev/generate/image/' + data.aweme_id}`
},
{
name: 'og:type',
Expand Down

0 comments on commit 5cea1cd

Please sign in to comment.