mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Merge pull request #306 from iptv-org/update-znbc-co-zm
Update znbc.co.zm
This commit is contained in:
commit
31f649358b
2 changed files with 91 additions and 32 deletions
|
@ -1,5 +1,4 @@
|
||||||
const jsdom = require('jsdom')
|
const cheerio = require('cheerio')
|
||||||
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 timezone = require('dayjs/plugin/timezone')
|
||||||
|
@ -12,30 +11,32 @@ dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'znbc.co.zm',
|
site: 'znbc.co.zm',
|
||||||
ignore: true, // NOTE: site is down
|
|
||||||
url({ channel }) {
|
url({ channel }) {
|
||||||
return `https://www.znbc.co.zm/${channel.site_id}/`
|
return `https://www.znbc.co.zm/${channel.site_id}/`
|
||||||
},
|
},
|
||||||
logo({ content }) {
|
logo({ content }) {
|
||||||
const dom = new JSDOM(content)
|
const $ = cheerio.load(content)
|
||||||
const img = dom.window.document.querySelector(
|
const imgSrc = $(
|
||||||
'.elementor-tabs-content-wrapper > .elementor-tab-content > table > tbody > tr:nth-child(1) > td > span > img'
|
'.elementor-tab-content > table > tbody > tr:nth-child(1) > td span > img'
|
||||||
)
|
).data('src')
|
||||||
|
|
||||||
return img ? img.dataset.src : null
|
return imgSrc || null
|
||||||
},
|
},
|
||||||
parser({ content, date }) {
|
parser({ content, date }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
const items = parseItems(content, date)
|
const items = parseItems(content, date)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = item.title
|
const prev = programs[programs.length - 1]
|
||||||
const start = parseStart(item, date)
|
let start = parseStart(item, date)
|
||||||
const stop = start.add(30, 'm')
|
if (prev) {
|
||||||
if (programs.length) {
|
if (start.isBefore(prev.start)) {
|
||||||
programs[programs.length - 1].stop = start
|
start = start.add(1, 'd')
|
||||||
|
date = date.add(1, 'd')
|
||||||
|
}
|
||||||
|
prev.stop = start
|
||||||
}
|
}
|
||||||
|
const stop = start.add(30, 'm')
|
||||||
programs.push({ title, start, stop })
|
programs.push({ title: item.title, start, stop })
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
|
@ -43,29 +44,29 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item, date) {
|
function parseStart(item, date) {
|
||||||
const time = `${date.format('MM/DD/YYYY')} ${item.time}`
|
const dateString = `${date.format('YYYY-MM-DD')} ${item.time}`
|
||||||
|
|
||||||
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Africa/Lusaka')
|
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Africa/Lusaka')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, date) {
|
function parseItems(content, date) {
|
||||||
const items = []
|
const dayOfWeek = date.format('dddd').toUpperCase()
|
||||||
const day = date.day() // 0 => Sunday
|
const $ = cheerio.load(content)
|
||||||
const dom = new JSDOM(content)
|
const table = $(`.elementor-tab-mobile-title:contains("${dayOfWeek}")`).next().html()
|
||||||
const tabs = dom.window.document.querySelectorAll(
|
if (!table) return []
|
||||||
`.elementor-tabs-content-wrapper > div[id*='elementor-tab-content']`
|
const data = tabletojson.convert(table)
|
||||||
)
|
if (!Array.isArray(data) || !Array.isArray(data[0])) return []
|
||||||
const table = tabs[day].querySelector(`table`)
|
|
||||||
const data = tabletojson.convert(table.outerHTML)
|
|
||||||
if (!data) return items
|
|
||||||
const rows = data[0]
|
|
||||||
|
|
||||||
return rows
|
return data[0]
|
||||||
.map(row => {
|
.map(row => {
|
||||||
const time = row['0'].slice(0, 5).trim()
|
const [_, time, title] = row['0'].replace(/\s\s/g, ' ').match(/^(\d{2}:\d{2}) (.*)/) || [
|
||||||
const title = row['0'].replace(time, '').replace(/\s\s+/g, ' ').trim()
|
null,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
]
|
||||||
|
if (!time || !title.trim()) return null
|
||||||
|
|
||||||
return { time, title }
|
return { time, title: title.trim() }
|
||||||
})
|
})
|
||||||
.filter(i => dayjs(i.time, 'HH:mm').isValid())
|
.filter(i => i)
|
||||||
}
|
}
|
||||||
|
|
58
sites/znbc.co.zm/znbc.co.zm.test.js
Normal file
58
sites/znbc.co.zm/znbc.co.zm.test.js
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// npx epg-grabber --config=sites/znbc.co.zm/znbc.co.zm.config.js --channels=sites/znbc.co.zm/znbc.co.zm_zm.channels.xml --output=.gh-pages/guides/zm/znbc.co.zm.epg.xml --days=2
|
||||||
|
|
||||||
|
const { parser, url, logo } = require('./znbc.co.zm.config.js')
|
||||||
|
const dayjs = require('dayjs')
|
||||||
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
dayjs.extend(customParseFormat)
|
||||||
|
dayjs.extend(utc)
|
||||||
|
|
||||||
|
const date = dayjs.utc('2021-11-25', 'YYYY-MM-DD').startOf('d')
|
||||||
|
const channel = {
|
||||||
|
site_id: 'tv1',
|
||||||
|
xmltv_id: 'ZNBCTV1.zm'
|
||||||
|
}
|
||||||
|
const content = `<!DOCTYPE html><html lang="en-US"> <head></head> <body class=" page-template-default page page-id-3208 pmpro-body-has-access dark-background dark-version sticky-menu-on sticky-sidebar-on disable-floating-video header-vid-tech fullwidth-mode-enable beeteam368 elementor-default elementor-kit-8942 elementor-page elementor-page-3208 " > <div id="site-wrap-parent" class="site-wrap-parent site-wrap-parent-control"> <div id="site-wrap-children" class="site-wrap-children site-wrap-children-control"> <div id="primary-content-wrap" class="primary-content-wrap"> <div class="primary-content-control"> <div class="site__container fullwidth-vidorev-ctrl container-control"> <div class="site__row sidebar-direction"> <main id="main-content" class="site__col main-content"> <div class="single-page-wrapper global-single-wrapper"> <article id="post-3208" class=" single-page-content global-single-content post-3208 page type-page status-publish hentry pmpro-has-access " > <header class="entry-header"> <h1 class="entry-title extra-bold">TV1</h1> </header> <div class="entry-content"> <div data-elementor-type="wp-post" data-elementor-id="3208" class="elementor elementor-3208" data-elementor-settings="[]" > <div class="elementor-inner"> <div class="elementor-section-wrap"> <section class=" elementor-section elementor-top-section elementor-element elementor-element-10b3bf40 elementor-section-stretched elementor-section-full_width elementor-section-height-default elementor-section-height-default " data-id="10b3bf40" data-element_type="section" data-settings='{"stretch_section":"section-stretched"}' > <div class="elementor-container elementor-column-gap-default"> <div class="elementor-row"> <div class=" elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-50fbf4da " data-id="50fbf4da" data-element_type="column" > <div class="elementor-column-wrap elementor-element-populated" > <div class="elementor-widget-wrap"> <div class=" elementor-element elementor-element-54d50366 elementor-tabs-view-horizontal elementor-widget elementor-widget-tabs " data-id="54d50366" data-element_type="widget" data-widget_type="tabs.default" > <div class="elementor-widget-container"> <div class="elementor-tabs" role="tablist"> <div class="elementor-tabs-content-wrapper"> <div class=" elementor-tab-title elementor-tab-mobile-title " data-tab="4" role="tab" > WEDNESDAY </div><div id="elementor-tab-content-1424" class="elementor-tab-content elementor-clearfix" data-tab="4" role="tabpanel" aria-labelledby="elementor-tab-title-1424" > <table> <tbody> <tr> <td width="638"> <p>23:30 EYE ON SADC</p></td></tr></tbody> </table> </div><div class=" elementor-tab-title elementor-tab-mobile-title " data-tab="5" role="tab" > THURSDAY </div><div id="elementor-tab-content-1425" class="elementor-tab-content elementor-clearfix" data-tab="5" role="tabpanel" aria-labelledby="elementor-tab-title-1425" > <table> <tbody> <tr style="background-color: #f0eded"> <td> <span style="color: #000000" >TIME PROGRAMME<img alt="" width="91" height="32" data-src="https://www.znbc.co.zm/wp-content/uploads/2019/04/TV2-Logo.jpg" class=" wp-image-5259 alignright lazyloaded " src="https://www.znbc.co.zm/wp-content/uploads/2019/04/TV2-Logo.jpg"/></span> </td></tr><tr> <td width="638"> <p>00:00 MAIN NEWS – RPT</p></td></tr><tr> <td width="638"> <p> 01:00 BORN & BRED – Rebroadcast (Tuesday Edition) </p></td></tr><tr> <td width="638"> <p> <strong>02:00 </strong>DOCUMENTARY – DW </p></td></tr></tbody> </table> </div></div></div></div></div></div></div></div></div></div></section> </div></div></div></div></article> </div></main> </div></div></div></div></div></div></body></html>`
|
||||||
|
|
||||||
|
it('can generate valid url', () => {
|
||||||
|
expect(url({ channel })).toBe('https://www.znbc.co.zm/tv1/')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can generate valid logo url', () => {
|
||||||
|
expect(logo({ content })).toBe('https://www.znbc.co.zm/wp-content/uploads/2019/04/TV2-Logo.jpg')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can parse response', () => {
|
||||||
|
const result = parser({ content, channel, date }).map(p => {
|
||||||
|
p.start = p.start.toJSON()
|
||||||
|
p.stop = p.stop.toJSON()
|
||||||
|
return p
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toMatchObject([
|
||||||
|
{
|
||||||
|
start: '2021-11-24T22:00:00.000Z',
|
||||||
|
stop: '2021-11-24T23:00:00.000Z',
|
||||||
|
title: `MAIN NEWS – RPT`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: '2021-11-24T23:00:00.000Z',
|
||||||
|
stop: '2021-11-25T00:00:00.000Z',
|
||||||
|
title: `BORN & BRED – Rebroadcast (Tuesday Edition)`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
start: '2021-11-25T00:00:00.000Z',
|
||||||
|
stop: '2021-11-25T00:30:00.000Z',
|
||||||
|
title: `DOCUMENTARY – DW`
|
||||||
|
}
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can handle empty guide', () => {
|
||||||
|
const result = parser({
|
||||||
|
date,
|
||||||
|
channel,
|
||||||
|
content: `<!DOCTYPE html><html><head></head><body></body></html>`
|
||||||
|
})
|
||||||
|
expect(result).toMatchObject([])
|
||||||
|
})
|
Loading…
Add table
Add a link
Reference in a new issue