mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Merge pull request #305 from iptv-org/update-hd-plus-de
Update hd-plus.de
This commit is contained in:
commit
9d5bbf473e
2 changed files with 81 additions and 21 deletions
|
@ -1,5 +1,4 @@
|
|||
const jsdom = require('jsdom')
|
||||
const { JSDOM } = jsdom
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
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}`
|
||||
},
|
||||
logo({ content }) {
|
||||
const dom = new JSDOM(content)
|
||||
const img = dom.window.document.querySelector('header > img')
|
||||
const $ = cheerio.load(content)
|
||||
const imgSrc = $('header > img').attr('src')
|
||||
|
||||
return img ? img.src : null
|
||||
return imgSrc ? `https:${imgSrc}` : null
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const title = parseTitle(item)
|
||||
let start = parseStart(item, date)
|
||||
const stop = start.add(1, 'h')
|
||||
if (programs.length) {
|
||||
programs[programs.length - 1].stop = start
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date)
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
|
||||
programs.push({ title, start, stop })
|
||||
const stop = start.add(1, 'h')
|
||||
programs.push({ title: parseTitle($item), start, stop })
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
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}`
|
||||
function parseStart($item, date) {
|
||||
const timeString = $item('td:nth-child(2)').text().split(' ').pop()
|
||||
const dateString = `${date.format('YYYY-MM-DD')} ${timeString}`
|
||||
|
||||
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) {
|
||||
return (item.querySelector('td:nth-child(1) > a') || { textContent: '' }).textContent
|
||||
function parseTitle($item) {
|
||||
return $item('td:nth-child(1) > a').text()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
|
58
sites/hd-plus.de/hd-plus.de.test.js
Normal file
58
sites/hd-plus.de/hd-plus.de.test.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
// npx epg-grabber --config=sites/hd-plus.de/hd-plus.de.config.js --channels=sites/hd-plus.de/hd-plus.de_de.channels.xml --output=.gh-pages/guides/de/hd-plus.de.epg.xml --days=2
|
||||
|
||||
const { parser, url, logo } = require('./hd-plus.de.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2021-11-25', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '1-2-3-tv-hd',
|
||||
xmltv_id: '123TV.de'
|
||||
}
|
||||
const content = `<!DOCTYPE html><html> <head lang="de"></head> <body data-sensory-parallax-role="main" data-sensory-controller='{"controllerName": "OffscreenController"}' class="webshop-epg red" > <main data-sensory-controller='{"controllerName": "TeaserController"}'> <div class="grid-container-epg channel"> <div class="site_overlay"> <div class="loading_icon"></div></div><div class="site_wrapper"> <div id="UIChannelContent-619fb9d2e185d" class="channel-content"> <header> <img src="//cdn.hd-plus.de/senderlogos/bright-cropped/24444-2.png" alt="1-2-3.tv HD" class="channel-image"/> <h2 class="title">1-2-3.tv HD</h2> </header> <table> <thead> <tr> <th>Titel</th> <th>Ausstrahlungszeit</th> </tr></thead> <tbody> <tr> <td> <a href="/epg/show/1-2-3-tv-hd-ihre-lieblingsuhren/1442396582" >Ihre Lieblingsuhren</a > </td><td>Do 25.11 00:00</td></tr><tr> <td> <a href="/epg/show/1-2-3-tv-hd-ihre-lieblingsuhren/1442396584" >Ihre Lieblingsuhren</a > </td><td>Do 25.11 01:00</td></tr><tr> <td><a href="/epg/show/1-2-3-tv-hd-flash-deals/1452944370">Flash Deals</a></td><td>Do 25.11 06:00</td></tr></tbody> </table> </div></div></div></main> </body></html>`
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe('https://www.hd-plus.de/epg/channel/1-2-3-tv-hd?d=0')
|
||||
})
|
||||
|
||||
it('can generate valid logo url', () => {
|
||||
expect(logo({ content })).toBe('https://cdn.hd-plus.de/senderlogos/bright-cropped/24444-2.png')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const result = parser({ content, channel, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2021-11-24T23:00:00.000Z',
|
||||
stop: '2021-11-25T00:00:00.000Z',
|
||||
title: `Ihre Lieblingsuhren`
|
||||
},
|
||||
{
|
||||
start: '2021-11-25T00:00:00.000Z',
|
||||
stop: '2021-11-25T05:00:00.000Z',
|
||||
title: `Ihre Lieblingsuhren`
|
||||
},
|
||||
{
|
||||
start: '2021-11-25T05:00:00.000Z',
|
||||
stop: '2021-11-25T06:00:00.000Z',
|
||||
title: `Flash Deals`
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: `<!DOCTYPE html><html><head></head><body></body></html>`
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue