music-metadata
Advanced tools
Comparing version 0.9.3 to 0.9.4
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Common_1 = require("../common/Common"); | ||
var Util_1 = require("../common/Util"); | ||
var strtok3_1 = require("strtok3"); | ||
@@ -149,3 +149,3 @@ var Token = require("token-types"); | ||
offset += 4; | ||
var zero = Common_1.default.findZero(buffer, offset, buffer.length); | ||
var zero = Util_1.default.findZero(buffer, offset, buffer.length); | ||
var key = buffer.toString("ascii", offset, zero); | ||
@@ -168,3 +168,3 @@ offset = zero + 1; | ||
var off = 0; | ||
zero = Common_1.default.findZero(picData, off, picData.length); | ||
zero = Util_1.default.findZero(picData, off, picData.length); | ||
var description = picData.toString("utf8", off, zero); | ||
@@ -171,0 +171,0 @@ off = zero + 1; |
@@ -14,6 +14,6 @@ // ASF Objects | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Common_1 = require("../common/Common"); | ||
var Util_1 = require("../common/Util"); | ||
var Token = require("token-types"); | ||
var GUID_1 = require("./GUID"); | ||
var Util_1 = require("./Util"); | ||
var Util_2 = require("./Util"); | ||
var ID3v2_1 = require("../id3v2/ID3v2"); | ||
@@ -59,3 +59,3 @@ /** | ||
objectId: GUID_1.default.fromBin(new Token.BufferType(16).get(buf, off)), | ||
objectSize: Util_1.Util.readUInt64LE(buf, off + 16), | ||
objectSize: Util_2.Util.readUInt64LE(buf, off + 16), | ||
numberOfHeaderObjects: Token.UINT32_LE.get(buf, off + 24) | ||
@@ -75,3 +75,3 @@ // Reserved: 2 bytes | ||
objectId: GUID_1.default.fromBin(new Token.BufferType(16).get(buf, off)), | ||
objectSize: Util_1.Util.readUInt64LE(buf, off + 16) | ||
objectSize: Util_2.Util.readUInt64LE(buf, off + 16) | ||
}; | ||
@@ -111,11 +111,11 @@ } | ||
fileId: GUID_1.default.fromBin(buf, off), | ||
fileSize: Util_1.Util.readUInt64LE(buf, off + 16), | ||
creationDate: Util_1.Util.readUInt64LE(buf, off + 24), | ||
dataPacketsCount: Util_1.Util.readUInt64LE(buf, off + 32), | ||
playDuration: Util_1.Util.readUInt64LE(buf, off + 40), | ||
sendDuration: Util_1.Util.readUInt64LE(buf, off + 48), | ||
preroll: Util_1.Util.readUInt64LE(buf, off + 56), | ||
fileSize: Util_2.Util.readUInt64LE(buf, off + 16), | ||
creationDate: Util_2.Util.readUInt64LE(buf, off + 24), | ||
dataPacketsCount: Util_2.Util.readUInt64LE(buf, off + 32), | ||
playDuration: Util_2.Util.readUInt64LE(buf, off + 40), | ||
sendDuration: Util_2.Util.readUInt64LE(buf, off + 48), | ||
preroll: Util_2.Util.readUInt64LE(buf, off + 56), | ||
flags: { | ||
broadcast: Common_1.default.strtokBITSET.get(buf, off + 64, 24), | ||
seekable: Common_1.default.strtokBITSET.get(buf, off + 64, 25) | ||
broadcast: Util_1.default.strtokBITSET.get(buf, off + 64, 24), | ||
seekable: Util_1.default.strtokBITSET.get(buf, off + 64, 25) | ||
}, | ||
@@ -190,3 +190,3 @@ // flagsNumeric: Token.UINT32_LE.get(buf, off + 64), | ||
var end = pos + length_1; | ||
tags.push({ id: tagName, value: Util_1.Util.parseUnicodeAttr(buf.slice(pos, end)) }); | ||
tags.push({ id: tagName, value: Util_2.Util.parseUnicodeAttr(buf.slice(pos, end)) }); | ||
pos = end; | ||
@@ -218,3 +218,3 @@ } | ||
pos += 2; | ||
var name_1 = Util_1.Util.parseUnicodeAttr(buf.slice(pos, pos + nameLen)); | ||
var name_1 = Util_2.Util.parseUnicodeAttr(buf.slice(pos, pos + nameLen)); | ||
pos += nameLen; | ||
@@ -227,3 +227,3 @@ var valueType = buf.readUInt16LE(pos); | ||
pos += valueLen; | ||
var parseAttr = Util_1.Util.getParserForAttr(valueType); | ||
var parseAttr = Util_2.Util.getParserForAttr(valueType); | ||
if (!parseAttr) { | ||
@@ -251,4 +251,4 @@ throw new Error("unexpected value headerType: " + valueType); | ||
return { | ||
startTime: Util_1.Util.readUInt64LE(buf, off), | ||
endTime: Util_1.Util.readUInt64LE(buf, off + 8), | ||
startTime: Util_2.Util.readUInt64LE(buf, off), | ||
endTime: Util_2.Util.readUInt64LE(buf, off + 8), | ||
dataBitrate: buf.readInt32LE(off + 12), | ||
@@ -262,5 +262,5 @@ bufferSize: buf.readInt32LE(off + 16), | ||
flags: { | ||
reliableFlag: Common_1.default.strtokBITSET.get(buf, off + 40, 0), | ||
seekableFlag: Common_1.default.strtokBITSET.get(buf, off + 40, 1), | ||
resendLiveCleanpointsFlag: Common_1.default.strtokBITSET.get(buf, off + 40, 2) | ||
reliableFlag: Util_1.default.strtokBITSET.get(buf, off + 40, 0), | ||
seekableFlag: Util_1.default.strtokBITSET.get(buf, off + 40, 1), | ||
resendLiveCleanpointsFlag: Util_1.default.strtokBITSET.get(buf, off + 40, 2) | ||
}, | ||
@@ -302,7 +302,7 @@ // flagsNumeric: Token.UINT32_LE.get(buf, off + 64), | ||
pos += 4; | ||
var name_2 = Util_1.Util.parseUnicodeAttr(buf.slice(pos, pos + nameLen)); | ||
var name_2 = Util_2.Util.parseUnicodeAttr(buf.slice(pos, pos + nameLen)); | ||
pos += nameLen; | ||
var data = buf.slice(pos, pos + dataLen); | ||
pos += dataLen; | ||
var parseAttr = Util_1.Util.getParserForAttr(dataType); | ||
var parseAttr = Util_2.Util.getParserForAttr(dataType); | ||
if (!parseAttr) { | ||
@@ -309,0 +309,0 @@ throw new Error("unexpected value headerType: " + dataType); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Common_1 = require("../common/Common"); | ||
var Util_1 = require("../common/Util"); | ||
var Util = /** @class */ (function () { | ||
@@ -11,3 +11,3 @@ function Util() { | ||
Util.parseUnicodeAttr = function (buf) { | ||
return Common_1.default.stripNulls(Common_1.default.decodeString(buf, "utf16le")); | ||
return Util_1.default.stripNulls(Util_1.default.decodeString(buf, "utf16le")); | ||
}; | ||
@@ -14,0 +14,0 @@ Util.readUInt64LE = function (buf, offset) { |
@@ -13,3 +13,3 @@ 'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Common_1 = require("../common/Common"); | ||
var Util_1 = require("../common/Util"); | ||
var strtok3_1 = require("strtok3"); | ||
@@ -154,4 +154,4 @@ var Token = require("token-types"); | ||
return { | ||
lastBlock: Common_1.default.strtokBITSET.get(buf, off, 7), | ||
type: Common_1.default.getBitAllignedNumber(buf, off, 1, 7), | ||
lastBlock: Util_1.default.strtokBITSET.get(buf, off, 7), | ||
type: Util_1.default.getBitAllignedNumber(buf, off, 1, 7), | ||
length: Token.UINT24_BE.get(buf, off + 1) | ||
@@ -186,10 +186,10 @@ }; | ||
// (number of channels)-1. FLAC supports from 1 to 8 channels | ||
channels: Common_1.default.getBitAllignedNumber(buf, off + 12, 4, 3) + 1, | ||
channels: Util_1.default.getBitAllignedNumber(buf, off + 12, 4, 3) + 1, | ||
// bits per sample)-1. | ||
// FLAC supports from 4 to 32 bits per sample. Currently the reference encoder and decoders only support up to 24 bits per sample. | ||
bitsPerSample: Common_1.default.getBitAllignedNumber(buf, off + 12, 7, 5) + 1, | ||
bitsPerSample: Util_1.default.getBitAllignedNumber(buf, off + 12, 7, 5) + 1, | ||
// Total samples in stream. | ||
// 'Samples' means inter-channel sample, i.e. one second of 44.1Khz audio will have 44100 samples regardless of the number of channels. | ||
// A value of zero here means the number of total samples is unknown. | ||
totalSamples: Common_1.default.getBitAllignedNumber(buf, off + 13, 4, 36), | ||
totalSamples: Util_1.default.getBitAllignedNumber(buf, off + 13, 4, 36), | ||
// the MD5 hash of the file (see notes for usage... it's a littly tricky) | ||
@@ -196,0 +196,0 @@ fileMD5: new Token.BufferType(16).get(buf, off + 18) |
@@ -1,5 +0,4 @@ | ||
import { INativeTagMap } from "../tagmap"; | ||
/** | ||
* ID3v1 tag mappings | ||
*/ | ||
export declare const ID3v1TagMap: INativeTagMap; | ||
import { CommonTagMapper } from "../common/GenericTagMapper"; | ||
export declare class ID3v1TagMapper extends CommonTagMapper { | ||
constructor(); | ||
} |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var GenericTagMapper_1 = require("../common/GenericTagMapper"); | ||
/** | ||
* ID3v1 tag mappings | ||
*/ | ||
exports.ID3v1TagMap = { | ||
var id3v1TagMap = { | ||
title: 'title', | ||
@@ -15,1 +26,9 @@ artist: 'artist', | ||
}; | ||
var ID3v1TagMapper = /** @class */ (function (_super) { | ||
__extends(ID3v1TagMapper, _super); | ||
function ID3v1TagMapper() { | ||
return _super.call(this, ['ID3v1.1'], id3v1TagMap) || this; | ||
} | ||
return ID3v1TagMapper; | ||
}(GenericTagMapper_1.CommonTagMapper)); | ||
exports.ID3v1TagMapper = ID3v1TagMapper; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Common_1 = require("../common/Common"); | ||
var Util_1 = require("../common/Util"); | ||
var Token = require("token-types"); | ||
@@ -20,3 +20,3 @@ var ID3v2_1 = require("./ID3v2"); | ||
case 'IPLS':// v2.3: Involved people list | ||
var text = Common_1.default.decodeString(b.slice(1), encoding).replace(/\x00+$/, ''); | ||
var text = Util_1.default.decodeString(b.slice(1), encoding).replace(/\x00+$/, ''); | ||
// id3v2.4 defines that multiple T* values are separated by 0x00 | ||
@@ -44,3 +44,3 @@ // id3v2.3 defines that multiple T* values are separated by / | ||
description: output.id, | ||
text: FrameParser.splitValue(major, Common_1.default.decodeString(output.data, encoding).replace(/\x00+$/, '')) | ||
text: FrameParser.splitValue(major, Util_1.default.decodeString(output.data, encoding).replace(/\x00+$/, '')) | ||
}; | ||
@@ -55,3 +55,3 @@ break; | ||
case 2: | ||
pic.format = Common_1.default.decodeString(b.slice(offset, offset + 3), encoding); | ||
pic.format = Util_1.default.decodeString(b.slice(offset, offset + 3), encoding); | ||
offset += 3; | ||
@@ -62,4 +62,4 @@ break; | ||
var enc = 'iso-8859-1'; | ||
fzero = Common_1.default.findZero(b, offset, length, enc); | ||
pic.format = Common_1.default.decodeString(b.slice(offset, fzero), enc); | ||
fzero = Util_1.default.findZero(b, offset, length, enc); | ||
pic.format = Util_1.default.decodeString(b.slice(offset, fzero), enc); | ||
offset = fzero + 1; | ||
@@ -72,4 +72,4 @@ break; | ||
offset += 1; | ||
fzero = Common_1.default.findZero(b, offset, length, encoding); | ||
pic.description = Common_1.default.decodeString(b.slice(offset, fzero), encoding); | ||
fzero = Util_1.default.findZero(b, offset, length, encoding); | ||
pic.description = Util_1.default.decodeString(b.slice(offset, fzero), encoding); | ||
offset = fzero + nullTerminatorLength; | ||
@@ -93,5 +93,5 @@ pic.data = new Buffer(b.slice(offset, length)); | ||
while (offset < length) { | ||
var txt = b.slice(offset, offset = Common_1.default.findZero(b, offset, length, encoding)); | ||
var txt = b.slice(offset, offset = Util_1.default.findZero(b, offset, length, encoding)); | ||
offset += 5; // push offset forward one + 4 byte timestamp | ||
output.push(Common_1.default.decodeString(txt, encoding)); | ||
output.push(Util_1.default.decodeString(txt, encoding)); | ||
} | ||
@@ -104,8 +104,8 @@ break; | ||
offset += 1; | ||
out.language = Common_1.default.decodeString(b.slice(offset, offset + 3), 'iso-8859-1'); | ||
out.language = Util_1.default.decodeString(b.slice(offset, offset + 3), 'iso-8859-1'); | ||
offset += 3; | ||
fzero = Common_1.default.findZero(b, offset, length, encoding); | ||
out.description = Common_1.default.decodeString(b.slice(offset, fzero), encoding); | ||
fzero = Util_1.default.findZero(b, offset, length, encoding); | ||
out.description = Util_1.default.decodeString(b.slice(offset, fzero), encoding); | ||
offset = fzero + nullTerminatorLength; | ||
out.text = Common_1.default.decodeString(b.slice(offset, length), encoding).replace(/\x00+$/, ''); | ||
out.text = Util_1.default.decodeString(b.slice(offset, length), encoding).replace(/\x00+$/, ''); | ||
output = [out]; | ||
@@ -150,4 +150,4 @@ break; | ||
FrameParser.readIdentifierAndData = function (b, offset, length, encoding) { | ||
var fzero = Common_1.default.findZero(b, offset, length, encoding); | ||
var id = Common_1.default.decodeString(b.slice(offset, fzero), encoding); | ||
var fzero = Util_1.default.findZero(b, offset, length, encoding); | ||
var id = Util_1.default.decodeString(b.slice(offset, fzero), encoding); | ||
offset = fzero + FrameParser.getNullTerminatorLength(encoding); | ||
@@ -154,0 +154,0 @@ return { id: id, data: b.slice(offset, length) }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Common_1 = require("../common/Common"); | ||
var Util_1 = require("../common/Util"); | ||
var Token = require("token-types"); | ||
@@ -68,8 +68,8 @@ /** | ||
// Unsynchronisation | ||
unsynchronisation: Common_1.default.strtokBITSET.get(buf, off + 5, 7), | ||
unsynchronisation: Util_1.default.strtokBITSET.get(buf, off + 5, 7), | ||
// Extended header | ||
isExtendedHeader: Common_1.default.strtokBITSET.get(buf, off + 5, 6), | ||
isExtendedHeader: Util_1.default.strtokBITSET.get(buf, off + 5, 6), | ||
// Experimental indicator | ||
expIndicator: Common_1.default.strtokBITSET.get(buf, off + 5, 5), | ||
footer: Common_1.default.strtokBITSET.get(buf, off + 5, 4) | ||
expIndicator: Util_1.default.strtokBITSET.get(buf, off + 5, 5), | ||
footer: Util_1.default.strtokBITSET.get(buf, off + 5, 4) | ||
}, | ||
@@ -91,3 +91,3 @@ size: ID3v2Token.UINT32SYNCSAFE.get(buf, off + 6) | ||
// CRC data present | ||
crcDataPresent: Common_1.default.strtokBITSET.get(buf, off + 4, 31) | ||
crcDataPresent: Util_1.default.strtokBITSET.get(buf, off + 4, 31) | ||
}; | ||
@@ -94,0 +94,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var util_1 = require("util"); | ||
var Common_1 = require("../common/Common"); | ||
var Util_1 = require("../common/Util"); | ||
var Token = require("token-types"); | ||
@@ -72,12 +72,12 @@ var FrameParser_1 = require("./FrameParser"); | ||
status: { | ||
tag_alter_preservation: Common_1.default.strtokBITSET.get(b, 0, 6), | ||
file_alter_preservation: Common_1.default.strtokBITSET.get(b, 0, 5), | ||
read_only: Common_1.default.strtokBITSET.get(b, 0, 4) | ||
tag_alter_preservation: Util_1.default.strtokBITSET.get(b, 0, 6), | ||
file_alter_preservation: Util_1.default.strtokBITSET.get(b, 0, 5), | ||
read_only: Util_1.default.strtokBITSET.get(b, 0, 4) | ||
}, | ||
format: { | ||
grouping_identity: Common_1.default.strtokBITSET.get(b, 1, 7), | ||
compression: Common_1.default.strtokBITSET.get(b, 1, 3), | ||
encryption: Common_1.default.strtokBITSET.get(b, 1, 2), | ||
unsynchronisation: Common_1.default.strtokBITSET.get(b, 1, 1), | ||
data_length_indicator: Common_1.default.strtokBITSET.get(b, 1, 0) | ||
grouping_identity: Util_1.default.strtokBITSET.get(b, 1, 7), | ||
compression: Util_1.default.strtokBITSET.get(b, 1, 3), | ||
encryption: Util_1.default.strtokBITSET.get(b, 1, 2), | ||
unsynchronisation: Util_1.default.strtokBITSET.get(b, 1, 1), | ||
data_length_indicator: Util_1.default.strtokBITSET.get(b, 1, 0) | ||
} | ||
@@ -84,0 +84,0 @@ }; |
/// <reference types="node" /> | ||
import { TagType } from './tagmap'; | ||
import { TagType } from './common/GenericTagTypes'; | ||
import * as Stream from "stream"; | ||
import { IGenericTagMapper } from "./common/GenericTagMapper"; | ||
export interface IPicture { | ||
@@ -208,17 +209,26 @@ format: string; | ||
} | ||
/** | ||
* Combines all generic-tag-mappers for each tag type | ||
*/ | ||
export declare class CombinedTagMapper { | ||
tagMappers: { | ||
[index: string]: IGenericTagMapper; | ||
}; | ||
constructor(); | ||
/** | ||
* Process and set common tags | ||
* @param comTags Target metadata to | ||
* write common tags to | ||
* @param comTags Generic tag results (output of this function) | ||
* @param tag Native tag | ||
*/ | ||
setGenericTag(comTags: ICommonTagsResult, tagType: TagType, tag: ITag): void; | ||
private registerTagMapper(genericTagMapper); | ||
} | ||
export declare class MusicMetadataParser { | ||
static getInstance(): MusicMetadataParser; | ||
static toIntOrNull(str: string): number; | ||
static cleanupTrack(origVal: number | string): { | ||
no: number; | ||
of: number; | ||
}; | ||
static cleanupPicture(picture: any): { | ||
format: any; | ||
data: any; | ||
}; | ||
private tagMapper; | ||
/** | ||
* ToDo: move to respective format implementations | ||
*/ | ||
private tagMap; | ||
/** | ||
@@ -250,10 +260,2 @@ * Extract metadata from the given audio file | ||
parseNativeTags(nativeData: INativeAudioMetadata, includeNative?: boolean): IAudioMetadata; | ||
/** | ||
* Process and set common tags | ||
* @param comTags Target metadata to wrote common tags to | ||
* @param type Native tagTypes e.g.: 'iTunes MP4' | 'asf' | 'ID3v1.1' | 'ID3v2.4' | 'vorbis' | ||
* @param tag Native tag | ||
* @param value Native tag value | ||
*/ | ||
private setCommonTags(comTags, type, tag, value); | ||
} | ||
@@ -260,0 +262,0 @@ /** |
284
lib/index.js
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Common_1 = require("./common/Common"); | ||
var tagmap_1 = require("./tagmap"); | ||
var GenericTagTypes_1 = require("./common/GenericTagTypes"); | ||
var ParserFactory_1 = require("./ParserFactory"); | ||
var ID3v24TagMapper_1 = require("./id3v2/ID3v24TagMapper"); | ||
var MP4TagMapper_1 = require("./mp4/MP4TagMapper"); | ||
var VorbisTagMapper_1 = require("./vorbis/VorbisTagMapper"); | ||
var APEv2TagMapper_1 = require("./apev2/APEv2TagMapper"); | ||
var ID3v22TagMapper_1 = require("./id3v2/ID3v22TagMapper"); | ||
var ID3v1TagMap_1 = require("./id3v1/ID3v1TagMap"); | ||
var AsfTagMapper_1 = require("./asf/AsfTagMapper"); | ||
/** | ||
* Combines all generic-tag-mappers for each tag type | ||
*/ | ||
var CombinedTagMapper = /** @class */ (function () { | ||
function CombinedTagMapper() { | ||
var _this = this; | ||
this.tagMappers = {}; | ||
[ | ||
new ID3v1TagMap_1.ID3v1TagMapper(), | ||
new ID3v22TagMapper_1.ID3v22TagMapper(), | ||
new ID3v24TagMapper_1.ID3v24TagMapper(), | ||
new MP4TagMapper_1.MP4TagMapper(), | ||
new MP4TagMapper_1.MP4TagMapper(), | ||
new VorbisTagMapper_1.VorbisTagMapper(), | ||
new APEv2TagMapper_1.APEv2TagMapper(), | ||
new AsfTagMapper_1.AsfTagMapper() | ||
].forEach(function (mapper) { | ||
_this.registerTagMapper(mapper); | ||
}); | ||
} | ||
/** | ||
* Process and set common tags | ||
* @param comTags Target metadata to | ||
* write common tags to | ||
* @param comTags Generic tag results (output of this function) | ||
* @param tag Native tag | ||
*/ | ||
CombinedTagMapper.prototype.setGenericTag = function (comTags, tagType, tag) { | ||
var tagMapper = this.tagMappers[tagType]; | ||
if (tagMapper) { | ||
this.tagMappers[tagType].setGenericTag(comTags, tag); | ||
} | ||
else { | ||
throw new Error("No generic tag mapper defined for tag-format: " + tagType); | ||
} | ||
}; | ||
CombinedTagMapper.prototype.registerTagMapper = function (genericTagMapper) { | ||
for (var _i = 0, _a = genericTagMapper.tagTypes; _i < _a.length; _i++) { | ||
var tagType = _a[_i]; | ||
this.tagMappers[tagType] = genericTagMapper; | ||
} | ||
}; | ||
return CombinedTagMapper; | ||
}()); | ||
exports.CombinedTagMapper = CombinedTagMapper; | ||
var MusicMetadataParser = /** @class */ (function () { | ||
function MusicMetadataParser() { | ||
/** | ||
* ToDo: move to respective format implementations | ||
*/ | ||
/* | ||
private static headerTypes = [ | ||
{ | ||
buf: GUID.HeaderObject.toBin(), | ||
tag: require('./asf/AsfParser') | ||
}, | ||
{ | ||
buf: new Buffer('ID3'), | ||
tag: require('./id3v2') | ||
}, | ||
{ | ||
buf: new Buffer('ftypM4A'), | ||
tag: require('./id4'), | ||
offset: 4 | ||
}, | ||
{ | ||
buf: new Buffer('ftypmp42'), | ||
tag: require('./id4'), | ||
offset: 4 | ||
}, | ||
{ | ||
buf: new Buffer('OggS'), | ||
tag: require('./ogg') | ||
}, | ||
{ | ||
buf: new Buffer('fLaC'), | ||
tag: require('./flac') | ||
}, | ||
{ | ||
buf: new Buffer('MAC'), | ||
tag: require('./monkeysaudio') | ||
} | ||
];*/ | ||
this.tagMap = new tagmap_1.default(); | ||
this.tagMapper = new CombinedTagMapper(); | ||
} | ||
@@ -49,30 +64,39 @@ MusicMetadataParser.getInstance = function () { | ||
}; | ||
MusicMetadataParser.toIntOrNull = function (str) { | ||
var cleaned = parseInt(str, 10); | ||
return isNaN(cleaned) ? null : cleaned; | ||
}; | ||
// TODO: a string of 1of1 would fail to be converted | ||
// converts 1/10 to no : 1, of : 10 | ||
// or 1 to no : 1, of : 0 | ||
MusicMetadataParser.cleanupTrack = function (origVal) { | ||
var split = origVal.toString().split('/'); | ||
return { | ||
no: parseInt(split[0], 10) || null, | ||
of: parseInt(split[1], 10) || null | ||
}; | ||
}; | ||
MusicMetadataParser.cleanupPicture = function (picture) { | ||
var newFormat; | ||
if (picture.format) { | ||
var split = picture.format.toLowerCase().split('/'); | ||
newFormat = (split.length > 1) ? split[1] : split[0]; | ||
if (newFormat === 'jpeg') | ||
newFormat = 'jpg'; | ||
} | ||
else { | ||
newFormat = 'jpg'; | ||
} | ||
return { format: newFormat, data: picture.data }; | ||
}; | ||
/** | ||
* ToDo: move to respective format implementations | ||
*/ | ||
/* | ||
private static headerTypes = [ | ||
{ | ||
buf: GUID.HeaderObject.toBin(), | ||
tag: require('./asf/AsfParser') | ||
}, | ||
{ | ||
buf: new Buffer('ID3'), | ||
tag: require('./id3v2') | ||
}, | ||
{ | ||
buf: new Buffer('ftypM4A'), | ||
tag: require('./id4'), | ||
offset: 4 | ||
}, | ||
{ | ||
buf: new Buffer('ftypmp42'), | ||
tag: require('./id4'), | ||
offset: 4 | ||
}, | ||
{ | ||
buf: new Buffer('OggS'), | ||
tag: require('./ogg') | ||
}, | ||
{ | ||
buf: new Buffer('fLaC'), | ||
tag: require('./flac') | ||
}, | ||
{ | ||
buf: new Buffer('MAC'), | ||
tag: require('./monkeysaudio') | ||
} | ||
];*/ | ||
/** | ||
* Extract metadata from the given audio file | ||
@@ -127,3 +151,3 @@ * @param filePath File path of the audio file to parse | ||
} | ||
for (var _i = 0, TagPriority_1 = tagmap_1.TagPriority; _i < TagPriority_1.length; _i++) { | ||
for (var _i = 0, TagPriority_1 = GenericTagTypes_1.TagPriority; _i < TagPriority_1.length; _i++) { | ||
var tagType = TagPriority_1[_i]; | ||
@@ -133,3 +157,3 @@ if (nativeData.native[tagType]) { | ||
var tag = _b[_a]; | ||
this.setCommonTags(metadata.common, tagType, tag.id, tag.value); | ||
this.tagMapper.setGenericTag(metadata.common, tagType, tag); | ||
} | ||
@@ -155,126 +179,2 @@ break; | ||
}; | ||
/** | ||
* Process and set common tags | ||
* @param comTags Target metadata to wrote common tags to | ||
* @param type Native tagTypes e.g.: 'iTunes MP4' | 'asf' | 'ID3v1.1' | 'ID3v2.4' | 'vorbis' | ||
* @param tag Native tag | ||
* @param value Native tag value | ||
*/ | ||
MusicMetadataParser.prototype.setCommonTags = function (comTags, type, tag, value) { | ||
switch (type) { | ||
/* | ||
case 'vorbis': | ||
switch (tag) { | ||
case 'TRACKTOTAL': | ||
case 'TOTALTRACKS': // rare tag | ||
comTags.track.of = MusicMetadataParser.toIntOrNull(value) | ||
return | ||
case 'DISCTOTAL': | ||
case 'TOTALDISCS': // rare tag | ||
comTags.disk.of = MusicMetadataParser.toIntOrNull(value) | ||
return | ||
default: | ||
} | ||
break | ||
*/ | ||
case 'ID3v2.3': | ||
case 'ID3v2.4': | ||
switch (tag) { | ||
/* | ||
case 'TXXX': | ||
tag += ':' + value.description | ||
value = value.text | ||
break*/ | ||
case 'UFID':// decode MusicBrainz Recording Id | ||
if (value.owner_identifier === 'http://musicbrainz.org') { | ||
tag += ':' + value.owner_identifier; | ||
value = Common_1.default.decodeString(value.identifier, 'iso-8859-1'); | ||
} | ||
break; | ||
case 'PRIV': | ||
switch (value.owner_identifier) { | ||
// decode Windows Media Player | ||
case 'AverageLevel': | ||
case 'PeakValue': | ||
tag += ':' + value.owner_identifier; | ||
value = value.data.readUInt32LE(); | ||
break; | ||
default: | ||
} | ||
break; | ||
case 'MCDI': | ||
break; | ||
case 'COMM': | ||
value = value ? value.text : null; | ||
break; | ||
default: | ||
} | ||
break; | ||
default: | ||
} | ||
// Convert native tag event to common (aliased) event | ||
var alias = this.tagMap.getCommonName(type, tag); | ||
if (alias) { | ||
// Common tag (alias) found | ||
// check if we need to do something special with common tag | ||
// if the event has been aliased then we need to clean it before | ||
// it is emitted to the user. e.g. genre (20) -> Electronic | ||
switch (alias) { | ||
case 'genre': | ||
value = Common_1.default.parseGenre(value); | ||
break; | ||
case 'barcode': | ||
value = typeof value === 'string' ? parseInt(value, 10) : value; | ||
break; | ||
case 'picture': | ||
value = MusicMetadataParser.cleanupPicture(value); | ||
break; | ||
case 'totaltracks': | ||
comTags.track.of = MusicMetadataParser.toIntOrNull(value); | ||
return; | ||
case 'totaldiscs': | ||
comTags.disk.of = MusicMetadataParser.toIntOrNull(value); | ||
return; | ||
case 'track': | ||
case 'disk': | ||
var of = comTags[alias].of; // store of value, maybe maybe overwritten | ||
comTags[alias] = MusicMetadataParser.cleanupTrack(value); | ||
comTags[alias].of = of != null ? of : comTags[alias].of; | ||
return; | ||
case 'year': | ||
case 'originalyear': | ||
value = parseInt(value, 10); | ||
break; | ||
case 'date': | ||
// ToDo: be more strict on 'YYYY...' | ||
var year = parseInt(value.substr(0, 4), 10); | ||
if (year && !isNaN(year)) { | ||
comTags.year = year; | ||
} | ||
break; | ||
case 'discogs_release_id': | ||
value = typeof value === 'string' ? parseInt(value, 10) : value; | ||
break; | ||
case 'replaygain_track_peak': | ||
value = typeof value === 'string' ? parseFloat(value) : value; | ||
break; | ||
default: | ||
} | ||
if (alias !== 'artist' && tagmap_1.default.isSingleton(alias)) { | ||
comTags[alias] = value; | ||
} | ||
else { | ||
if (comTags.hasOwnProperty(alias)) { | ||
comTags[alias].push(value); | ||
} | ||
else { | ||
// if we haven't previously seen this tag then | ||
// initialize it to an array, ready for values to be entered | ||
comTags[alias] = [value]; | ||
} | ||
} | ||
} | ||
}; | ||
return MusicMetadataParser; | ||
@@ -281,0 +181,0 @@ }()); |
@@ -15,3 +15,3 @@ "use strict"; | ||
var strtok3_1 = require("strtok3"); | ||
var Common_1 = require("../common/Common"); | ||
var Util_1 = require("../common/Util"); | ||
var Token = require("token-types"); | ||
@@ -33,27 +33,27 @@ var es6_promise_1 = require("es6-promise"); | ||
// B(20,19): MPEG Audio versionIndex ID | ||
this.versionIndex = Common_1.default.getBitAllignedNumber(buf, off + 1, 3, 2); | ||
this.versionIndex = Util_1.default.getBitAllignedNumber(buf, off + 1, 3, 2); | ||
// C(18,17): Layer description | ||
this.layer = MpegFrameHeader.LayerDescription[Common_1.default.getBitAllignedNumber(buf, off + 1, 5, 2)]; | ||
this.layer = MpegFrameHeader.LayerDescription[Util_1.default.getBitAllignedNumber(buf, off + 1, 5, 2)]; | ||
if (this.layer === null) | ||
throw new Error("Invalid MPEG layer"); | ||
// D(16): Protection bit (if true 16-bit CRC follows header) | ||
this.isProtectedByCRC = !Common_1.default.isBitSet(buf, off + 1, 7); | ||
this.isProtectedByCRC = !Util_1.default.isBitSet(buf, off + 1, 7); | ||
// E(15,12): Bitrate index | ||
this.bitrateIndex = Common_1.default.getBitAllignedNumber(buf, off + 2, 0, 4); | ||
this.bitrateIndex = Util_1.default.getBitAllignedNumber(buf, off + 2, 0, 4); | ||
// F(11,10): Sampling rate frequency index | ||
this.sampRateFreqIndex = Common_1.default.getBitAllignedNumber(buf, off + 2, 4, 2); | ||
this.sampRateFreqIndex = Util_1.default.getBitAllignedNumber(buf, off + 2, 4, 2); | ||
// G(9): Padding bit | ||
this.padding = Common_1.default.isBitSet(buf, off + 2, 6); | ||
this.padding = Util_1.default.isBitSet(buf, off + 2, 6); | ||
// H(8): Private bit | ||
this.privateBit = Common_1.default.isBitSet(buf, off + 2, 7); | ||
this.privateBit = Util_1.default.isBitSet(buf, off + 2, 7); | ||
// I(7,6): Channel Mode | ||
this.channelModeIndex = Common_1.default.getBitAllignedNumber(buf, off + 3, 0, 2); | ||
this.channelModeIndex = Util_1.default.getBitAllignedNumber(buf, off + 3, 0, 2); | ||
// J(5,4): Mode extension (Only used in Joint stereo) | ||
this.modeExtension = Common_1.default.getBitAllignedNumber(buf, off + 3, 2, 2); | ||
this.modeExtension = Util_1.default.getBitAllignedNumber(buf, off + 3, 2, 2); | ||
// K(3): Copyright | ||
this.isCopyrighted = Common_1.default.isBitSet(buf, off + 3, 4); | ||
this.isCopyrighted = Util_1.default.isBitSet(buf, off + 3, 4); | ||
// L(2): Original | ||
this.isOriginalMedia = Common_1.default.isBitSet(buf, off + 3, 5); | ||
this.isOriginalMedia = Util_1.default.isBitSet(buf, off + 3, 5); | ||
// M(3): The original bit indicates, if it is set, that the frame is located on its original media. | ||
this.emphasis = Common_1.default.getBitAllignedNumber(buf, off + 3, 7, 2); | ||
this.emphasis = Util_1.default.getBitAllignedNumber(buf, off + 3, 7, 2); | ||
this.version = MpegFrameHeader.VersionID[this.versionIndex]; | ||
@@ -288,3 +288,3 @@ if (this.version === null) | ||
var format = _this.metadata.format; | ||
// ToDo: this.format.dataformat = "MPEG-" + header.version + " Audio Layer " + Common.romanize(header.layer); | ||
// format.dataformat = "MPEG-" + header.version + " Audio Layer " + Util.romanize(header.layer); | ||
format.dataformat = "mp" + header.layer; | ||
@@ -399,3 +399,3 @@ format.lossless = false; | ||
_this.offset += XingTag_1.XingInfoTag.len; // 12 | ||
_this.metadata.format.encoder = Common_1.default.stripNulls(infoTag.encoder); | ||
_this.metadata.format.encoder = Util_1.default.stripNulls(infoTag.encoder); | ||
if ((infoTag.headerFlags[3] & 0x01) === 1) { | ||
@@ -402,0 +402,0 @@ _this.metadata.format.duration = _this.audioFrameHeader.calcDuration(infoTag.numFrames); |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Common_1 = require("../common/Common"); | ||
var Util_1 = require("../common/Util"); | ||
var VorbisParser_1 = require("../vorbis/VorbisParser"); | ||
@@ -37,3 +37,3 @@ var FourCC_1 = require("../common/FourCC"); | ||
return _this.tokenizer.readToken(new Token.BufferType(header.segmentTable)).then(function (segments) { | ||
var pageLength = Common_1.default.sum(segments); | ||
var pageLength = Util_1.default.sum(segments); | ||
return _this.tokenizer.readToken(new Token.BufferType(pageLength)).then(function (pageData) { | ||
@@ -72,5 +72,5 @@ if (header.headerType.firstPage) { | ||
headerType: { | ||
continued: Common_1.default.strtokBITSET.get(buf, off + 5, 0), | ||
firstPage: Common_1.default.strtokBITSET.get(buf, off + 5, 1), | ||
lastPage: Common_1.default.strtokBITSET.get(buf, off + 5, 2) | ||
continued: Util_1.default.strtokBITSET.get(buf, off + 5, 0), | ||
firstPage: Util_1.default.strtokBITSET.get(buf, off + 5, 1), | ||
lastPage: Util_1.default.strtokBITSET.get(buf, off + 5, 2) | ||
}, | ||
@@ -77,0 +77,0 @@ // packet_flag: buf.readUInt8(off + 5), |
@@ -1,2 +0,2 @@ | ||
import { INativeTagMap } from "../tagmap"; | ||
import { INativeTagMap } from "../common/GenericTagTypes"; | ||
/** | ||
@@ -3,0 +3,0 @@ * RIFF Info Tags; part of the EXIF 2.3 |
@@ -19,3 +19,3 @@ "use strict"; | ||
var ID3v2Parser_1 = require("../id3v2/ID3v2Parser"); | ||
var Common_1 = require("../common/Common"); | ||
var Util_1 = require("../common/Util"); | ||
var FourCC_1 = require("../common/FourCC"); | ||
@@ -91,3 +91,3 @@ var es6_promise_1 = require("es6-promise"); | ||
}); | ||
case "fmt ":// The Common Chunk | ||
case "fmt ":// The Util Chunk | ||
return _this.tokenizer.readToken(new WaveChunk.Format(header)) | ||
@@ -129,3 +129,3 @@ .then(function (common) { | ||
return _this.tokenizer.readToken(valueToken).then(function (value) { | ||
_this.riffInfoTags.push({ id: header.chunkID, value: Common_1.default.stripNulls(value) }); | ||
_this.riffInfoTags.push({ id: header.chunkID, value: Util_1.default.stripNulls(value) }); | ||
chunkSize -= (8 + valueToken.len); | ||
@@ -132,0 +132,0 @@ if (chunkSize > 8) { |
{ | ||
"name": "music-metadata", | ||
"description": "Streaming music metadata parser for node and the browser.", | ||
"version": "0.9.3", | ||
"version": "0.9.4", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Borewit", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
273020
84
6726