Files
epg/sites/tvguide.co.uk.config.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-03-11 17:06:43 +03:00
const jsdom = require('jsdom')
const { JSDOM } = jsdom
2021-03-12 17:42:01 +03:00
const { htmlToText } = require('html-to-text')
2021-03-11 17:06:43 +03:00
const dayjs = require('dayjs')
2021-03-13 16:17:38 +03:00
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
2021-03-11 17:06:43 +03:00
dayjs.extend(customParseFormat)
module.exports = {
2021-03-12 17:17:57 +03:00
lang: 'en',
2021-03-13 15:51:19 +03:00
site: 'tvguide.co.uk',
2021-03-13 16:17:38 +03:00
channels: 'tvguide.co.uk.channels.xml',
2021-03-13 15:51:19 +03:00
output: '.gh-pages/guides/tvguide.co.uk.xml',
2021-03-11 17:06:43 +03:00
url: function ({ date, channel }) {
return `https://www.tvguide.co.uk/mobile/channellisting.asp?ch=${channel.site_id}`
},
2021-03-13 17:43:54 +03:00
parser: function ({ content, date }) {
2021-03-11 17:06:43 +03:00
const programs = []
const dom = new JSDOM(content)
const channelListings = dom.window.document.querySelector('#channel-listings')
const rows = channelListings.querySelectorAll('table:first-of-type > tbody > tr')
rows.forEach(tr => {
2021-03-13 17:48:44 +03:00
const time = (tr.getElementsByClassName('time')[0] || { textContent: '' }).textContent
2021-03-11 17:06:43 +03:00
.toString()
.trim()
2021-03-13 17:48:44 +03:00
const title = (tr.getElementsByClassName('title')[0] || { textContent: '' }).textContent
2021-03-11 17:06:43 +03:00
.toString()
.trim()
2021-03-13 17:48:44 +03:00
const detail = tr.getElementsByClassName('detail')[0] || { textContent: '' }
const description = htmlToText(detail.textContent)
2021-03-11 17:06:43 +03:00
if (time && title) {
2021-03-12 00:07:14 +03:00
const start = dayjs
.utc(time, 'h:mma')
2021-03-11 17:06:43 +03:00
.set('D', date.get('D'))
.set('M', date.get('M'))
.set('y', date.get('y'))
.toString()
2021-03-12 01:23:14 +03:00
if (programs.length && !programs[programs.length - 1].stop) {
programs[programs.length - 1].stop = start
}
2021-03-11 17:06:43 +03:00
programs.push({
title,
2021-03-11 23:36:44 +03:00
description,
2021-03-12 17:51:59 +03:00
start
2021-03-11 17:06:43 +03:00
})
}
})
return programs
}
}