From ff585584f6c3f0ac1cf80a7c17d76e48ae6d4d98 Mon Sep 17 00:00:00 2001 From: n1073645 Date: Wed, 18 Mar 2020 12:51:47 +0000 Subject: [PATCH] MP3 Extractor --- src/core/lib/FileSignatures.mjs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/lib/FileSignatures.mjs b/src/core/lib/FileSignatures.mjs index 7ec0af21..f6f2c80f 100644 --- a/src/core/lib/FileSignatures.mjs +++ b/src/core/lib/FileSignatures.mjs @@ -780,7 +780,7 @@ export const FILE_SIGNATURES = { 1: 0xfb } ], - extractor: null + extractor: extractMP3 }, { name: "MPEG-4 Part 14 audio", @@ -3067,6 +3067,30 @@ export function extractWAV(bytes, offset) { } +/** + * MP3 extractor. + * + * @param {Uint8Array} bytes + * @param {Number} offset + * @returns {Uint8Array} + */ +export function extractMP3(bytes, offset) { + const stream = new Stream(bytes.slice(offset)); + + if (stream.readInt(1) === 0xff) { + console.log("gggg"); + } else if (stream.getBytes(3) === [0x49, 0x44, 0x33]) { + stream.moveTo(6); + const tagSize = (stream.readInt(1)<<23) | (stream.readInt(1)<<15) | (stream.readInt(1)<<7) | stream.readInt(1); + stream.moveForwardsBy(tagSize); + + if (stream.getBytes(4) !== [0xff, 0xfb, 0x30, 0xc4]) + console.log("always bad"); + + } +} + + /** * FLV extractor. *