music-metadata 11.1.0 → 11.2.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/lib/core.d.ts CHANGED
@@ -3,10 +3,11 @@
3
3
  */
4
4
  import { type AnyWebByteStream, type IFileInfo, type ITokenizer, type IRandomAccessTokenizer } from 'strtok3';
5
5
  import type { IAudioMetadata, INativeTagDict, IOptions, IPicture, IPrivateOptions, ITag } from './type.js';
6
+ import type { Readable } from 'node:stream';
6
7
  export type { IFileInfo } from 'strtok3';
7
8
  export { type IAudioMetadata, type IOptions, type ITag, type INativeTagDict, type ICommonTagsResult, type IFormat, type IPicture, type IRatio, type IChapter, type ILyricsTag, LyricsContentType, TimestampFormat, IMetadataEventTag, IMetadataEvent } from './type.js';
8
9
  export { CouldNotDetermineFileTypeError, UnsupportedFileTypeError } from './ParseError.js';
9
- export type * from './ParseError.js';
10
+ export * from './ParseError.js';
10
11
  /**
11
12
  * Parse Web API File
12
13
  * Requires Blob to be able to stream using a ReadableStreamBYOBReader, only available since Node.js ≥ 20
@@ -63,6 +64,11 @@ export declare function scanAppendingHeaders(tokenizer: IRandomAccessTokenizer,
63
64
  * This method will throw an Error, always.
64
65
  */
65
66
  export declare function parseFile(filePath: string, options?: IOptions): Promise<IAudioMetadata>;
67
+ /**
68
+ * Implementation only available when loaded as Node.js
69
+ * This method will throw an Error, always.
70
+ */
71
+ export declare function parseStream(stream: Readable, fileInfo?: IFileInfo | string, options?: IOptions): Promise<IAudioMetadata>;
66
72
  /**
67
73
  * Return a list of supported mime-types
68
74
  */
package/lib/core.js CHANGED
@@ -8,6 +8,7 @@ import { hasID3v1Header } from './id3v1/ID3v1Parser.js';
8
8
  import { getLyricsHeaderLength } from './lyrics3/Lyrics3.js';
9
9
  export { LyricsContentType, TimestampFormat } from './type.js';
10
10
  export { CouldNotDetermineFileTypeError, UnsupportedFileTypeError } from './ParseError.js';
11
+ export * from './ParseError.js';
11
12
  /**
12
13
  * Parse Web API File
13
14
  * Requires Blob to be able to stream using a ReadableStreamBYOBReader, only available since Node.js ≥ 20
@@ -109,7 +110,14 @@ export async function scanAppendingHeaders(tokenizer, options = {}) {
109
110
  * This method will throw an Error, always.
110
111
  */
111
112
  export async function parseFile(filePath, options = {}) {
112
- throw new Error('To load Web API File objects use parseBlob instead. For loading files, you need to import with the "node" condition is set.');
113
+ throw new Error('This function require a Node engine. To load Web API File objects use parseBlob instead.');
114
+ }
115
+ /**
116
+ * Implementation only available when loaded as Node.js
117
+ * This method will throw an Error, always.
118
+ */
119
+ export async function parseStream(stream, fileInfo, options = {}) {
120
+ throw new Error('This function require a Node engine.');
113
121
  }
114
122
  /**
115
123
  * Return a list of supported mime-types
@@ -462,6 +462,9 @@ export class MP4Parser extends BasicParser {
462
462
  }
463
463
  const chapters = [];
464
464
  for (let i = 0; i < chapterTrack.chunkOffsetTable.length && len > 0; ++i) {
465
+ const start = chapterTrack.timeToSampleTable
466
+ .slice(0, i)
467
+ .reduce((acc, cur) => acc + cur.duration, 0);
465
468
  const chunkOffset = chapterTrack.chunkOffsetTable[i];
466
469
  const nextChunkLen = chunkOffset - this.tokenizer.position;
467
470
  const sampleSize = chapterTrack.sampleSize > 0 ? chapterTrack.sampleSize : chapterTrack.sampleSizeTable[i];
@@ -473,6 +476,8 @@ export class MP4Parser extends BasicParser {
473
476
  debug(`Chapter ${i + 1}: ${title}`);
474
477
  const chapter = {
475
478
  title,
479
+ timeScale: chapterTrack.timeScale,
480
+ start,
476
481
  sampleOffset: this.findSampleOffset(track, this.tokenizer.position)
477
482
  };
478
483
  debug(`Chapter title=${chapter.title}, offset=${chapter.sampleOffset}/${this.tracks[0].duration}`);
package/lib/type.d.ts CHANGED
@@ -485,6 +485,15 @@ export interface IChapter {
485
485
  * Duration offset is sampleOffset / format.sampleRate
486
486
  */
487
487
  sampleOffset: number;
488
+ /**
489
+ * Timestamp where the chapter starts
490
+ * Chapter timestamp is start/timeScale in seconds.
491
+ */
492
+ start: number;
493
+ /**
494
+ * Time value that indicates the time scale for chapter tracks, the number of time units that pass per second in its time coordinate system.
495
+ */
496
+ timeScale: number;
488
497
  }
489
498
  /**
490
499
  * Flat list of tags
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "music-metadata",
3
3
  "description": "Music metadata parser for Node.js, supporting virtual any audio and tag format.",
4
- "version": "11.1.0",
4
+ "version": "11.2.0",
5
5
  "author": {
6
6
  "name": "Borewit",
7
7
  "url": "https://github.com/Borewit"
@@ -107,7 +107,7 @@
107
107
  "@tokenizer/token": "^0.3.0",
108
108
  "content-type": "^1.0.5",
109
109
  "debug": "^4.4.0",
110
- "file-type": "^19.6.0",
110
+ "file-type": "^20.4.1",
111
111
  "link": "^2.1.1",
112
112
  "media-typer": "^1.1.0",
113
113
  "strtok3": "^10.2.2",
@@ -122,7 +122,7 @@
122
122
  "@types/debug": "^4.1.12",
123
123
  "@types/media-typer": "^1.1.3",
124
124
  "@types/mocha": "^10.0.10",
125
- "@types/node": "^22.14.0",
125
+ "@types/node": "^22.14.1",
126
126
  "c8": "^10.1.3",
127
127
  "chai": "^5.2.0",
128
128
  "chai-as-promised": "^8.0.1",
@@ -133,7 +133,7 @@
133
133
  "remark-cli": "^12.0.1",
134
134
  "remark-preset-lint-consistent": "^6.0.1",
135
135
  "ts-node": "^10.9.2",
136
- "typescript": "^5.8.2"
136
+ "typescript": "^5.8.3"
137
137
  },
138
138
  "engines": {
139
139
  "node": ">=18"