misc.anonradio: add http fallback

This commit is contained in:
Cynthia Foxwell 2022-12-10 16:16:39 -07:00
parent 5b07c150dc
commit 6efea6a824

View file

@ -278,14 +278,20 @@ anonradio.callback = async function () {
const playing = await fetch("https://anonradio.net/playing").then((res) =>
res.text()
);
const schedule = await fetch("https://anonradio.net/schedule/").then((res) =>
res.text()
);
const icecast = await fetch("http://anonradio.net:8010/status-json.xsl")
.then((res) => res.text())
.then((data) =>
JSON.parse(data.replace(/"title": - ,/g, '"title":" - ",'))
let schedule;
try {
schedule = await fetch("https://anonradio.net/schedule/").then((res) =>
res.text()
);
} catch (err) {
try {
schedule = await fetch("http://anonradio.net/schedule/").then((res) =>
res.text()
);
} catch (err) {}
}
if (!schedule) return "Failed to fetch schedule.";
let lines = schedule.split("\n");
lines = lines.slice(4, lines.length - 2);
@ -367,6 +373,11 @@ anonradio.callback = async function () {
let openmicTime = "";
if (liveNow.id == "openmic") {
const icecast = await fetch("http://anonradio.net:8010/status-json.xsl")
.then((res) => res.text())
.then((data) =>
JSON.parse(data.replace(/"title": - ,/g, '"title":" - ",'))
);
const streamData = icecast.icestats.source.find(
(src) => src.listenurl == "http://anonradio.net:8010/openmic"
);