music-metadata 8.0.0 → 8.0.1
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/lib/ParserFactory.d.ts +48 -0
- package/lib/aiff/AiffParser.d.ts +14 -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/browser.js +99 -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/FourCC.d.ts +6 -0
- 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/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 +3 -3
package/lib/browser.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import initDebug from 'debug';
|
|
2
|
+
import { ReadableWebToNodeStream } from 'readable-web-to-node-stream';
|
|
3
|
+
import * as mm from './core.js';
|
|
4
|
+
export { parseBuffer, parseFromTokenizer, orderTags, ratingToStars, selectCover } from './core.js';
|
|
5
|
+
const debug = initDebug('music-metadata-browser:main');
|
|
6
|
+
/**
|
|
7
|
+
* Parse audio Stream
|
|
8
|
+
* @param stream - ReadableStream
|
|
9
|
+
* @param contentType - MIME-Type
|
|
10
|
+
* @param options - Parsing options
|
|
11
|
+
* @returns Metadata
|
|
12
|
+
*/
|
|
13
|
+
export const parseNodeStream = mm.parseStream;
|
|
14
|
+
/**
|
|
15
|
+
* Parse Web API ReadableStream: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
|
|
16
|
+
* @param stream - ReadableStream (web stream according WTWG Streams Standard)
|
|
17
|
+
* @param fileInfo FileInfo object or MIME-Type
|
|
18
|
+
* @param options - Parsing options
|
|
19
|
+
* @returns Metadata
|
|
20
|
+
*/
|
|
21
|
+
export async function parseReadableStream(stream, fileInfo, options) {
|
|
22
|
+
const ns = new ReadableWebToNodeStream(stream);
|
|
23
|
+
const res = await parseNodeStream(ns, typeof fileInfo === 'string' ? { mimeType: fileInfo } : fileInfo, options);
|
|
24
|
+
await ns.close();
|
|
25
|
+
return res;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parse Web API File
|
|
29
|
+
* @param blob - Blob to parse
|
|
30
|
+
* @param options - Parsing options
|
|
31
|
+
* @returns Metadata
|
|
32
|
+
*/
|
|
33
|
+
export async function parseBlob(blob, options) {
|
|
34
|
+
const fileInfo = { mimeType: blob.type, size: blob.size };
|
|
35
|
+
if (blob instanceof File) {
|
|
36
|
+
fileInfo.path = blob.name;
|
|
37
|
+
}
|
|
38
|
+
const stream = blob.stream ? blob.stream() : convertBlobToReadableStream(blob);
|
|
39
|
+
return parseReadableStream(stream, { mimeType: blob.type, size: blob.size }, options);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Convert Blob to ReadableStream
|
|
43
|
+
* Fallback for Safari versions < 14.1
|
|
44
|
+
* @param blob
|
|
45
|
+
*/
|
|
46
|
+
function convertBlobToReadableStream(blob) {
|
|
47
|
+
const fileReader = new FileReader();
|
|
48
|
+
return new ReadableStream({
|
|
49
|
+
start(controller) {
|
|
50
|
+
// The following function handles each data chunk
|
|
51
|
+
fileReader.onloadend = event => {
|
|
52
|
+
let data = event.target.result;
|
|
53
|
+
if (data instanceof ArrayBuffer) {
|
|
54
|
+
data = new Uint8Array(data);
|
|
55
|
+
}
|
|
56
|
+
controller.enqueue(data);
|
|
57
|
+
controller.close();
|
|
58
|
+
};
|
|
59
|
+
fileReader.onerror = error => {
|
|
60
|
+
controller.close();
|
|
61
|
+
};
|
|
62
|
+
fileReader.onabort = error => {
|
|
63
|
+
controller.close();
|
|
64
|
+
};
|
|
65
|
+
fileReader.readAsArrayBuffer(blob);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parse fetched file, using the Web Fetch API
|
|
71
|
+
* @param audioTrackUrl - URL to download the audio track from
|
|
72
|
+
* @param options - Parsing options
|
|
73
|
+
* @returns Metadata
|
|
74
|
+
*/
|
|
75
|
+
export async function fetchFromUrl(audioTrackUrl, options) {
|
|
76
|
+
const response = await fetch(audioTrackUrl);
|
|
77
|
+
const fileInfo = {
|
|
78
|
+
size: parseInt(response.headers.get('Content-Length'), 10),
|
|
79
|
+
mimeType: response.headers.get('Content-Type')
|
|
80
|
+
};
|
|
81
|
+
if (response.ok) {
|
|
82
|
+
if (response.body) {
|
|
83
|
+
const res = await parseReadableStream(response.body, fileInfo, options);
|
|
84
|
+
debug('Closing HTTP-readable-stream...');
|
|
85
|
+
if (!response.body.locked) { // Prevent error in Firefox
|
|
86
|
+
await response.body.cancel();
|
|
87
|
+
}
|
|
88
|
+
debug('HTTP-readable-stream closed.');
|
|
89
|
+
return res;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// Fall back on Blob
|
|
93
|
+
return parseBlob(await response.blob(), options);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
throw new Error(`HTTP error status=${response.status}: ${response.statusText}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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';
|
|
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;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BasicParser } from '../common/BasicParser.js';
|
|
2
|
+
import { IRandomReader } from '../type.js';
|
|
3
|
+
/**
|
|
4
|
+
* ID3v1 Genre mappings
|
|
5
|
+
* Ref: https://de.wikipedia.org/wiki/Liste_der_ID3v1-Genres
|
|
6
|
+
*/
|
|
7
|
+
export declare const Genres: string[];
|
|
8
|
+
export declare class ID3v1Parser extends BasicParser {
|
|
9
|
+
private static getGenre;
|
|
10
|
+
parse(): Promise<void>;
|
|
11
|
+
private addTag;
|
|
12
|
+
}
|
|
13
|
+
export declare function hasID3v1Header(reader: IRandomReader): Promise<boolean>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ITokenizer } from 'strtok3/core';
|
|
2
|
+
import { BasicParser } from '../common/BasicParser.js';
|
|
3
|
+
/**
|
|
4
|
+
* Abstract parser which tries take ID3v2 and ID3v1 headers.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class AbstractID3Parser extends BasicParser {
|
|
7
|
+
static startsWithID3v2Header(tokenizer: ITokenizer): Promise<boolean>;
|
|
8
|
+
private id3parser;
|
|
9
|
+
parse(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Called after ID3v2 headers are parsed
|
|
12
|
+
*/
|
|
13
|
+
abstract postId3v2Parse(): Promise<void>;
|
|
14
|
+
protected finalize(): void;
|
|
15
|
+
private parseID3v2;
|
|
16
|
+
private tryReadId3v2Headers;
|
|
17
|
+
}
|