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

66 lines
1.7 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')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(customParseFormat)
module.exports = {
2021-09-29 19:48:57 +03:00
days: 1,
2021-04-05 18:56:33 +03:00
site: 'mi.tv',
url({ date, channel }) {
const [country, id] = channel.site_id.split('#')
2021-09-28 01:23:22 +03:00
2021-09-28 01:19:39 +03:00
return `https://mi.tv/${country}/async/channel/${id}/${date.format('YYYY-MM-DD')}/0`
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')
2021-09-24 15:34:42 +03:00
const stop = start.add(1, 'h')
2021-08-27 20:26:11 +03:00
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 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}`
2021-09-28 01:19:39 +03:00
return dayjs.utc(time, 'MM/DD/YYYY HH:mm')
2021-08-27 20:26:11 +03:00
}
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')
}