music-metadata 11.10.0 → 11.10.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.
@@ -84,6 +84,7 @@ export class OggParser extends BasicParser {
84
84
  */
85
85
  async parse() {
86
86
  this.streams = new Map();
87
+ let enfOfStream = false;
87
88
  let header;
88
89
  try {
89
90
  do {
@@ -105,6 +106,7 @@ export class OggParser extends BasicParser {
105
106
  catch (err) {
106
107
  if (err instanceof EndOfStreamError) {
107
108
  debug("Reached end-of-stream");
109
+ enfOfStream = true;
108
110
  }
109
111
  else if (err instanceof OggContentError) {
110
112
  this.metadata.addWarning(`Corrupt Ogg content at ${this.tokenizer.position}`);
@@ -117,7 +119,7 @@ export class OggParser extends BasicParser {
117
119
  this.metadata.addWarning(`End-of-stream reached before reaching last page in Ogg stream serial=${stream.streamSerial}`);
118
120
  await stream.pageConsumer?.flush();
119
121
  }
120
- stream.pageConsumer?.calculateDuration();
122
+ stream.pageConsumer?.calculateDuration(enfOfStream);
121
123
  }
122
124
  }
123
125
  }
@@ -75,7 +75,7 @@ export interface IPageConsumer {
75
75
  /**
76
76
  * Calculate duration of provided header
77
77
  */
78
- calculateDuration(): void;
78
+ calculateDuration(enfOfStream: boolean): void;
79
79
  /**
80
80
  * Force to parse pending segments
81
81
  */
@@ -20,5 +20,5 @@ export declare class OpusStream extends VorbisStream {
20
20
  */
21
21
  protected parseFirstPage(_header: IPageHeader, pageData: Uint8Array): void;
22
22
  protected parseFullPage(pageData: Uint8Array): Promise<void>;
23
- calculateDuration(): void;
23
+ calculateDuration(enfOfStream: boolean): void;
24
24
  }
@@ -41,8 +41,8 @@ export class OpusStream extends VorbisStream {
41
41
  break;
42
42
  }
43
43
  }
44
- calculateDuration() {
45
- if (this.lastPageHeader && this.metadata.format.sampleRate && this.lastPageHeader.absoluteGranulePosition >= 0) {
44
+ calculateDuration(enfOfStream) {
45
+ if (this.lastPageHeader && (enfOfStream || this.lastPageHeader.headerType.lastPage) && this.metadata.format.sampleRate && this.lastPageHeader.absoluteGranulePosition >= 0) {
46
46
  // Calculate duration
47
47
  const pos_48bit = this.lastPageHeader.absoluteGranulePosition - this.idHeader.preSkip;
48
48
  this.metadata.setFormat('numberOfSamples', pos_48bit);
@@ -37,7 +37,7 @@ export declare class VorbisStream implements IPageConsumer {
37
37
  flush(): Promise<void>;
38
38
  parseUserComment(pageData: Uint8Array, offset: number): Promise<number>;
39
39
  addTag(id: string, value: string | IVorbisPicture): Promise<void>;
40
- calculateDuration(): void;
40
+ calculateDuration(enfOfStream: boolean): void;
41
41
  /**
42
42
  * Parse first Ogg/Vorbis page
43
43
  * @param _header
@@ -77,7 +77,7 @@ export class VorbisStream {
77
77
  }
78
78
  await this.metadata.addTag('vorbis', id, value);
79
79
  }
80
- calculateDuration() {
80
+ calculateDuration(enfOfStream) {
81
81
  if (this.lastPageHeader && this.metadata.format.sampleRate && this.lastPageHeader.absoluteGranulePosition >= 0) {
82
82
  // Calculate duration
83
83
  this.metadata.setFormat('numberOfSamples', this.lastPageHeader.absoluteGranulePosition);
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.10.0",
4
+ "version": "11.10.1",
5
5
  "author": {
6
6
  "name": "Borewit",
7
7
  "url": "https://github.com/Borewit"
@@ -110,14 +110,14 @@
110
110
  "@tokenizer/token": "^0.3.0",
111
111
  "content-type": "^1.0.5",
112
112
  "debug": "^4.4.3",
113
- "file-type": "^21.0.0",
113
+ "file-type": "^21.1.0",
114
114
  "media-typer": "^1.1.0",
115
115
  "strtok3": "^10.3.4",
116
116
  "token-types": "^6.1.1",
117
117
  "uint8array-extras": "^1.5.0"
118
118
  },
119
119
  "devDependencies": {
120
- "@biomejs/biome": "2.3.4",
120
+ "@biomejs/biome": "2.3.5",
121
121
  "@types/chai": "^5.2.2",
122
122
  "@types/chai-as-promised": "^8.0.2",
123
123
  "@types/content-type": "^1.1.9",
@@ -126,7 +126,7 @@
126
126
  "@types/mocha": "^10.0.10",
127
127
  "@types/node": "^24.5.0",
128
128
  "c8": "^10.1.3",
129
- "chai": "^6.2.0",
129
+ "chai": "^6.2.1",
130
130
  "chai-as-promised": "^8.0.2",
131
131
  "del-cli": "^7.0.0",
132
132
  "mime": "^4.1.0",