From 17815aa4b537e948e5dda5223b599cfc5b4eec07 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 26 Sep 2021 17:29:07 +0300 Subject: [PATCH] Create zap.co.ao.config.js --- sites/zap.co.ao.config.js | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 sites/zap.co.ao.config.js diff --git a/sites/zap.co.ao.config.js b/sites/zap.co.ao.config.js new file mode 100644 index 00000000..c044b85c --- /dev/null +++ b/sites/zap.co.ao.config.js @@ -0,0 +1,60 @@ +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 = { + lang: 'pt', + days: 3, + site: 'zap.co.ao', + channels: 'zap.co.ao.channels.xml', + output: '.gh-pages/guides/zap.co.ao.guide.xml', + url: function ({ date, channel }) { + return `https://www.zap.co.ao/_api/channels/${date.format('YYYY-M-D')}/epg.json` + }, + logo({ content, channel }) { + const channels = JSON.parse(content) + const data = channels.find(ch => ch.id == channel.site_id) + + return data.image_uri + }, + parser: function ({ content, channel }) { + let PM = false + const programs = [] + const items = parseItems(content, channel) + if (!items.length) return programs + items.forEach(item => { + let start = parseStart(item) + if (start.hour() > 11) PM = true + if (start.hour() < 12 && PM) start = start.add(1, 'd') + 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) + + return data.epg +} + +function parseStart(item) { + const [date] = item.date.split('T') + const [hours, minutes] = item.start_time.split('h') + const time = `${date} ${hours}:${minutes}` + + return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Africa/Luanda') +}