diff --git a/lib/id3v2/ID3v2Parser.ts b/lib/id3v2/ID3v2Parser.ts index 8f89c4d6..93c29ac9 100644 --- a/lib/id3v2/ID3v2Parser.ts +++ b/lib/id3v2/ID3v2Parser.ts @@ -104,7 +104,7 @@ export class ID3v2Parser { await (id3Header.flags.isExtendedHeader ? this.parseExtendedHeader() : this.parseId3Data(id3Header.size)); // Post process - const chapters = ID3v2Parser.mapId3v2Chapters(this.metadata.native[this.headerType], this.metadata.format.sampleRate); + const chapters = ID3v2Parser.mapId3v2Chapters(this.metadata.native[this.headerType]); this.metadata.setFormat('chapters', chapters); } @@ -178,10 +178,9 @@ export class ID3v2Parser { * This function expects the `native` tags already to contain parsed `CHAP` and `CTOC` frame values, * as produced by `FrameParser.readData`. */ - private static mapId3v2Chapters( - id3Tags: ITag[], - sampleRate?: number - ): IChapter[] | undefined { + private static mapId3v2Chapters(id3Tags?: ITag[]): IChapter[] | undefined { + + if (!id3Tags) return; const chapFrames = id3Tags.filter(t => t.id === 'CHAP') as any[] | undefined; if (!chapFrames?.length) return; diff --git a/test/samples/mp3/notags.mp3 b/test/samples/mp3/notags.mp3 new file mode 100644 index 00000000..40a38fb1 Binary files /dev/null and b/test/samples/mp3/notags.mp3 differ diff --git a/test/test-file-mp3.ts b/test/test-file-mp3.ts index 0ffcefc0..44da780e 100644 --- a/test/test-file-mp3.ts +++ b/test/test-file-mp3.ts @@ -24,6 +24,14 @@ describe('Parse MP3 files', () => { const mp3SamplePath = path.join(samplePath, 'mp3'); + it('should handle MP3 without any tags', async () => { + const filePath = path.join(mp3SamplePath, 'notags.mp3'); + const {format, native} = await mm.parseFile(filePath, {includeChapters: true}); + assert.strictEqual(format.container, 'MPEG'); + assert.strictEqual(format.codec, 'MPEG 2 Layer 3'); + assert.strictEqual(Object.keys(native).length, 0, 'Should be empty'); + }); + describe('Test patterns for ISO/MPEG ', () => { it.skip('ISO/MPEG 1 Layer 1', async () => {