mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 17:49:16 +02:00
Add support for FLAC in sniffer and codecs package.
This commit is contained in:
parent
44beb992bf
commit
303c635b90
5 changed files with 17 additions and 4 deletions
|
@ -51,9 +51,11 @@ export function getShortMIMEString(info) {
|
|||
if (!info) throw `Invalid ProbeInfo`;
|
||||
if (!info.streams || info.streams.length === 0) throw `No streams in ProbeInfo`;
|
||||
|
||||
// mp3 files are always considered audio/.
|
||||
// mp3/flac files are always considered audio/ (even with mjpeg video streams).
|
||||
if (info.format.format_name === 'mp3') {
|
||||
return 'audio/mpeg';
|
||||
} else if (info.format.format_name === 'flac') {
|
||||
return 'audio/flac';
|
||||
}
|
||||
|
||||
// Otherwise, any file with at least 1 video stream is considered video/.
|
||||
|
@ -106,8 +108,9 @@ export function getShortMIMEString(info) {
|
|||
export function getFullMIMEString(info) {
|
||||
/** A string like 'video/mp4' */
|
||||
let contentType = `${getShortMIMEString(info)}`;
|
||||
// If MP3, just send back the type.
|
||||
if (contentType === 'audio/mpeg') {
|
||||
// If MP3/FLAC, just send back the type.
|
||||
if (contentType === 'audio/mpeg'
|
||||
|| contentType === 'audio/flac') {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
|
@ -124,6 +127,7 @@ export function getFullMIMEString(info) {
|
|||
case 'opus': codecFrags.add('opus'); break;
|
||||
// I'm going off of what Chromium calls this one, with the dash.
|
||||
case 'ac3': codecFrags.add('ac-3'); break;
|
||||
case 'flac': codecFrags.add('flac'); break;
|
||||
default:
|
||||
throw `Could not handle codec_name ${stream.codec_name}, ` +
|
||||
`codec_tag_string ${stream.codec_tag_string} for file ${info.format.filename} yet. ` +
|
||||
|
|
|
@ -31,6 +31,7 @@ const fileSignatures = {
|
|||
'image/webp': [[0x52, 0x49, 0x46, 0x46, '??', '??', '??', '??', 0x57, 0x45, 0x42, 0x50]],
|
||||
// Audio/Video formats.
|
||||
'application/ogg': [[0x4F, 0x67, 0x67, 0x53]],
|
||||
'audio/flac': [[0x66, 0x4C, 0x61, 0x43]],
|
||||
'audio/mpeg': [[0xFF, 0xFB], [0xFF, 0xF3], [0xFF, 0xF2], [0x49, 0x44, 0x33]],
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@codedread/bitjs",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.9",
|
||||
"description": "Binary Tools for JavaScript",
|
||||
"homepage": "https://github.com/codedread/bitjs",
|
||||
"author": "Jeff Schiller",
|
||||
|
|
|
@ -47,6 +47,13 @@ describe('codecs test suite', () => {
|
|||
})).equals('audio/mpeg');
|
||||
});
|
||||
|
||||
it('detects FLAC', () => {
|
||||
expect(getShortMIMEString({
|
||||
format: { format_name: 'flac' },
|
||||
streams: [ { codec_type: 'audio'}, { codec_type: 'video' } ],
|
||||
})).equals('audio/flac');
|
||||
});
|
||||
|
||||
it('detects AVI video', () => {
|
||||
expect(getShortMIMEString({
|
||||
format: { format_name: 'avi' },
|
||||
|
|
|
@ -36,4 +36,5 @@ describe('bitjs.file.sniffer', () => {
|
|||
it('OGG', () => { sniffTest('application/ogg', [0x4F, 0x67, 0x67, 0x53]); });
|
||||
it('TAR_1', () => { sniffTest('application/x-tar', [0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30]); });
|
||||
it('TAR_2', () => { sniffTest('application/x-tar', [0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00]); });
|
||||
it('FLAC', () => { sniffTest('audio/flac', [0x66, 0x4C, 0x61, 0x43]); });
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue