mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Update beinsports.com.config.js
This commit is contained in:
parent
b21527134f
commit
8879c1e0c7
1 changed files with 32 additions and 35 deletions
|
@ -1,9 +1,11 @@
|
||||||
const cheerio = require('cheerio')
|
const cheerio = require('cheerio')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -14,32 +16,32 @@ module.exports = {
|
||||||
)}`
|
)}`
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel, date }) {
|
parser: function ({ content, channel, date }) {
|
||||||
let offset = -1
|
|
||||||
let programs = []
|
let programs = []
|
||||||
const items = parseItems(content, channel)
|
const items = parseItems(content, channel)
|
||||||
|
date = date.subtract(1, 'd')
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = parseTitle(item)
|
const $item = cheerio.load(item)
|
||||||
const category = parseCategory(item)
|
const title = parseTitle($item)
|
||||||
let start = parseStart(item, date)
|
if (!title) return
|
||||||
if (!start) return
|
const category = parseCategory($item)
|
||||||
if (start.hour() > 18 && offset === -1) {
|
const prev = programs[programs.length - 1]
|
||||||
start = start.subtract(1, 'd')
|
let start = parseStart($item, date)
|
||||||
} else if (start.hour() < 12 && offset === -1) {
|
if (prev) {
|
||||||
offset++
|
if (start.isBefore(prev.start)) {
|
||||||
|
start = start.add(1, 'd')
|
||||||
|
date = date.add(1, 'd')
|
||||||
|
}
|
||||||
|
prev.stop = start
|
||||||
}
|
}
|
||||||
let stop = parseStop(item, date)
|
let stop = parseStop($item, start)
|
||||||
if (!stop) return
|
if (stop.isBefore(start)) {
|
||||||
if (stop.hour() > 18 && offset === -1) {
|
stop = stop.add(1, 'd')
|
||||||
stop = stop.subtract(1, 'd')
|
|
||||||
} else if (stop.hour() < 12 && offset === -1) {
|
|
||||||
offset++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title,
|
title,
|
||||||
category,
|
category,
|
||||||
start: start.toString(),
|
start,
|
||||||
stop: stop.toString()
|
stop
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -47,42 +49,37 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle(item) {
|
function parseTitle($item) {
|
||||||
const $ = cheerio.load(item)
|
return $item('.title').text()
|
||||||
|
|
||||||
return $('.title').text()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCategory(item) {
|
function parseCategory($item) {
|
||||||
const $ = cheerio.load(item)
|
return $item('.format').text()
|
||||||
|
|
||||||
return $('.format').text()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item, date) {
|
function parseStart($item, date) {
|
||||||
const $ = cheerio.load(item)
|
let [_, time] = $item('.time')
|
||||||
let [_, time] = $('.time')
|
|
||||||
.text()
|
.text()
|
||||||
.match(/^(\d{2}:\d{2})/) || [null, null]
|
.match(/^(\d{2}:\d{2})/) || [null, null]
|
||||||
if (!time) return null
|
if (!time) return null
|
||||||
time = `${date.format('YYYY-MM-DD')} ${time}`
|
time = `${date.format('YYYY-MM-DD')} ${time}`
|
||||||
|
|
||||||
return dayjs.utc(time, 'YYYY-MM-DD HH:mm')
|
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Asia/Qatar')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStop(item, date) {
|
function parseStop($item, date) {
|
||||||
const $ = cheerio.load(item)
|
let [_, time] = $item('.time')
|
||||||
let [_, time] = $('.time')
|
|
||||||
.text()
|
.text()
|
||||||
.match(/(\d{2}:\d{2})$/) || [null, null]
|
.match(/(\d{2}:\d{2})$/) || [null, null]
|
||||||
if (!time) return null
|
if (!time) return null
|
||||||
time = `${date.format('YYYY-MM-DD')} ${time}`
|
time = `${date.format('YYYY-MM-DD')} ${time}`
|
||||||
|
|
||||||
return dayjs.utc(time, 'YYYY-MM-DD HH:mm')
|
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Asia/Qatar')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, channel) {
|
function parseItems(content, channel) {
|
||||||
|
const [_, channelId] = channel.site_id.split('#')
|
||||||
const $ = cheerio.load(content)
|
const $ = cheerio.load(content)
|
||||||
|
|
||||||
return $(`#channels_${channel.site_id} .slider > ul:first-child > li`).toArray()
|
return $(`#channels_${channelId} .slider > ul:first-child > li`).toArray()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue