From 3e8527437341aea7e094f8d42a9dc9d98c4d331a Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 15 Nov 2021 21:59:06 +0300 Subject: [PATCH] Create gatotv.com.config.js --- sites/gatotv.com/gatotv.com.config.js | 102 ++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 sites/gatotv.com/gatotv.com.config.js diff --git a/sites/gatotv.com/gatotv.com.config.js b/sites/gatotv.com/gatotv.com.config.js new file mode 100644 index 00000000..330e0a44 --- /dev/null +++ b/sites/gatotv.com/gatotv.com.config.js @@ -0,0 +1,102 @@ +const axios = require('axios') +const cheerio = require('cheerio') +const dayjs = require('dayjs') +const timezone = require('dayjs/plugin/timezone') +var url = require('url') +var path = require('path') + +dayjs.extend(timezone) + +module.exports = { + site: 'gatotv.com', + url: function ({ channel, date }) { + return `https://www.gatotv.com/canal/${channel.site_id}/${date.format('YYYY-MM-DD')}` + }, + logo({ content }) { + const $ = cheerio.load(content) + + return $('.div_MainPicture img').attr('src') + }, + parser: function ({ content, date }) { + let programs = [] + const items = parseItems(content) + items.forEach((item, index) => { + const $item = cheerio.load(item) + const title = parseTitle($item) + const icon = parseIcon($item) + const description = parseDescription($item) + let start = parseStart($item, date) + if (index === 0 && start.hour() > 12) { + start = start.subtract(1, 'd') + date = date.subtract(1, 'd') + } + let stop = parseStop($item, date) + if (start.isAfter(stop)) { + stop = stop.add(1, 'd') + date = date.add(1, 'd') + } + + programs.push({ title, description, icon, start, stop }) + }) + + return programs + }, + async channels({ country }) { + const data = await axios + .get(`https://www.gatotv.com/guia_tv/${country}`) + .then(response => response.data) + .catch(console.log) + + const $ = cheerio.load(data) + const items = $('.tbl_EPG_row,.tbl_EPG_rowAlternate').toArray() + const channels = items.map(item => { + const $item = cheerio.load(item) + const link = $item('td:nth-child(1) > div:nth-child(2) > a:nth-child(3)').attr('href') + const parsed = url.parse(link) + + return { + lang: 'es', + site_id: path.basename(parsed.pathname), + name: $item('td:nth-child(1) > div:nth-child(2) > a:nth-child(3)').text() + } + }) + + return channels + } +} + +function parseTitle($item) { + return $item('td:nth-child(4) > div > div > a > span,td:nth-child(3) > div > div > span').text() +} + +function parseDescription($item) { + return $item('td:nth-child(4) > div').clone().children().remove().end().text().trim() +} + +function parseIcon($item) { + return $item('td:nth-child(3) > a > img').attr('src') +} + +function parseStart($item, date) { + let time = $item('td:nth-child(1) > div > time').attr('datetime') + time = `${date.format('YYYY-MM-DD')} ${time}` + + return dayjs.tz(time, 'YYYY-MM-DD HH:mm', dayjs.tz.guess()) +} + +function parseStop($item, date) { + let time = $item('td:nth-child(2) > div > time').attr('datetime') + time = `${date.format('YYYY-MM-DD')} ${time}` + + return dayjs.tz(time, 'YYYY-MM-DD HH:mm', dayjs.tz.guess()) +} + +function parseItems(content) { + const $ = cheerio.load(content) + + return $( + 'body > div.div_content > table:nth-child(8) > tbody > tr:nth-child(2) > td:nth-child(1) > table.tbl_EPG' + ) + .find('.tbl_EPG_row,.tbl_EPG_rowAlternate,.tbl_EPG_row_selected') + .toArray() +}