mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 17:40:07 -04:00
Update znbc.co.zm.config.js
This commit is contained in:
parent
22b197d3f4
commit
1489992f00
1 changed files with 41 additions and 30 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')
|
||||||
|
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)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -24,43 +26,52 @@ module.exports = {
|
||||||
return img ? img.dataset.src : null
|
return img ? img.dataset.src : null
|
||||||
},
|
},
|
||||||
parser({ content, date }) {
|
parser({ content, date }) {
|
||||||
const day = date.day() // 0 => Sunday
|
|
||||||
const programs = []
|
const programs = []
|
||||||
const dom = new JSDOM(content)
|
const items = parseItems(content, date)
|
||||||
const tabs = dom.window.document.querySelectorAll(
|
|
||||||
`.elementor-tabs-content-wrapper > div[id*='elementor-tab-content']`
|
|
||||||
)
|
|
||||||
const items = tabs[day].querySelectorAll(`table > tbody > tr`)
|
|
||||||
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const row = (item.querySelector('td > p') || { textContent: '' }).textContent
|
const title = parseTitle(item)
|
||||||
const parts = row.split(' ')
|
const start = parseStart(item, date)
|
||||||
const time = parts.shift()
|
const stop = parseStop(item, start)
|
||||||
const title = parts
|
if (programs.length) {
|
||||||
.filter(str => str && /\S/g.test(str))
|
|
||||||
.map(i => i.trim())
|
|
||||||
.join(' ')
|
|
||||||
|
|
||||||
if (!time || !title) return false
|
|
||||||
|
|
||||||
const start = dayjs
|
|
||||||
.utc(time, 'HH:mm')
|
|
||||||
.set('D', date.get('D'))
|
|
||||||
.set('M', date.get('M'))
|
|
||||||
.set('y', date.get('y'))
|
|
||||||
|
|
||||||
if (!start.isValid()) return false
|
|
||||||
|
|
||||||
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, start, stop })
|
||||||
title,
|
|
||||||
start
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseStop(item, date) {
|
||||||
|
return date.endOf('d')
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseStart(item, date) {
|
||||||
|
const row = (item.querySelector('td > p') || { textContent: '' }).textContent
|
||||||
|
let time = row.split(' ').shift()
|
||||||
|
time = `${date.format('MM/DD/YYYY')} ${time}`
|
||||||
|
|
||||||
|
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Africa/Lusaka')
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseTitle(item) {
|
||||||
|
const row = (item.querySelector('td > p') || { textContent: '' }).textContent
|
||||||
|
const title = row.split(' ')
|
||||||
|
title.shift()
|
||||||
|
|
||||||
|
return title
|
||||||
|
.map(i => i.trim())
|
||||||
|
.filter(s => s)
|
||||||
|
.join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseItems(content, date) {
|
||||||
|
const day = date.day() // 0 => Sunday
|
||||||
|
const dom = new JSDOM(content)
|
||||||
|
const tabs = dom.window.document.querySelectorAll(
|
||||||
|
`.elementor-tabs-content-wrapper > div[id*='elementor-tab-content']`
|
||||||
|
)
|
||||||
|
|
||||||
|
return tabs[day].querySelectorAll(`table > tbody > tr:not(:first-child)`)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue