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
22b197d3f4
commit
1e4b9e8971
1 changed files with 41 additions and 24 deletions
|
@ -3,11 +3,14 @@ const iconv = require('iconv-lite')
|
||||||
const { JSDOM } = jsdom
|
const { JSDOM } = jsdom
|
||||||
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 customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
|
let PM = false
|
||||||
module.exports = {
|
module.exports = {
|
||||||
lang: 'uk',
|
lang: 'uk',
|
||||||
site: 'tvgid.ua',
|
site: 'tvgid.ua',
|
||||||
|
@ -18,36 +21,50 @@ module.exports = {
|
||||||
},
|
},
|
||||||
parser: function ({ buffer, date }) {
|
parser: function ({ buffer, date }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
const string = iconv.decode(buffer, 'win1251')
|
const items = parseItems(buffer)
|
||||||
const dom = new JSDOM(string)
|
|
||||||
const items = dom.window.document.querySelectorAll(
|
|
||||||
'#container > tbody > tr:nth-child(2) > td > table > tbody > tr > td > table:nth-child(2) > tbody > tr'
|
|
||||||
)
|
|
||||||
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const time = (item.querySelector('td > table > tbody > tr > td.time') || { textContent: '' })
|
const title = parseTitle(item)
|
||||||
.textContent
|
let start = parseStart(item, date)
|
||||||
const title = (
|
if (!start) return
|
||||||
item.querySelector('td > table > tbody > tr > td.item > a') ||
|
if (start.hour() > 11) PM = true
|
||||||
item.querySelector('td > table > tbody > tr > td.item') || { textContent: '' }
|
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||||
).textContent
|
const stop = parseStop(item, start)
|
||||||
|
if (programs.length) {
|
||||||
const start = dayjs
|
|
||||||
.utc(time, 'HH:mm')
|
|
||||||
.set('D', date.get('D'))
|
|
||||||
.set('M', date.get('M'))
|
|
||||||
.set('y', date.get('y'))
|
|
||||||
|
|
||||||
if (programs.length && !programs[programs.length - 1].stop) {
|
|
||||||
programs[programs.length - 1].stop = start
|
programs[programs.length - 1].stop = start
|
||||||
}
|
}
|
||||||
|
|
||||||
programs.push({
|
programs.push({ title, start, stop })
|
||||||
title,
|
|
||||||
start
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
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)'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue