mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
Merge pull request #62 from iptv-org/update-programtv-onet-pl
Update programtv.onet.pl.config.js
This commit is contained in:
commit
9744fdb304
1 changed files with 43 additions and 18 deletions
|
@ -2,11 +2,14 @@ const jsdom = require('jsdom')
|
|||
const { JSDOM } = jsdom
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
let PM = false
|
||||
module.exports = {
|
||||
lang: 'pl',
|
||||
site: 'programtv.onet.pl',
|
||||
|
@ -24,24 +27,16 @@ module.exports = {
|
|||
},
|
||||
parser: function ({ content, date }) {
|
||||
const programs = []
|
||||
const dom = new JSDOM(content)
|
||||
const items = dom.window.document.querySelectorAll(
|
||||
'#channelTV > section > div.emissions > ul > li'
|
||||
)
|
||||
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const title = (item.querySelector('.titles > a') || { textContent: '' }).textContent
|
||||
const description = (item.querySelector('.titles > p') || { textContent: '' }).textContent
|
||||
const category = (item.querySelector('.titles > .type') || { textContent: '' }).textContent
|
||||
const hour = (item.querySelector('.hours > .hour') || { textContent: '' }).textContent
|
||||
|
||||
const start = dayjs
|
||||
.utc(hour, 'H:mm')
|
||||
.set('D', date.get('D'))
|
||||
.set('M', date.get('M'))
|
||||
.set('y', date.get('y'))
|
||||
|
||||
if (programs.length && !programs[programs.length - 1].stop) {
|
||||
const title = parseTitle(item)
|
||||
const description = parseDescription(item)
|
||||
const category = parseCategory(item)
|
||||
let start = parseStart(item, date)
|
||||
if (start.hour() > 11) PM = true
|
||||
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||
const stop = parseStop(item, date)
|
||||
if (programs.length) {
|
||||
programs[programs.length - 1].stop = start
|
||||
}
|
||||
|
||||
|
@ -49,10 +44,40 @@ module.exports = {
|
|||
title,
|
||||
description,
|
||||
category,
|
||||
start
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStop(item, date) {
|
||||
return date.add(1, 'd').hour(3).startOf('h')
|
||||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
let time = (item.querySelector('.hours > .hour') || { textContent: '' }).textContent
|
||||
time = `${date.format('MM/DD/YYYY')} ${time}`
|
||||
|
||||
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Warsaw')
|
||||
}
|
||||
|
||||
function parseCategory(item) {
|
||||
return (item.querySelector('.titles > .type') || { textContent: '' }).textContent
|
||||
}
|
||||
|
||||
function parseDescription(item) {
|
||||
return (item.querySelector('.titles > p') || { textContent: '' }).textContent
|
||||
}
|
||||
|
||||
function parseTitle(item) {
|
||||
return (item.querySelector('.titles > a') || { textContent: '' }).textContent
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const dom = new JSDOM(content)
|
||||
|
||||
return dom.window.document.querySelectorAll('#channelTV > section > div.emissions > ul > li')
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue