Closed Borewit closed 4 months ago
I think it caused by https://github.com/Borewit/peek-readable/issues/724
parseBlob()
works now, but I still get the same error from parseWebStream()
for mkv files (mp4 works fine!)
TypeError: Cannot read properties of undefined (reading 'docType')
at MatroskaParser.parse (MatroskaParser.js:50:68)
at async parse (ParserFactory.js:57:5)
at async retrieveMetadata (index.js:3166:16)
Thanks for testing @hvianna .
The only way I have tested web streams is via Blob.toStream().
How do you turn that file into a Web Stream and get to the error?
@Borewit
I'm using JS-native fetch()
, which offers a ReadableStream via response.body
.
You can use the simple HTML file below to test it. No need for webpack, just serve it via a local webserver for fetch to work.
<!DOCTYPE html>
<html>
<body>
<script type="module">
import { parseWebStream } from 'https://cdn.skypack.dev/music-metadata?min';
fetch('test.mkv')
.then( response => parseWebStream( response.body, response.headers.get('content-type'), { skipPostHeaders: true } ) )
.then( metadata => console.log( metadata ) );
</script>
</body>
</html>
This is working fine for mp4 and flac files, but throws that error for mkv.
Workaround for the issue you experience is, to parse the content-length to the parser.
import { parseWebStream } from 'music-metadata';
async function parseMetadata(url) {
console.info('Fetching ' + url);
const response = await fetch(url);
const contentType = response.headers.get('Content-Type');
const contentLength = response.headers.get('Content-Length');
console.info('Content-type = ' + contentType);
const metadata = await parseWebStream(response.body, {mimeType: contentType, size: contentLength ? parseInt(contentLength) : undefined});
console.info('Got metadata');
console.info(metadata);
}
parseMetadata('../sample/5.1 Surround Test (AAC).mkv').catch(error => {
console.error(error);
});
I am getting errors for
.webm
and.mkv
.using
parseWebStream()
:using
parseBlob()
:Originally posted by @hvianna in https://github.com/Borewit/music-metadata/issues/2135#issuecomment-2226079597
Yes, same error. I tried with a few video formats (webm, mkv, mp4)..
Fileinfo of one of them: