epg/sites/tvguide.co.uk.js
freearhey 448c47cb5c wip
2021-03-11 23:36:44 +03:00

48 lines
1.5 KiB
JavaScript

const jsdom = require('jsdom')
const { JSDOM } = jsdom
const dayjs = require('dayjs')
var customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
const { htmlToText } = require('html-to-text')
module.exports = {
url: function ({ date, channel }) {
return `https://www.tvguide.co.uk/mobile/channellisting.asp?ch=${channel.site_id}`
},
parser: function ({ channel, content, date }) {
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 => {
const time = (tr.getElementsByClassName('time')[0] || { innerHTML: '' }).innerHTML
.toString()
.trim()
const title = (tr.getElementsByClassName('title')[0] || { innerHTML: '' }).innerHTML
.toString()
.trim()
const detail = tr.getElementsByClassName('detail')[0] || { innerHTML: '' }
const description = htmlToText(detail.innerHTML)
if (time && title) {
const start = dayjs(time, 'h:mma')
.set('D', date.get('D'))
.set('M', date.get('M'))
.set('y', date.get('y'))
.toString()
programs.push({
title,
description,
start,
stop: null,
lang: 'en',
channel: channel['xmltv_id']
})
}
})
return programs
}
}