Skip to content

Commit

Permalink
Map tag ID3v2.2 TBP to common.bpm
Browse files Browse the repository at this point in the history
Also ensures `common.bpm` is a numeric value.
  • Loading branch information
Borewit committed Jan 12, 2022
1 parent feb15be commit 48f9571
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/common/MetadataCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class MetadataCollector implements INativeMetadataCollector {
this.common[tag.id].of = of != null ? of : this.common[tag.id].of;
return;

case 'bpm':
case 'year':
case 'originalyear':
tag.value = parseInt(tag.value, 10);
Expand Down
5 changes: 4 additions & 1 deletion lib/id3v2/ID3v22TagMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export const id3v22TagMap: INativeTagMap = {
TSC: 'composersort',
TSP: 'artistsort',
TST: 'titlesort',
WFD: 'podcasturl'
WFD: 'podcasturl',

TBP: 'bpm'

};

export class ID3v22TagMapper extends CaseInsensitiveTagMap {
Expand Down
Binary file added test/samples/mp3/Betty Lou.mp3
Binary file not shown.
17 changes: 17 additions & 0 deletions test/test-id3v2.2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ describe('ID3v2Parser', () => {
assert.strictEqual(pics[0].type, 'Cover (front)', 'picture type');
});

describe('Tag mapping', () => {

it("TBP (beats per minute)", async () => {

const filePath = path.join(samplePath, 'mp3', 'Betty Lou.mp3');

const {format, common, native} = await mm.parseFile(filePath, {duration: true});
assert.strictEqual(format.container, 'MPEG', 'format.container');
assert.strictEqual(format.codec, 'MPEG 1 Layer 3', 'format.codec');

assert.strictEqual(common.title, 'Betty Lou', 'common.title');
assert.strictEqual(common.artist, 'The Hub Caps', 'common.artist,');

assert.strictEqual(common.bpm, 177, 'common.bpm,');
});
});

});

describe('Post parse genre', () => {
Expand Down

0 comments on commit 48f9571

Please sign in to comment.