+1
-24
src/Javascript/Brain/artwork.ts
+1
-24
src/Javascript/Brain/artwork.ts
···
2
2
// Album Covers
3
3
// (◕‿◕✿)
4
4
5
-
import MediaInfoFactory, { MediaInfo } from "mediainfo.js"
6
-
7
5
import { transformUrl } from "../urls"
8
6
import * as processing from "../processing"
9
7
···
30
28
31
29
32
30
async function findUsingTags(prep, app) {
33
-
const mediainfo = await mediaInfoClient()
34
-
35
31
return Promise.all(
36
32
[
37
33
transformUrl(prep.trackHeadUrl, app),
···
42
38
headUrl,
43
39
getUrl,
44
40
prep.trackFilename,
45
-
mediainfo
41
+
{ covers: true }
46
42
47
43
)).then(tags => {
48
44
return tags?.picture
···
114
110
.catch(_ => lastFmCover(remainingMatches.slice(1)))
115
111
: album && lastFmCover(remainingMatches.slice(1))
116
112
}
117
-
118
-
119
-
120
-
// 🛠️
121
-
122
-
123
-
let client: MediaInfo<"object"> | null
124
-
125
-
126
-
async function mediaInfoClient() {
127
-
if (client) return client
128
-
client = await MediaInfoFactory({
129
-
coverData: true,
130
-
locateFile: () => {
131
-
return "../../wasm/media-info.wasm"
132
-
},
133
-
})
134
-
return client
135
-
}
+6
-7
src/Javascript/processing.ts
+6
-7
src/Javascript/processing.ts
···
14
14
// --------
15
15
16
16
export async function processContext(context, app) {
17
-
const mediainfo = await mediaInfoClient();
18
17
const initialPromise = Promise.resolve([]);
19
18
20
19
return context.urlsForTags
···
24
23
25
24
return Promise.all([transformUrl(urls.headUrl, app), transformUrl(urls.getUrl, app)])
26
25
.then(([headUrl, getUrl]) => {
27
-
return getTags(headUrl, getUrl, filename, mediainfo);
26
+
return getTags(headUrl, getUrl, filename, { covers: false });
28
27
})
29
28
.then((r) => {
30
29
return col.concat(r);
···
75
74
tokenizer.rangeRequestClient.resolvedUrl = undefined;
76
75
}
77
76
78
-
const mmResult = await musicMetadata.parseFromTokenizer(tokenizer, { skipCovers: !covers });
79
-
const mmTags = pickTagsFromMusicMetadata(filename, mmResult);
77
+
const mmResult = await musicMetadata.parseFromTokenizer(tokenizer, { skipCovers: !covers }).catch(() => null);
78
+
const mmTags = mmResult && pickTagsFromMusicMetadata(filename, mmResult);
80
79
if (mmTags) return mmTags;
81
80
82
-
const miResult = (await mediaInfoClient())
81
+
const miResult = await (await mediaInfoClient(covers))
83
82
.analyzeData(getSize(headUrl), readChunk(getUrl))
84
83
.catch((_) => null);
85
84
const miTags = miResult && pickTagsFromMediaInfo(filename, miResult);
···
219
218
// 🛠️
220
219
// --
221
220
222
-
async function mediaInfoClient() {
221
+
async function mediaInfoClient(covers: boolean) {
223
222
const MediaInfoFactory = await import("mediainfo.js").then(a => a.default)
224
223
225
224
return await MediaInfoFactory({
226
-
coverData: false,
225
+
coverData: covers,
227
226
locateFile: () => {
228
227
return "../../wasm/media-info.wasm";
229
228
},