Files
epg/sites/ontvtonight.com/ontvtonight.com.config.js

76 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-11-25 05:43:31 +03:00
const cheerio = require('cheerio')
2021-03-13 02:25:56 +03:00
const dayjs = require('dayjs')
2021-03-13 16:17:38 +03:00
const utc = require('dayjs/plugin/utc')
2021-08-23 15:24:18 +03:00
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
2021-03-13 16:17:38 +03:00
dayjs.extend(utc)
2021-08-23 15:24:18 +03:00
dayjs.extend(timezone)
2021-03-13 02:25:56 +03:00
dayjs.extend(customParseFormat)
2021-09-24 20:42:01 +03:00
const tz = {
au: 'Australia/Sydney',
ie: 'Europe/Dublin',
uk: 'Europe/London'
}
2021-03-13 02:25:56 +03:00
module.exports = {
2021-03-13 15:51:19 +03:00
site: 'ontvtonight.com',
2021-03-13 02:25:56 +03:00
url: function ({ date, channel }) {
2021-03-18 17:17:17 +03:00
const [region, id] = channel.site_id.split('#')
2021-09-24 20:42:01 +03:00
let url = `https://www.ontvtonight.com`
if (region) url += `/${region}`
url += `/guide/listings/channel/${id}.html?dt=${date.format('YYYY-MM-DD')}`
return url
2021-03-13 02:25:56 +03:00
},
2021-09-24 20:42:01 +03:00
parser: function ({ content, date, channel }) {
2021-03-13 02:25:56 +03:00
const programs = []
2021-08-23 15:24:18 +03:00
const items = parseItems(content)
2021-03-13 02:25:56 +03:00
items.forEach(item => {
2021-11-25 05:43:31 +03:00
const prev = programs[programs.length - 1]
const $item = cheerio.load(item)
const start = parseStart($item, date, channel)
if (prev) {
2021-11-25 19:24:36 +03:00
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
2021-11-25 05:43:31 +03:00
prev.stop = start
2021-03-13 02:25:56 +03:00
}
2021-11-25 05:43:31 +03:00
const stop = start.add(1, 'h')
programs.push({
title: parseTitle($item),
description: parseDescription($item),
start,
stop
})
2021-03-13 02:25:56 +03:00
})
return programs
}
}
2021-08-23 15:24:18 +03:00
2021-11-25 05:43:31 +03:00
function parseStart($item, date, channel) {
2021-09-24 20:42:01 +03:00
const [region, id] = channel.site_id.split('#')
const timezone = region ? tz[region] : tz['uk']
2021-11-25 05:43:31 +03:00
const timeString = $item('td:nth-child(1) > h5').text().trim()
const dateString = `${date.format('YYYY-MM-DD')} ${timeString}`
2021-08-27 17:11:54 +03:00
2021-11-25 05:43:31 +03:00
return dayjs.tz(dateString, 'YYYY-MM-DD H:mm a', timezone)
}
2021-08-23 15:24:18 +03:00
2021-11-25 05:43:31 +03:00
function parseTitle($item) {
return $item('td:nth-child(2) > h5').text().trim()
2021-08-23 15:24:18 +03:00
}
2021-11-25 05:43:31 +03:00
function parseDescription($item) {
return $item('td:nth-child(2) > h6').text().trim()
2021-08-23 15:24:18 +03:00
}
function parseItems(content) {
2021-11-25 05:43:31 +03:00
const $ = cheerio.load(content)
2021-08-23 15:24:18 +03:00
2021-11-25 05:43:31 +03:00
return $('#content > div > div > div.span6 > table > tbody > tr').toArray()
2021-08-23 15:24:18 +03:00
}