Files
epg/sites/tvgid.ua/tvgid.ua.config.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-04-01 01:57:08 +03:00
const iconv = require('iconv-lite')
2021-11-24 22:43:36 +03:00
const cheerio = require('cheerio')
2021-04-01 01:57:08 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
2021-08-28 01:48:40 +03:00
const timezone = require('dayjs/plugin/timezone')
2021-04-01 01:57:08 +03:00
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
2021-08-28 01:48:40 +03:00
dayjs.extend(timezone)
2021-04-01 01:57:08 +03:00
dayjs.extend(customParseFormat)
module.exports = {
site: 'tvgid.ua',
url: function ({ date, channel }) {
return `https://tvgid.ua/channels/${channel.site_id}/${date.format('DDMMYYYY')}/tmall/`
},
parser: function ({ buffer, date }) {
const programs = []
2021-08-28 01:48:40 +03:00
const items = parseItems(buffer)
2021-04-01 01:57:08 +03:00
items.forEach(item => {
2021-11-24 22:43:36 +03:00
const $item = cheerio.load(item)
const prev = programs[programs.length - 1]
let start = parseStart($item, date)
2021-08-28 01:48:40 +03:00
if (!start) return
2021-09-24 17:15:03 +03:00
const stop = start.add(1, 'h')
2021-11-24 22:43:36 +03:00
if (prev) {
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
prev.stop = start
2021-04-01 01:57:08 +03:00
}
2021-11-24 22:43:36 +03:00
programs.push({ title: parseTitle($item), start, stop })
2021-04-01 01:57:08 +03:00
})
return programs
}
}
2021-08-28 01:48:40 +03:00
2021-11-24 22:43:36 +03:00
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}`
2021-08-28 01:48:40 +03:00
2021-11-24 22:43:36 +03:00
return dayjs.tz(dateString, 'MM/DD/YYYY HH:mm', 'Europe/Kiev')
2021-08-28 01:48:40 +03:00
}
2021-11-24 22:43:36 +03:00
function parseTitle($item) {
return $item('td > table > tbody > tr > td.item').text().trim()
2021-08-28 01:48:40 +03:00
}
function parseItems(buffer) {
2021-11-24 22:43:36 +03:00
if (!buffer) return []
const html = iconv.decode(buffer, 'win1251')
const $ = cheerio.load(html)
2021-08-28 01:48:40 +03:00
2021-11-24 22:43:36 +03:00
return $(
2021-08-28 01:48:40 +03:00
'#container > tbody > tr:nth-child(2) > td > table > tbody > tr > td > table:nth-child(2) > tbody > tr:not(:first-child)'
2021-11-24 22:43:36 +03:00
).toArray()
2021-08-28 01:48:40 +03:00
}