Skip to content

Commit

Permalink
feat: add age restriction warning #12
Browse files Browse the repository at this point in the history
  • Loading branch information
okdargy committed Aug 13, 2024
1 parent 977eb78 commit e2fcc44
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 14 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ Don't want all that statistic clutter on your embed and only want the video or i

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.

| | [tnktok.com](https://www.tnktok.com) | Default TikTok | [tiktxk.com](https://tiktxk.com) | [vxtiktok.com](https://vxtiktok.com) | [tfxktok.com](https://tfxktok.com) |
| -------------------------------------- | -------------------------------------------------- | -------------- | -------------------------------- | ----------------------------------------------------------------------------- | ---------------------------------- |
| Embed playable videos | ☑️ ||| ☑️ | ☑️ |
| Embed multi-image slideshows | ☑️ | | | [](https://github.com/dylanpdx/vxtiktok/issues/142#issuecomment-2128030983) | ☑️ |
| Embed lives | ☑️ ||| | ☑️ |
| Open source | ☑️ || ☑️ | ☑️ ||
| Supports direct embeds | [](https://github.com/okdargy/fxTikTok/issues/9) | | | ||
| Shows like, shares, comments | ☑️ ||| ☑️ | ☑️ |
| Removes tracking for redirects | ☑️ || ☑️ | ☑️ | ☑️ |
| Support for multi-continent short URLs | [☑️](https://github.com/okdargy/fxTikTok/issues/5) | ☑️ | ☑️ | ☑️ ||
| Support for h265/high quality | ☑️ ||| ||
| Last commit | [![][tnk]][tnkc] | N/A | [![][txk]][txkc] | [![][vxt]][vxtc] | N/A |
| | [tnktok.com](https://www.tnktok.com) | Default TikTok | [tiktxk.com](https://tiktxk.com) | [vxtiktok.com](https://vxtiktok.com) | [tfxktok.com](https://tfxktok.com) |
| -------------------------------------- | ------------------------------------ | -------------- | -------------------------------- | ------------------------------------ | ---------------------------------- |
| Embed playable videos | ☑️ ||| ☑️ | ☑️ |
| Embed multi-image slideshows | ☑️ | | | | ☑️ |
| Embed lives | ☑️ |||| ☑️ |
| Open source | ☑️ || ☑️ | ☑️ ||
| Supports direct embeds | ☑️ | || ||
| Shows like, shares, comments | ☑️ ||| ☑️ | ☑️ |
| Removes tracking for redirects | ☑️ || ☑️ | ☑️ | ☑️ |
| Support for multi-continent short URLs | ☑️ | ☑️ | ☑️ | ☑️ ||
| Support for h265/high quality | ☑️ |||||
| Last commit | [![][tnk]][tnkc] | N/A | [![][txk]][txkc] | [![][vxt]][vxtc] | N/A |

[tnk]: https://img.shields.io/github/last-commit/okdargy/fxTikTok?label
[tnkc]: https://github.com/okdargy/fxTikTok/commits
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cache } from 'hono/cache'

import { scrapeLiveData, scrapeVideoData } from './services/tiktok'
import { grabAwemeId } from './services/tiktok'
import { VideoResponse, ErrorResponse, LiveResponse } from './templates'
import { VideoResponse, ErrorResponse, LiveResponse, WarningResponse } from './templates'
import generateAlternate from './util/generateAlternate'
import { returnHTMLResponse } from './util/responseHelper'

Expand Down Expand Up @@ -141,6 +141,11 @@ async function handleVideo(c: any): Promise<Response> {
})
}
} else {
if (videoInfo.isContentClassified === true) {
const responseContent = await WarningResponse('Sensitive Content', 'the video being age-restricted')
return returnHTMLResponse(responseContent, 200)
}

const responseContent = await VideoResponse(videoInfo)
return returnHTMLResponse(responseContent)
}
Expand Down
1 change: 1 addition & 0 deletions src/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './pages/VideoResponse'
export * from './pages/Error'
export * from './pages/LiveResponse'
export * from './pages/WarningResponse'
1 change: 0 additions & 1 deletion src/templates/pages/Error.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AwemeList } from '../../types/API'
import MetaHelper from '../../util/metaHelper'

export function ErrorResponse(error: string): JSX.Element {
Expand Down
22 changes: 22 additions & 0 deletions src/templates/pages/WarningResponse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import MetaHelper from '../../util/metaHelper'

export function WarningResponse(title: string, reason: string): JSX.Element {
return (
<>
{MetaHelper([
{
name: 'og:title',
content: `⚠️ ${title}`
},
{
name: 'theme-color',
content: '#f7c500'
},
{
name: 'og:description',
content: `Sorry, we were unable to show this video due to ${reason}. If you would like to view the video, please visit TikTok directly.`
}
])}
</>
)
}
16 changes: 16 additions & 0 deletions src/tests/video.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ describe('GET /@i/video/:videoId', () => {
})
})

// age restricted video
describe('GET /@i/video/:videoId (age restricted)', () => {
// /t/ZP81NmQk9/
it('should return 200', async () => {
const res = await app.request('/t/ZP81NmQk9', {
method: 'GET',
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)'
}
})

expect(res.status).toBe(200)
expect(await res.text()).toContain('⚠️')
})
})

describe('GET /t/:videoId', () => {
it('should return 200', async () => {
const res = await app.request('/t/ZPRKrbUB1', {
Expand Down
1 change: 1 addition & 0 deletions src/types/Web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2899,6 +2899,7 @@ export interface ItemStruct {
collected: boolean
channelTags: any[]
item_control: ItemControl
isContentClassified: boolean
IsAigc: boolean
AIGCDescription: string
}
Expand Down

0 comments on commit e2fcc44

Please sign in to comment.