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 iconv = require('iconv-lite')
|
||||||
const { JSDOM } = jsdom
|
const cheerio = require('cheerio')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
|
@ -16,48 +15,47 @@ module.exports = {
|
||||||
return `https://tvgid.ua/channels/${channel.site_id}/${date.format('DDMMYYYY')}/tmall/`
|
return `https://tvgid.ua/channels/${channel.site_id}/${date.format('DDMMYYYY')}/tmall/`
|
||||||
},
|
},
|
||||||
parser: function ({ buffer, date }) {
|
parser: function ({ buffer, date }) {
|
||||||
let PM = false
|
|
||||||
const programs = []
|
const programs = []
|
||||||
const items = parseItems(buffer)
|
const items = parseItems(buffer)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = parseTitle(item)
|
const $item = cheerio.load(item)
|
||||||
let start = parseStart(item, date)
|
const prev = programs[programs.length - 1]
|
||||||
|
let start = parseStart($item, date)
|
||||||
if (!start) return
|
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')
|
const stop = start.add(1, 'h')
|
||||||
if (programs.length) {
|
if (prev) {
|
||||||
programs[programs.length - 1].stop = start
|
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
|
return programs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item, date) {
|
function parseStart($item, date) {
|
||||||
let time = (item.querySelector('td > table > tbody > tr > td.time') || { textContent: '' })
|
const timeString = $item('td > table > tbody > tr > td.time').text()
|
||||||
.textContent
|
if (!timeString) return null
|
||||||
if (!time) return null
|
const dateString = `${date.format('MM/DD/YYYY')} ${timeString}`
|
||||||
time = `${date.format('MM/DD/YYYY')} ${time}`
|
|
||||||
|
|
||||||
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) {
|
function parseTitle($item) {
|
||||||
return (
|
return $item('td > table > tbody > tr > td.item').text().trim()
|
||||||
item.querySelector('td > table > tbody > tr > td.item > a') ||
|
|
||||||
item.querySelector('td > table > tbody > tr > td.item') || { textContent: '' }
|
|
||||||
).textContent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(buffer) {
|
function parseItems(buffer) {
|
||||||
const string = iconv.decode(buffer, 'win1251')
|
if (!buffer) return []
|
||||||
const dom = new JSDOM(string)
|
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)'
|
'#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