|
@@ -1,5 +1,6 @@
|
|
|
const fetch = require('isomorphic-unfetch')
|
|
|
const shows = require('./shows.js')
|
|
|
+const calendar = require('./calendar.js')
|
|
|
|
|
|
function getStreaminfoUrl (siteurl) {
|
|
|
return siteurl + '/streaminfo.json' // XXX: improve this logic
|
|
@@ -15,13 +16,14 @@ function getAttribute(el, attr, default_value) {
|
|
|
}
|
|
|
|
|
|
class Radio {
|
|
|
- constructor (sources, schedule, showsURL, feed) {
|
|
|
+ constructor (sources, scheduleURL, showsURL, feed) {
|
|
|
this.streaming = new RadioStreaming(sources)
|
|
|
- this.schedule = schedule
|
|
|
+ this.scheduleURL = scheduleURL
|
|
|
this.showsURL = showsURL
|
|
|
this.feed = feed
|
|
|
this.name = ''
|
|
|
this.shows = []
|
|
|
+ this.schedule = null
|
|
|
}
|
|
|
|
|
|
getStreaming () {
|
|
@@ -36,10 +38,12 @@ class Radio {
|
|
|
return this.shows
|
|
|
}
|
|
|
getShowByName (showName) {
|
|
|
+ if (this.shows === undefined) return null
|
|
|
return this.shows.find(s => s.name === showName)
|
|
|
}
|
|
|
|
|
|
getSchedule () {
|
|
|
+ return this.schedule
|
|
|
}
|
|
|
|
|
|
getShowAtTime () {
|
|
@@ -62,9 +66,9 @@ class Radio {
|
|
|
|
|
|
res = doc.evaluate('/radio-manifest/schedule', doc)
|
|
|
const scheduleEl = res.iterateNext()
|
|
|
- let schedule = null
|
|
|
+ let scheduleURL = null
|
|
|
if (scheduleEl !== null) {
|
|
|
- schedule = scheduleEl.getAttribute('src')
|
|
|
+ scheduleURL = scheduleEl.getAttribute('src')
|
|
|
}
|
|
|
|
|
|
res = xml.evaluate('/radio-manifest/shows', xml)
|
|
@@ -81,7 +85,7 @@ class Radio {
|
|
|
feed = feedEl.getAttribute('src')
|
|
|
}
|
|
|
|
|
|
- const manifest = new Radio(sources, schedule, showsURL, feed)
|
|
|
+ const manifest = new Radio(sources, scheduleURL, showsURL, feed)
|
|
|
return manifest
|
|
|
}
|
|
|
}
|
|
@@ -150,6 +154,15 @@ async function get (siteurl, options) {
|
|
|
console.error("Error while fetching shows file", e)
|
|
|
}
|
|
|
|
|
|
+ try {
|
|
|
+ manifest.schedule = await calendar.get(manifest)
|
|
|
+ if (manifest.schedule !== undefined)
|
|
|
+ manifest.schedule.radio = manifest
|
|
|
+ } catch (e) {
|
|
|
+ console.error("Error while fetching shows file", e)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
resp = null
|
|
|
try {
|
|
|
resp = await fetch(getStreaminfoUrl(siteurl))
|