diff --git a/src/Javascript/processing.ts b/src/Javascript/processing.ts --- a/src/Javascript/processing.ts +++ b/src/Javascript/processing.ts @@ -14,7 +14,6 @@ // -------- export async function processContext(context, app) { - const mediainfo = await mediaInfoClient(); const initialPromise = Promise.resolve([]); return context.urlsForTags @@ -24,7 +23,7 @@ return Promise.all([transformUrl(urls.headUrl, app), transformUrl(urls.getUrl, app)]) .then(([headUrl, getUrl]) => { - return getTags(headUrl, getUrl, filename, mediainfo); + return getTags(headUrl, getUrl, filename, { covers: false }); }) .then((r) => { return col.concat(r); @@ -75,11 +74,11 @@ tokenizer.rangeRequestClient.resolvedUrl = undefined; } - const mmResult = await musicMetadata.parseFromTokenizer(tokenizer, { skipCovers: !covers }); - const mmTags = pickTagsFromMusicMetadata(filename, mmResult); + const mmResult = await musicMetadata.parseFromTokenizer(tokenizer, { skipCovers: !covers }).catch(() => null); + const mmTags = mmResult && pickTagsFromMusicMetadata(filename, mmResult); if (mmTags) return mmTags; - const miResult = (await mediaInfoClient()) + const miResult = await (await mediaInfoClient(covers)) .analyzeData(getSize(headUrl), readChunk(getUrl)) .catch((_) => null); const miTags = miResult && pickTagsFromMediaInfo(filename, miResult); @@ -219,11 +218,11 @@ // 🛠️ // -- -async function mediaInfoClient() { +async function mediaInfoClient(covers: boolean) { const MediaInfoFactory = await import("mediainfo.js").then(a => a.default) return await MediaInfoFactory({ - coverData: false, + coverData: covers, locateFile: () => { return "../../wasm/media-info.wasm"; }, diff --git a/src/Javascript/Brain/artwork.ts b/src/Javascript/Brain/artwork.ts --- a/src/Javascript/Brain/artwork.ts +++ b/src/Javascript/Brain/artwork.ts @@ -2,8 +2,6 @@ // Album Covers // (◕‿◕✿) -import MediaInfoFactory, { MediaInfo } from "mediainfo.js" - import { transformUrl } from "../urls" import * as processing from "../processing" @@ -30,8 +28,6 @@ async function findUsingTags(prep, app) { - const mediainfo = await mediaInfoClient() - return Promise.all( [ transformUrl(prep.trackHeadUrl, app), @@ -42,7 +38,7 @@ headUrl, getUrl, prep.trackFilename, - mediainfo + { covers: true } )).then(tags => { return tags?.picture @@ -113,23 +109,4 @@ .then(r => r.blob()) .catch(_ => lastFmCover(remainingMatches.slice(1))) : album && lastFmCover(remainingMatches.slice(1)) -} - - - -// 🛠️ - - -let client: MediaInfo<"object"> | null - - -async function mediaInfoClient() { - if (client) return client - client = await MediaInfoFactory({ - coverData: true, - locateFile: () => { - return "../../wasm/media-info.wasm" - }, - }) - return client }