File tree Expand file tree Collapse file tree
packages/metascraper-tiktok Expand file tree Collapse file tree Original file line number Diff line number Diff 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 = $ (
Original file line number Diff line number Diff 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+ } )
You can’t perform that action at this time.
0 commit comments