Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/metascraper-instagram/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const test = memoizeOne(

const getDescription = memoizeOne(
(_, $) => $('meta[property="og:description"]').attr('content'),
memoizeOne.EqualityUrlAndHtmlDom
memoizeOne.EqualityFirstArgument
)

module.exports = () => {
Expand Down
19 changes: 0 additions & 19 deletions packages/metascraper-instagram/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,6 @@ test('from photo post', async t => {
t.snapshot(metadata)
})

test('does not reuse memoized description for same url with different html', async t => {
const url = 'https://www.instagram.com/p/CPeC-Eenc8l/'
const [photoHtml, videoHtml] = await Promise.all([
readFile(resolve(__dirname, 'fixtures/post-with-photo.html')),
readFile(resolve(__dirname, 'fixtures/post-with-video.html'))
])

const photoMetadata = await metascraper({ url, html: photoHtml })
const videoMetadataWithSameUrl = await metascraper({ url, html: videoHtml })
const videoMetadata = await metascraper({
url: 'https://www.instagram.com/p/CPQjO5RIIO9/',
html: videoHtml
})

t.truthy(photoMetadata.date)
t.not(videoMetadataWithSameUrl.date, photoMetadata.date)
t.is(videoMetadataWithSameUrl.date, videoMetadata.date)
})

test('from multi photo post', async t => {
const url = 'https://www.instagram.com/p/COn3M4TnRi1/'
const html = await readFile(
Expand Down
3 changes: 2 additions & 1 deletion packages/metascraper-tiktok/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports = () => {
date: [
toDate((_, url) => {
const id = url.split('/video/')[1]?.split('?')[0]
return id ? getTimestampFromId(id) : undefined
if (!id || !/^\d+$/.test(id)) return
return getTimestampFromId(id)
}),
toDate($ => {
const content = $(
Expand Down
13 changes: 12 additions & 1 deletion packages/metascraper-tiktok/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ test('from profile', async t => {
const html = await readFile(resolve(__dirname, 'fixtures/profile.html'))
const metascraper = createMetascraper()
const metadata = await metascraper({ url, html })
console.log(metadata)
t.snapshot(metadata)
})

test('fallback date extraction when video id is invalid', async t => {
const html = await readFile(resolve(__dirname, 'fixtures/video.html'))
const metascraper = createMetascraper()

const metadata = await metascraper({
url: 'https://www.tiktok.com/@illojuan/video/not-a-number',
html
})

t.truthy(metadata.date)
})
Loading