Files
epg/sites/ontvtonight.com.config.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-03-13 02:25:56 +03:00
const jsdom = require('jsdom')
const { JSDOM } = jsdom
const dayjs = require('dayjs')
2021-03-13 16:17:38 +03:00
const utc = require('dayjs/plugin/utc')
2021-08-23 15:24:18 +03:00
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
2021-03-13 16:17:38 +03:00
dayjs.extend(utc)
2021-08-23 15:24:18 +03:00
dayjs.extend(timezone)
2021-03-13 02:25:56 +03:00
dayjs.extend(customParseFormat)
2021-09-24 20:42:01 +03:00
const tz = {
au: 'Australia/Sydney',
ie: 'Europe/Dublin',
uk: 'Europe/London'
}
2021-03-13 02:25:56 +03:00
module.exports = {
2021-03-13 15:51:19 +03:00
site: 'ontvtonight.com',
2021-03-13 02:25:56 +03:00
url: function ({ date, channel }) {
2021-03-18 17:17:17 +03:00
const [region, id] = channel.site_id.split('#')
2021-09-24 20:42:01 +03:00
let url = `https://www.ontvtonight.com`
if (region) url += `/${region}`
url += `/guide/listings/channel/${id}.html?dt=${date.format('YYYY-MM-DD')}`
return url
2021-03-13 02:25:56 +03:00
},
2021-03-20 14:47:05 +03:00
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')
return img ? img.src : null
},
2021-09-24 20:42:01 +03:00
parser: function ({ content, date, channel }) {
2021-03-13 02:25:56 +03:00
const programs = []
2021-08-23 15:24:18 +03:00
const items = parseItems(content)
2021-03-13 02:25:56 +03:00
items.forEach(item => {
2021-08-23 15:24:18 +03:00
const title = parseTitle(item)
2021-09-24 20:42:01 +03:00
const start = parseStart(item, date, channel)
const stop = start.add(1, 'h')
2021-03-13 02:25:56 +03:00
2021-08-23 15:24:18 +03:00
if (title && start) {
2021-08-27 17:11:54 +03:00
if (programs.length) {
2021-03-13 02:25:56 +03:00
programs[programs.length - 1].stop = start
}
programs.push({
title,
2021-08-27 17:11:54 +03:00
start,
stop
2021-03-13 02:25:56 +03:00
})
}
})
return programs
}
}
2021-08-23 15:24:18 +03:00
2021-09-24 20:42:01 +03:00
function parseStart(item, date, channel) {
const [region, id] = channel.site_id.split('#')
const timezone = region ? tz[region] : tz['uk']
2021-08-27 17:11:54 +03:00
2021-08-23 15:24:18 +03:00
let time = (item.querySelector('td:nth-child(1) > h5') || { textContent: '' }).textContent.trim()
time = `${date.format('DD/MM/YYYY')} ${time.toUpperCase()}`
2021-09-24 20:42:01 +03:00
return dayjs.tz(time, 'DD/MM/YYYY H:mm A', timezone)
2021-08-23 15:24:18 +03:00
}
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'
)
}