mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 17:40:07 -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 { 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 customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
|
let PM = false
|
||||||
module.exports = {
|
module.exports = {
|
||||||
lang: 'pl',
|
lang: 'pl',
|
||||||
site: 'programtv.onet.pl',
|
site: 'programtv.onet.pl',
|
||||||
|
@ -24,24 +27,16 @@ module.exports = {
|
||||||
},
|
},
|
||||||
parser: function ({ content, date }) {
|
parser: function ({ content, date }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
const dom = new JSDOM(content)
|
const items = parseItems(content)
|
||||||
const items = dom.window.document.querySelectorAll(
|
|
||||||
'#channelTV > section > div.emissions > ul > li'
|
|
||||||
)
|
|
||||||
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = (item.querySelector('.titles > a') || { textContent: '' }).textContent
|
const title = parseTitle(item)
|
||||||
const description = (item.querySelector('.titles > p') || { textContent: '' }).textContent
|
const description = parseDescription(item)
|
||||||
const category = (item.querySelector('.titles > .type') || { textContent: '' }).textContent
|
const category = parseCategory(item)
|
||||||
const hour = (item.querySelector('.hours > .hour') || { textContent: '' }).textContent
|
let start = parseStart(item, date)
|
||||||
|
if (start.hour() > 11) PM = true
|
||||||
const start = dayjs
|
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||||
.utc(hour, 'H:mm')
|
const stop = parseStop(item, date)
|
||||||
.set('D', date.get('D'))
|
if (programs.length) {
|
||||||
.set('M', date.get('M'))
|
|
||||||
.set('y', date.get('y'))
|
|
||||||
|
|
||||||
if (programs.length && !programs[programs.length - 1].stop) {
|
|
||||||
programs[programs.length - 1].stop = start
|
programs[programs.length - 1].stop = start
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,10 +44,40 @@ module.exports = {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
category,
|
category,
|
||||||
start
|
start,
|
||||||
|
stop
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
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