Add title and description to metalinks

Fixes #250
This commit is contained in:
Nils Maier 2020-08-30 00:29:26 +02:00
parent 3c644e615d
commit 49a589cb87

View File

@ -81,6 +81,14 @@ function importMeta4(data: string) {
if (mask) { if (mask) {
item.mask = mask; item.mask = mask;
} }
const description = file.querySelector("description");
if (description && description.textContent) {
item.description = description.textContent.trim();
}
const title = file.getElementsByTagNameNS(NS_DTA, "title");
if (title && title[0] && title[0].textContent) {
item.title = title[0].textContent;
}
items.push(item); items.push(item);
} }
catch (ex) { catch (ex) {
@ -94,9 +102,9 @@ function parseKV(current: BaseItem, line: string) {
const [k, v] = line.split("=", 2); const [k, v] = line.split("=", 2);
switch (k.toLocaleLowerCase().trim()) { switch (k.toLocaleLowerCase().trim()) {
case "referer": { case "referer": {
const rurls = getTextLinks(v); const refererUrls = getTextLinks(v);
if (rurls && rurls.length) { if (refererUrls && refererUrls.length) {
current.referrer = rurls.pop(); current.referrer = refererUrls.pop();
current.usableReferrer = decodeURIComponent(current.referrer || ""); current.usableReferrer = decodeURIComponent(current.referrer || "");
} }
break; break;
@ -203,9 +211,9 @@ class MetalinkExporter {
)); ));
for (const item of items) { for (const item of items) {
const aitem = item as any; const anyItem = item as any;
const f = document.createElementNS(NS_METALINK_RFC5854, "file"); const f = document.createElementNS(NS_METALINK_RFC5854, "file");
f.setAttribute("name", aitem.currentName); f.setAttribute("name", anyItem.currentName);
if (item.batch) { if (item.batch) {
f.setAttributeNS(NS_DTA, "num", item.batch.toString()); f.setAttributeNS(NS_DTA, "num", item.batch.toString());
} }
@ -225,13 +233,19 @@ class MetalinkExporter {
f.appendChild(n); f.appendChild(n);
} }
if (item.title) {
const n = document.createElementNS(NS_DTA, "title");
n.textContent = item.title;
f.appendChild(n);
}
const u = document.createElementNS(NS_METALINK_RFC5854, "url"); const u = document.createElementNS(NS_METALINK_RFC5854, "url");
u.textContent = item.url; u.textContent = item.url;
f.appendChild(u); f.appendChild(u);
if (aitem.totalSize > 0) { if (anyItem.totalSize > 0) {
const s = document.createElementNS(NS_METALINK_RFC5854, "size"); const s = document.createElementNS(NS_METALINK_RFC5854, "size");
s.textContent = aitem.totalSize.toString(); s.textContent = anyItem.totalSize.toString();
f.appendChild(s); f.appendChild(s);
} }
root.appendChild(f); root.appendChild(f);