From 0ace0feca7495831cc6758fd38098bc214a32975 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 23 Aug 2021 15:24:18 +0300 Subject: [PATCH 1/2] Update ontvtonight.com.config.js --- sites/ontvtonight.com.config.js | 50 ++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/sites/ontvtonight.com.config.js b/sites/ontvtonight.com.config.js index 544f0953..6c77dc50 100644 --- a/sites/ontvtonight.com.config.js +++ b/sites/ontvtonight.com.config.js @@ -2,9 +2,11 @@ const jsdom = require('jsdom') const { JSDOM } = jsdom const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') -var customParseFormat = require('dayjs/plugin/customParseFormat') +const timezone = require('dayjs/plugin/timezone') +const customParseFormat = require('dayjs/plugin/customParseFormat') dayjs.extend(utc) +dayjs.extend(timezone) dayjs.extend(customParseFormat) module.exports = { @@ -32,29 +34,12 @@ module.exports = { }, parser: function ({ content, date }) { const programs = [] - const dom = new JSDOM(content) - const items = dom.window.document.querySelectorAll( - '#content > div > div > div.span6 > table > tbody > tr' - ) - + const items = parseItems(content) items.forEach(item => { - const time = (item.querySelector('td:nth-child(1) > h5') || { textContent: '' }).textContent - .toString() - .trim() - const title = ( - item.querySelector('td:nth-child(2) > h5 > a') || { textContent: '' } - ).textContent - .toString() - .trim() - - if (time && title) { - const start = dayjs - .utc(time, 'h:mma') - .set('D', date.get('D')) - .set('M', date.get('M')) - .set('y', date.get('y')) - .toString() + const title = parseTitle(item) + const start = parseStart(item, date) + if (title && start) { if (programs.length && !programs[programs.length - 1].stop) { programs[programs.length - 1].stop = start } @@ -69,3 +54,24 @@ module.exports = { return programs } } + +function parseStart(item, date) { + 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', 'Europe/London') +} + +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' + ) +} From dab0737cd6fa10e03725f3589a32887515f1ab59 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 27 Aug 2021 17:11:54 +0300 Subject: [PATCH 2/2] Update ontvtonight.com.config.js --- sites/ontvtonight.com.config.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sites/ontvtonight.com.config.js b/sites/ontvtonight.com.config.js index 6c77dc50..07f10f08 100644 --- a/sites/ontvtonight.com.config.js +++ b/sites/ontvtonight.com.config.js @@ -38,15 +38,17 @@ module.exports = { items.forEach(item => { const title = parseTitle(item) const start = parseStart(item, date) + const stop = parseStop(item, date) if (title && start) { - if (programs.length && !programs[programs.length - 1].stop) { + if (programs.length) { programs[programs.length - 1].stop = start } programs.push({ title, - start + start, + stop }) } }) @@ -55,6 +57,10 @@ module.exports = { } } +function parseStop(item, date) { + return date.tz('Europe/London').endOf('d') +} + function parseStart(item, date) { let time = (item.querySelector('td:nth-child(1) > h5') || { textContent: '' }).textContent.trim() time = `${date.format('DD/MM/YYYY')} ${time.toUpperCase()}`