1
0
Fork 0
radiomanifest.js/ui.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-11-19 18:08:09 +01:00
// const radiomanifest = require('radiomanifest.js')
2022-01-30 02:24:40 +01:00
function updateNow(radio) {
var box = document.querySelector('#now-info')
const show = radio.getSchedule().getNowShow()
try {
2022-01-30 14:49:56 +01:00
var showText = show.getName() + '\nfeed: ' + show.getWebsite()
2022-01-30 02:24:40 +01:00
} catch (e) {
2022-01-30 14:49:56 +01:00
var showText = String(show)
2022-01-30 02:24:40 +01:00
}
2022-01-30 14:49:56 +01:00
var text = radio.getName() + ' - ' + radio.getDescription() + ' -- ' + showText
2022-01-30 02:24:40 +01:00
box.textContent = text
}
2021-11-19 18:08:09 +01:00
async function fai () {
2022-01-30 00:26:58 +01:00
const radio = await radiomanifest.get('https://radiomanifest.degenerazione.xyz/v0.2/examples/full-ondarossa')
2021-11-19 18:08:09 +01:00
console.log('radio?', radio)
const s = radio.getStreaming()
2021-12-26 20:00:47 +01:00
console.log(s.sources)
2021-11-19 18:08:09 +01:00
console.log(s.getOptions())
console.log(s.getSource(s.getOptions()[0]))
2021-12-26 20:00:47 +01:00
console.log(s.getSource())
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
const showList = document.querySelector('#shows > ul')
for (const show of radio.getShows()) {
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)
}
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
updateNow(radio)
console.log(radio.getSchedule())
setInterval(function() { updateNow(radio) }, 2000)
2021-11-16 23:22:16 +01:00
}
fai()