Skip to content

Commit

Permalink
Add RIFF/EXIF to common mapping.
Browse files Browse the repository at this point in the history
Related issue #83, #28.
  • Loading branch information
Borewit committed Apr 26, 2018
1 parent f5df95f commit 2c159e9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/common/GenericTagTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type TagType = 'vorbis' | 'ID3v1.1' | 'ID3v2.2' | 'ID3v2.3' | 'ID3v2.4' | 'APEv2' | 'asf' | 'iTunes MP4';
export type TagType = 'vorbis' | 'ID3v1.1' | 'ID3v2.2' | 'ID3v2.3' | 'ID3v2.4' | 'APEv2' | 'asf' | 'iTunes MP4' | 'exif';

export type CommonTag =
'track'
Expand Down Expand Up @@ -99,7 +99,7 @@ export type CommonTag =
'replaygain_track_gain'
| 'replaygain_track_peak';

export const TagPriority = ['APEv2', 'vorbis', 'ID3v2.4', 'ID3v2.3', 'ID3v2.2', 'asf', 'iTunes MP4', 'ID3v1.1'];
export const TagPriority = ['APEv2', 'vorbis', 'ID3v2.4', 'ID3v2.3', 'ID3v2.2', 'exif', 'asf', 'iTunes MP4', 'ID3v1.1'];

export interface INativeTagMap {
[index: string]: CommonTag;
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {APEv2TagMapper} from "./apev2/APEv2TagMapper";
import {ID3v22TagMapper} from "./id3v2/ID3v22TagMapper";
import {ID3v1TagMapper} from "./id3v1/ID3v1TagMap";
import {AsfTagMapper} from "./asf/AsfTagMapper";
import {RiffInfoTagMapper} from "./riff/RiffInfoTagMap";

export interface IPicture {
format: string,
Expand Down Expand Up @@ -259,7 +260,8 @@ export class CombinedTagMapper {
new MP4TagMapper(),
new VorbisTagMapper(),
new APEv2TagMapper(),
new AsfTagMapper()
new AsfTagMapper(),
new RiffInfoTagMapper()
].forEach(mapper => {
this.registerTagMapper(mapper);
});
Expand Down
24 changes: 22 additions & 2 deletions src/riff/RiffInfoTagMap.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
import {INativeTagMap} from "../common/GenericTagTypes";
import {CommonTagMapper} from "../common/GenericTagMapper";

/**
* RIFF Info Tags; part of the EXIF 2.3
* Ref: http://owl.phy.queensu.ca/~phil/exiftool/TagNames/RIFF.html#Info
*/
export const RiffInfoTagMap: INativeTagMap = {
export const riffInfoTagMap: INativeTagMap = {
IART: 'artist', // Artist
ICRD: 'date', // DateCreated
INAM: 'title', // Title
TITL: 'title',
IPRD: 'album', // Product
ITRK: 'track'
ITRK: 'track',
COMM: 'comment', // Comments
ICMT: 'comment', // Country
ICNT: 'releasecountry',
GNRE: 'genre', // Genre
IWRI: 'writer', // WrittenBy
RATE: '_rating',
YEAR: 'year',
ISFT: 'encodedby', // Software
CODE: 'encodedby', // EncodedBy
TURL: 'website' // URL
// ITCH: 'technician' //Technician
};

export class RiffInfoTagMapper extends CommonTagMapper {

public constructor() {
super(['exif'], riffInfoTagMap);
}
}
29 changes: 29 additions & 0 deletions test/test_riff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ describe("Extract metadata from RIFF (Resource Interchange File Format)", () =>
});
});

// Issue https://github.com/Borewit/music-metadata/issues/75
it("should map RIFF tags to common", () => {

const filePath = path.join(__dirname, "samples", "issue_83.wav");

return mm.parseFile(filePath, {duration: true, native: true}).then(metadata => {

const format = metadata.format;
assert.deepEqual(format.dataformat, "WAVE");
assert.deepEqual(format.bitsPerSample, 24);
assert.deepEqual(format.sampleRate, 48000);
assert.deepEqual(format.numberOfSamples, 29762);
assert.deepEqual(format.duration, 0.6200416666666667);
assert.deepEqual(format.tagTypes, [ 'exif' ]);

const exif = mm.orderTags(metadata.native.exif);
assert.deepEqual(exif.IART, ["FUCK ZORRO"]);
assert.deepEqual(exif.ICRD, ["2018-04-25T18:00:33-05:00"]);
assert.deepEqual(exif.ISFT, ["Adobe Audition CC 2018.1 (Macintosh)"]);

const common = metadata.common;
assert.deepEqual(common.artists, ["FUCK ZORRO"]);
assert.deepEqual(common.date, "2018-04-25T18:00:33-05:00");
assert.deepEqual(common.year, 2018);
assert.deepEqual(common.encodedby, "Adobe Audition CC 2018.1 (Macintosh)");

});
});

});

});

0 comments on commit 2c159e9

Please sign in to comment.