-
Notifications
You must be signed in to change notification settings - Fork 2
/
checklive.js
98 lines (89 loc) · 2.73 KB
/
checklive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { parse } from "fast-xml-parser";
import { decode } from "html-entities";
export const get = async (req, res) => {
try {
let url = req.query.url;
const response = await fetch(url, {
"User-Agent": "CurioHoster",
});
const feed = (await response.text()) || {};
const parserOptions = {
attributeNamePrefix: "@_",
//attrNodeName: false,
//textNodeName : "#text",
ignoreAttributes: false,
ignoreNameSpace: false,
attrValueProcessor: (val, attrName) => decode(val), //default is a=>a
tagValueProcessor: (val, tagName) => decode(val), //default is a=>a
};
xmlJson = parse(feed, parserOptions);
let liveItem = [].concat(xmlJson?.rss?.channel?.["podcast:liveItem"]);
let item = [].concat(xmlJson?.rss?.channel?.item);
let live = liveItem
.filter((v) => v && v["@_status"].toLowerCase() === "live")
.map((v) => {
return {
description: v.description || "",
enclosureType: v.enclosure["@_type"],
enclosureUrl: v.enclosure["@_url"],
explicit: null,
guid: v.guid,
image: v?.["itunes:image"]?.["@_href"],
title: v.title,
persons: null,
value: parseValue(v["podcast:value"]),
liveStatus: v["@_status"].toLowerCase(),
chat: v["@_chat"],
startTime: v["@_start"],
};
});
let pending = liveItem
.filter((v) => v && v["@_status"].toLowerCase() === "pending")
.map((v) => {
return {
description: v.description || "",
enclosureType: v.enclosure["@_type"],
enclosureUrl: v.enclosure["@_url"],
explicit: null,
guid: v.guid,
image: v.image,
title: v.title,
persons: null,
value:
parseValue(v["podcast:value"]) ||
parseValue(feed?.rss?.channel?.["podcast:value"]),
liveStatus: v["@_status"].toLowerCase(),
chat: v["@_chat"],
startTime: v["@_start"],
};
});
res.status(200).json({ live: live, pending: pending, item: item });
} catch (err) {
console.log("getepisodes.js Error:", err);
res.status(500).json([]);
}
};
function parseValue(v) {
if (v) {
let value = {
model: {
method: v["@_method"],
suggested: v["@_suggested"],
type: v["@_type"],
},
};
let destinations = v["podcast:valueRecipient"].map((w) => {
return {
address: w["@_address"],
customKey: w["@_customKey"],
customValue: w["@_customValue"],
name: w["@_name"],
split: w["@_split"],
type: w["@_type"],
};
});
value.destinations = destinations;
return value;
}
return undefined;
}