Skip to content

Commit f92682a

Browse files
authored
fix(tiktok): fallback date parsing when video id is invalid (#807)
1 parent ceede91 commit f92682a

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

packages/metascraper-tiktok/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ module.exports = () => {
5151
date: [
5252
toDate((_, url) => {
5353
const id = url.split('/video/')[1]?.split('?')[0]
54-
return id ? getTimestampFromId(id) : undefined
54+
if (!id || !/^\d+$/.test(id)) return
55+
return getTimestampFromId(id)
5556
}),
5657
toDate($ => {
5758
const content = $(

packages/metascraper-tiktok/test/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ test('from profile', async t => {
3535
const metadata = await metascraper({ url, html })
3636
t.snapshot(metadata)
3737
})
38+
39+
test('fallback date extraction when video id is invalid', async t => {
40+
const html = await readFile(resolve(__dirname, 'fixtures/video.html'))
41+
const metascraper = createMetascraper()
42+
43+
const metadata = await metascraper({
44+
url: 'https://www.tiktok.com/@illojuan/video/not-a-number',
45+
html
46+
})
47+
48+
t.truthy(metadata.date)
49+
})

0 commit comments

Comments
 (0)