mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00
Create thesportplus.com.config.js
This commit is contained in:
parent
b85abb2885
commit
506c7fd18e
1 changed files with 73 additions and 0 deletions
73
sites/thesportplus.com/thesportplus.com.config.js
Normal file
73
sites/thesportplus.com/thesportplus.com.config.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
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 timezones = {
|
||||
usa: 'America/New_York',
|
||||
aus: 'Australia/Sydney',
|
||||
euro: 'UTC'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
site: 'thesportplus.com',
|
||||
days: 2,
|
||||
url({ channel, date }) {
|
||||
return `https://www.thesportplus.com/schedule_${channel.site_id}.php?d=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}`
|
||||
},
|
||||
parser({ content, date, channel }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart($item, date, channel)
|
||||
if (!start) return
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start) && start.hour() < 12) {
|
||||
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 parseTitle($item) {
|
||||
return $item('h5:last').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('p').text().trim()
|
||||
}
|
||||
|
||||
function parseStart($item, date, channel) {
|
||||
const timezone = timezones[channel.site_id]
|
||||
const time = $item('h4').text().trim()
|
||||
const dateString = `${date.format('YYYY-MM-DD')} ${time}`
|
||||
|
||||
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', timezone)
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('.resume-item').toArray()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue