@iptv/xmltv
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -145,3 +145,3 @@ /** | ||
*/ | ||
stereo?: "mono" | "stereo" | "dolby" | "dolby digital" | "bilingual" | "surround"; | ||
stereo?: 'mono' | 'stereo' | 'dolby' | 'dolby digital' | 'bilingual' | 'surround'; | ||
}; | ||
@@ -229,3 +229,3 @@ | ||
*/ | ||
type?: "person" | "character"; | ||
type?: 'person' | 'character'; | ||
}; | ||
@@ -341,3 +341,3 @@ | ||
*/ | ||
system?: "onscreen" | "xmltv_ns"; | ||
system?: 'onscreen' | 'xmltv_ns'; | ||
/** | ||
@@ -405,3 +405,3 @@ * The episode number as a XMLTV episode number string eg. "2.3.2". | ||
*/ | ||
type?: "poster" | "backdrop" | "still"; | ||
type?: 'poster' | 'backdrop' | 'still'; | ||
/** | ||
@@ -427,3 +427,3 @@ * URL of the image | ||
*/ | ||
orient?: "L" | "P" | "l" | "p"; | ||
orient?: 'L' | 'P' | 'l' | 'p'; | ||
/** | ||
@@ -460,3 +460,3 @@ * A string to describe where the image came from, eg IMDB | ||
*/ | ||
units: "seconds" | "minutes" | "hours"; | ||
units: 'seconds' | 'minutes' | 'hours'; | ||
}; | ||
@@ -1094,3 +1094,3 @@ | ||
*/ | ||
type: "text" | "url"; | ||
type: 'text' | 'url'; | ||
/** | ||
@@ -1153,3 +1153,3 @@ * The source of the review | ||
export declare type XmltvSubtitle = { | ||
type?: "teletext" | "onscreen" | "deaf-signed"; | ||
type?: 'teletext' | 'onscreen' | 'deaf-signed'; | ||
language?: XmltvStringWithLang; | ||
@@ -1156,0 +1156,0 @@ }; |
@@ -1,156 +0,36 @@ | ||
function k(t) { | ||
let e = 0; | ||
const a = "<", i = ">", o = a.charCodeAt(0), s = i.charCodeAt(0), r = "-".charCodeAt(0), n = "/".charCodeAt(0), c = "!".charCodeAt(0), f = "'".charCodeAt(0), d = '"'.charCodeAt(0), A = "[".charCodeAt(0), T = "]".charCodeAt(0), O = "?".charCodeAt(0), w = `\r | ||
>/= `, X = ["new", "icon", "previously-shown"]; | ||
function E(h) { | ||
const l = []; | ||
for (; t[e]; ) | ||
if (t.charCodeAt(e) == o) { | ||
if (t.charCodeAt(e + 1) === n) { | ||
const g = e + 2; | ||
if (e = t.indexOf(i, e), t.substring(g, e).indexOf(h) == -1) { | ||
const u = t.substring(0, e).split(` | ||
`); | ||
throw new Error( | ||
`Unexpected close tag | ||
Line: ` + (u.length - 1) + ` | ||
Column: ` + (u[u.length - 1].length + 1) + ` | ||
Char: ` + t[e] | ||
); | ||
} | ||
return e + 1 && (e += 1), l; | ||
} else if (t.charCodeAt(e + 1) === c) { | ||
if (t.charCodeAt(e + 2) == r) { | ||
for (; e !== -1 && !(t.charCodeAt(e) === s && t.charCodeAt(e - 1) == r && t.charCodeAt(e - 2) == r && e != -1); ) | ||
e = t.indexOf(i, e + 1); | ||
e === -1 && (e = t.length); | ||
} else { | ||
const g = e + 1; | ||
e += 2; | ||
let C = !1; | ||
for (; (t.charCodeAt(e) !== s || C === !0) && t[e]; ) | ||
t.charCodeAt(e) === A ? C = !0 : C === !0 && t.charCodeAt(e) === T && (C = !1), e++; | ||
l.push(t.substring(g, e)); | ||
} | ||
e++; | ||
continue; | ||
} | ||
const p = L(); | ||
if (l.push(p), p.tagName.charCodeAt(0) === O) { | ||
for (let g = 0, C = p.children.length; g < C; g++) | ||
l.push(p.children[g]); | ||
p.children = []; | ||
} | ||
} else { | ||
const p = Z().trim(); | ||
p.length > 0 && l.push(p), e++; | ||
} | ||
return l; | ||
} | ||
function Z() { | ||
const h = e; | ||
return e = t.indexOf(a, e) - 1, e === -2 && (e = t.length), t.slice(h, e + 1); | ||
} | ||
function $() { | ||
const h = e; | ||
for (; w.indexOf(t[e]) === -1 && t[e]; ) | ||
e++; | ||
return t.slice(h, e); | ||
} | ||
function L() { | ||
e++; | ||
const h = $(), l = {}; | ||
let p = []; | ||
for (; t.charCodeAt(e) !== s && t[e]; ) { | ||
const g = t.charCodeAt(e); | ||
if (g > 64 && g < 91 || g > 96 && g < 123) { | ||
const C = $(); | ||
let u = t.charCodeAt(e), v; | ||
for (; u && u !== f && u !== d && !(u > 64 && u < 91 || u > 96 && u < 123) && u !== s; ) | ||
e++, u = t.charCodeAt(e); | ||
if (u === f || u === d) { | ||
if (v = R(), e === -1) | ||
return { | ||
tagName: h, | ||
attributes: l, | ||
children: p | ||
}; | ||
} else | ||
v = null, e--; | ||
l[C] = v; | ||
} | ||
e++; | ||
function A(t) { | ||
t = t.replace(/[\s]/g, ""); | ||
let e, n; | ||
const i = t.replace(/\D+/g, ""); | ||
if (i.length <= 8) { | ||
if (i.length === 8) { | ||
const b = parseInt(i.slice(0, 4), 10), w = parseInt(i.slice(4, 6), 10) - 1 || 0, N = parseInt(i.slice(6, 8), 10) || 1; | ||
return new Date(Date.UTC(b, w, N)); | ||
} | ||
return t.charCodeAt(e - 1) !== n && X.indexOf(h) === -1 ? (e++, p = E(h)) : e++, { | ||
tagName: h, | ||
attributes: l, | ||
children: p | ||
}; | ||
} | ||
function R() { | ||
const h = t[e], l = e + 1; | ||
return e = t.indexOf(h, l), t.slice(l, e); | ||
} | ||
return E(""); | ||
} | ||
function _(t) { | ||
let e = ""; | ||
function a(s) { | ||
if (s) | ||
for (var r = 0; r < s.length; r++) | ||
if (typeof s[r] == "string") { | ||
if (s[r].includes("!DOCTYPE")) { | ||
e += "<" + s[r].trim() + ">"; | ||
continue; | ||
} | ||
e += s[r].trim(); | ||
} else | ||
i(s[r]); | ||
} | ||
function i(s) { | ||
if (typeof s != "string") { | ||
e += "<" + s.tagName; | ||
for (const r in s.attributes) | ||
typeof s.attributes[r] == "string" && s.attributes[r].indexOf('"') === -1 ? e += " " + r + '="' + s.attributes[r].trim() + '"' : typeof s.attributes[r] == "boolean" ? e += " " + r + '="' + (s.attributes[r] ? "yes" : "no") + '"' : e += " " + r + "='" + s.attributes[r] + "'"; | ||
if (["new", "icon", "previously-shown"].indexOf(s.tagName) >= 0) { | ||
e += "/>"; | ||
return; | ||
} | ||
if (s.tagName === "?xml") { | ||
e += "?>"; | ||
return; | ||
} | ||
if (e += ">", typeof s.children == "boolean") { | ||
e += s.children ? "yes" : "no"; | ||
return; | ||
} | ||
a(s.children), e += "</" + s.tagName + ">"; | ||
if (i.length === 6) { | ||
const b = parseInt(i.slice(0, 4), 10), w = parseInt(i.slice(4, 6), 10) - 1 || 0; | ||
return new Date(Date.UTC(b, w)); | ||
} | ||
if (i.length === 4) | ||
return new Date(i); | ||
} | ||
a(t); | ||
let o = ""; | ||
return e.indexOf("?xml") === -1 && (o += '<?xml version="1.0" encoding="UTF-8"?>'), e.indexOf("!DOCTYPE") === -1 && (o += '<!DOCTYPE tv SYSTEM "xmltv.dtd">'), o + e; | ||
} | ||
function y(t) { | ||
t = t.trim().replace(/[\s]/g, ""); | ||
let e, a; | ||
t.endsWith("Z") ? (e = t.slice(0, -1), a = null) : (e = t.slice(0, -5), a = t.slice(-5)); | ||
const i = e.replace(/[-:Zz]/g, ""), o = parseInt(i.slice(0, 4), 10), s = parseInt(i.slice(4, 6), 10) - 1 || 0, r = parseInt(i.slice(6, 8), 10) || 1, n = parseInt(i.slice(8, 10), 10) || 0, c = parseInt(i.slice(10, 12), 10) || 0, f = parseInt(i.slice(12, 14), 10) || 0, d = new Date(Date.UTC(o, s, r, n, c, f)); | ||
if (a) { | ||
const A = a.slice(0, 1), T = parseInt(a.slice(1, 3), 10), O = parseInt(a.slice(3, 5), 10), w = T * 60 + O; | ||
A === "+" ? d.setUTCMinutes(d.getUTCMinutes() - w) : A === "-" && d.setUTCMinutes(d.getUTCMinutes() + w); | ||
t.endsWith("Z") ? (e = t.slice(0, -1), n = null) : (e = t.slice(0, -5), n = t.slice(-5)); | ||
const a = e.replace(/[-:Zz]/g, ""), s = parseInt(a.slice(0, 4), 10), r = parseInt(a.slice(4, 6), 10) - 1 || 0, o = parseInt(a.slice(6, 8), 10) || 1, c = parseInt(a.slice(8, 10), 10) || 0, p = parseInt(a.slice(10, 12), 10) || 0, C = parseInt(a.slice(12, 14), 10) || 0, y = new Date(Date.UTC(s, r, o, c, p, C)); | ||
if (n) { | ||
const b = n.slice(0, 1), w = parseInt(n.slice(1, 3), 10), N = parseInt(n.slice(3, 5), 10), D = w * 60 + N; | ||
b === "+" ? y.setUTCMinutes(y.getUTCMinutes() - D) : b === "-" && y.setUTCMinutes(y.getUTCMinutes() + D); | ||
} | ||
return d; | ||
return y; | ||
} | ||
function N(t) { | ||
const e = (c) => c < 10 ? `0${c}` : c.toString(), a = e(t.getUTCFullYear()), i = e(t.getUTCMonth() + 1), o = e(t.getUTCDate()), s = e(t.getUTCHours()), r = e(t.getUTCMinutes()), n = e(t.getUTCSeconds()); | ||
return `${a}${i}${o}${s}${r}${n} +0000`; | ||
function O(t) { | ||
const e = (c) => c < 10 ? `0${c}` : c.toString(), n = e(t.getUTCFullYear()), i = e(t.getUTCMonth() + 1), a = e(t.getUTCDate()), s = e(t.getUTCHours()), r = e(t.getUTCMinutes()), o = e(t.getUTCSeconds()); | ||
return `${n}${i}${a}${s}${r}${o} +0000`; | ||
} | ||
function z(t) { | ||
function B(t) { | ||
const e = /* @__PURE__ */ new Map(); | ||
for (const [a, i] of t.entries()) | ||
e.set(i, a); | ||
for (const [n, i] of t.entries()) | ||
e.set(i, n); | ||
return e; | ||
} | ||
const B = [ | ||
const q = [ | ||
"actor", | ||
@@ -201,3 +81,3 @@ "adapter", | ||
"writer" | ||
], U = [ | ||
], I = [ | ||
"channel", | ||
@@ -231,18 +111,16 @@ "clumpidx", | ||
"width" | ||
], M = new Map([ | ||
...B.map((t) => [t, t]) | ||
]), I = new Map([ | ||
...U.map((t) => [t, t]) | ||
]), q = z(M), Y = z(I); | ||
], M = new Map([...q.map((t) => [t, t])]), E = new Map([ | ||
...I.map((t) => [t, t]) | ||
]), Y = B(M), P = B(E); | ||
function m(t, e) { | ||
if (!B.includes(t)) | ||
if (!q.includes(t)) | ||
throw new Error(`Invalid tag: ${t}`); | ||
const a = M, i = q; | ||
a && i && (a.set(t, e), i.set(e, t)); | ||
const n = M, i = Y; | ||
n && i && (n.set(t, e), i.set(e, t)); | ||
} | ||
function b(t, e) { | ||
if (!U.includes(t)) | ||
function T(t, e) { | ||
if (!I.includes(t)) | ||
throw new Error(`Invalid attribute: ${t}`); | ||
const a = I, i = Y; | ||
a && i && (a.set(t, e), i.set(e, t)); | ||
const n = E, i = P; | ||
n && i && (n.set(t, e), i.set(e, t)); | ||
} | ||
@@ -258,12 +136,12 @@ m("display-name", "displayName"); | ||
m("programme", "programmes"); | ||
b("generator-info-name", "generatorInfoName"); | ||
b("generator-info-url", "generatorInfoUrl"); | ||
b("pdc-start", "pdcStart"); | ||
b("vps-start", "vpsStart"); | ||
b("source-data-url", "sourceDataUrl"); | ||
b("source-info-name", "sourceInfoName"); | ||
b("source-info-url", "sourceInfoUrl"); | ||
function D(t, e = "tv", a = !1) { | ||
T("generator-info-name", "generatorInfoName"); | ||
T("generator-info-url", "generatorInfoUrl"); | ||
T("pdc-start", "pdcStart"); | ||
T("vps-start", "vpsStart"); | ||
T("source-data-url", "sourceDataUrl"); | ||
T("source-info-name", "sourceInfoName"); | ||
T("source-info-url", "sourceInfoUrl"); | ||
function U(t, e = "tv", n = !1) { | ||
if (Array.isArray(t)) | ||
return t.map((s) => D(s, e, !0)); | ||
return t.map((s) => U(s, e, !0)); | ||
if (typeof t == "number") | ||
@@ -274,6 +152,6 @@ return t.toString(); | ||
if (t instanceof Date && e !== "date") | ||
return N(t); | ||
return O(t); | ||
if (typeof t == "boolean" && e !== "new") | ||
return t ? "yes" : "no"; | ||
const i = q.get(e) || e, o = { | ||
const i = Y.get(e) || e, a = { | ||
tagName: i, | ||
@@ -284,3 +162,3 @@ attributes: {}, | ||
for (let s in t) { | ||
const r = Y.get(s) || s; | ||
const r = P.get(s) || s; | ||
if (t[s].tagName === "new") { | ||
@@ -290,64 +168,163 @@ t[i].children = []; | ||
} | ||
if (U.indexOf(r) >= 0 && typeof t[s] != "object" || t[s] instanceof Date) { | ||
if (o.tagName === "credits" && s === "guest") | ||
if (I.indexOf(r) >= 0 && typeof t[s] != "object" || t[s] instanceof Date) { | ||
if (a.tagName === "credits" && s === "guest") | ||
continue; | ||
if (o.tagName === "programme" && s === "channel") { | ||
o.attributes[r] = t[s]; | ||
if (a.tagName === "programme" && s === "channel") { | ||
a.attributes[r] = t[s]; | ||
continue; | ||
} | ||
if (o.tagName === "tv" && s === "date") { | ||
o.attributes[r] = N( | ||
t[s] | ||
); | ||
if (a.tagName === "tv" && s === "date") { | ||
a.attributes[r] = O(t[s]); | ||
continue; | ||
} | ||
if (o.tagName === "programme" && s === "date") { | ||
o.children.push({ | ||
if (a.tagName === "programme" && s === "date") { | ||
a.children.push({ | ||
tagName: r, | ||
attributes: {}, | ||
children: [N(t[s])] | ||
children: [O(t[s])] | ||
}); | ||
continue; | ||
} | ||
const n = typeof t[s]; | ||
if (n === "number") { | ||
o.attributes[r] = t[s].toString(); | ||
const o = typeof t[s]; | ||
if (o === "number") { | ||
a.attributes[r] = t[s].toString(); | ||
continue; | ||
} | ||
if (n === "boolean") { | ||
o.attributes[r] = t[s] ? "yes" : "no"; | ||
if (o === "boolean") { | ||
a.attributes[r] = t[s] ? "yes" : "no"; | ||
continue; | ||
} | ||
if (n === "object" && !Array.isArray(t[s])) { | ||
if (o === "object" && !Array.isArray(t[s])) { | ||
if (t[s] instanceof Date) { | ||
t[s] = N(t[s]), o.attributes[r] = t[s]; | ||
t[s] = O(t[s]), a.attributes[r] = t[s]; | ||
continue; | ||
} | ||
const c = Object.keys(t[s]).map((f) => { | ||
t[s][f] = t[s][f].toString(); | ||
const c = Object.keys(t[s]).map((p) => { | ||
t[s][p] = t[s][p].toString(); | ||
}); | ||
o.attributes[r] = c; | ||
a.attributes[r] = c; | ||
continue; | ||
} | ||
o.attributes[r] = t[s]; | ||
a.attributes[r] = t[s]; | ||
} else { | ||
const n = D(t[s], s); | ||
if (Array.isArray(n)) | ||
for (let c = 0, f = n.length; c < f; c++) | ||
o.children.push(n[c]); | ||
const o = U(t[s], s); | ||
if (Array.isArray(o)) | ||
for (let c = 0, p = o.length; c < p; c++) | ||
a.children.push(o[c]); | ||
else { | ||
if (s !== "_value") { | ||
o.children.push({ | ||
a.children.push({ | ||
tagName: r, | ||
attributes: {}, | ||
children: [n] | ||
children: [o] | ||
}); | ||
continue; | ||
} | ||
o.children.push(n); | ||
a.children.push(o); | ||
} | ||
} | ||
} | ||
return a ? o : [o]; | ||
return n ? a : [a]; | ||
} | ||
function k(t) { | ||
let e = 0; | ||
const n = "<", i = ">", a = n.charCodeAt(0), s = i.charCodeAt(0), r = "-".charCodeAt(0), o = "/".charCodeAt(0), c = "!".charCodeAt(0), p = "'".charCodeAt(0), C = '"'.charCodeAt(0), y = "[".charCodeAt(0), b = "]".charCodeAt(0), w = "?".charCodeAt(0), N = `\r | ||
>/= `, D = ["new", "icon", "previously-shown"]; | ||
function $(l) { | ||
const f = []; | ||
for (; t[e]; ) | ||
if (t.charCodeAt(e) == a) { | ||
if (t.charCodeAt(e + 1) === o) { | ||
const d = e + 2; | ||
if (e = t.indexOf(i, e), t.substring(d, e).indexOf(l) == -1) { | ||
const u = t.substring(0, e).split(` | ||
`); | ||
throw new Error( | ||
`Unexpected close tag | ||
Line: ` + (u.length - 1) + ` | ||
Column: ` + (u[u.length - 1].length + 1) + ` | ||
Char: ` + t[e] | ||
); | ||
} | ||
return e + 1 && (e += 1), f; | ||
} else if (t.charCodeAt(e + 1) === c) { | ||
if (t.charCodeAt(e + 2) == r) { | ||
for (; e !== -1 && !(t.charCodeAt(e) === s && t.charCodeAt(e - 1) == r && t.charCodeAt(e - 2) == r && e != -1); ) | ||
e = t.indexOf(i, e + 1); | ||
e === -1 && (e = t.length); | ||
} else { | ||
const d = e + 1; | ||
e += 2; | ||
let g = !1; | ||
for (; (t.charCodeAt(e) !== s || g === !0) && t[e]; ) | ||
t.charCodeAt(e) === y ? g = !0 : g === !0 && t.charCodeAt(e) === b && (g = !1), e++; | ||
f.push(t.substring(d, e)); | ||
} | ||
e++; | ||
continue; | ||
} | ||
const h = L(); | ||
if (f.push(h), h.tagName.charCodeAt(0) === w && h.children) { | ||
for (let d = 0, g = h.children.length; d < g; d++) | ||
f.push(h.children[d]); | ||
h.children = []; | ||
} | ||
} else { | ||
const h = Z().trim(); | ||
h.length > 0 && f.push(h), e++; | ||
} | ||
return f; | ||
} | ||
function Z() { | ||
const l = e; | ||
return e = t.indexOf(n, e) - 1, e === -2 && (e = t.length), t.slice(l, e + 1); | ||
} | ||
function _() { | ||
const l = e; | ||
for (; N.indexOf(t[e]) === -1 && t[e]; ) | ||
e++; | ||
return t.slice(l, e); | ||
} | ||
function L() { | ||
e++; | ||
const l = _(), f = {}; | ||
let h = []; | ||
for (; t.charCodeAt(e) !== s && t[e]; ) { | ||
const d = t.charCodeAt(e); | ||
if (d > 64 && d < 91 || d > 96 && d < 123) { | ||
const g = _(); | ||
let u = t.charCodeAt(e), v; | ||
for (; u && u !== p && u !== C && !(u > 64 && u < 91 || u > 96 && u < 123) && u !== s; ) | ||
e++, u = t.charCodeAt(e); | ||
if (u === p || u === C) { | ||
if (v = R(), e === -1) | ||
return { | ||
tagName: l, | ||
attributes: f, | ||
children: h | ||
}; | ||
} else | ||
v = null, e--; | ||
f[g] = v; | ||
} | ||
e++; | ||
} | ||
return t.charCodeAt(e - 1) !== o && D.indexOf(l) === -1 ? (e++, h = $(l)) : e++, l === "date" ? { | ||
tagName: l, | ||
attributes: f, | ||
children: h.map( | ||
(d) => O(A(d)) | ||
) | ||
} : { | ||
tagName: l, | ||
attributes: f, | ||
children: h | ||
}; | ||
} | ||
function R() { | ||
const l = t[e], f = e + 1; | ||
return e = t.indexOf(l, f), t.slice(f, e); | ||
} | ||
return $(""); | ||
} | ||
const F = "?".charCodeAt(0), H = [ | ||
@@ -376,15 +353,7 @@ "credits", | ||
"value" | ||
], Q = [ | ||
"date", | ||
"value", | ||
"aspect", | ||
"present", | ||
"colour", | ||
"quality", | ||
"stereo" | ||
]; | ||
function P(t, e = { tagName: "tv", attributes: {}, children: [] }) { | ||
let a = {}; | ||
], Q = ["date", "value", "aspect", "present", "colour", "quality", "stereo"]; | ||
function X(t, e = { tagName: "tv", attributes: {}, children: [] }) { | ||
let n = {}; | ||
if (!t.length) | ||
return a; | ||
return n; | ||
if (t.length === 1 && typeof t[0] == "string" && (t[0] === "yes" || t[0] === "no")) | ||
@@ -396,57 +365,85 @@ return t[0] === "yes"; | ||
} : t[0]; | ||
for (let i = 0, o = t.length; i < o; i++) { | ||
for (let i = 0, a = t.length; i < a; i++) { | ||
let s = t[i]; | ||
if (typeof e != "string" && e.tagName === "actor" && typeof s == "string" && (a._value = s), typeof s != "object" || s.tagName.charCodeAt(0) === F) | ||
if (typeof e != "string" && e.tagName === "actor" && typeof s == "string" && (n._value = s), typeof s != "object" || s.tagName.charCodeAt(0) === F) | ||
continue; | ||
if (s.tagName === "new") { | ||
a[s.tagName] = !0; | ||
n[s.tagName] = !0; | ||
continue; | ||
} | ||
s.tagName === "tv" && (a = {}); | ||
s.tagName === "tv" && (n = {}); | ||
const r = M.get(s.tagName) || s.tagName; | ||
!a[r] && H.indexOf(s.tagName) === -1 && (a[r] = []); | ||
let n = P(s.children || [], s); | ||
if (Object.keys(s.attributes).length && !Array.isArray(n)) { | ||
s.attributes.size && (s.attributes.size = Number(s.attributes.size)), r === "programmes" ? (s.attributes.stop && (s.attributes.stop = y( | ||
s.attributes.stop | ||
)), s.attributes["pdc-start"] && (s.attributes["pdc-start"] = y( | ||
s.attributes["pdc-start"] | ||
)), s.attributes["vps-start"] && (s.attributes["vps-start"] = y( | ||
s.attributes["vps-start"] | ||
))) : r === "icon" ? (s.attributes.width && (s.attributes.width = Number(s.attributes.width)), s.attributes.height && (s.attributes.height = Number(s.attributes.height))) : s.attributes.units ? n._value = Number(n._value) : s.attributes.guest && (s.attributes.guest = s.attributes.guest === "yes"), s.attributes.date && (s.attributes.date = y( | ||
s.attributes.date | ||
)), s.attributes.start && (s.attributes.start = y( | ||
s.attributes.start | ||
)); | ||
!n[r] && H.indexOf(s.tagName) === -1 && (n[r] = []); | ||
let o = X(s.children || [], s); | ||
if (Object.keys(s.attributes).length && !Array.isArray(o)) { | ||
s.attributes.size && (s.attributes.size = Number(s.attributes.size)), r === "programmes" ? (s.attributes.stop && (s.attributes.stop = A(s.attributes.stop)), s.attributes["pdc-start"] && (s.attributes["pdc-start"] = A(s.attributes["pdc-start"])), s.attributes["vps-start"] && (s.attributes["vps-start"] = A(s.attributes["vps-start"]))) : r === "icon" ? (s.attributes.width && (s.attributes.width = Number(s.attributes.width)), s.attributes.height && (s.attributes.height = Number(s.attributes.height))) : s.attributes.units ? o._value = Number(o._value) : s.attributes.guest && (s.attributes.guest = s.attributes.guest === "yes"), s.attributes.date && (s.attributes.date = A(s.attributes.date)), s.attributes.start && (s.attributes.start = A(s.attributes.start)); | ||
const c = Object.keys(s.attributes).reduce( | ||
(f, d) => (f[I.get(d) || d] = s.attributes[d], f), | ||
(p, C) => (p[E.get(C) || C] = s.attributes[C], p), | ||
{} | ||
); | ||
Object.assign(n, c); | ||
Object.assign(o, c); | ||
} | ||
if (r === "subtitles") { | ||
typeof n.language == "string" && (n.language = { _value: n.language }), a[r].push(n); | ||
typeof o.language == "string" && (o.language = { _value: o.language }), n[r].push(o); | ||
continue; | ||
} | ||
if (r === "tv") { | ||
a = n; | ||
n = o; | ||
continue; | ||
} | ||
if (r === "date") { | ||
a[r] = y(n); | ||
n[r] = A(o); | ||
continue; | ||
} | ||
if (typeof n == "string" && Q.indexOf(s.tagName) === -1 && (n = { | ||
_value: n | ||
}), Array.isArray(a[r])) { | ||
a[r].push(n); | ||
if (typeof o == "string" && Q.indexOf(s.tagName) === -1 && (o = { | ||
_value: o | ||
}), Array.isArray(n[r])) { | ||
n[r].push(o); | ||
continue; | ||
} | ||
a[r] = n; | ||
n[r] = o; | ||
} | ||
return a; | ||
return n; | ||
} | ||
function z(t) { | ||
let e = ""; | ||
function n(s) { | ||
if (s) | ||
for (var r = 0; r < s.length; r++) | ||
if (typeof s[r] == "string") { | ||
if (s[r].includes("!DOCTYPE")) { | ||
e += "<" + s[r].trim() + ">"; | ||
continue; | ||
} | ||
e += s[r].trim(); | ||
} else | ||
i(s[r]); | ||
} | ||
function i(s) { | ||
if (typeof s != "string") { | ||
e += "<" + s.tagName; | ||
for (const r in s.attributes) | ||
typeof s.attributes[r] == "string" && s.attributes[r].indexOf('"') === -1 ? e += " " + r + '="' + s.attributes[r].trim() + '"' : typeof s.attributes[r] == "boolean" ? e += " " + r + '="' + (s.attributes[r] ? "yes" : "no") + '"' : e += " " + r + "='" + s.attributes[r] + "'"; | ||
if (["new", "icon", "previously-shown"].indexOf(s.tagName) >= 0) { | ||
e += "/>"; | ||
return; | ||
} | ||
if (s.tagName === "?xml") { | ||
e += "?>"; | ||
return; | ||
} | ||
if (e += ">", typeof s.children == "boolean") { | ||
e += s.children ? "yes" : "no"; | ||
return; | ||
} | ||
n(s.children), e += "</" + s.tagName + ">"; | ||
} | ||
} | ||
n(t); | ||
let a = ""; | ||
return e.indexOf("?xml") === -1 && (a += '<?xml version="1.0" encoding="UTF-8"?>'), e.indexOf("!DOCTYPE") === -1 && (a += '<!DOCTYPE tv SYSTEM "xmltv.dtd">'), a + e; | ||
} | ||
function J(t, e = { asDom: !1 }) { | ||
const a = k(t); | ||
return e.asDom ? a : P(a); | ||
const n = k(t); | ||
return e.asDom ? n : X(n); | ||
} | ||
@@ -456,18 +453,16 @@ function K(t, e = { fromDom: !1 }) { | ||
if (typeof t == "object" && !Array.isArray(t)) | ||
throw new Error( | ||
"Cannot write XMLTV from a DOM object that has been converted to an object" | ||
); | ||
return _(t); | ||
throw new Error("Cannot write XMLTV from a DOM object that has been converted to an object"); | ||
return z(t); | ||
} | ||
const a = D(t); | ||
return _(a); | ||
const n = U(t); | ||
return z(n); | ||
} | ||
export { | ||
b as addAttributeTranslation, | ||
T as addAttributeTranslation, | ||
m as addTagTranslation, | ||
D as objectToDom, | ||
U as objectToDom, | ||
J as parseXmltv, | ||
k as parser, | ||
K as writeXmltv, | ||
_ as writer | ||
z as writer | ||
}; |
{ | ||
"name": "@iptv/xmltv", | ||
"description": "An extremely fast XMLTV parser and generator for Node and the browser.", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"license": "MIT", | ||
@@ -40,5 +40,6 @@ "author": { | ||
"@changesets/changelog-github": "^0.4.8", | ||
"@changesets/cli": "^2.26.1", | ||
"@changesets/cli": "^2.26.2", | ||
"@trivago/prettier-plugin-sort-imports": "^4.2.0", | ||
"@types/argparse": "^2.0.10", | ||
"@types/node": "^18.15.11", | ||
"@types/node": "^20.5.0", | ||
"@vitest/coverage-c8": "^0.29.8", | ||
@@ -48,8 +49,9 @@ "argparse": "^2.0.1", | ||
"epg-parser": "^0.2.0", | ||
"fast-xml-parser": "^4.1.3", | ||
"fast-xml-parser": "^4.2.7", | ||
"nanobench": "^3.0.0", | ||
"typescript": "^4.9.3", | ||
"vite": "^4.2.0", | ||
"vite-plugin-dts": "^2.1.0", | ||
"vitest": "^0.29.8", | ||
"prettier": "^3.0.2", | ||
"typescript": "^5.1.6", | ||
"vite": "^4.4.9", | ||
"vite-plugin-dts": "^3.5.2", | ||
"vitest": "^0.34.2", | ||
"xmltv": "^0.3.0" | ||
@@ -77,4 +79,5 @@ }, | ||
"prerelease": "pnpm run build && pnpm run test:ci", | ||
"release": "changeset publish" | ||
"release": "changeset publish", | ||
"prettier": "prettier --write ." | ||
} | ||
} |
@@ -61,3 +61,3 @@ <div align="center"> | ||
```typescript | ||
import { parseXmltv, writeXmltv } from "@iptv/xmltv"; | ||
import { parseXmltv, writeXmltv } from '@iptv/xmltv'; | ||
``` | ||
@@ -511,3 +511,3 @@ | ||
```typescript | ||
const xml = "..."; // XMLTV file contents | ||
const xml = '...'; // XMLTV file contents | ||
const parsed = parseXmltv(xml, { asDom: true }); | ||
@@ -526,7 +526,7 @@ // or import { parser } from '@iptv/xmltv'; | ||
// find the <tv> tag | ||
return node.tagName === "tv"; | ||
return node.tagName === 'tv'; | ||
}) | ||
.children.filter((node) => { | ||
// filter it's children for <programme> tags | ||
return node.tagName === "programme"; | ||
return node.tagName === 'programme'; | ||
}) | ||
@@ -536,3 +536,3 @@ .map((programme) => { | ||
return { | ||
title: programme.children.find((t) => t.tagName === "title").children[0], | ||
title: programme.children.find((t) => t.tagName === 'title').children[0], | ||
start: new Date(programme.attributes.start), | ||
@@ -559,3 +559,3 @@ stop: new Date(programme.attributes.stop), | ||
#### Parsing XMLTV file (example.xml) | ||
#### Parsing XMLTV file (c1-p1.xml) | ||
@@ -568,3 +568,2 @@ <table> | ||
<th align="left">Ops/sec</th> | ||
<th align="left">rme</th> | ||
</tr> | ||
@@ -576,4 +575,3 @@ </thead> | ||
<th align="left">@iptv/xmltv</th> | ||
<td align="right">21,219</td> | ||
<td align="right">±0.28%</td> | ||
<td align="right">1,094,286</td> | ||
</tr> | ||
@@ -583,4 +581,3 @@ <tr> | ||
<th align="left">@iptv/xmltv (DOM only)</th> | ||
<td align="right">34,632</td> | ||
<td align="right">±0.28%</td> | ||
<td align="right">1,246,439</td> | ||
</tr> | ||
@@ -590,4 +587,3 @@ <tr> | ||
<th align="left">fast-xml-parser</th> | ||
<td align="right">6,803</td> | ||
<td align="right">±0.53%</td> | ||
<td align="right">426,947</td> | ||
</tr> | ||
@@ -597,4 +593,3 @@ <tr> | ||
<th align="left">epg-parser</th> | ||
<td align="right">2,321</td> | ||
<td align="right">±0.42%</td> | ||
<td align="right">96,468</td> | ||
</tr> | ||
@@ -604,4 +599,3 @@ <tr> | ||
<th align="left">xmltv</th> | ||
<td align="right">2,448</td> | ||
<td align="right">±1.90%</td> | ||
<td align="right">14,750</td> | ||
</tr> | ||
@@ -611,3 +605,3 @@ </tbody> | ||
#### Writing XMLTV file (example.xml) | ||
#### Writing XMLTV file (c1-p1.xml) | ||
@@ -620,3 +614,2 @@ <table> | ||
<th align="left">Ops/sec</th> | ||
<th align="left">rme</th> | ||
</tr> | ||
@@ -628,4 +621,3 @@ </thead> | ||
<th align="left">@iptv/xmltv</th> | ||
<td align="right">93,292</td> | ||
<td align="right">±0.17%</td> | ||
<td align="right">2,920,103</td> | ||
</tr> | ||
@@ -635,4 +627,3 @@ <tr> | ||
<th align="left">fast-xml-parser</th> | ||
<td align="right">26,886</td> | ||
<td align="right">±0.16%</td> | ||
<td align="right">1,257,938</td> | ||
</tr> | ||
@@ -673,9 +664,9 @@ </tbody> | ||
<th align="left">@iptv/xmltv</th> | ||
<td align="right">~340 μs</td> | ||
<td align="right">~1.67 ms</td> | ||
<td align="right">~83 ms</td> | ||
<td align="right">~535 ms</td> | ||
<td align="right">~1.13 s</td> | ||
<td align="right">~2.41 s</td> | ||
<td align="right">~5.61 s</td> | ||
<td align="right">~60 μs</td> | ||
<td align="right">~1.24 ms</td> | ||
<td align="right">~39 ms</td> | ||
<td align="right">~342 ms</td> | ||
<td align="right">~980 ms</td> | ||
<td align="right">~2.15 s</td> | ||
<td align="right">~5.37 s</td> | ||
</tr> | ||
@@ -685,9 +676,9 @@ <tr> | ||
<th align="left">epg-parser</th> | ||
<td align="right">~1.71 ms</td> | ||
<td align="right">~11 ms</td> | ||
<td align="right">~263 ms</td> | ||
<td align="right">~2.43 s</td> | ||
<td align="right">~5.7 s</td> | ||
<td align="right">~12 s</td> | ||
<td align="right">~29 s</td> | ||
<td align="right">~362 μs</td> | ||
<td align="right">~9.83 ms</td> | ||
<td align="right">~256 ms</td> | ||
<td align="right">~2.25 s</td> | ||
<td align="right">~6.26 s</td> | ||
<td align="right">~13 s</td> | ||
<td align="right">~28 s</td> | ||
</tr> | ||
@@ -694,0 +685,0 @@ </tbody> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
92000
17
723