Files
epg/sites/zap.co.ao/zap.co.ao.config.js

54 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-09-26 17:29:07 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
module.exports = {
2022-12-02 17:48:21 +03:00
skip: true, // NOTE: Connection timeout
2021-09-26 17:29:07 +03:00
site: 'zap.co.ao',
2023-01-10 12:40:01 +03:00
days: 2,
2021-09-26 17:29:07 +03:00
url: function ({ date, channel }) {
return `https://www.zap.co.ao/_api/channels/${date.format('YYYY-M-D')}/epg.json`
},
2021-11-25 03:05:32 +03:00
parser: function ({ content, channel, date }) {
2021-09-26 17:29:07 +03:00
const programs = []
const items = parseItems(content, channel)
if (!items.length) return programs
items.forEach(item => {
2021-11-25 03:05:32 +03:00
const prev = programs[programs.length - 1]
let start = parseStart(item, date)
if (prev && start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
2021-09-26 17:29:07 +03:00
const stop = start.add(item.duration, 's')
programs.push({
title: item.name,
description: item.sinopse,
start,
stop
})
})
return programs
}
}
function parseItems(content, channel) {
const channels = JSON.parse(content)
const data = channels.find(ch => ch.id == channel.site_id)
2021-10-06 04:57:05 +03:00
return data ? data.epg : []
2021-09-26 17:29:07 +03:00
}
2021-11-25 03:05:32 +03:00
function parseStart(item, date) {
2021-09-26 17:29:07 +03:00
const [hours, minutes] = item.start_time.split('h')
2021-11-25 03:05:32 +03:00
const dateString = `${date.format('YYYY-MM-DD')} ${hours}:${minutes}`
2021-09-26 17:29:07 +03:00
2021-11-25 03:05:32 +03:00
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Africa/Luanda')
2021-09-26 17:29:07 +03:00
}