misc.anonradio: forgot one

This commit is contained in:
Cynthia Foxwell 2022-12-10 16:19:21 -07:00
parent 6efea6a824
commit d145ff2940
1 changed files with 19 additions and 9 deletions

View File

@ -275,9 +275,18 @@ anonradio.helpText = "aNONradio.net schedule";
anonradio.callback = async function () {
const now = new Date();
const playing = await fetch("https://anonradio.net/playing").then((res) =>
res.text()
);
let playing;
try {
playing = await fetch("https://anonradio.net/playing").then((res) =>
res.text()
);
} catch (err) {
try {
playing = await fetch("http://anonradio.net/playing").then((res) =>
res.text()
);
} catch (err) {}
}
let schedule;
try {
schedule = await fetch("https://anonradio.net/schedule/").then((res) =>
@ -291,7 +300,13 @@ anonradio.callback = async function () {
} catch (err) {}
}
if (!schedule) return "Failed to fetch schedule.";
if (!playing || !schedule) return "Failed to fetch schedule.";
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 lines = schedule.split("\n");
lines = lines.slice(4, lines.length - 2);
@ -373,11 +388,6 @@ 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"
);