mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
Merge pull request #300 from iptv-org/update-ontvtonight-com
Update ontvtonight.com
This commit is contained in:
commit
7c569ef4d7
3 changed files with 93 additions and 45 deletions
|
@ -1,5 +1,4 @@
|
|||
const jsdom = require('jsdom')
|
||||
const { JSDOM } = jsdom
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
@ -26,58 +25,55 @@ module.exports = {
|
|||
return url
|
||||
},
|
||||
logo: function ({ content }) {
|
||||
const dom = new JSDOM(content)
|
||||
const img =
|
||||
dom.window.document.querySelector('#content > div > div > div.span6 > img') ||
|
||||
dom.window.document.querySelector('#inner-headline > div > div > div > img')
|
||||
const $ = cheerio.load(content)
|
||||
const imgSrc = $(
|
||||
'#content > div > div > div.span6 > img,#inner-headline > div > div > div > img'
|
||||
).attr('src')
|
||||
|
||||
return img ? img.src : null
|
||||
return imgSrc || null
|
||||
},
|
||||
parser: function ({ content, date, channel }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const title = parseTitle(item)
|
||||
const start = parseStart(item, date, channel)
|
||||
const stop = start.add(1, 'h')
|
||||
|
||||
if (title && start) {
|
||||
if (programs.length) {
|
||||
programs[programs.length - 1].stop = start
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
const start = parseStart($item, date, channel)
|
||||
if (prev) {
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.add(1, 'h')
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart(item, date, channel) {
|
||||
function parseStart($item, date, channel) {
|
||||
const [region, id] = channel.site_id.split('#')
|
||||
const timezone = region ? tz[region] : tz['uk']
|
||||
const timeString = $item('td:nth-child(1) > h5').text().trim()
|
||||
const dateString = `${date.format('YYYY-MM-DD')} ${timeString}`
|
||||
|
||||
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', timezone)
|
||||
return dayjs.tz(dateString, 'YYYY-MM-DD H:mm a', timezone)
|
||||
}
|
||||
|
||||
function parseTitle(item) {
|
||||
return (item.querySelector('td:nth-child(2) > h5 > a') || { textContent: '' }).textContent
|
||||
.toString()
|
||||
.trim()
|
||||
function parseTitle($item) {
|
||||
return $item('td:nth-child(2) > h5').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('td:nth-child(2) > h6').text().trim()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const dom = new JSDOM(content)
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return dom.window.document.querySelectorAll(
|
||||
'#content > div > div > div.span6 > table > tbody > tr'
|
||||
)
|
||||
return $('#content > div > div > div.span6 > table > tbody > tr').toArray()
|
||||
}
|
||||
|
|
63
sites/ontvtonight.com/ontvtonight.com.test.js
Normal file
63
sites/ontvtonight.com/ontvtonight.com.test.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
// npx epg-grabber --config=sites/ontvtonight.com/ontvtonight.com.config.js --channels=sites/ontvtonight.com/ontvtonight.com_au.channels.xml --output=.gh-pages/guides/au/ontvtonight.com.epg.xml --days=2
|
||||
|
||||
const { parser, url, logo } = require('./ontvtonight.com.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: 'au#1692/7two',
|
||||
xmltv_id: '7Two.au'
|
||||
}
|
||||
const content = `<!DOCTYPE html><html lang="en-AU" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"> <head> </head> <body> <div id="wrapper"> <section id="content"> <div class="container"> <div class="row"> <div class="span6"> <img src="https://otv-us-web.s3-us-west-2.amazonaws.com/logos/guide/media/ed49cf4f-1123-4bee-9c90-a6af375af310.png" border="0" align="right" alt="7TWO" width="140"/> <table class="table table-hover"> <tbody> <tr> <td width="90"> <h5 class="thin">12:10 am</h5> </td><td> <h5 class="thin"> <a href="https://www.ontvtonight.com/au/guide/listings/programme?cid=1692&sid=165632&dt=2021-11-24+13%3A10%3A00" target="_blank" rel="nofollow" > What A Carry On</a > </h5> </td></tr><tr> <td width="90"> <h5 class="thin">12:50 am</h5> </td><td> <h5 class="thin"> <a href="https://www.ontvtonight.com/au/guide/listings/programme?cid=1692&sid=159923&dt=2021-11-24+13%3A50%3A00" target="_blank" rel="nofollow" > Bones</a > </h5> <h6>The Devil In The Details</h6> </td></tr><tr> <td width="90"> <h5 class="thin">10:50 pm</h5> </td><td> <h5 class="thin"> <a href="https://www.ontvtonight.com/au/guide/listings/programme?cid=1692&sid=372057&dt=2021-11-25+11%3A50%3A00" target="_blank" rel="nofollow" > Inspector Morse: The Remorseful Day</a > </h5> </td></tr></tbody> </table> </div></div></div></section> </div></body></html>`
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.ontvtonight.com/au/guide/listings/channel/1692/7two.html?dt=2021-11-25'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid logo url', () => {
|
||||
expect(logo({ content })).toBe(
|
||||
'https://otv-us-web.s3-us-west-2.amazonaws.com/logos/guide/media/ed49cf4f-1123-4bee-9c90-a6af375af310.png'
|
||||
)
|
||||
})
|
||||
|
||||
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-24T13:10:00.000Z',
|
||||
stop: '2021-11-24T13:50:00.000Z',
|
||||
title: `What A Carry On`
|
||||
},
|
||||
{
|
||||
start: '2021-11-24T13:50:00.000Z',
|
||||
stop: '2021-11-25T11:50:00.000Z',
|
||||
title: `Bones`,
|
||||
description: 'The Devil In The Details'
|
||||
},
|
||||
{
|
||||
start: '2021-11-25T11:50:00.000Z',
|
||||
stop: '2021-11-25T12:50:00.000Z',
|
||||
title: `Inspector Morse: The Remorseful Day`
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: `<!DOCTYPE html><html><head></head><body></body></html>`
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="ontvtonight.com">
|
||||
<channels>
|
||||
<channel lang="en" xmltv_id="BBCArabic.uk" site_id="#4600837033/bbc-arabic-dish">BBC Arabic</channel>
|
||||
<channel lang="en" xmltv_id="DWEnglish.de" site_id="#69044840/dw-deutsche-welle">DW English</channel>
|
||||
<channel lang="en" xmltv_id="GodTVUK.uk" site_id="#1700792530/god-tv">God TV UK</channel>
|
||||
<channel lang="en" xmltv_id="MavTV.us" site_id="#69026971/mavtv">MavTV</channel>
|
||||
<channel lang="en" xmltv_id="OutdoorChannel.us" site_id="#69023268/outdoor-channel">Outdoor Channel</channel>
|
||||
<channel lang="en" xmltv_id="SkyNewsArabia.uk" site_id="#3293880923/sky-news-arabia">Sky News Arabia</channel>
|
||||
</channels>
|
||||
</site>
|
Loading…
Add table
Add a link
Reference in a new issue