music-metadata 11.1.1 → 11.2.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/README.md CHANGED
@@ -788,9 +788,10 @@ For older Node.js version < 22, you need to dynamically import **music-metadata*
788
788
  })();
789
789
  ```
790
790
 
791
- For CommonJS TypeScript projects, using a Node.js version < 22, you can use [load-esm](https://github.com/Borewit/load-esm):
791
+ For CommonJS TypeScript projects, I recommend to avoid using `commonjs` for the TypeScript compiler `module` option,
792
+ and either use `node16` or `nodenext`, which enable utilizing [dynamic import](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/import).
792
793
 
793
- This method shall has replaced the embedded CJS loader function: `loadMusicMetadata()`.
794
+ If you do want to use the classic `commonjs` option, this is how you can get the _dynamic import_ to work.
794
795
 
795
796
  ```js
796
797
  import {loadEsm} from 'load-esm';
@@ -801,6 +802,8 @@ import {loadEsm} from 'load-esm';
801
802
  })();
802
803
  ```
803
804
 
805
+ When you use Node.js version ≥ 22, which supports loading ESM modules via require, this compensates for that issue.
806
+
804
807
  ## Frequently Asked Questions
805
808
 
806
809
  ### How can I traverse (a long) list of files?
@@ -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.1",
4
+ "version": "11.2.1",
5
5
  "author": {
6
6
  "name": "Borewit",
7
7
  "url": "https://github.com/Borewit"
@@ -107,8 +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",
111
- "link": "^2.1.1",
110
+ "file-type": "^20.4.1",
112
111
  "media-typer": "^1.1.0",
113
112
  "strtok3": "^10.2.2",
114
113
  "token-types": "^6.0.0",
@@ -122,7 +121,7 @@
122
121
  "@types/debug": "^4.1.12",
123
122
  "@types/media-typer": "^1.1.3",
124
123
  "@types/mocha": "^10.0.10",
125
- "@types/node": "^22.14.0",
124
+ "@types/node": "^22.14.1",
126
125
  "c8": "^10.1.3",
127
126
  "chai": "^5.2.0",
128
127
  "chai-as-promised": "^8.0.1",
@@ -133,7 +132,7 @@
133
132
  "remark-cli": "^12.0.1",
134
133
  "remark-preset-lint-consistent": "^6.0.1",
135
134
  "ts-node": "^10.9.2",
136
- "typescript": "^5.8.2"
135
+ "typescript": "^5.8.3"
137
136
  },
138
137
  "engines": {
139
138
  "node": ">=18"
@@ -145,5 +144,5 @@
145
144
  "bugs": {
146
145
  "url": "https://github.com/Borewit/music-metadata/issues"
147
146
  },
148
- "packageManager": "yarn@4.8.1"
147
+ "packageManager": "yarn@4.9.1"
149
148
  }