Skip to content

Commit

Permalink
feat: combining modes @Apocolypto
Browse files Browse the repository at this point in the history
  • Loading branch information
okdargy committed Jan 21, 2025
1 parent 6ccceb6 commit 793a83e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/run-jest.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Run Unit Tests with Jest

on:
push:
branches:
- main
- master
- hono-rewrite
pull_request:
branches:
- main
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ However, we want to give users the option to add it in case it brings additional
TikTok supports H.265/HEVC (High Efficiency Video Coding) which offers significantly better quality at the same file size compared to H.264, at the cost of compatibility. By default, we use H.264 quality since [many users report issues with embeds breaking with H.265](https://github.com/okdargy/fxTikTok/issues/14), but support enabling H.265.

To enable high quality H.265 playback, add `?hq=true` or use `hq.tnktok.com`:
| Before | After |
| Before | After |
| :--------------------: | :------------------: |
| **www**.t**i**ktok.com | **hq**.t**n**ktok.com |

### Combining Modes

You can combine different modes by using specific hostnames or URL query parameters. For example, if you want to enable H.265 and also see the caption, you can use `hq.a.tnktok.com` or add `?hq=true&addDesc=true` to the URL.

> You cannot use Direct Mode and Caption Mode simultaneously since they contradict themselves.
### Why use tnktok.com?

We check all the boxes for being one of the best TikTok embedding services with many features that others don't have. Here's a table comparing our service, tnktok.com, with the other TikTok embedding services as well as TikTok's default embeds.
Expand Down
27 changes: 18 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,26 @@ async function handleVideo(c: any): Promise<Response> {
const extensions = ['mp4', 'png', 'jpg', 'jpeg', 'webp', 'webm']

if (
url.hostname.includes('d.tnktok.com') ||
url.hostname.includes('d.') ||
c.req.query('isDirect') === 'true' ||
extensions.some((suffix) => c.req.path.endsWith(suffix))
) {
if (videoInfo.video.duration > 0) {
return new Response('', {
status: 302,
headers: {
Location: 'https://fxtiktok-rewrite.dargy.workers.dev/generate/video/' + videoInfo.id
}
})
if ((hq || 'false').toLowerCase() == 'true' || url.hostname.includes('hq.')) {
return new Response('', {
status: 302,
headers: {
Location: 'https://fxtiktok-rewrite.dargy.workers.dev/generate/video/' + videoInfo.id + '?hq=true'
}
})
} else {
return new Response('', {
status: 302,
headers: {
Location: 'https://fxtiktok-rewrite.dargy.workers.dev/generate/video/' + videoInfo.id
}
})
}
} else {
return new Response('', {
status: 302,
Expand All @@ -126,8 +135,8 @@ async function handleVideo(c: any): Promise<Response> {

const responseContent = await VideoResponse(
videoInfo,
(addDesc || 'false').toLowerCase() == 'true' || url.hostname.includes('a.tnktok.com'),
(url.hostname.includes('hq.tnktok.com') || (hq || 'false').toLowerCase() == 'true')
(addDesc || 'false').toLowerCase() == 'true' || url.hostname.includes('a.'),
(hq || 'false').toLowerCase() == 'true' || url.hostname.includes('hq.')
)
return returnHTMLResponse(responseContent)
}
Expand Down
3 changes: 2 additions & 1 deletion src/services/tiktok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export async function scrapeVideoData(awemeId: string, author?: string): Promise
method: 'GET',
headers: {
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0',
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36',
Cookie: cookie.getCookiesAsString()
},
cf: {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './pages/VideoResponse'
export * from './pages/Error'
export * from './pages/LiveResponse'
export * from './pages/WarningResponse'
export * from './pages/Message'
export * from './pages/Message'
16 changes: 6 additions & 10 deletions src/util/responseHelper.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
export const returnHTMLResponse = (
content: string,
status?: number,
noCache?: boolean,
): Response => {
export const returnHTMLResponse = (content: string, status?: number, noCache?: boolean): Response => {
return new Response(content, {
status: status || 200,
headers: {
"Content-Type": "text/html; charset=utf-8",
"Cache-Control": noCache ? "no-store" : "public, max-age=3600",
},
});
};
'Content-Type': 'text/html; charset=utf-8',
'Cache-Control': noCache ? 'no-store' : 'public, max-age=3600'
}
})
}

0 comments on commit 793a83e

Please sign in to comment.