Skip to content

Commit

Permalink
fix(audio): mp4 audio only files
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 29, 2023
1 parent d1f8bce commit c5b7a01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/metascraper-audio/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const toAudioFromDom = toRule((domNodes, opts) => {
.get(1)
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
.replace('mpeg', 'mp3')
/* mp4 is commonly used for video */
.replace('mp4', 'mp3')
.value()
}))
.uniqWith(isEqual)
Expand Down
15 changes: 15 additions & 0 deletions packages/metascraper-audio/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,18 @@ test('`audio > source:src` with content type and relative src', async t => {
'https://www.theverge.com/2018/1/22/16921092/audio-small'
)
})

test('`audio > source:src` with mp4 mime type', async t => {
const html = `
<audio controls>
<source type="audio/mp4" src="https://cdn.microlink.io/file-examples/sample-audio.mp4">
</audio>
`
const url = 'https://metascraper.js.org'
const metascraper = createMetascraper()
const metadata = await metascraper({ html, url })
t.is(
metadata.audio,
'https://cdn.microlink.io/file-examples/sample-audio.mp4'
)
})

0 comments on commit c5b7a01

Please sign in to comment.