mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Normalize imeta MIME casing
This commit is contained in:
1 parent
53627b72cd
commit
462f4bed9e
5 files changed
+23
-4
No files matched your search
+2
-1
@@ -177,7 +177,8 @@ function buildImetaTags(variants) {
|
||||
const dim = stringFromInput(variant.dim);
|
||||
const url = stringFromInput(variant.url);
|
||||
const x = stringFromInput(variant.x);
|
||||
const mime = stringFromInput(variant.m);
|
||||
const rawMime = stringFromInput(variant.m);
|
||||
const mime = rawMime ? rawMime.toLowerCase() : "";
|
||||
const duration = formatNonNegativeNumber(variant.duration, {
|
||||
allowFloat: true,
|
||||
});
|
||||
|
||||
@@ -85,7 +85,7 @@ function normalizeImetaVariant(variant) {
|
||||
}
|
||||
const normalized = {};
|
||||
const m = normalizeString(variant.m);
|
||||
if (m) normalized.m = m;
|
||||
if (m) normalized.m = m.toLowerCase();
|
||||
const dim = normalizeString(variant.dim);
|
||||
if (dim) normalized.dim = dim;
|
||||
const url = normalizeString(variant.url);
|
||||
|
||||
@@ -86,3 +86,21 @@ test("30078 events carry nip71 metadata tags and hydrate fallback metadata", ()
|
||||
assert.deepEqual(video.nip71.references, ["https://example.com/info"]);
|
||||
assert.equal(video.nip71Source?.eventId, "event-123");
|
||||
});
|
||||
|
||||
test("imeta tags lower-case mime values", () => {
|
||||
const metadataInput = {
|
||||
imeta: [
|
||||
{ m: "VIDEO/MP4", url: "https://cdn.example/video.mp4" },
|
||||
{ m: "APPLICATION/DASH+XML" },
|
||||
],
|
||||
};
|
||||
|
||||
const tags = buildNip71MetadataTags(metadataInput);
|
||||
const mimeEntries = tags
|
||||
.filter((tag) => tag[0] === "imeta")
|
||||
.map((tag) => tag.find((value) => typeof value === "string" && value.startsWith("m ")))
|
||||
.filter(Boolean)
|
||||
.map((entry) => entry.slice(2));
|
||||
|
||||
assert.deepEqual(mimeEntries, ["video/mp4", "application/dash+xml"]);
|
||||
});
|
||||
@@ -145,7 +145,7 @@ test("buildNip71VideoEvent assembles rich metadata", () => {
|
||||
assert.deepEqual(imetaTags[1], [
|
||||
"imeta",
|
||||
"url https://cdn.example/video-hls.m3u8",
|
||||
"m application/x-mpegURL",
|
||||
"m application/x-mpegurl",
|
||||
"duration 45.789",
|
||||
"bitrate 2200000",
|
||||
]);
|
||||
|
||||
@@ -92,7 +92,7 @@ test("buildNip71MetadataTags normalizes structured fields", () => {
|
||||
tags.some(
|
||||
(tag) =>
|
||||
tag[0] === "p" &&
|
||||
tag[1] === "A".repeat(64) &&
|
||||
tag[1] === "a".repeat(64) &&
|
||||
tag[2] === "wss://relay.example",
|
||||
),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user