1
0
Fork 0
radiomanifest.js/ui.js

55 lines
1.8 KiB
JavaScript

// const radiomanifest = require('radiomanifest.js')
function updateNow(radio) {
var box = document.querySelector('#now-info')
const show = radio.getSchedule().getNowShow()
try {
var showText = show.getName() + '\nfeed: ' + show.getWebsite()
} catch (e) {
var showText = String(show)
}
var text = radio.getName() + ' - ' + radio.getDescription() + ' -- ' + showText
box.textContent = text
}
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())
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)
})
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)
updateNow(radio)
console.log(radio.getSchedule())
setInterval(function() { updateNow(radio) }, 2000)
}
fai()