Browse Source

Handle case where webm has no metadata that can be leeched off

pull/7/head
coomdev 2 years ago
parent
commit
79357ebd3a
  1. 609
      main.user.js
  2. 8
      src/main.ts
  3. 46
      src/webm.ts

609
main.user.js

File diff suppressed because it is too large

8
src/main.ts

@ -155,7 +155,6 @@ const processPost = async (post: HTMLDivElement) => {
};
const startup = async () => {
await Promise.all([...document.querySelectorAll('.postContainer')].map(e => processPost(e as any)));
//await Promise.all([...document.querySelectorAll('.postContainer')].filter(e => e.textContent?.includes("191 KB")).map(e => processPost(e as any)));
@ -173,6 +172,7 @@ const startup = async () => {
};
let injected = false;
debugger;
document.addEventListener('QRDialogCreation', <any>((e: CustomEvent<string>) => {
if (injected)
return;
@ -196,14 +196,18 @@ const startup = async () => {
const proc = processors.find(e => file.name.match(e[0]));
if (!proc)
return;
const buff = await proc[2](file, input.files[0]);
document.dispatchEvent(new CustomEvent('QRSetFile', {
detail: await proc[2](file, input.files[0])
detail: { file: new Blob([buff]), name: input.files[0].name }
}));
}
});
input.click();
};
}));
await Promise.all([...document.querySelectorAll('.postContainer')].map(e => processPost(e as any)));
};
document.addEventListener('4chanXInitFinished', startup);

46
src/webm.ts

@ -33,14 +33,52 @@ const printChunks = (chunks: ebml.EBMLElementDetail[], ptr = 0, depth = 0): void
}
};
const findEnclosingTag = (ch: ebml.EBMLElementDetail[], name: string): [number, number] | undefined => {
const first = ch.findIndex(e => e.type == 'm' && e.name == name);
if (first < 0)
return;
const second = ch.slice(first).findIndex(e => e.type == 'm' && e.name == name);
if (second < 0)
return;
return [
first, first + second
];
};
const embed = (webm: Buffer, data: Buffer) => {
const dec = new ebml.Decoder();
const chunks = dec.decode(webm);
const enc = new ebml.Encoder();
const embed = chunks.findIndex(e => e.name == "Targets" && e.type == "m" && e.isEnd);
if (embed == -1)
throw "Cannot embed, no tags section...";
// That's basically budget binary XML
let embed = chunks.findIndex(e => e.name == "Tracks" && e.type == "m" && e.isEnd);
const findOrInsert = (n: string) => {
let tags = findEnclosingTag(chunks, n);
const stack = [];
if (!tags) {
stack.push({
type: "m",
isEnd: false,
name: n,
data: Buffer.from('')
});
stack.push({
type: "m",
isEnd: true,
name: n,
data: Buffer.from('')
});
chunks.splice(embed + 1, 0, ...stack as any);
tags = findEnclosingTag(chunks, n);
}
embed = tags![1];
};
findOrInsert('Tags');
findOrInsert('Tag');
findOrInsert('Targets');
embed++;
chunks.splice(embed + 1, 0, ...[
{
type: "m",

Loading…
Cancel
Save