mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update mi.tv.config.js
This commit is contained in:
parent
22b197d3f4
commit
a6be3a5ad4
1 changed files with 40 additions and 21 deletions
|
@ -2,11 +2,14 @@ const jsdom = require('jsdom')
|
|||
const { JSDOM } = jsdom
|
||||
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)
|
||||
|
||||
let PM = false
|
||||
module.exports = {
|
||||
lang: 'pt',
|
||||
site: 'mi.tv',
|
||||
|
@ -23,32 +26,48 @@ module.exports = {
|
|||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const dom = new JSDOM(content)
|
||||
const items = dom.window.document.querySelectorAll('#listings > ul > li')
|
||||
const items = parseItems(content)
|
||||
|
||||
items.forEach(item => {
|
||||
const title = (item.querySelector('a > div.content > h2') || { textContent: '' }).textContent
|
||||
const time = (item.querySelector('a > div.content > span.time') || { textContent: '' })
|
||||
.textContent
|
||||
|
||||
if (title && time) {
|
||||
const start = dayjs
|
||||
.utc(time, 'HH:mm')
|
||||
.set('D', date.get('D'))
|
||||
.set('M', date.get('M'))
|
||||
.set('y', date.get('y'))
|
||||
|
||||
if (programs.length && !programs[programs.length - 1].stop) {
|
||||
programs[programs.length - 1].stop = start
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title,
|
||||
start
|
||||
})
|
||||
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
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStop(item, date) {
|
||||
return date.endOf('d').add(6, 'h')
|
||||
}
|
||||
|
||||
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')
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue