radiomanifest.js/ui.js

68 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2023-09-14 01:16:21 +02:00
/* global radiomanifest */
2021-11-19 18:08:09 +01:00
// const radiomanifest = require('radiomanifest.js')
2022-01-30 02:24:40 +01:00
function updateNow(radio) {
2023-09-14 01:07:07 +02:00
var box = document.querySelector("#now-info");
const show = radio.getSchedule().getNowShow();
2023-09-14 01:16:21 +02:00
var showText;
2022-01-30 02:24:40 +01:00
try {
2023-09-14 01:16:21 +02:00
showText = show.getName() + "\nfeed: " + show.getWebsite();
2022-01-30 02:24:40 +01:00
} catch (e) {
2023-09-14 01:16:21 +02:00
showText = String(show);
2022-01-30 02:24:40 +01:00
}
2023-09-14 01:07:07 +02:00
var text =
radio.getName() + " - " + radio.getDescription() + " -- " + showText;
box.textContent = text;
2022-01-30 02:24:40 +01:00
}
2023-09-14 01:07:07 +02:00
async function fai() {
const radio = await radiomanifest.get(
"https://radiomanifest.degenerazione.xyz/v0.2/examples/full-ondarossa",
);
console.log("radio?", radio);
const s = radio.getStreaming();
console.log(s.sources);
console.log(s.getOptions());
console.log(s.getSource(s.getOptions()[0]));
console.log(s.getSource());
2021-12-26 20:00:47 +01:00
2023-09-14 01:07:07 +02:00
var audioEl = document.querySelector("#player audio");
var urls = await s.pickURLs();
console.log("audios", urls);
urls.forEach(function (url) {
var srcEl = document.createElement("source");
srcEl.setAttribute("src", url);
console.log("src", srcEl, url);
audioEl.appendChild(srcEl);
});
2022-01-30 01:00:30 +01:00
2023-09-14 01:07:07 +02:00
const showList = document.querySelector("#shows > ul");
2022-01-30 01:00:30 +01:00
for (const show of radio.getShows()) {
2023-09-14 01:07:07 +02:00
const item = document.createElement("li");
const link = document.createElement("a");
link.dataset["show"] = show.getName();
link.textContent = show.getName();
link.setAttribute("href", show.getWebsite());
item.appendChild(link);
showList.appendChild(item);
2022-01-30 01:00:30 +01:00
}
2023-09-14 01:07:07 +02:00
showList.addEventListener(
"mouseenter",
function (evt) {
if (evt.target.dataset["show"] === undefined) return;
const info = document.querySelector("#show-info");
info.textContent = radio
.getShowByName(evt.target.dataset["show"])
.getFeed();
},
true,
);
2022-01-30 02:24:40 +01:00
2023-09-14 01:07:07 +02:00
updateNow(radio);
console.log(radio.getSchedule());
setInterval(function () {
updateNow(radio);
}, 2000);
2021-11-16 23:22:16 +01:00
}
2023-09-14 01:07:07 +02:00
fai();