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

114 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2025-09-28 17:55:05 +03:00
const axios = require('axios')
const cheerio = require('cheerio')
const path = require('path')
2026-04-09 00:02:18 +02:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(utc)
dayjs.extend(timezone)
2025-09-28 17:55:05 +03:00
module.exports = {
site: 'gatotv.com',
days: 2,
url({ channel, date }) {
return `https://www.gatotv.com/canal/${channel.site_id}/${date.format('YYYY-MM-DD')}`
},
parser({ content, date }) {
let programs = []
const items = parseItems(content)
2026-04-09 00:02:18 +02:00
date = date.subtract(1, 'day')
2025-09-28 17:55:05 +03:00
items.forEach((item, i) => {
const $item = cheerio.load(item)
let start = parseStart($item, date)
2026-04-09 00:02:18 +02:00
if (i === 0 && start.hour() >= 5) {
start = start.add(1, 'day')
date = date.add(1, 'day')
2025-09-28 17:55:05 +03:00
}
let stop = parseStop($item, date)
if (stop < start) {
2026-04-09 00:02:18 +02:00
stop = stop.add(1, 'day')
date = date.add(1, 'day')
2025-09-28 17:55:05 +03:00
}
programs.push({
title: parseTitle($item),
description: parseDescription($item),
image: parseImage($item),
start,
stop
})
})
return programs
},
async channels() {
const data = await axios
2026-04-18 12:33:52 +02:00
.get('https://www.gatotv.com/canales_de_tv')
2025-09-28 17:55:05 +03:00
.then(response => response.data)
.catch(console.log)
const $ = cheerio.load(data)
2026-04-18 12:33:52 +02:00
const items = $('table.tbl_tv_guide tr.tbl_EPG_row, table.tbl_tv_guide tr.tbl_EPG_rowAlternate').toArray()
2025-09-28 17:55:05 +03:00
2026-04-18 12:33:52 +02:00
return items
.map(item => {
const $item = cheerio.load(item)
const link = $item('a[href*="/canal/"]').first().attr('href')
if (!link) return null
2025-09-28 17:55:05 +03:00
2026-04-18 12:33:52 +02:00
let pathname
try {
pathname = new URL(link, 'https://www.gatotv.com').pathname
} catch {
return null
}
const name = $item('td:nth-child(2) a').text().trim() || $item('a[href*="/canal/"]').last().text().trim()
if (!name) return null
return {
lang: 'es',
site_id: path.basename(pathname),
name
}
})
.filter(Boolean)
2025-09-28 17:55:05 +03:00
}
}
function parseTitle($item) {
return $item(
'td:nth-child(4) > div > div > a > span,td:nth-child(3) > div > div > span,td:nth-child(3) > div > div > a > span'
).text()
}
function parseDescription($item) {
return $item('td:nth-child(4) > div').clone().children().remove().end().text().trim()
}
function parseImage($item) {
return $item('td:nth-child(3) > a > img').attr('src')
}
function parseStart($item, date) {
const time = $item('td:nth-child(1) > div > time').attr('datetime')
2026-04-09 00:02:18 +02:00
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'EST').utc()
2025-09-28 17:55:05 +03:00
}
function parseStop($item, date) {
const time = $item('td:nth-child(2) > div > time').attr('datetime')
2026-04-09 00:02:18 +02:00
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'EST').utc()
2025-09-28 17:55:05 +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()
}