music-metadata 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/lib/ParserFactory.d.ts +48 -0
- package/lib/aiff/AiffParser.d.ts +15 -0
- package/lib/aiff/AiffParser.js +13 -1
- package/lib/aiff/AiffTagMap.d.ts +4 -0
- package/lib/aiff/AiffTagMap.js +16 -0
- package/lib/aiff/AiffToken.d.ts +23 -0
- package/lib/apev2/APEv2Parser.d.ts +30 -0
- package/lib/apev2/APEv2TagMapper.d.ts +4 -0
- package/lib/apev2/APEv2Token.d.ts +100 -0
- package/lib/asf/AsfObject.d.ts +320 -0
- package/lib/asf/AsfParser.d.ts +17 -0
- package/lib/asf/AsfTagMapper.d.ts +7 -0
- package/lib/asf/AsfUtil.d.ts +14 -0
- package/lib/asf/GUID.d.ts +84 -0
- package/lib/common/BasicParser.d.ts +17 -0
- package/lib/common/CaseInsensitiveTagMap.d.ts +10 -0
- package/lib/common/CombinedTagMapper.d.ts +19 -0
- package/lib/common/CombinedTagMapper.js +3 -1
- package/lib/common/FourCC.d.ts +6 -0
- package/lib/common/FourCC.js +2 -5
- package/lib/common/GenericTagMapper.d.ts +51 -0
- package/lib/common/GenericTagTypes.d.ts +33 -0
- package/lib/common/MetadataCollector.d.ts +76 -0
- package/lib/common/MetadataCollector.js +2 -2
- package/lib/common/RandomFileReader.d.ts +22 -0
- package/lib/common/RandomUint8ArrayReader.d.ts +18 -0
- package/lib/common/Util.d.ts +57 -0
- package/lib/core.d.ts +48 -0
- package/lib/dsdiff/DsdiffParser.d.ts +14 -0
- package/lib/dsdiff/DsdiffToken.d.ts +9 -0
- package/lib/dsf/DsfChunk.d.ts +86 -0
- package/lib/dsf/DsfParser.d.ts +9 -0
- package/lib/flac/FlacParser.d.ts +28 -0
- package/lib/id3v1/ID3v1Parser.d.ts +13 -0
- package/lib/id3v1/ID3v1TagMap.d.ts +4 -0
- package/lib/id3v2/AbstractID3Parser.d.ts +17 -0
- package/lib/id3v2/FrameParser.d.ts +31 -0
- package/lib/id3v2/ID3v22TagMapper.d.ts +9 -0
- package/lib/id3v2/ID3v24TagMapper.d.ts +14 -0
- package/lib/id3v2/ID3v2Parser.d.ts +28 -0
- package/lib/id3v2/ID3v2Token.d.ts +73 -0
- package/lib/iff/index.d.ts +33 -0
- package/lib/index.d.ts +21 -0
- package/lib/lyrics3/Lyrics3.d.ts +3 -0
- package/lib/matroska/MatroskaDtd.d.ts +8 -0
- package/lib/matroska/MatroskaParser.d.ts +37 -0
- package/lib/matroska/MatroskaTagMapper.d.ts +4 -0
- package/lib/matroska/types.d.ts +175 -0
- package/lib/mp4/Atom.d.ts +16 -0
- package/lib/mp4/AtomToken.d.ts +395 -0
- package/lib/mp4/MP4Parser.d.ts +30 -0
- package/lib/mp4/MP4TagMapper.d.ts +5 -0
- package/lib/mpeg/ExtendedLameHeader.d.ts +27 -0
- package/lib/mpeg/MpegParser.d.ts +49 -0
- package/lib/mpeg/ReplayGainDataFormat.d.ts +55 -0
- package/lib/mpeg/XingTag.d.ts +45 -0
- package/lib/musepack/index.d.ts +5 -0
- package/lib/musepack/sv7/BitReader.d.ts +13 -0
- package/lib/musepack/sv7/MpcSv7Parser.d.ts +8 -0
- package/lib/musepack/sv7/StreamVersion7.d.ts +28 -0
- package/lib/musepack/sv8/MpcSv8Parser.d.ts +6 -0
- package/lib/musepack/sv8/StreamVersion8.d.ts +40 -0
- package/lib/ogg/Ogg.d.ts +72 -0
- package/lib/ogg/OggParser.d.ts +23 -0
- package/lib/ogg/opus/Opus.d.ts +48 -0
- package/lib/ogg/opus/OpusParser.d.ts +25 -0
- package/lib/ogg/speex/Speex.d.ts +36 -0
- package/lib/ogg/speex/SpeexParser.d.ts +22 -0
- package/lib/ogg/theora/Theora.d.ts +20 -0
- package/lib/ogg/theora/TheoraParser.d.ts +28 -0
- package/lib/ogg/vorbis/Vorbis.d.ts +69 -0
- package/lib/ogg/vorbis/VorbisDecoder.d.ts +12 -0
- package/lib/ogg/vorbis/VorbisParser.d.ts +36 -0
- package/lib/ogg/vorbis/VorbisTagMapper.d.ts +7 -0
- package/lib/riff/RiffChunk.d.ts +16 -0
- package/lib/riff/RiffInfoTagMap.d.ts +10 -0
- package/lib/type.d.ts +593 -0
- package/lib/wav/BwfChunk.d.ts +17 -0
- package/lib/wav/WaveChunk.d.ts +64 -0
- package/lib/wav/WaveParser.d.ts +24 -0
- package/lib/wavpack/WavPackParser.d.ts +14 -0
- package/lib/wavpack/WavPackToken.d.ts +64 -0
- package/package.json +13 -13
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/**
|
|
3
|
+
* Ref:
|
|
4
|
+
* - https://tools.ietf.org/html/draft-fleischman-asf-01, Appendix A: ASF GUIDs
|
|
5
|
+
* - http://drang.s4.xrea.com/program/tips/id3tag/wmp/10_asf_guids.html
|
|
6
|
+
* - http://drang.s4.xrea.com/program/tips/id3tag/wmp/index.html
|
|
7
|
+
* - http://drang.s4.xrea.com/program/tips/id3tag/wmp/10_asf_guids.html
|
|
8
|
+
*
|
|
9
|
+
* ASF File Structure:
|
|
10
|
+
* - https://msdn.microsoft.com/en-us/library/windows/desktop/ee663575(v=vs.85).aspx
|
|
11
|
+
*
|
|
12
|
+
* ASF GUIDs:
|
|
13
|
+
* - http://drang.s4.xrea.com/program/tips/id3tag/wmp/10_asf_guids.html
|
|
14
|
+
* - https://github.com/dji-sdk/FFmpeg/blob/master/libavformat/asf.c
|
|
15
|
+
*/
|
|
16
|
+
export default class GUID {
|
|
17
|
+
str: string;
|
|
18
|
+
static HeaderObject: GUID;
|
|
19
|
+
static DataObject: GUID;
|
|
20
|
+
static SimpleIndexObject: GUID;
|
|
21
|
+
static IndexObject: GUID;
|
|
22
|
+
static MediaObjectIndexObject: GUID;
|
|
23
|
+
static TimecodeIndexObject: GUID;
|
|
24
|
+
static FilePropertiesObject: GUID;
|
|
25
|
+
static StreamPropertiesObject: GUID;
|
|
26
|
+
static HeaderExtensionObject: GUID;
|
|
27
|
+
static CodecListObject: GUID;
|
|
28
|
+
static ScriptCommandObject: GUID;
|
|
29
|
+
static MarkerObject: GUID;
|
|
30
|
+
static BitrateMutualExclusionObject: GUID;
|
|
31
|
+
static ErrorCorrectionObject: GUID;
|
|
32
|
+
static ContentDescriptionObject: GUID;
|
|
33
|
+
static ExtendedContentDescriptionObject: GUID;
|
|
34
|
+
static ContentBrandingObject: GUID;
|
|
35
|
+
static StreamBitratePropertiesObject: GUID;
|
|
36
|
+
static ContentEncryptionObject: GUID;
|
|
37
|
+
static ExtendedContentEncryptionObject: GUID;
|
|
38
|
+
static DigitalSignatureObject: GUID;
|
|
39
|
+
static PaddingObject: GUID;
|
|
40
|
+
static ExtendedStreamPropertiesObject: GUID;
|
|
41
|
+
static AdvancedMutualExclusionObject: GUID;
|
|
42
|
+
static GroupMutualExclusionObject: GUID;
|
|
43
|
+
static StreamPrioritizationObject: GUID;
|
|
44
|
+
static BandwidthSharingObject: GUID;
|
|
45
|
+
static LanguageListObject: GUID;
|
|
46
|
+
static MetadataObject: GUID;
|
|
47
|
+
static MetadataLibraryObject: GUID;
|
|
48
|
+
static IndexParametersObject: GUID;
|
|
49
|
+
static MediaObjectIndexParametersObject: GUID;
|
|
50
|
+
static TimecodeIndexParametersObject: GUID;
|
|
51
|
+
static CompatibilityObject: GUID;
|
|
52
|
+
static AdvancedContentEncryptionObject: GUID;
|
|
53
|
+
static AudioMedia: GUID;
|
|
54
|
+
static VideoMedia: GUID;
|
|
55
|
+
static CommandMedia: GUID;
|
|
56
|
+
static JFIF_Media: GUID;
|
|
57
|
+
static Degradable_JPEG_Media: GUID;
|
|
58
|
+
static FileTransferMedia: GUID;
|
|
59
|
+
static BinaryMedia: GUID;
|
|
60
|
+
static ASF_Index_Placeholder_Object: GUID;
|
|
61
|
+
static fromBin(bin: Buffer, offset?: number): GUID;
|
|
62
|
+
/**
|
|
63
|
+
* Decode GUID in format like "B503BF5F-2EA9-CF11-8EE3-00C00C205365"
|
|
64
|
+
* @param objectId Binary GUID
|
|
65
|
+
* @param offset Read offset in bytes, default 0
|
|
66
|
+
* @returns GUID as dashed hexadecimal representation
|
|
67
|
+
*/
|
|
68
|
+
static decode(objectId: Buffer, offset?: number): string;
|
|
69
|
+
/**
|
|
70
|
+
* Decode stream type
|
|
71
|
+
* @param mediaType Media type GUID
|
|
72
|
+
* @returns Media type
|
|
73
|
+
*/
|
|
74
|
+
static decodeMediaType(mediaType: GUID): 'audio' | 'video' | 'command' | 'degradable-jpeg' | 'file-transfer' | 'binary' | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Encode GUID
|
|
77
|
+
* @param guid GUID like: "B503BF5F-2EA9-CF11-8EE3-00C00C205365"
|
|
78
|
+
* @returns Encoded Binary GUID
|
|
79
|
+
*/
|
|
80
|
+
static encode(str: string): Buffer;
|
|
81
|
+
constructor(str: string);
|
|
82
|
+
equals(guid: GUID): boolean;
|
|
83
|
+
toBin(): Buffer;
|
|
84
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ITokenizer } from 'strtok3/core';
|
|
2
|
+
import { ITokenParser } from '../ParserFactory.js';
|
|
3
|
+
import { IOptions, IPrivateOptions } from '../type.js';
|
|
4
|
+
import { INativeMetadataCollector } from './MetadataCollector.js';
|
|
5
|
+
export declare abstract class BasicParser implements ITokenParser {
|
|
6
|
+
protected metadata: INativeMetadataCollector;
|
|
7
|
+
protected tokenizer: ITokenizer;
|
|
8
|
+
protected options: IPrivateOptions;
|
|
9
|
+
/**
|
|
10
|
+
* Initialize parser with output (metadata), input (tokenizer) & parsing options (options).
|
|
11
|
+
* @param {INativeMetadataCollector} metadata Output
|
|
12
|
+
* @param {ITokenizer} tokenizer Input
|
|
13
|
+
* @param {IOptions} options Parsing options
|
|
14
|
+
*/
|
|
15
|
+
init(metadata: INativeMetadataCollector, tokenizer: ITokenizer, options: IOptions): ITokenParser;
|
|
16
|
+
abstract parse(): any;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { INativeTagMap, TagType } from './GenericTagTypes.js';
|
|
2
|
+
import { CommonTagMapper } from './GenericTagMapper.js';
|
|
3
|
+
export declare class CaseInsensitiveTagMap extends CommonTagMapper {
|
|
4
|
+
constructor(tagTypes: TagType[], tagMap: INativeTagMap);
|
|
5
|
+
/**
|
|
6
|
+
* @tag Native header tag
|
|
7
|
+
* @return common tag name (alias)
|
|
8
|
+
*/
|
|
9
|
+
protected getCommonName(tag: string): import("./GenericTagTypes.js").GenericTagId;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IGenericTag, TagType } from './GenericTagTypes.js';
|
|
2
|
+
import { IGenericTagMapper } from './GenericTagMapper.js';
|
|
3
|
+
import { ITag } from '../type.js';
|
|
4
|
+
import { INativeMetadataCollector } from './MetadataCollector.js';
|
|
5
|
+
export declare class CombinedTagMapper {
|
|
6
|
+
tagMappers: {
|
|
7
|
+
[index: string]: IGenericTagMapper;
|
|
8
|
+
};
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Convert native to generic (common) tags
|
|
12
|
+
* @param tagType Originating tag format
|
|
13
|
+
* @param tag Native tag to map to a generic tag id
|
|
14
|
+
* @param warnings
|
|
15
|
+
* @return Generic tag result (output of this function)
|
|
16
|
+
*/
|
|
17
|
+
mapTag(tagType: TagType, tag: ITag, warnings: INativeMetadataCollector): IGenericTag;
|
|
18
|
+
private registerTagMapper;
|
|
19
|
+
}
|
|
@@ -7,6 +7,7 @@ import { MP4TagMapper } from '../mp4/MP4TagMapper.js';
|
|
|
7
7
|
import { VorbisTagMapper } from '../ogg/vorbis/VorbisTagMapper.js';
|
|
8
8
|
import { RiffInfoTagMapper } from '../riff/RiffInfoTagMap.js';
|
|
9
9
|
import { MatroskaTagMapper } from '../matroska/MatroskaTagMapper.js';
|
|
10
|
+
import { AiffTagMapper } from '../aiff/AiffTagMap.js';
|
|
10
11
|
export class CombinedTagMapper {
|
|
11
12
|
constructor() {
|
|
12
13
|
this.tagMappers = {};
|
|
@@ -20,7 +21,8 @@ export class CombinedTagMapper {
|
|
|
20
21
|
new APEv2TagMapper(),
|
|
21
22
|
new AsfTagMapper(),
|
|
22
23
|
new RiffInfoTagMapper(),
|
|
23
|
-
new MatroskaTagMapper()
|
|
24
|
+
new MatroskaTagMapper(),
|
|
25
|
+
new AiffTagMapper()
|
|
24
26
|
].forEach(mapper => {
|
|
25
27
|
this.registerTagMapper(mapper);
|
|
26
28
|
});
|
package/lib/common/FourCC.js
CHANGED
|
@@ -8,11 +8,8 @@ export const FourCcToken = {
|
|
|
8
8
|
len: 4,
|
|
9
9
|
get: (buf, off) => {
|
|
10
10
|
const id = buf.toString('binary', off, off + FourCcToken.len);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!id.match(validFourCC)) {
|
|
14
|
-
throw new Error(`FourCC contains invalid characters: ${util.a2hex(id)} "${id}"`);
|
|
15
|
-
}
|
|
11
|
+
if (!id.match(validFourCC)) {
|
|
12
|
+
throw new Error(`FourCC contains invalid characters: ${util.a2hex(id)} "${id}"`);
|
|
16
13
|
}
|
|
17
14
|
return id;
|
|
18
15
|
},
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as generic from './GenericTagTypes.js';
|
|
2
|
+
import { ITag } from '../type.js';
|
|
3
|
+
import { INativeMetadataCollector, IWarningCollector } from './MetadataCollector.js';
|
|
4
|
+
export interface IGenericTagMapper {
|
|
5
|
+
/**
|
|
6
|
+
* Which tagType it able to map to the generic mapping format
|
|
7
|
+
*/
|
|
8
|
+
tagTypes: generic.TagType[];
|
|
9
|
+
/**
|
|
10
|
+
* Basic tag map
|
|
11
|
+
*/
|
|
12
|
+
tagMap: generic.INativeTagMap;
|
|
13
|
+
/**
|
|
14
|
+
* Map native tag to generic tag
|
|
15
|
+
* @param tag Native tag
|
|
16
|
+
* @param warnings Register warnings
|
|
17
|
+
* @return Generic tag, if native tag could be mapped
|
|
18
|
+
*/
|
|
19
|
+
mapGenericTag(tag: ITag, warnings: INativeMetadataCollector): generic.IGenericTag;
|
|
20
|
+
}
|
|
21
|
+
export declare class CommonTagMapper implements IGenericTagMapper {
|
|
22
|
+
tagTypes: generic.TagType[];
|
|
23
|
+
tagMap: generic.INativeTagMap;
|
|
24
|
+
static maxRatingScore: number;
|
|
25
|
+
static toIntOrNull(str: string): number;
|
|
26
|
+
static normalizeTrack(origVal: number | string): {
|
|
27
|
+
no: number;
|
|
28
|
+
of: number;
|
|
29
|
+
};
|
|
30
|
+
constructor(tagTypes: generic.TagType[], tagMap: generic.INativeTagMap);
|
|
31
|
+
/**
|
|
32
|
+
* Process and set common tags
|
|
33
|
+
* write common tags to
|
|
34
|
+
* @param tag Native tag
|
|
35
|
+
* @param warnings Register warnings
|
|
36
|
+
* @return common name
|
|
37
|
+
*/
|
|
38
|
+
mapGenericTag(tag: ITag, warnings: IWarningCollector): generic.IGenericTag;
|
|
39
|
+
/**
|
|
40
|
+
* Convert native tag key to common tag key
|
|
41
|
+
* @param tag Native header tag
|
|
42
|
+
* @return common tag name (alias)
|
|
43
|
+
*/
|
|
44
|
+
protected getCommonName(tag: string): generic.GenericTagId;
|
|
45
|
+
/**
|
|
46
|
+
* Handle post mapping exceptions / correction
|
|
47
|
+
* @param tag Tag e.g. {"©alb", "Buena Vista Social Club")
|
|
48
|
+
* @param warnings Used to register warnings
|
|
49
|
+
*/
|
|
50
|
+
protected postMap(tag: ITag, warnings: IWarningCollector): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare type TagType = 'vorbis' | 'ID3v1' | 'ID3v2.2' | 'ID3v2.3' | 'ID3v2.4' | 'APEv2' | 'asf' | 'iTunes' | 'exif' | 'matroska' | 'AIFF';
|
|
2
|
+
export interface IGenericTag {
|
|
3
|
+
id: GenericTagId;
|
|
4
|
+
value: any;
|
|
5
|
+
}
|
|
6
|
+
export declare type GenericTagId = 'track' | 'disk' | 'year' | 'title' | 'artist' | 'artists' | 'albumartist' | 'album' | 'date' | 'originaldate' | 'originalyear' | 'comment' | 'genre' | 'picture' | 'composer' | 'lyrics' | 'albumsort' | 'titlesort' | 'work' | 'artistsort' | 'albumartistsort' | 'composersort' | 'lyricist' | 'writer' | 'conductor' | 'remixer' | 'arranger' | 'engineer' | 'technician' | 'producer' | 'djmixer' | 'mixer' | 'publisher' | 'label' | 'grouping' | 'subtitle' | 'discsubtitle' | 'totaltracks' | 'totaldiscs' | 'compilation' | 'rating' | 'bpm' | 'mood' | 'media' | 'catalognumber' | 'tvShow' | 'tvShowSort' | 'tvEpisode' | 'tvEpisodeId' | 'tvNetwork' | 'tvSeason' | 'podcast' | 'podcasturl' | 'releasestatus' | 'releasetype' | 'releasecountry' | 'script' | 'language' | 'copyright' | 'license' | 'encodedby' | 'encodersettings' | 'gapless' | 'barcode' | 'isrc' | 'asin' | 'musicbrainz_recordingid' | 'musicbrainz_trackid' | 'musicbrainz_albumid' | 'musicbrainz_artistid' | 'musicbrainz_albumartistid' | 'musicbrainz_releasegroupid' | 'musicbrainz_workid' | 'musicbrainz_trmid' | 'musicbrainz_discid' | 'acoustid_id' | 'acoustid_fingerprint' | 'musicip_puid' | 'musicip_fingerprint' | 'website' | 'performer:instrument' | 'peakLevel' | 'averageLevel' | 'notes' | 'key' | 'originalalbum' | 'originalartist' | 'discogs_artist_id' | 'discogs_label_id' | 'discogs_master_release_id' | 'discogs_rating' | 'discogs_release_id' | 'discogs_votes' | 'replaygain_track_gain' | 'replaygain_track_peak' | 'replaygain_album_gain' | 'replaygain_album_peak' | 'replaygain_track_minmax' | 'replaygain_album_minmax' | 'replaygain_undo' | 'description' | 'longDescription' | 'category' | 'hdVideo' | 'keywords' | 'movement' | 'movementIndex' | 'movementTotal' | 'podcastId' | 'showMovement' | 'stik';
|
|
7
|
+
export interface INativeTagMap {
|
|
8
|
+
[index: string]: GenericTagId;
|
|
9
|
+
}
|
|
10
|
+
export interface ITagInfo {
|
|
11
|
+
/**
|
|
12
|
+
* True if result is an array
|
|
13
|
+
*/
|
|
14
|
+
multiple: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* True if the result is an array and each value in the array should be unique
|
|
17
|
+
*/
|
|
18
|
+
unique?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface ITagInfoMap {
|
|
21
|
+
[index: string]: ITagInfo;
|
|
22
|
+
}
|
|
23
|
+
export declare const commonTags: ITagInfoMap;
|
|
24
|
+
/**
|
|
25
|
+
* @param alias Name of common tag
|
|
26
|
+
* @returns {boolean|*} true if given alias is mapped as a singleton', otherwise false
|
|
27
|
+
*/
|
|
28
|
+
export declare function isSingleton(alias: GenericTagId): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* @param alias Common (generic) tag
|
|
31
|
+
* @returns {boolean|*} true if given alias is a singleton or explicitly marked as unique
|
|
32
|
+
*/
|
|
33
|
+
export declare function isUnique(alias: GenericTagId): boolean;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { FormatId, IAudioMetadata, ICommonTagsResult, IFormat, INativeTags, IOptions, IQualityInformation, ITrackInfo } from '../type.js';
|
|
2
|
+
import { IGenericTag, TagType } from './GenericTagTypes.js';
|
|
3
|
+
/**
|
|
4
|
+
* Combines all generic-tag-mappers for each tag type
|
|
5
|
+
*/
|
|
6
|
+
export interface IWarningCollector {
|
|
7
|
+
/**
|
|
8
|
+
* Register parser warning
|
|
9
|
+
* @param warning
|
|
10
|
+
*/
|
|
11
|
+
addWarning(warning: string): any;
|
|
12
|
+
}
|
|
13
|
+
export interface INativeMetadataCollector extends IWarningCollector {
|
|
14
|
+
/**
|
|
15
|
+
* Only use this for reading
|
|
16
|
+
*/
|
|
17
|
+
readonly format: IFormat;
|
|
18
|
+
readonly native: INativeTags;
|
|
19
|
+
readonly quality: IQualityInformation;
|
|
20
|
+
/**
|
|
21
|
+
* @returns {boolean} true if one or more tags have been found
|
|
22
|
+
*/
|
|
23
|
+
hasAny(): boolean;
|
|
24
|
+
setFormat(key: FormatId, value: any): void;
|
|
25
|
+
addTag(tagType: TagType, tagId: string, value: any): void;
|
|
26
|
+
addStreamInfo(streamInfo: ITrackInfo): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Provided to the parser to uodate the metadata result.
|
|
30
|
+
* Responsible for triggering async updates
|
|
31
|
+
*/
|
|
32
|
+
export declare class MetadataCollector implements INativeMetadataCollector {
|
|
33
|
+
private opts;
|
|
34
|
+
readonly format: IFormat;
|
|
35
|
+
readonly native: INativeTags;
|
|
36
|
+
readonly common: ICommonTagsResult;
|
|
37
|
+
readonly quality: IQualityInformation;
|
|
38
|
+
/**
|
|
39
|
+
* Keeps track of origin priority for each mapped id
|
|
40
|
+
*/
|
|
41
|
+
private readonly commonOrigin;
|
|
42
|
+
/**
|
|
43
|
+
* Maps a tag type to a priority
|
|
44
|
+
*/
|
|
45
|
+
private readonly originPriority;
|
|
46
|
+
private tagMapper;
|
|
47
|
+
constructor(opts: IOptions);
|
|
48
|
+
/**
|
|
49
|
+
* @returns {boolean} true if one or more tags have been found
|
|
50
|
+
*/
|
|
51
|
+
hasAny(): boolean;
|
|
52
|
+
addStreamInfo(streamInfo: ITrackInfo): void;
|
|
53
|
+
setFormat(key: FormatId, value: any): void;
|
|
54
|
+
addTag(tagType: TagType, tagId: string, value: any): void;
|
|
55
|
+
addWarning(warning: string): void;
|
|
56
|
+
postMap(tagType: TagType | 'artificial', tag: IGenericTag): any;
|
|
57
|
+
/**
|
|
58
|
+
* Convert native tags to common tags
|
|
59
|
+
* @returns {IAudioMetadata} Native + common tags
|
|
60
|
+
*/
|
|
61
|
+
toCommonMetadata(): IAudioMetadata;
|
|
62
|
+
/**
|
|
63
|
+
* Fix some common issues with picture object
|
|
64
|
+
* @param picture Picture
|
|
65
|
+
*/
|
|
66
|
+
private postFixPicture;
|
|
67
|
+
/**
|
|
68
|
+
* Convert native tag to common tags
|
|
69
|
+
*/
|
|
70
|
+
private toCommon;
|
|
71
|
+
/**
|
|
72
|
+
* Set generic tag
|
|
73
|
+
*/
|
|
74
|
+
private setGenericTag;
|
|
75
|
+
}
|
|
76
|
+
export declare function joinArtists(artists: string[]): string;
|
|
@@ -6,7 +6,7 @@ import { CommonTagMapper } from './GenericTagMapper.js';
|
|
|
6
6
|
import { toRatio } from './Util.js';
|
|
7
7
|
import { fileTypeFromBuffer } from 'file-type';
|
|
8
8
|
const debug = initDebug('music-metadata:collector');
|
|
9
|
-
const TagPriority = ['matroska', 'APEv2', 'vorbis', 'ID3v2.4', 'ID3v2.3', 'ID3v2.2', 'exif', 'asf', 'iTunes', 'ID3v1'];
|
|
9
|
+
const TagPriority = ['matroska', 'APEv2', 'vorbis', 'ID3v2.4', 'ID3v2.3', 'ID3v2.2', 'exif', 'asf', 'iTunes', 'AIFF', 'ID3v1'];
|
|
10
10
|
/**
|
|
11
11
|
* Provided to the parser to uodate the metadata result.
|
|
12
12
|
* Responsible for triggering async updates
|
|
@@ -41,7 +41,7 @@ export class MetadataCollector {
|
|
|
41
41
|
this.originPriority[tagType] = priority++;
|
|
42
42
|
}
|
|
43
43
|
this.originPriority.artificial = 500; // Filled using alternative tags
|
|
44
|
-
this.originPriority.id3v1 = 600; // Consider worst
|
|
44
|
+
this.originPriority.id3v1 = 600; // Consider as the worst because of the field length limit
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* @returns {boolean} true if one or more tags have been found
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { IRandomReader } from '../type.js';
|
|
3
|
+
/**
|
|
4
|
+
* Provides abstract file access via the IRandomRead interface
|
|
5
|
+
*/
|
|
6
|
+
export declare class RandomFileReader implements IRandomReader {
|
|
7
|
+
private readonly fileHandle;
|
|
8
|
+
filePath: string;
|
|
9
|
+
fileSize: number;
|
|
10
|
+
private constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Read from a given position of an abstracted file or buffer.
|
|
13
|
+
* @param buffer {Buffer} is the buffer that the data will be written to.
|
|
14
|
+
* @param offset {number} is the offset in the buffer to start writing at.
|
|
15
|
+
* @param length {number}is an integer specifying the number of bytes to read.
|
|
16
|
+
* @param position {number} is an argument specifying where to begin reading from in the file.
|
|
17
|
+
* @return {Promise<number>} bytes read
|
|
18
|
+
*/
|
|
19
|
+
randomRead(buffer: Buffer, offset: number, length: number, position: number): Promise<number>;
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
static init(filePath: string, fileSize: number): Promise<RandomFileReader>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IRandomReader } from '../type.js';
|
|
2
|
+
/**
|
|
3
|
+
* Provides abstract Uint8Array access via the IRandomRead interface
|
|
4
|
+
*/
|
|
5
|
+
export declare class RandomUint8ArrayReader implements IRandomReader {
|
|
6
|
+
private readonly uint8Array;
|
|
7
|
+
readonly fileSize: number;
|
|
8
|
+
constructor(uint8Array: Uint8Array);
|
|
9
|
+
/**
|
|
10
|
+
* Read from a given position of an abstracted file or buffer.
|
|
11
|
+
* @param uint8Array - Uint8Array that the data will be written to.
|
|
12
|
+
* @param offset - Offset in the buffer to start writing at.
|
|
13
|
+
* @param length - Integer specifying the number of bytes to read.
|
|
14
|
+
* @param position - Specifies where to begin reading from in the file.
|
|
15
|
+
* @return Promise providing bytes read
|
|
16
|
+
*/
|
|
17
|
+
randomRead(uint8Array: Uint8Array, offset: number, length: number, position: number): Promise<number>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IRatio } from '../type.js';
|
|
2
|
+
export declare type StringEncoding = 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64url' | 'latin1' | 'hex';
|
|
3
|
+
export interface ITextEncoding {
|
|
4
|
+
encoding: StringEncoding;
|
|
5
|
+
bom?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function getBit(buf: Uint8Array, off: number, bit: number): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Found delimiting zero in uint8Array
|
|
10
|
+
* @param uint8Array Uint8Array to find the zero delimiter in
|
|
11
|
+
* @param start Offset in uint8Array
|
|
12
|
+
* @param end Last position to parse in uint8Array
|
|
13
|
+
* @param encoding The string encoding used
|
|
14
|
+
* @return Absolute position on uint8Array where zero found
|
|
15
|
+
*/
|
|
16
|
+
export declare function findZero(uint8Array: Uint8Array, start: number, end: number, encoding?: StringEncoding): number;
|
|
17
|
+
export declare function trimRightNull(x: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Decode string
|
|
20
|
+
*/
|
|
21
|
+
export declare function decodeString(uint8Array: Uint8Array, encoding: StringEncoding): string;
|
|
22
|
+
export declare function stripNulls(str: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Read bit-aligned number start from buffer
|
|
25
|
+
* Total offset in bits = byteOffset * 8 + bitOffset
|
|
26
|
+
* @param source Byte buffer
|
|
27
|
+
* @param byteOffset Starting offset in bytes
|
|
28
|
+
* @param bitOffset Starting offset in bits: 0 = lsb
|
|
29
|
+
* @param len Length of number in bits
|
|
30
|
+
* @return Decoded bit aligned number
|
|
31
|
+
*/
|
|
32
|
+
export declare function getBitAllignedNumber(source: Uint8Array, byteOffset: number, bitOffset: number, len: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Read bit-aligned number start from buffer
|
|
35
|
+
* Total offset in bits = byteOffset * 8 + bitOffset
|
|
36
|
+
* @param source Byte Uint8Array
|
|
37
|
+
* @param byteOffset Starting offset in bytes
|
|
38
|
+
* @param bitOffset Starting offset in bits: 0 = most significant bit, 7 is the least significant bit
|
|
39
|
+
* @return True if bit is set
|
|
40
|
+
*/
|
|
41
|
+
export declare function isBitSet(source: Uint8Array, byteOffset: number, bitOffset: number): boolean;
|
|
42
|
+
export declare function a2hex(str: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Convert power ratio to DB
|
|
45
|
+
* ratio: [0..1]
|
|
46
|
+
*/
|
|
47
|
+
export declare function ratioToDb(ratio: number): number;
|
|
48
|
+
/**
|
|
49
|
+
* Convert dB to ratio
|
|
50
|
+
* db Decibels
|
|
51
|
+
*/
|
|
52
|
+
export declare function dbToRatio(dB: number): number;
|
|
53
|
+
/**
|
|
54
|
+
* Convert replay gain to ratio and Decibel
|
|
55
|
+
* @param value string holding a ratio like '0.034' or '-7.54 dB'
|
|
56
|
+
*/
|
|
57
|
+
export declare function toRatio(value: string): IRatio;
|
package/lib/core.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
import * as strtok3 from 'strtok3/core';
|
|
4
|
+
import { IAudioMetadata, INativeTagDict, IOptions, IPicture, IPrivateOptions, IRandomReader, ITag } from './type.js';
|
|
5
|
+
export { IFileInfo } from 'strtok3/core';
|
|
6
|
+
/**
|
|
7
|
+
* Parse audio from Node Stream.Readable
|
|
8
|
+
* @param stream - Stream to read the audio track from
|
|
9
|
+
* @param options - Parsing options
|
|
10
|
+
* @param fileInfo - File information object or MIME-type string
|
|
11
|
+
* @returns Metadata
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseStream(stream: Readable, fileInfo?: strtok3.IFileInfo | string, options?: IOptions): Promise<IAudioMetadata>;
|
|
14
|
+
/**
|
|
15
|
+
* Parse audio from Node Buffer
|
|
16
|
+
* @param uint8Array - Uint8Array holding audio data
|
|
17
|
+
* @param fileInfo - File information object or MIME-type string
|
|
18
|
+
* @param options - Parsing options
|
|
19
|
+
* @returns Metadata
|
|
20
|
+
* Ref: https://github.com/Borewit/strtok3/blob/e6938c81ff685074d5eb3064a11c0b03ca934c1d/src/index.ts#L15
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseBuffer(uint8Array: Uint8Array, fileInfo?: strtok3.IFileInfo | string, options?: IOptions): Promise<IAudioMetadata>;
|
|
23
|
+
/**
|
|
24
|
+
* Parse audio from ITokenizer source
|
|
25
|
+
* @param tokenizer - Audio source implementing the tokenizer interface
|
|
26
|
+
* @param options - Parsing options
|
|
27
|
+
* @returns Metadata
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseFromTokenizer(tokenizer: strtok3.ITokenizer, options?: IOptions): Promise<IAudioMetadata>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a dictionary ordered by their tag id (key)
|
|
32
|
+
* @param nativeTags list of tags
|
|
33
|
+
* @returns tags indexed by id
|
|
34
|
+
*/
|
|
35
|
+
export declare function orderTags(nativeTags: ITag[]): INativeTagDict;
|
|
36
|
+
/**
|
|
37
|
+
* Convert rating to 1-5 star rating
|
|
38
|
+
* @param rating: Normalized rating [0..1] (common.rating[n].rating)
|
|
39
|
+
* @returns Number of stars: 1, 2, 3, 4 or 5 stars
|
|
40
|
+
*/
|
|
41
|
+
export declare function ratingToStars(rating: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Select most likely cover image.
|
|
44
|
+
* @param pictures Usually metadata.common.picture
|
|
45
|
+
* @return Cover image, if any, otherwise null
|
|
46
|
+
*/
|
|
47
|
+
export declare function selectCover(pictures?: IPicture[]): IPicture | null;
|
|
48
|
+
export declare function scanAppendingHeaders(randomReader: IRandomReader, options?: IPrivateOptions): Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BasicParser } from '../common/BasicParser.js';
|
|
2
|
+
/**
|
|
3
|
+
* DSDIFF - Direct Stream Digital Interchange File Format (Phillips)
|
|
4
|
+
*
|
|
5
|
+
* Ref:
|
|
6
|
+
* - http://www.sonicstudio.com/pdf/dsd/DSDIFF_1.5_Spec.pdf
|
|
7
|
+
*/
|
|
8
|
+
export declare class DsdiffParser extends BasicParser {
|
|
9
|
+
parse(): Promise<void>;
|
|
10
|
+
private readFmt8Chunks;
|
|
11
|
+
private readData;
|
|
12
|
+
private handleSoundPropertyChunks;
|
|
13
|
+
private handleChannelChunks;
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IGetToken } from 'strtok3/core';
|
|
2
|
+
import { IChunkHeader64 } from '../iff/index.js';
|
|
3
|
+
export { IChunkHeader64 } from '../iff/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* DSDIFF chunk header
|
|
6
|
+
* The data-size encoding is deviating from EA-IFF 85
|
|
7
|
+
* Ref: http://www.sonicstudio.com/pdf/dsd/DSDIFF_1.5_Spec.pdf
|
|
8
|
+
*/
|
|
9
|
+
export declare const ChunkHeader64: IGetToken<IChunkHeader64>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { IGetToken } from 'strtok3/core';
|
|
2
|
+
/**
|
|
3
|
+
* Common interface for the common chunk DSD header
|
|
4
|
+
*/
|
|
5
|
+
export interface IChunkHeader {
|
|
6
|
+
/**
|
|
7
|
+
* Chunk ID
|
|
8
|
+
*/
|
|
9
|
+
id: string;
|
|
10
|
+
/**
|
|
11
|
+
* Chunk size
|
|
12
|
+
*/
|
|
13
|
+
size: bigint;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Common chunk DSD header: the 'chunk name (Four-CC)' & chunk size
|
|
17
|
+
*/
|
|
18
|
+
export declare const ChunkHeader: IGetToken<IChunkHeader>;
|
|
19
|
+
/**
|
|
20
|
+
* Interface to DSD payload chunk
|
|
21
|
+
*/
|
|
22
|
+
export interface IDsdChunk {
|
|
23
|
+
/**
|
|
24
|
+
* Total file size
|
|
25
|
+
*/
|
|
26
|
+
fileSize: bigint;
|
|
27
|
+
/**
|
|
28
|
+
* If Metadata doesn’t exist, set 0. If the file has ID3v2 tag, then set the pointer to it.
|
|
29
|
+
* ID3v2 tag should be located in the end of the file.
|
|
30
|
+
*/
|
|
31
|
+
metadataPointer: bigint;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Common chunk DSD header: the 'chunk name (Four-CC)' & chunk size
|
|
35
|
+
*/
|
|
36
|
+
export declare const DsdChunk: IGetToken<IDsdChunk>;
|
|
37
|
+
export declare enum ChannelType {
|
|
38
|
+
mono = 1,
|
|
39
|
+
stereo = 2,
|
|
40
|
+
channels = 3,
|
|
41
|
+
quad = 4,
|
|
42
|
+
'4 channels' = 5,
|
|
43
|
+
'5 channels' = 6,
|
|
44
|
+
'5.1 channels' = 7
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Interface to format chunk payload chunk
|
|
48
|
+
*/
|
|
49
|
+
export interface IFormatChunk {
|
|
50
|
+
/**
|
|
51
|
+
* Version of this file format
|
|
52
|
+
*/
|
|
53
|
+
formatVersion: number;
|
|
54
|
+
/**
|
|
55
|
+
* Format ID
|
|
56
|
+
*/
|
|
57
|
+
formatID: number;
|
|
58
|
+
/**
|
|
59
|
+
* Channel Type
|
|
60
|
+
*/
|
|
61
|
+
channelType: ChannelType;
|
|
62
|
+
/**
|
|
63
|
+
* Channel num
|
|
64
|
+
*/
|
|
65
|
+
channelNum: number;
|
|
66
|
+
/**
|
|
67
|
+
* Sampling frequency
|
|
68
|
+
*/
|
|
69
|
+
samplingFrequency: number;
|
|
70
|
+
/**
|
|
71
|
+
* Bits per sample
|
|
72
|
+
*/
|
|
73
|
+
bitsPerSample: number;
|
|
74
|
+
/**
|
|
75
|
+
* Sample count
|
|
76
|
+
*/
|
|
77
|
+
sampleCount: bigint;
|
|
78
|
+
/**
|
|
79
|
+
* Block size per channel
|
|
80
|
+
*/
|
|
81
|
+
blockSizePerChannel: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Common chunk DSD header: the 'chunk name (Four-CC)' & chunk size
|
|
85
|
+
*/
|
|
86
|
+
export declare const FormatChunk: IGetToken<IFormatChunk>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbstractID3Parser } from '../id3v2/AbstractID3Parser.js';
|
|
2
|
+
/**
|
|
3
|
+
* DSF (dsd stream file) File Parser
|
|
4
|
+
* Ref: https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf
|
|
5
|
+
*/
|
|
6
|
+
export declare class DsfParser extends AbstractID3Parser {
|
|
7
|
+
postId3v2Parse(): Promise<void>;
|
|
8
|
+
private parseChunks;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ITokenizer } from 'strtok3/core';
|
|
2
|
+
import { AbstractID3Parser } from '../id3v2/AbstractID3Parser.js';
|
|
3
|
+
import { INativeMetadataCollector } from '../common/MetadataCollector.js';
|
|
4
|
+
import { IOptions } from '../type.js';
|
|
5
|
+
import { ITokenParser } from '../ParserFactory.js';
|
|
6
|
+
export declare class FlacParser extends AbstractID3Parser {
|
|
7
|
+
private vorbisParser;
|
|
8
|
+
private padding;
|
|
9
|
+
/**
|
|
10
|
+
* Initialize parser with output (metadata), input (tokenizer) & parsing options (options).
|
|
11
|
+
* @param {INativeMetadataCollector} metadata Output
|
|
12
|
+
* @param {ITokenizer} tokenizer Input
|
|
13
|
+
* @param {IOptions} options Parsing options
|
|
14
|
+
*/
|
|
15
|
+
init(metadata: INativeMetadataCollector, tokenizer: ITokenizer, options: IOptions): ITokenParser;
|
|
16
|
+
postId3v2Parse(): Promise<void>;
|
|
17
|
+
private parseDataBlock;
|
|
18
|
+
/**
|
|
19
|
+
* Parse STREAMINFO
|
|
20
|
+
*/
|
|
21
|
+
private parseBlockStreamInfo;
|
|
22
|
+
/**
|
|
23
|
+
* Parse VORBIS_COMMENT
|
|
24
|
+
* Ref: https://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-640004.2.3
|
|
25
|
+
*/
|
|
26
|
+
private parseComment;
|
|
27
|
+
private parsePicture;
|
|
28
|
+
}
|