Update astro.com.my.config.js

This commit is contained in:
Aleksandr Statciuk 2022-08-29 19:37:25 +03:00
parent 995d7950a1
commit 585e7ef434

View file

@ -7,12 +7,9 @@ module.exports = {
url: function ({ channel }) {
return `https://contenthub-api.eco.astro.com.my/channel/${channel.site_id}.json`
},
parser: function ({ content }) {
parser: function ({ content, date }) {
const programs = []
const data = JSON.parse(content)
const schedules = data.response.schedule
for(let items of Object.values(schedules)){
const items = parseItems(content, date)
items.forEach(item => {
const start = dayjs.utc(item.datetimeInUtc)
const duration = parseDuration(item.duration)
@ -24,11 +21,21 @@ module.exports = {
})
})
}
return programs
}
}
function parseItems(content, date) {
try {
const data = JSON.parse(content)
const schedules = data.response.schedule
return schedules[date.format('YYYY-MM-DD')] || []
} catch (e) {
return []
}
}
function parseDuration(duration) {
const match = duration.match(/(\d{2}):(\d{2}):(\d{2})/)
const hours = parseInt(match[1])