Files
epg/sites/mi.tv.config.js

75 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-04-05 18:56:33 +03:00
const jsdom = require('jsdom')
const { JSDOM } = jsdom
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
2021-08-27 20:26:11 +03:00
const timezone = require('dayjs/plugin/timezone')
2021-04-05 18:56:33 +03:00
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
2021-08-27 20:26:11 +03:00
dayjs.extend(timezone)
2021-04-05 18:56:33 +03:00
dayjs.extend(customParseFormat)
module.exports = {
lang: 'pt',
2021-09-24 15:11:09 +03:00
days: 3,
2021-04-05 18:56:33 +03:00
site: 'mi.tv',
channels: 'mi.tv.channels.xml',
output: '.gh-pages/guides/mi.tv.guide.xml',
url({ date, channel }) {
const [country, id] = channel.site_id.split('#')
2021-09-24 15:11:09 +03:00
return `https://mi.tv/${country}/async/channel/${id}/${date.format('YYYY-MM-DD')}/-180`
2021-04-05 18:56:33 +03:00
},
logo({ content }) {
const dom = new JSDOM(content)
const img = dom.window.document.querySelector('#listings > div.channel-info > img')
return img ? img.src : null
},
parser({ content, date }) {
2021-09-24 15:11:09 +03:00
let PM = false
2021-04-05 18:56:33 +03:00
const programs = []
2021-08-27 20:26:11 +03:00
const items = parseItems(content)
2021-04-05 18:56:33 +03:00
items.forEach(item => {
2021-08-27 20:26:11 +03:00
const title = parseTitle(item)
let start = parseStart(item, date)
if (!start) return
if (start.hour() > 11) PM = true
if (start.hour() < 12 && PM) start = start.add(1, 'd')
const stop = parseStop(item, start)
if (programs.length) {
programs[programs.length - 1].stop = start
2021-04-05 18:56:33 +03:00
}
2021-08-27 20:26:11 +03:00
programs.push({
title,
start,
stop
})
2021-04-05 18:56:33 +03:00
})
return programs
}
}
2021-08-27 20:26:11 +03:00
function parseStop(item, date) {
2021-09-24 15:11:09 +03:00
return date.tz('America/Sao_Paulo').add(1, 'h')
2021-08-27 20:26:11 +03:00
}
function parseStart(item, date) {
let time = (item.querySelector('a > div.content > span.time') || { textContent: '' }).textContent
if (!time) return null
time = `${date.format('MM/DD/YYYY')} ${time}`
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'America/Sao_Paulo')
}
function parseTitle(item) {
return (item.querySelector('a > div.content > h2') || { textContent: '' }).textContent
}
function parseItems(content) {
const dom = new JSDOM(content)
return dom.window.document.querySelectorAll('#listings > ul > li')
}