From 5cea1cd756cd801903c04f3eb66bdddd0a7fb67c Mon Sep 17 00:00:00 2001 From: dargy Date: Fri, 15 Mar 2024 18:29:10 -0500 Subject: [PATCH] minor: switch from /generate/video to tiktok api /v1/play not removing /generate/video from index.ts to ensure that old urls stay working --- src/index.ts | 5 ----- src/templates/pages/VideoResponse.tsx | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 792a858..a3ae46b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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({ diff --git a/src/templates/pages/VideoResponse.tsx b/src/templates/pages/VideoResponse.tsx index f587ba6..86c12a3 100644 --- a/src/templates/pages/VideoResponse.tsx +++ b/src/templates/pages/VideoResponse.tsx @@ -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 ( <> { @@ -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',