mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 17:40:07 -04:00
Update mi.tv.config.js
This commit is contained in:
parent
f333bc45cc
commit
5fdc38501f
1 changed files with 43 additions and 24 deletions
|
@ -1,5 +1,4 @@
|
||||||
const jsdom = require('jsdom')
|
const cheerio = require('cheerio')
|
||||||
const { JSDOM } = jsdom
|
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
@ -15,27 +14,32 @@ module.exports = {
|
||||||
return `https://mi.tv/${country}/async/channel/${id}/${date.format('YYYY-MM-DD')}/0`
|
return `https://mi.tv/${country}/async/channel/${id}/${date.format('YYYY-MM-DD')}/0`
|
||||||
},
|
},
|
||||||
logo({ content }) {
|
logo({ content }) {
|
||||||
const dom = new JSDOM(content)
|
const $ = cheerio.load(content)
|
||||||
const img = dom.window.document.querySelector('#listings > div.channel-info > img')
|
const imgSrc = $('#listings > div.channel-info > img').attr('src')
|
||||||
return img ? img.src : null
|
|
||||||
|
return imgSrc || null
|
||||||
},
|
},
|
||||||
parser({ content, date }) {
|
parser({ content, date }) {
|
||||||
let PM = false
|
|
||||||
const programs = []
|
const programs = []
|
||||||
const items = parseItems(content)
|
const items = parseItems(content)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = parseTitle(item)
|
const prev = programs[programs.length - 1]
|
||||||
let start = parseStart(item, date)
|
const $item = cheerio.load(item)
|
||||||
|
let start = parseStart($item, date)
|
||||||
if (!start) return
|
if (!start) return
|
||||||
if (start.hour() > 11) PM = true
|
if (prev) {
|
||||||
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
if (start.isBefore(prev.start)) {
|
||||||
const stop = start.add(1, 'h')
|
start = start.add(1, 'd')
|
||||||
if (programs.length) {
|
date = date.add(1, 'd')
|
||||||
programs[programs.length - 1].stop = start
|
}
|
||||||
|
prev.stop = start
|
||||||
}
|
}
|
||||||
|
const stop = start.add(1, 'h')
|
||||||
programs.push({
|
programs.push({
|
||||||
title,
|
title: parseTitle($item),
|
||||||
|
category: parseCategory($item),
|
||||||
|
description: parseDescription($item),
|
||||||
|
icon: parseIcon($item),
|
||||||
start,
|
start,
|
||||||
stop
|
stop
|
||||||
})
|
})
|
||||||
|
@ -45,20 +49,35 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item, date) {
|
function parseStart($item, date) {
|
||||||
let time = (item.querySelector('a > div.content > span.time') || { textContent: '' }).textContent
|
const timeString = $item('a > div.content > span.time').text()
|
||||||
if (!time) return null
|
if (!timeString) return null
|
||||||
time = `${date.format('MM/DD/YYYY')} ${time}`
|
const dateString = `${date.format('MM/DD/YYYY')} ${timeString}`
|
||||||
|
|
||||||
return dayjs.utc(time, 'MM/DD/YYYY HH:mm')
|
return dayjs.utc(dateString, 'MM/DD/YYYY HH:mm')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle(item) {
|
function parseTitle($item) {
|
||||||
return (item.querySelector('a > div.content > h2') || { textContent: '' }).textContent
|
return $item('a > div.content > h2').text().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCategory($item) {
|
||||||
|
return $item('a > div.content > span.sub-title').text().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseDescription($item) {
|
||||||
|
return $item('a > div.content > p.synopsis').text().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseIcon($item) {
|
||||||
|
const backgroundImage = $item('a > div.image-parent > div.image').css('background-image')
|
||||||
|
const [_, icon] = backgroundImage.match(/url\(\'(.*)'\)/) || [null, null]
|
||||||
|
|
||||||
|
return icon
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content) {
|
function parseItems(content) {
|
||||||
const dom = new JSDOM(content)
|
const $ = cheerio.load(content)
|
||||||
|
|
||||||
return dom.window.document.querySelectorAll('#listings > ul > li')
|
return $('#listings > ul > li').toArray()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue