mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Merge pull request #47 from iptv-org/fix-ontvtonight-com-guide
Update ontvtonight.com.config.js
This commit is contained in:
commit
91fc09829e
1 changed files with 36 additions and 24 deletions
|
@ -2,9 +2,11 @@ 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')
|
||||||
var customParseFormat = require('dayjs/plugin/customParseFormat')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -32,36 +34,21 @@ 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(
|
|
||||||
'#content > div > div > div.span6 > table > tbody > tr'
|
|
||||||
)
|
|
||||||
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const time = (item.querySelector('td:nth-child(1) > h5') || { textContent: '' }).textContent
|
const title = parseTitle(item)
|
||||||
.toString()
|
const start = parseStart(item, date)
|
||||||
.trim()
|
const stop = parseStop(item, date)
|
||||||
const title = (
|
|
||||||
item.querySelector('td:nth-child(2) > h5 > a') || { textContent: '' }
|
|
||||||
).textContent
|
|
||||||
.toString()
|
|
||||||
.trim()
|
|
||||||
|
|
||||||
if (time && title) {
|
if (title && start) {
|
||||||
const start = dayjs
|
if (programs.length) {
|
||||||
.utc(time, 'h:mma')
|
|
||||||
.set('D', date.get('D'))
|
|
||||||
.set('M', date.get('M'))
|
|
||||||
.set('y', date.get('y'))
|
|
||||||
.toString()
|
|
||||||
|
|
||||||
if (programs.length && !programs[programs.length - 1].stop) {
|
|
||||||
programs[programs.length - 1].stop = start
|
programs[programs.length - 1].stop = start
|
||||||
}
|
}
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title,
|
title,
|
||||||
start
|
start,
|
||||||
|
stop
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -69,3 +56,28 @@ module.exports = {
|
||||||
return programs
|
return programs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseStop(item, date) {
|
||||||
|
return date.tz('Europe/London').endOf('d')
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseStart(item, date) {
|
||||||
|
let time = (item.querySelector('td:nth-child(1) > h5') || { textContent: '' }).textContent.trim()
|
||||||
|
time = `${date.format('DD/MM/YYYY')} ${time.toUpperCase()}`
|
||||||
|
|
||||||
|
return dayjs.tz(time, 'DD/MM/YYYY H:mm A', 'Europe/London')
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseTitle(item) {
|
||||||
|
return (item.querySelector('td:nth-child(2) > h5 > a') || { textContent: '' }).textContent
|
||||||
|
.toString()
|
||||||
|
.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseItems(content) {
|
||||||
|
const dom = new JSDOM(content)
|
||||||
|
|
||||||
|
return dom.window.document.querySelectorAll(
|
||||||
|
'#content > div > div > div.span6 > table > tbody > tr'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue