mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update tvgid.ua.config.js
This commit is contained in:
parent
75655b0353
commit
30f96f3ead
1 changed files with 23 additions and 25 deletions
|
@ -1,6 +1,5 @@
|
|||
const jsdom = require('jsdom')
|
||||
const iconv = require('iconv-lite')
|
||||
const { JSDOM } = jsdom
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
@ -16,48 +15,47 @@ module.exports = {
|
|||
return `https://tvgid.ua/channels/${channel.site_id}/${date.format('DDMMYYYY')}/tmall/`
|
||||
},
|
||||
parser: function ({ buffer, date }) {
|
||||
let PM = false
|
||||
const programs = []
|
||||
const items = parseItems(buffer)
|
||||
items.forEach(item => {
|
||||
const title = parseTitle(item)
|
||||
let start = parseStart(item, date)
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
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 = start.add(1, 'h')
|
||||
if (programs.length) {
|
||||
programs[programs.length - 1].stop = start
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
|
||||
programs.push({ title, start, stop })
|
||||
programs.push({ title: parseTitle($item), start, stop })
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
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}`
|
||||
function parseStart($item, date) {
|
||||
const timeString = $item('td > table > tbody > tr > td.time').text()
|
||||
if (!timeString) return null
|
||||
const dateString = `${date.format('MM/DD/YYYY')} ${timeString}`
|
||||
|
||||
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Kiev')
|
||||
return dayjs.tz(dateString, '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 parseTitle($item) {
|
||||
return $item('td > table > tbody > tr > td.item').text().trim()
|
||||
}
|
||||
|
||||
function parseItems(buffer) {
|
||||
const string = iconv.decode(buffer, 'win1251')
|
||||
const dom = new JSDOM(string)
|
||||
if (!buffer) return []
|
||||
const html = iconv.decode(buffer, 'win1251')
|
||||
const $ = cheerio.load(html)
|
||||
|
||||
return dom.window.document.querySelectorAll(
|
||||
return $(
|
||||
'#container > tbody > tr:nth-child(2) > td > table > tbody > tr > td > table:nth-child(2) > tbody > tr:not(:first-child)'
|
||||
)
|
||||
).toArray()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue