mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-12 01:50:07 -04:00
Update hd-plus.de.config.js
This commit is contained in:
parent
f2b92e9553
commit
5d98790132
1 changed files with 23 additions and 21 deletions
|
@ -1,5 +1,4 @@
|
||||||
const jsdom = require('jsdom')
|
const cheerio = require('cheerio')
|
||||||
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 timezone = require('dayjs/plugin/timezone')
|
||||||
|
@ -19,43 +18,46 @@ module.exports = {
|
||||||
return `https://www.hd-plus.de/epg/channel/${channel.site_id}?d=${day}`
|
return `https://www.hd-plus.de/epg/channel/${channel.site_id}?d=${day}`
|
||||||
},
|
},
|
||||||
logo({ content }) {
|
logo({ content }) {
|
||||||
const dom = new JSDOM(content)
|
const $ = cheerio.load(content)
|
||||||
const img = dom.window.document.querySelector('header > img')
|
const imgSrc = $('header > img').attr('src')
|
||||||
|
|
||||||
return img ? img.src : null
|
return imgSrc ? `https:${imgSrc}` : null
|
||||||
},
|
},
|
||||||
parser({ content, date }) {
|
parser({ content, date }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
const items = parseItems(content)
|
const items = parseItems(content)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = parseTitle(item)
|
const prev = programs[programs.length - 1]
|
||||||
let start = parseStart(item, date)
|
const $item = cheerio.load(item)
|
||||||
const stop = start.add(1, 'h')
|
let start = parseStart($item, date)
|
||||||
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
|
||||||
}
|
}
|
||||||
|
const stop = start.add(1, 'h')
|
||||||
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:nth-child(2)') || { textContent: '' }).textContent
|
const timeString = $item('td:nth-child(2)').text().split(' ').pop()
|
||||||
time = time.split(' ').pop()
|
const dateString = `${date.format('YYYY-MM-DD')} ${timeString}`
|
||||||
time = `${date.format('MM/DD/YYYY')} ${time}`
|
|
||||||
|
|
||||||
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Berlin')
|
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Europe/Berlin')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle(item) {
|
function parseTitle($item) {
|
||||||
return (item.querySelector('td:nth-child(1) > a') || { textContent: '' }).textContent
|
return $item('td:nth-child(1) > a').text()
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content) {
|
function parseItems(content) {
|
||||||
const dom = new JSDOM(content)
|
const $ = cheerio.load(content)
|
||||||
|
|
||||||
return dom.window.document.querySelectorAll('table > tbody > tr')
|
return $('table > tbody > tr').toArray()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue