mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
Merge pull request #61 from iptv-org/update-hd-plus-de
Update hd-plus.de.config.js
This commit is contained in:
commit
29671884bc
1 changed files with 34 additions and 21 deletions
|
@ -2,12 +2,12 @@ const jsdom = require('jsdom')
|
|||
const { JSDOM } = jsdom
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
lang: 'de',
|
||||
|
@ -26,29 +26,42 @@ module.exports = {
|
|||
|
||||
return img ? img.src : null
|
||||
},
|
||||
parser({ content }) {
|
||||
const dom = new JSDOM(content)
|
||||
const items = dom.window.document.querySelectorAll('table > tbody > tr')
|
||||
let programs = []
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const title = (item.querySelector('td:nth-child(1) > a') || { textContent: '' }).textContent
|
||||
const fullDate = (item.querySelector('td:nth-child(2)') || { textContent: '' }).textContent
|
||||
if (title && fullDate) {
|
||||
const time = fullDate.split(' ').pop()
|
||||
const local = dayjs.utc(time, 'HH:mm').toString()
|
||||
const start = dayjs.tz(local.toString(), 'Europe/Berlin').toString()
|
||||
|
||||
if (programs.length && !programs[programs.length - 1].stop) {
|
||||
programs[programs.length - 1].stop = start
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title,
|
||||
start
|
||||
})
|
||||
const title = parseTitle(item)
|
||||
let start = parseStart(item, date)
|
||||
const stop = parseStop(item, date)
|
||||
if (programs.length) {
|
||||
programs[programs.length - 1].stop = start
|
||||
}
|
||||
|
||||
programs.push({ title, start, stop })
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStop(item, date) {
|
||||
return date.endOf('d')
|
||||
}
|
||||
|
||||
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')
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue