mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
70 lines
2 KiB
JavaScript
70 lines
2 KiB
JavaScript
const jsdom = require('jsdom')
|
|
const iconv = require('iconv-lite')
|
|
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: 'uk',
|
|
site: 'tvgid.ua',
|
|
channels: 'tvgid.ua.channels.xml',
|
|
output: '.gh-pages/guides/tvgid.ua.guide.xml',
|
|
url: function ({ date, channel }) {
|
|
return `https://tvgid.ua/channels/${channel.site_id}/${date.format('DDMMYYYY')}/tmall/`
|
|
},
|
|
parser: function ({ buffer, date }) {
|
|
const programs = []
|
|
const items = parseItems(buffer)
|
|
items.forEach(item => {
|
|
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.hour(7)
|
|
}
|
|
|
|
function parseStart(item, date) {
|
|
let time = (item.querySelector('td > table > tbody > tr > td.time') || { textContent: '' })
|
|
.textContent
|
|
if (!time) return null
|
|
time = `${date.format('MM/DD/YYYY')} ${time}`
|
|
|
|
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Kiev')
|
|
}
|
|
|
|
function parseTitle(item) {
|
|
return (
|
|
item.querySelector('td > table > tbody > tr > td.item > a') ||
|
|
item.querySelector('td > table > tbody > tr > td.item') || { textContent: '' }
|
|
).textContent
|
|
}
|
|
|
|
function parseItems(buffer) {
|
|
const string = iconv.decode(buffer, 'win1251')
|
|
const dom = new JSDOM(string)
|
|
|
|
return dom.window.document.querySelectorAll(
|
|
'#container > tbody > tr:nth-child(2) > td > table > tbody > tr > td > table:nth-child(2) > tbody > tr:not(:first-child)'
|
|
)
|
|
}
|