mirror of
https://github.com/iptv-org/epg
synced 2026-04-29 14:06:59 -04:00
Fixes linter errors
This commit is contained in:
@@ -1,77 +1,77 @@
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
const tz = {
|
||||
au: 'Australia/Sydney',
|
||||
ie: 'Europe/Dublin',
|
||||
uk: 'Europe/London',
|
||||
us: 'America/New_York'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
site: 'ontvtonight.com',
|
||||
days: 2,
|
||||
url: function ({ date, channel }) {
|
||||
const [region, id] = channel.site_id.split('#')
|
||||
let url = 'https://www.ontvtonight.com'
|
||||
if (region) url += `/${region}`
|
||||
url += `/guide/listings/channel/${id}.html?dt=${date.format('YYYY-MM-DD')}`
|
||||
|
||||
return url
|
||||
},
|
||||
parser: function ({ content, date, channel }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date, channel)
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.add(1, 'h')
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item, date, channel) {
|
||||
const [region] = channel.site_id.split('#')
|
||||
const timezone = region ? tz[region] : tz['uk']
|
||||
const timeString = $item('td:nth-child(1) > h5').text().trim()
|
||||
const dateString = `${date.format('YYYY-MM-DD')} ${timeString}`
|
||||
|
||||
return dayjs.tz(dateString, 'YYYY-MM-DD H:mm a', timezone)
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('td:nth-child(2) > h5').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('td:nth-child(2) > h6').text().trim()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('#content > div > div > div.span6 > table > tbody > tr').toArray()
|
||||
}
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
const tz = {
|
||||
au: 'Australia/Sydney',
|
||||
ie: 'Europe/Dublin',
|
||||
uk: 'Europe/London',
|
||||
us: 'America/New_York'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
site: 'ontvtonight.com',
|
||||
days: 2,
|
||||
url: function ({ date, channel }) {
|
||||
const [region, id] = channel.site_id.split('#')
|
||||
let url = 'https://www.ontvtonight.com'
|
||||
if (region) url += `/${region}`
|
||||
url += `/guide/listings/channel/${id}.html?dt=${date.format('YYYY-MM-DD')}`
|
||||
|
||||
return url
|
||||
},
|
||||
parser: function ({ content, date, channel }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date, channel)
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.add(1, 'h')
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item, date, channel) {
|
||||
const [region] = channel.site_id.split('#')
|
||||
const timezone = region ? tz[region] : tz['uk']
|
||||
const timeString = $item('td:nth-child(1) > h5').text().trim()
|
||||
const dateString = `${date.format('YYYY-MM-DD')} ${timeString}`
|
||||
|
||||
return dayjs.tz(dateString, 'YYYY-MM-DD H:mm a', timezone)
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('td:nth-child(2) > h5').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('td:nth-child(2) > h6').text().trim()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('#content > div > div > div.span6 > table > tbody > tr').toArray()
|
||||
}
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
// npm run grab -- --site=ontvtonight.com
|
||||
// npm run grab -- --site=ontvtonight.com
|
||||
|
||||
const { parser, url } = require('./ontvtonight.com.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2021-11-25', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'au#1692/7two',
|
||||
xmltv_id: '7two.au'
|
||||
}
|
||||
const content =
|
||||
'<!DOCTYPE html><html lang="en-AU" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"> <head> </head> <body> <div id="wrapper"> <section id="content"> <div class="container"> <div class="row"> <div class="span6"> <img src="https://otv-us-web.s3-us-west-2.amazonaws.com/logos/guide/media/ed49cf4f-1123-4bee-9c90-a6af375af310.png" border="0" align="right" alt="7TWO" width="140"/> <table class="table table-hover"> <tbody> <tr> <td width="90"> <h5 class="thin">12:10 am</h5> </td><td> <h5 class="thin"> <a href="https://www.ontvtonight.com/au/guide/listings/programme?cid=1692&sid=165632&dt=2021-11-24+13%3A10%3A00" target="_blank" rel="nofollow" > What A Carry On</a > </h5> </td></tr><tr> <td width="90"> <h5 class="thin">12:50 am</h5> </td><td> <h5 class="thin"> <a href="https://www.ontvtonight.com/au/guide/listings/programme?cid=1692&sid=159923&dt=2021-11-24+13%3A50%3A00" target="_blank" rel="nofollow" > Bones</a > </h5> <h6>The Devil In The Details</h6> </td></tr><tr> <td width="90"> <h5 class="thin">10:50 pm</h5> </td><td> <h5 class="thin"> <a href="https://www.ontvtonight.com/au/guide/listings/programme?cid=1692&sid=372057&dt=2021-11-25+11%3A50%3A00" target="_blank" rel="nofollow" > Inspector Morse: The Remorseful Day</a > </h5> </td></tr></tbody> </table> </div></div></div></section> </div></body></html>'
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.ontvtonight.com/au/guide/listings/channel/1692/7two.html?dt=2021-11-25'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const result = parser({ content, channel, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2021-11-24T13:10:00.000Z',
|
||||
stop: '2021-11-24T13:50:00.000Z',
|
||||
title: 'What A Carry On'
|
||||
},
|
||||
{
|
||||
start: '2021-11-24T13:50:00.000Z',
|
||||
stop: '2021-11-25T11:50:00.000Z',
|
||||
title: 'Bones',
|
||||
description: 'The Devil In The Details'
|
||||
},
|
||||
{
|
||||
start: '2021-11-25T11:50:00.000Z',
|
||||
stop: '2021-11-25T12:50:00.000Z',
|
||||
title: 'Inspector Morse: The Remorseful Day'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: '<!DOCTYPE html><html><head></head><body></body></html>'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
// npm run grab -- --site=ontvtonight.com
|
||||
// npm run grab -- --site=ontvtonight.com
|
||||
|
||||
const { parser, url } = require('./ontvtonight.com.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2021-11-25', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'au#1692/7two',
|
||||
xmltv_id: '7two.au'
|
||||
}
|
||||
const content =
|
||||
'<!DOCTYPE html><html lang="en-AU" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"> <head> </head> <body> <div id="wrapper"> <section id="content"> <div class="container"> <div class="row"> <div class="span6"> <img src="https://otv-us-web.s3-us-west-2.amazonaws.com/logos/guide/media/ed49cf4f-1123-4bee-9c90-a6af375af310.png" border="0" align="right" alt="7TWO" width="140"/> <table class="table table-hover"> <tbody> <tr> <td width="90"> <h5 class="thin">12:10 am</h5> </td><td> <h5 class="thin"> <a href="https://www.ontvtonight.com/au/guide/listings/programme?cid=1692&sid=165632&dt=2021-11-24+13%3A10%3A00" target="_blank" rel="nofollow" > What A Carry On</a > </h5> </td></tr><tr> <td width="90"> <h5 class="thin">12:50 am</h5> </td><td> <h5 class="thin"> <a href="https://www.ontvtonight.com/au/guide/listings/programme?cid=1692&sid=159923&dt=2021-11-24+13%3A50%3A00" target="_blank" rel="nofollow" > Bones</a > </h5> <h6>The Devil In The Details</h6> </td></tr><tr> <td width="90"> <h5 class="thin">10:50 pm</h5> </td><td> <h5 class="thin"> <a href="https://www.ontvtonight.com/au/guide/listings/programme?cid=1692&sid=372057&dt=2021-11-25+11%3A50%3A00" target="_blank" rel="nofollow" > Inspector Morse: The Remorseful Day</a > </h5> </td></tr></tbody> </table> </div></div></div></section> </div></body></html>'
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://www.ontvtonight.com/au/guide/listings/channel/1692/7two.html?dt=2021-11-25'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const result = parser({ content, channel, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2021-11-24T13:10:00.000Z',
|
||||
stop: '2021-11-24T13:50:00.000Z',
|
||||
title: 'What A Carry On'
|
||||
},
|
||||
{
|
||||
start: '2021-11-24T13:50:00.000Z',
|
||||
stop: '2021-11-25T11:50:00.000Z',
|
||||
title: 'Bones',
|
||||
description: 'The Devil In The Details'
|
||||
},
|
||||
{
|
||||
start: '2021-11-25T11:50:00.000Z',
|
||||
stop: '2021-11-25T12:50:00.000Z',
|
||||
title: 'Inspector Morse: The Remorseful Day'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: '<!DOCTYPE html><html><head></head><body></body></html>'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user