From 860349086b7b32fa2e715e24b4a2f69724548190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20P=C3=B6mp?= Date: Sun, 10 Nov 2024 19:06:45 +0100 Subject: [PATCH] build(project): fix building umd with current music-metadata library --- .../AudioFormats/music-metadata-format.ts | 29 ++++----------- libs/web-media/vite.config.ts | 1 + package-lock.json | 35 +++++++++++++------ package.json | 2 +- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/libs/web-media/src/lib/audio/AudioFormats/music-metadata-format.ts b/libs/web-media/src/lib/audio/AudioFormats/music-metadata-format.ts index 04d00ab5f..7db608c30 100644 --- a/libs/web-media/src/lib/audio/AudioFormats/music-metadata-format.ts +++ b/libs/web-media/src/lib/audio/AudioFormats/music-metadata-format.ts @@ -1,5 +1,5 @@ import { AudioFormat } from './audio-format'; -import { MpegParser, parseBlob, OggParser, MP4Parser, FlacParser} from 'music-metadata-remastered'; +import { parseBlob } from 'music-metadata'; export class MusicMetadataFormat extends AudioFormat { protected override _decoder: 'web-audio' | 'octra' = 'web-audio'; @@ -34,42 +34,25 @@ export class MusicMetadataFormat extends AudioFormat { } override async readAudioInformation(buffer: ArrayBuffer) { - let parser: any | undefined; - const ext = this._filename.substring(this._filename.lastIndexOf(".")); - - switch (ext) { - case ".mp3": - parser = MpegParser; - break; - case ".ogg": - parser = OggParser; - break; - case ".m4a": - parser = MP4Parser; - break; - case ".flac": - parser = FlacParser; - break; - } - const parsed = await parseBlob( - new File([buffer], this._filename, { type: this._mimeType }), - parser + new File([buffer], this._filename, { type: this._mimeType }) ); const format = parsed.format; if ( !format.sampleRate || - !format.numberOfSamples || + !(format.numberOfSamples || format.duration) || !format.numberOfChannels ) { throw new Error( "Can't read one of the following audio information: sampleRate, numberOfSamples, numberOfChannels." ); } else { + const numberOfSamples = + format.numberOfSamples ?? Math.ceil(format.duration! * format.sampleRate); this._sampleRate = format.sampleRate; this._duration = { - samples: format.numberOfSamples, + samples: numberOfSamples, seconds: format.duration!, }; this._channels = format.numberOfChannels; diff --git a/libs/web-media/vite.config.ts b/libs/web-media/vite.config.ts index 925cf4295..29a1b0632 100644 --- a/libs/web-media/vite.config.ts +++ b/libs/web-media/vite.config.ts @@ -43,6 +43,7 @@ export default defineConfig({ '@octra/utilities': 'OctraUtilities', '@octra/media': 'OctraMedia', }, + inlineDynamicImports: true }, // External packages that should not be bundled into your library. external: ['@octra/utilities', '@octra/media'], diff --git a/package-lock.json b/package-lock.json index 55fd18df1..11c53f1e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -105,7 +105,7 @@ "jest-environment-jsdom": "29.7.0", "jest-preset-angular": "14.1.0", "jsonc-eslint-parser": "^2.1.0", - "music-metadata-remastered": "file:music-metadata-remastered-0.0.1.tgz", + "music-metadata": "^10.5.1", "ng-packagr": "18.2.1", "ngx-deploy-npm": "8.2.0", "nx": "20.0.11", @@ -21605,11 +21605,21 @@ "multicast-dns": "cli.js" } }, - "node_modules/music-metadata-remastered": { - "version": "0.0.1", - "resolved": "file:music-metadata-remastered-0.0.1.tgz", - "integrity": "sha512-hFx/egbowW0NZfEf1hT5C/rAwKEXjAQonH2GL3P+Ws6i4nhwXElAi7UIyEMy3J+plndNOoTwDzQ6LuKzvj83Eg==", + "node_modules/music-metadata": { + "version": "10.5.1", + "resolved": "https://registry.npmjs.org/music-metadata/-/music-metadata-10.5.1.tgz", + "integrity": "sha512-lrBqOlhgAlqzBkqEMiqnVaCXwfQBkid8eXborPVceYv/t4lfXN3DiCBHed3fu+5kpqpaAez/rn3/PiT/fCYU4g==", "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + }, + { + "type": "buymeacoffee", + "url": "https://buymeacoffee.com/borewit" + } + ], "dependencies": { "@tokenizer/token": "^0.3.0", "content-type": "^1.0.5", @@ -21619,9 +21629,12 @@ "strtok3": "^9.0.1", "token-types": "^6.0.0", "uint8array-extras": "^1.4.0" + }, + "engines": { + "node": ">=16.0.0" } }, - "node_modules/music-metadata-remastered/node_modules/file-type": { + "node_modules/music-metadata/node_modules/file-type": { "version": "19.6.0", "resolved": "https://registry.npmjs.org/file-type/-/file-type-19.6.0.tgz", "integrity": "sha512-VZR5I7k5wkD0HgFnMsq5hOsSc710MJMu5Nc5QYsbe38NN5iPV/XTObYLc/cpttRTf6lX538+5uO1ZQRhYibiZQ==", @@ -21639,7 +21652,7 @@ "url": "https://github.com/sindresorhus/file-type?sponsor=1" } }, - "node_modules/music-metadata-remastered/node_modules/get-stream": { + "node_modules/music-metadata/node_modules/get-stream": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-9.0.1.tgz", "integrity": "sha512-kVCxPF3vQM/N0B1PmoqVUqgHP+EeVjmZSQn+1oCRPxd2P21P2F19lIgbR3HBosbB1PUhOAoctJnfEn2GbN2eZA==", @@ -21655,7 +21668,7 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/music-metadata-remastered/node_modules/is-stream": { + "node_modules/music-metadata/node_modules/is-stream": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-4.0.1.tgz", "integrity": "sha512-Dnz92NInDqYckGEUJv689RbRiTSEHCQ7wOVeALbkOz999YpqT46yMRIGtSNl2iCL1waAZSx40+h59NV/EwzV/A==", @@ -21667,7 +21680,7 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/music-metadata-remastered/node_modules/media-typer": { + "node_modules/music-metadata/node_modules/media-typer": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", @@ -21676,7 +21689,7 @@ "node": ">= 0.8" } }, - "node_modules/music-metadata-remastered/node_modules/strtok3": { + "node_modules/music-metadata/node_modules/strtok3": { "version": "9.0.1", "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-9.0.1.tgz", "integrity": "sha512-ERPW+XkvX9W2A+ov07iy+ZFJpVdik04GhDA4eVogiG9hpC97Kem2iucyzhFxbFRvQ5o2UckFtKZdp1hkGvnrEw==", @@ -21693,7 +21706,7 @@ "url": "https://github.com/sponsors/Borewit" } }, - "node_modules/music-metadata-remastered/node_modules/token-types": { + "node_modules/music-metadata/node_modules/token-types": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/token-types/-/token-types-6.0.0.tgz", "integrity": "sha512-lbDrTLVsHhOMljPscd0yitpozq7Ga2M5Cvez5AjGg8GASBjtt6iERCAJ93yommPmz62fb45oFIXHEZ3u9bfJEA==", diff --git a/package.json b/package.json index 7ff328c43..e79c3cf4c 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,7 @@ "jest-environment-jsdom": "29.7.0", "jest-preset-angular": "14.1.0", "jsonc-eslint-parser": "^2.1.0", - "music-metadata-remastered": "file:music-metadata-remastered-0.0.1.tgz", + "music-metadata": "^10.5.1", "ng-packagr": "18.2.1", "ngx-deploy-npm": "8.2.0", "nx": "20.0.11",