Update ontvtonight.com.config.js

This commit is contained in:
Aleksandr Statciuk 2021-09-24 20:42:01 +03:00
parent 9e928c1b87
commit 7c9b5ec2ac

View file

@ -9,20 +9,25 @@ dayjs.extend(utc)
dayjs.extend(timezone) dayjs.extend(timezone)
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
const tz = {
au: 'Australia/Sydney',
ie: 'Europe/Dublin',
uk: 'Europe/London'
}
module.exports = { module.exports = {
lang: 'en', lang: 'en',
days: 3,
site: 'ontvtonight.com', site: 'ontvtonight.com',
channels: 'ontvtonight.com.channels.xml', channels: 'ontvtonight.com.channels.xml',
output: '.gh-pages/guides/ontvtonight.com.guide.xml', output: '.gh-pages/guides/ontvtonight.com.guide.xml',
url: function ({ date, channel }) { url: function ({ date, channel }) {
const [region, id] = channel.site_id.split('#') const [region, id] = channel.site_id.split('#')
return region let url = `https://www.ontvtonight.com`
? `https://www.ontvtonight.com/${region}/guide/listings/channel/${id}.html?dt=${date.format( if (region) url += `/${region}`
'YYYY-MM-DD' url += `/guide/listings/channel/${id}.html?dt=${date.format('YYYY-MM-DD')}`
)}`
: `https://www.ontvtonight.com/guide/listings/channel/${id}.html?dt=${date.format( return url
'YYYY-MM-DD'
)}`
}, },
logo: function ({ content }) { logo: function ({ content }) {
const dom = new JSDOM(content) const dom = new JSDOM(content)
@ -32,13 +37,13 @@ module.exports = {
return img ? img.src : null return img ? img.src : null
}, },
parser: function ({ content, date }) { parser: function ({ content, date, channel }) {
const programs = [] const programs = []
const items = parseItems(content) const items = parseItems(content)
items.forEach(item => { items.forEach(item => {
const title = parseTitle(item) const title = parseTitle(item)
const start = parseStart(item, date) const start = parseStart(item, date, channel)
const stop = parseStop(item, date) const stop = start.add(1, 'h')
if (title && start) { if (title && start) {
if (programs.length) { if (programs.length) {
@ -57,15 +62,14 @@ module.exports = {
} }
} }
function parseStop(item, date) { function parseStart(item, date, channel) {
return date.tz('Europe/London').endOf('d') const [region, id] = channel.site_id.split('#')
} const timezone = region ? tz[region] : tz['uk']
function parseStart(item, date) {
let time = (item.querySelector('td:nth-child(1) > h5') || { textContent: '' }).textContent.trim() let time = (item.querySelector('td:nth-child(1) > h5') || { textContent: '' }).textContent.trim()
time = `${date.format('DD/MM/YYYY')} ${time.toUpperCase()}` time = `${date.format('DD/MM/YYYY')} ${time.toUpperCase()}`
return dayjs.tz(time, 'DD/MM/YYYY H:mm A', 'Europe/London') return dayjs.tz(time, 'DD/MM/YYYY H:mm A', timezone)
} }
function parseTitle(item) { function parseTitle(item) {