Files
epg/sites/dstv.com/dstv.com.config.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-09-27 00:20:43 +03:00
const cheerio = require('cheerio')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(customParseFormat)
module.exports = {
site: 'dstv.com',
2021-10-28 05:01:39 +03:00
request: {
2021-10-30 00:17:36 +03:00
timeout: 30000
2021-10-28 05:01:39 +03:00
},
2021-09-27 00:20:43 +03:00
url({ channel, date }) {
const [bouquetId] = channel.site_id.split('#')
2021-10-14 05:34:20 +03:00
return `https://guide.dstv.com/api/gridview/page?bouquetId=${bouquetId}&genre=all&date=${date.format(
2021-09-27 00:20:43 +03:00
'YYYY-MM-DD'
)}`
},
2021-11-09 13:34:13 +03:00
logo({ channel }) {
return channel.logo
2021-10-14 05:34:20 +03:00
},
2021-09-27 00:20:43 +03:00
parser({ content, date, channel }) {
let PM = false
const programs = []
const items = parseItems(content, date, channel)
items.forEach(item => {
const title = item.title
let start = parseStart(item, date)
2021-10-28 09:36:36 +03:00
if (start.hour() > 18 && !PM) start = start.subtract(1, 'd')
else if (start.hour() > 11 && start.hour() < 18) PM = true
else if (start.hour() < 12 && PM) start = start.add(1, 'd')
const stop = start.add(1, 'h')
2021-09-27 00:20:43 +03:00
if (programs.length) {
2021-10-28 09:36:36 +03:00
programs[programs.length - 1].stop = start.toString()
2021-09-27 00:20:43 +03:00
}
programs.push({
title,
2021-10-28 09:36:36 +03:00
start: start.toString(),
stop: stop.toString()
2021-09-27 00:20:43 +03:00
})
})
return programs
}
}
function parseStart(item, date) {
time = `${date.format('MM/DD/YYYY')} ${item.time}`
return dayjs.utc(time, 'MM/DD/YYYY HH:mm')
}
function parseItems(content, date, channel) {
const [_, channelTag] = channel.site_id.split('#')
2021-10-28 09:36:36 +03:00
const data = JSON.parse(content)
const html = data[channelTag]
2021-09-27 00:20:43 +03:00
if (!html) return []
const $ = cheerio.load(html)
return $('li')
.map((i, el) => {
return {
time: $(el).find('.event-time').text().trim(),
title: $(el).find('.event-title').text().trim()
}
})
.toArray()
.filter(i => i.time && i.title)
}