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

78 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-11-24 21:31:12 +03:00
const cheerio = require('cheerio')
2021-04-05 18:56:33 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(customParseFormat)
module.exports = {
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
},
parser({ content, date }) {
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-11-24 21:31:12 +03:00
const prev = programs[programs.length - 1]
const $item = cheerio.load(item)
let start = parseStart($item, date)
2021-08-27 20:26:11 +03:00
if (!start) return
2021-11-24 21:31:12 +03:00
if (prev) {
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
prev.stop = start
2021-04-05 18:56:33 +03:00
}
2021-11-24 21:31:12 +03:00
const stop = start.add(1, 'h')
2021-08-27 20:26:11 +03:00
programs.push({
2021-11-24 21:31:12 +03:00
title: parseTitle($item),
category: parseCategory($item),
description: parseDescription($item),
icon: parseIcon($item),
2021-08-27 20:26:11 +03:00
start,
stop
})
2021-04-05 18:56:33 +03:00
})
return programs
}
}
2021-08-27 20:26:11 +03:00
2021-11-24 21:31:12 +03:00
function parseStart($item, date) {
const timeString = $item('a > div.content > span.time').text()
if (!timeString) return null
const dateString = `${date.format('MM/DD/YYYY')} ${timeString}`
return dayjs.utc(dateString, 'MM/DD/YYYY HH:mm')
}
2021-08-27 20:26:11 +03:00
2021-11-24 21:31:12 +03:00
function parseTitle($item) {
return $item('a > div.content > h2').text().trim()
2021-08-27 20:26:11 +03:00
}
2021-11-24 21:31:12 +03:00
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
2021-08-27 20:26:11 +03:00
}
function parseItems(content) {
2021-11-24 21:31:12 +03:00
const $ = cheerio.load(content)
2021-08-27 20:26:11 +03:00
2021-11-24 21:31:12 +03:00
return $('#listings > ul > li').toArray()
2021-08-27 20:26:11 +03:00
}