mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Merge pull request #113 from iptv-org/update-znbc-co-zm
Update znbc.co.zm.config.js
This commit is contained in:
commit
ea1bf816f5
1 changed files with 18 additions and 21 deletions
|
@ -4,6 +4,7 @@ const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
const tabletojson = require('tabletojson').Tabletojson
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
|
@ -11,6 +12,7 @@ dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
lang: 'en',
|
lang: 'en',
|
||||||
|
days: 7,
|
||||||
site: 'znbc.co.zm',
|
site: 'znbc.co.zm',
|
||||||
channels: 'znbc.co.zm.channels.xml',
|
channels: 'znbc.co.zm.channels.xml',
|
||||||
output: '.gh-pages/guides/znbc.co.zm.guide.xml',
|
output: '.gh-pages/guides/znbc.co.zm.guide.xml',
|
||||||
|
@ -29,9 +31,9 @@ module.exports = {
|
||||||
const programs = []
|
const programs = []
|
||||||
const items = parseItems(content, date)
|
const items = parseItems(content, date)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = parseTitle(item)
|
const title = item.title
|
||||||
const start = parseStart(item, date)
|
const start = parseStart(item, date)
|
||||||
const stop = parseStop(item, date)
|
const stop = start.add(30, 'm')
|
||||||
if (programs.length) {
|
if (programs.length) {
|
||||||
programs[programs.length - 1].stop = start
|
programs[programs.length - 1].stop = start
|
||||||
}
|
}
|
||||||
|
@ -43,35 +45,30 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStop(item, date) {
|
|
||||||
return date.endOf('d')
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStart(item, date) {
|
function parseStart(item, date) {
|
||||||
const row = (item.querySelector('td > p') || { textContent: '' }).textContent
|
const time = `${date.format('MM/DD/YYYY')} ${item.time}`
|
||||||
let time = row.split(' ').shift()
|
|
||||||
time = `${date.format('MM/DD/YYYY')} ${time}`
|
|
||||||
|
|
||||||
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Africa/Lusaka')
|
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) {
|
function parseItems(content, date) {
|
||||||
|
const items = []
|
||||||
const day = date.day() // 0 => Sunday
|
const day = date.day() // 0 => Sunday
|
||||||
const dom = new JSDOM(content)
|
const dom = new JSDOM(content)
|
||||||
const tabs = dom.window.document.querySelectorAll(
|
const tabs = dom.window.document.querySelectorAll(
|
||||||
`.elementor-tabs-content-wrapper > div[id*='elementor-tab-content']`
|
`.elementor-tabs-content-wrapper > div[id*='elementor-tab-content']`
|
||||||
)
|
)
|
||||||
|
const table = tabs[day].querySelector(`table`)
|
||||||
|
const data = tabletojson.convert(table.outerHTML)
|
||||||
|
if (!data) return items
|
||||||
|
const rows = data[0]
|
||||||
|
|
||||||
return tabs[day].querySelectorAll(`table > tbody > tr:not(:first-child)`)
|
return rows
|
||||||
|
.map(row => {
|
||||||
|
const time = row['0'].slice(0, 5).trim()
|
||||||
|
const title = row['0'].replace(time, '').replace(/\s\s+/g, ' ').trim()
|
||||||
|
|
||||||
|
return { time, title }
|
||||||
|
})
|
||||||
|
.filter(i => dayjs(i.time, 'HH:mm').isValid())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue