Files
epg/sites/gatotv.com/gatotv.com.config.js
T

108 lines
3.0 KiB
JavaScript
Raw Normal View History

2021-11-15 21:59:06 +03:00
const axios = require('axios')
const cheerio = require('cheerio')
2023-01-31 03:34:14 +03:00
const url = require('url')
const path = require('path')
2021-11-15 21:59:06 +03:00
const dayjs = require('dayjs')
2023-01-31 03:34:14 +03:00
const utc = require('dayjs/plugin/utc')
2021-11-15 21:59:06 +03:00
const timezone = require('dayjs/plugin/timezone')
2023-01-31 03:34:14 +03:00
const customParseFormat = require('dayjs/plugin/customParseFormat')
2021-11-15 21:59:06 +03:00
2023-01-31 03:34:14 +03:00
dayjs.extend(utc)
2021-11-15 21:59:06 +03:00
dayjs.extend(timezone)
2023-01-31 03:34:14 +03:00
dayjs.extend(customParseFormat)
2021-11-15 21:59:06 +03:00
module.exports = {
site: 'gatotv.com',
2023-01-10 12:40:01 +03:00
days: 2,
2023-01-31 03:34:14 +03:00
url({ channel, date }) {
2021-11-15 21:59:06 +03:00
return `https://www.gatotv.com/canal/${channel.site_id}/${date.format('YYYY-MM-DD')}`
},
2023-01-31 03:34:14 +03:00
parser({ content, date }) {
2021-11-15 21:59:06 +03:00
let programs = []
const items = parseItems(content)
2023-01-31 03:34:14 +03:00
date = date.subtract(1, 'd')
2021-11-15 21:59:06 +03:00
items.forEach((item, index) => {
2021-11-25 03:22:10 +03:00
const prev = programs[programs.length - 1]
2021-11-15 21:59:06 +03:00
const $item = cheerio.load(item)
let start = parseStart($item, date)
2023-01-31 03:34:14 +03:00
if (prev) {
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
prev.stop = start
2021-11-15 21:59:06 +03:00
}
2023-01-31 03:34:14 +03:00
let stop = parseStop($item, start)
2021-11-25 03:22:10 +03:00
if (stop.isBefore(start)) {
2021-11-15 21:59:06 +03:00
stop = stop.add(1, 'd')
date = date.add(1, 'd')
}
2023-01-31 03:34:14 +03:00
2021-11-25 03:22:10 +03:00
programs.push({
title: parseTitle($item),
description: parseDescription($item),
icon: parseIcon($item),
start,
stop
})
2021-11-15 21:59:06 +03:00
})
return programs
},
2023-01-31 03:34:14 +03:00
async channels() {
2021-11-15 21:59:06 +03:00
const data = await axios
2023-01-31 03:34:14 +03:00
.get(`https://www.gatotv.com/guia_tv/completa`)
2021-11-15 21:59:06 +03:00
.then(response => response.data)
.catch(console.log)
const $ = cheerio.load(data)
const items = $('.tbl_EPG_row,.tbl_EPG_rowAlternate').toArray()
2023-01-31 03:34:14 +03:00
return items.map(item => {
2021-11-15 21:59:06 +03:00
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()
}
})
}
}
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) {
2023-01-31 03:34:14 +03:00
const time = $item('td:nth-child(1) > div > time').attr('datetime')
2021-11-15 21:59:06 +03:00
2023-01-31 03:34:14 +03:00
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'EST')
2021-11-15 21:59:06 +03:00
}
function parseStop($item, date) {
2023-01-31 03:34:14 +03:00
const time = $item('td:nth-child(2) > div > time').attr('datetime')
2021-11-15 21:59:06 +03:00
2023-01-31 03:34:14 +03:00
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'EST')
2021-11-15 21:59:06 +03:00
}
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()
}