Files
epg/sites/hd-plus.de.config.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-04-22 17:17:04 +03:00
const jsdom = require('jsdom')
const { JSDOM } = jsdom
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
2021-08-27 22:07:00 +03:00
const customParseFormat = require('dayjs/plugin/customParseFormat')
2021-04-22 17:17:04 +03:00
dayjs.extend(utc)
dayjs.extend(timezone)
2021-08-27 22:07:00 +03:00
dayjs.extend(customParseFormat)
2021-04-22 17:17:04 +03:00
module.exports = {
lang: 'de',
2021-09-24 18:57:50 +03:00
days: 3,
2021-04-22 17:17:04 +03:00
site: 'hd-plus.de',
channels: 'hd-plus.de.channels.xml',
output: '.gh-pages/guides/hd-plus.de.guide.xml',
url({ date, channel }) {
2021-09-24 18:57:50 +03:00
const today = dayjs().utc().startOf('d')
const day = date.diff(today, 'd')
2021-04-22 17:17:04 +03:00
return `https://www.hd-plus.de/epg/channel/${channel.site_id}?d=${day}`
},
logo({ content }) {
const dom = new JSDOM(content)
const img = dom.window.document.querySelector('header > img')
return img ? img.src : null
},
2021-08-27 22:07:00 +03:00
parser({ content, date }) {
const programs = []
const items = parseItems(content)
2021-04-22 17:17:04 +03:00
items.forEach(item => {
2021-08-27 22:07:00 +03:00
const title = parseTitle(item)
let start = parseStart(item, date)
2021-09-24 18:57:50 +03:00
const stop = start.add(1, 'h')
2021-08-27 22:07:00 +03:00
if (programs.length) {
programs[programs.length - 1].stop = start
2021-04-22 17:17:04 +03:00
}
2021-08-27 22:07:00 +03:00
programs.push({ title, start, stop })
2021-04-22 17:17:04 +03:00
})
return programs
}
}
2021-08-27 22:07:00 +03:00
function parseStart(item, date) {
let time = (item.querySelector('td:nth-child(2)') || { textContent: '' }).textContent
time = time.split(' ').pop()
time = `${date.format('MM/DD/YYYY')} ${time}`
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Berlin')
}
function parseTitle(item) {
return (item.querySelector('td:nth-child(1) > a') || { textContent: '' }).textContent
}
function parseItems(content) {
const dom = new JSDOM(content)
return dom.window.document.querySelectorAll('table > tbody > tr')
}