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

95 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-01-22 18:33:37 +03:00
const axios = require('axios')
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 = {
2022-03-10 23:16:30 +03:00
site: 'guide.dstv.com',
2023-01-22 00:09:39 +03:00
skip: true, // NOTE: website is down (HTTP Server Error 503)
2023-01-10 12:40:01 +03:00
days: 2,
2022-05-09 13:59:56 +03:00
request: {
cache: {
ttl: 60 * 60 * 1000,
interpretHeader: false
}
},
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'
)}`
},
2022-05-09 13:59:56 +03:00
parser({ content, date, channel, cached }) {
2021-09-27 00:20:43 +03:00
const programs = []
const items = parseItems(content, date, channel)
items.forEach(item => {
2021-11-24 21:52:04 +03:00
const prev = programs[programs.length - 1]
2021-09-27 00:20:43 +03:00
let start = parseStart(item, date)
2021-11-24 21:52:04 +03:00
if (prev) {
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
prev.stop = start
} else if (start.hour() > 12) {
start = start.subtract(1, 'd')
date = date.subtract(1, 'd')
2021-09-27 00:20:43 +03:00
}
2021-11-24 21:52:04 +03:00
const stop = start.add(1, 'h')
2021-09-27 00:20:43 +03:00
programs.push({
2021-11-24 21:52:04 +03:00
title: item.title,
start,
stop
2021-09-27 00:20:43 +03:00
})
})
return programs
2022-01-22 18:33:37 +03:00
},
async channels({ bouquet }) {
const data = await axios
.get(
`https://guide.dstv.com/api/channel/fetchChannelsByGenresInBouquet?bouquetId=${bouquet}&genre=all`
)
.then(r => r.data)
.catch(console.log)
const items = data.items
return items.map(item => {
return {
lang: 'en',
site_id: `${bouquet}#${item.channelTag}`,
2022-02-01 04:59:42 +03:00
name: item.channelName
2022-01-22 18:33:37 +03:00
}
})
2021-09-27 00:20:43 +03:00
}
}
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)
}