MCPcopy Create free account
hub / github.com/MathMan05/Fermi / IdentifyFile

Method IdentifyFile

src/webpage/media.ts:315–534  ·  view source on GitHub ↗
(url: string | media)

Source from the content-addressed store, hash-verified

313 }
314 static cache = new Map<string, media | Promise<media>>();
315 static async IdentifyFile(url: string | media): Promise<media | null> {
316 if (url instanceof Object) {
317 return url;
318 }
319 const cValue = this.cache.get(url);
320 if (cValue) {
321 return cValue;
322 }
323 let resMedio = (_: media) => {};
324 this.cache.set(url, new Promise<media>((res) => (resMedio = res)));
325 const prog = new ProgressiveArray(url, {method: "get"});
326 await prog.ready;
327
328 const output: Partial<media> = {
329 src: url,
330 };
331 try {
332 const head = String.fromCharCode(await prog.next(), await prog.next(), await prog.next());
333 if (head === "ID3") {
334 const version = (await prog.next()) + (await prog.next()) * 256;
335
336 if (version === 2) {
337 //TODO I'm like 90% I can ignore *all* of the flags, but I need to check more sometime
338 await prog.next();
339 //debugger;
340 const sizes = await prog.get8BitArray(4);
341 prog.sizeLeft = (sizes[0] << 21) + (sizes[1] << 14) + (sizes[2] << 7) + sizes[3];
342 const mappy = new Map<string, Uint8Array<ArrayBuffer>>();
343 while (prog.sizeLeft > 0) {
344 const Identify = String.fromCharCode(
345 await prog.next(),
346 await prog.next(),
347 await prog.next(),
348 );
349 const sizeArr = await prog.get8BitArray(3);
350 const size = (sizeArr[0] << 16) + (sizeArr[1] << 8) + sizeArr[2];
351 if (Identify === String.fromCharCode(0, 0, 0)) {
352 break;
353 }
354 if (!size) {
355 throw Error("weirdness");
356 }
357 if (!Identify.match(/[A-Z0-9]/gm)) {
358 console.error(`tried to get ${Identify} which doesn't exist`);
359 break;
360 }
361 if (mappy.has(Identify)) {
362 await prog.get8BitArray(size);
363 //console.warn("Got dupe", Identify);
364 } else {
365 mappy.set(Identify, await prog.get8BitArray(size));
366 }
367 }
368 const pic = mappy.get("PIC");
369 if (pic) {
370 let i = 5; //skipping info I don't need right now
371 const desc: number[] = [];
372 for (; pic[i]; i++) {

Callers 1

makePlayBoxFunction · 0.80

Calls 5

nextMethod · 0.95
get8BitArrayMethod · 0.95
closeMethod · 0.95
resFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected