mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Create bein.com.config.js
This commit is contained in:
parent
5ff8e40e92
commit
b5766abe08
1 changed files with 84 additions and 0 deletions
84
sites/bein.com/bein.com.config.js
Normal file
84
sites/bein.com/bein.com.config.js
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
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)
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
site: 'bein.com',
|
||||||
|
url: function ({ date }) {
|
||||||
|
return `https://www.bein.com/en/epg-ajax-template/?action=epg_fetch&category=sports&cdate=${date.format(
|
||||||
|
'YYYY-MM-DD'
|
||||||
|
)}&language=EN&loadindex=0&mins=00&offset=0&postid=25356&serviceidentity=bein.net`
|
||||||
|
},
|
||||||
|
parser: function ({ content, channel, date }) {
|
||||||
|
let programs = []
|
||||||
|
const items = parseItems(content, channel)
|
||||||
|
date = date.subtract(1, 'd')
|
||||||
|
items.forEach(item => {
|
||||||
|
const $item = cheerio.load(item)
|
||||||
|
const title = parseTitle($item)
|
||||||
|
if (!title) return
|
||||||
|
const category = parseCategory($item)
|
||||||
|
const prev = programs[programs.length - 1]
|
||||||
|
let start = parseStart($item, date)
|
||||||
|
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
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return programs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseTitle($item) {
|
||||||
|
return $item('.title').text()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCategory($item) {
|
||||||
|
return $item('.format').text()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseStart($item, date) {
|
||||||
|
let [_, time] = $item('.time')
|
||||||
|
.text()
|
||||||
|
.match(/^(\d{2}:\d{2})/) || [null, null]
|
||||||
|
if (!time) return null
|
||||||
|
time = `${date.format('YYYY-MM-DD')} ${time}`
|
||||||
|
|
||||||
|
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Asia/Qatar')
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseStop($item, date) {
|
||||||
|
let [_, time] = $item('.time')
|
||||||
|
.text()
|
||||||
|
.match(/(\d{2}:\d{2})$/) || [null, null]
|
||||||
|
if (!time) return null
|
||||||
|
time = `${date.format('YYYY-MM-DD')} ${time}`
|
||||||
|
|
||||||
|
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Asia/Qatar')
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseItems(content, channel) {
|
||||||
|
const $ = cheerio.load(content)
|
||||||
|
|
||||||
|
return $(`#channels_${channel.site_id} .slider > ul:first-child > li`).toArray()
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue