forked from boyska/radiomanifest.js
pickURLs added
This commit is contained in:
parent
f55ccec939
commit
935fc70e99
1 changed files with 49 additions and 20 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue