mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Update beinsports.com.config.js
Update beinsports.com config.js to pull from new api end point.
This commit is contained in:
parent
b1bcc08591
commit
5d68c721d4
1 changed files with 26 additions and 105 deletions
|
@ -13,118 +13,39 @@ module.exports = {
|
||||||
site: 'beinsports.com',
|
site: 'beinsports.com',
|
||||||
days: 2,
|
days: 2,
|
||||||
request: {
|
request: {
|
||||||
cache: {
|
headers: {
|
||||||
ttl: 60 * 60 * 1000, // 1h
|
'User-Agent':
|
||||||
interpretHeader: false
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
url: function ({ date, channel }) {
|
url: function ({ date, channel }) {
|
||||||
let [region] = channel.site_id.split('#')
|
return `https://www.beinsports.com/api/opta/tv-event?&startBefore=${date.add(1, 'd').format(
|
||||||
region = region ? `_${region}` : ''
|
"YYYY-MM-DDTHH:mm:ss.SSS")}Z&endAfter=${date.format(
|
||||||
|
"YYYY-MM-DDTHH:mm:ss.SSS")}Z&channelIds=${channel.site_id}`
|
||||||
return `https://epg.beinsports.com/utctime${region}.php?mins=00&serviceidentity=beinsports.com&cdate=${date.format(
|
|
||||||
'YYYY-MM-DD'
|
|
||||||
)}`
|
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel, date }) {
|
parser: function ({ content }) {
|
||||||
let programs = []
|
let programs = []
|
||||||
const items = parseItems(content, channel)
|
const items = parseItems(content)
|
||||||
let i = 0
|
if (!items.length == 0) {
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const $item = cheerio.load(item)
|
const start = dayjs.utc(item.startDate)
|
||||||
const title = parseTitle($item)
|
const stop = dayjs.utc(item.endDate)
|
||||||
if (!title) return
|
programs.push({
|
||||||
const category = parseCategory($item)
|
title: item.title,
|
||||||
const prev = programs[programs.length - 1]
|
description: item.description,
|
||||||
let start = parseStart($item, date)
|
start,
|
||||||
if (i === 0 && start.hour() > 18) {
|
stop
|
||||||
date = date.subtract(1, 'd')
|
})
|
||||||
start = start.subtract(1, 'd')
|
|
||||||
}
|
|
||||||
if (prev) {
|
|
||||||
if (start.isBefore(prev.start)) {
|
|
||||||
start = start.add(1, 'd')
|
|
||||||
date = date.add(1, 'd')
|
|
||||||
}
|
|
||||||
prev.stop = start
|
|
||||||
}
|
|
||||||
let stop = parseStop($item, start)
|
|
||||||
if (stop.isBefore(start)) {
|
|
||||||
stop = stop.add(1, 'd')
|
|
||||||
}
|
|
||||||
|
|
||||||
programs.push({ title, category, start, stop })
|
|
||||||
i++
|
|
||||||
})
|
|
||||||
|
|
||||||
return programs
|
|
||||||
},
|
|
||||||
async channels({ region, lang }) {
|
|
||||||
const suffix = region ? `_${region}` : ''
|
|
||||||
const content = await axios
|
|
||||||
.get(
|
|
||||||
`https://epg.beinsports.com/utctime${suffix}.php?mins=00&serviceidentity=beinsports.com&cdate=2022-05-08`
|
|
||||||
)
|
|
||||||
.then(r => r.data)
|
|
||||||
.catch(console.log)
|
|
||||||
const $ = cheerio.load(content)
|
|
||||||
const items = $('.container > div, #epg_div > div').toArray()
|
|
||||||
return items
|
|
||||||
.map(item => {
|
|
||||||
const $item = cheerio.load(item)
|
|
||||||
const id = $item('*').attr('id')
|
|
||||||
if (!/^channels_[0-9]+$/.test(id)) return null
|
|
||||||
const channelId = id.replace('channels_', '')
|
|
||||||
const imgSrc = $item('img').attr('src')
|
|
||||||
const [, , name] = imgSrc.match(/(\/|)([a-z0-9-_.]+)(.png|.svg)$/i) || [null, null, '']
|
|
||||||
|
|
||||||
return {
|
|
||||||
lang,
|
|
||||||
site_id: `${region}#${channelId}`,
|
|
||||||
name
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.filter(i => i)
|
}
|
||||||
|
return programs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle($item) {
|
function parseItems(content) {
|
||||||
return $item('.title').text()
|
const data = JSON.parse(content)
|
||||||
}
|
if (data.length === 0) {
|
||||||
|
return []
|
||||||
function parseCategory($item) {
|
}
|
||||||
return $item('.format')
|
return data['rows']
|
||||||
.map(function () {
|
|
||||||
return $item(this).text()
|
|
||||||
})
|
|
||||||
.get()
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStart($item, date) {
|
|
||||||
let time = $item('.time').text()
|
|
||||||
if (!time) return null
|
|
||||||
let [, start, period] = time.match(/^(\d{2}:\d{2})( AM| PM|)/) || [null, null, null]
|
|
||||||
if (!start) return null
|
|
||||||
start = `${date.format('YYYY-MM-DD')} ${start}${period}`
|
|
||||||
const format = period ? 'YYYY-MM-DD hh:mm A' : 'YYYY-MM-DD HH:mm'
|
|
||||||
|
|
||||||
return dayjs.tz(start, format, 'Asia/Qatar')
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStop($item, date) {
|
|
||||||
let time = $item('.time').text()
|
|
||||||
if (!time) return null
|
|
||||||
let [, stop, period] = time.match(/(\d{2}:\d{2})( AM| PM|)$/) || [null, null, null]
|
|
||||||
if (!stop) return null
|
|
||||||
stop = `${date.format('YYYY-MM-DD')} ${stop}${period}`
|
|
||||||
const format = period ? 'YYYY-MM-DD hh:mm A' : 'YYYY-MM-DD HH:mm'
|
|
||||||
|
|
||||||
return dayjs.tz(stop, format, 'Asia/Qatar')
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseItems(content, channel) {
|
|
||||||
const [, channelId] = channel.site_id.split('#')
|
|
||||||
const $ = cheerio.load(content)
|
|
||||||
|
|
||||||
return $(`#channels_${channelId} .slider > ul:first-child > li`).toArray()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue