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

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-03-11 17:06:43 +03:00
const jsdom = require('jsdom')
const { JSDOM } = jsdom
const dayjs = require('dayjs')
var customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
2021-03-11 23:36:44 +03:00
const { htmlToText } = require('html-to-text')
2021-03-11 17:06:43 +03:00
module.exports = {
url: function ({ date, channel }) {
return `https://www.tvguide.co.uk/mobile/channellisting.asp?ch=${channel.site_id}`
},
2021-03-12 02:49:09 +03:00
parser: function ({ channel, content, date, lang }) {
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 => {
const time = (tr.getElementsByClassName('time')[0] || { innerHTML: '' }).innerHTML
.toString()
.trim()
const title = (tr.getElementsByClassName('title')[0] || { innerHTML: '' }).innerHTML
.toString()
.trim()
2021-03-11 23:36:44 +03:00
const detail = tr.getElementsByClassName('detail')[0] || { innerHTML: '' }
const description = htmlToText(detail.innerHTML)
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-11 17:06:43 +03:00
start,
stop: null,
2021-03-12 02:49:09 +03:00
lang,
2021-03-11 17:06:43 +03:00
channel: channel['xmltv_id']
})
}
})
return programs
}
}