1
0
Fork 0

pickURLs added

This commit is contained in:
boyska 2021-12-26 20:00:17 +01:00
parent f55ccec939
commit 935fc70e99

View file

@ -7,6 +7,12 @@ function getManifestUrl (siteurl) {
return siteurl + '/radiomanifest.xml' // XXX: improve this logic
}
function getAttribute(el, attr, default_value) {
if(el.hasAttribute(attr))
return el.getAttribute(attr);
return default_value;
}
class Radio {
constructor (sources, schedule, shows, feed) {
this.streaming = new RadioStreaming(sources)
@ -47,9 +53,6 @@ class Radio {
}
sources.push(src)
}
sources.sort(function cmp (a, b) {
return parseInt(a.getAttribute('priority', 10)) < parseInt(b.getAttribute('priority', 10))
})
res = doc.evaluate('/radio-manifest/schedule', doc)
const scheduleEl = res.iterateNext()
@ -77,24 +80,50 @@ class Radio {
}
}
function RadioStreaming (sources) {
this.sources = sources
}
RadioStreaming.prototype.getOptions = function () {
return this.sources.map(function (x) {
return x.getAttribute('name')
})
}
RadioStreaming.prototype.getSource = function (name) {
if (name === undefined) {
class RadioStreaming {
constructor (sources) {
this.sources = sources.sort(
(a,b) => this.getPriority(a) < this.getPriority(a)
)
}
getOptions() {
return this.sources.map(function (x) {
return x.getAttribute('name')
})
}
// this is private
getPriority(element) {
return parseInt(getAttribute(element, 'priority', '1'))
}
// this is private
getTopPrioritySources() {
var topPriority = this.getPriority(this.sources[0])
return this.sources.filter(
(src) => parseInt(src.getAttribute('priority'), 10) === topPriority
)
}
getSource(name) {
if (name === undefined) {
return this.getTopPrioritySources()[0]
}
const s = this.sources.find(function (x) {
return x.getAttribute('name') === name
})
if (s === undefined) return s
return s.getAttribute('src')
}
async pickURLs() {
var allSources = this.getTopPrioritySources()
var allAudios = []
for(let src of allSources) {
let url = src.getAttribute('src')
let resp = await fetch(url)
allAudios.unshift(... parseM3U(await resp.text()))
}
return allAudios
}
const s = this.sources.find(function (x) {
return x.getAttribute('name') === name
})
if (s === undefined) return s
return s.getAttribute('src')
}
async function get (siteurl, options) {