mirror of
https://github.com/iptv-org/epg
synced 2026-04-30 14:36:58 -04:00
Fixes linter errors
This commit is contained in:
@@ -1,130 +1,130 @@
|
||||
const axios = require('axios')
|
||||
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: 'beinsports.com',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000, // 1h
|
||||
interpretHeader: false
|
||||
}
|
||||
},
|
||||
url: function ({ date, channel }) {
|
||||
let [region] = channel.site_id.split('#')
|
||||
region = region ? `_${region}` : ''
|
||||
|
||||
return `https://epg.beinsports.com/utctime${region}.php?mins=00&serviceidentity=beinsports.com&cdate=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}`
|
||||
},
|
||||
parser: function ({ content, channel, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
let i = 0
|
||||
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 (i === 0 && start.hour() > 18) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.title').text()
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('.format')
|
||||
.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()
|
||||
}
|
||||
const axios = require('axios')
|
||||
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: 'beinsports.com',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000, // 1h
|
||||
interpretHeader: false
|
||||
}
|
||||
},
|
||||
url: function ({ date, channel }) {
|
||||
let [region] = channel.site_id.split('#')
|
||||
region = region ? `_${region}` : ''
|
||||
|
||||
return `https://epg.beinsports.com/utctime${region}.php?mins=00&serviceidentity=beinsports.com&cdate=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}`
|
||||
},
|
||||
parser: function ({ content, channel, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
let i = 0
|
||||
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 (i === 0 && start.hour() > 18) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.title').text()
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('.format')
|
||||
.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()
|
||||
}
|
||||
|
||||
@@ -1,91 +1,91 @@
|
||||
// npm run channels:parse -- --config=./sites/beinsports.com/beinsports.com.config.js --output=./sites/beinsports.com/beinsports.com_qa-ar.channels.xml --set=lang:ar --set=region:ar
|
||||
// npm run grab -- --site=beinsports.com
|
||||
// npm run grab -- --site=beinsports.com
|
||||
|
||||
const { parser, url } = require('./beinsports.com.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
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('2022-05-08', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = { site_id: '#2', xmltv_id: 'BeINSports.qa' }
|
||||
|
||||
it('can generate valid url', () => {
|
||||
const result = url({ date, channel })
|
||||
expect(result).toBe(
|
||||
'https://epg.beinsports.com/utctime.php?mins=00&serviceidentity=beinsports.com&cdate=2022-05-08'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for arabic guide', () => {
|
||||
const channel = { site_id: 'ar#1', xmltv_id: 'BeINSports.qa' }
|
||||
const result = url({ date, channel })
|
||||
expect(result).toBe(
|
||||
'https://epg.beinsports.com/utctime_ar.php?mins=00&serviceidentity=beinsports.com&cdate=2022-05-08'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve('sites/beinsports.com/__data__/content.html'))
|
||||
const results = parser({ date, channel, content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-05-07T19:30:00.000Z',
|
||||
stop: '2022-05-07T21:20:00.000Z',
|
||||
title: 'Lorient vs Marseille',
|
||||
category: ['Ligue 1 2021/22']
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response for tomorrow', () => {
|
||||
const date = dayjs.utc('2022-05-09', 'YYYY-MM-DD').startOf('d')
|
||||
const content = fs.readFileSync(
|
||||
path.resolve('sites/beinsports.com/__data__/content_tomorrow.html')
|
||||
)
|
||||
const results = parser({ date, channel, content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-05-08T21:20:00.000Z',
|
||||
stop: '2022-05-08T23:10:00.000Z',
|
||||
title: 'Celtic vs Hearts',
|
||||
category: ['SPFL Premiership 2021/22']
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse US response', () => {
|
||||
const content = fs.readFileSync(path.resolve('sites/beinsports.com/__data__/content_us.html'))
|
||||
const results = parser({ date, channel, content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-05-07T20:00:00.000Z',
|
||||
stop: '2022-05-07T22:00:00.000Z',
|
||||
title: 'Basaksehir vs. Galatasaray',
|
||||
category: ['Fútbol Turco Superliga', 'Soccer']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const noContent = fs.readFileSync(path.resolve('sites/beinsports.com/__data__/no-content.html'))
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: noContent
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
// npm run channels:parse -- --config=./sites/beinsports.com/beinsports.com.config.js --output=./sites/beinsports.com/beinsports.com_qa-ar.channels.xml --set=lang:ar --set=region:ar
|
||||
// npm run grab -- --site=beinsports.com
|
||||
// npm run grab -- --site=beinsports.com
|
||||
|
||||
const { parser, url } = require('./beinsports.com.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
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('2022-05-08', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = { site_id: '#2', xmltv_id: 'BeINSports.qa' }
|
||||
|
||||
it('can generate valid url', () => {
|
||||
const result = url({ date, channel })
|
||||
expect(result).toBe(
|
||||
'https://epg.beinsports.com/utctime.php?mins=00&serviceidentity=beinsports.com&cdate=2022-05-08'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for arabic guide', () => {
|
||||
const channel = { site_id: 'ar#1', xmltv_id: 'BeINSports.qa' }
|
||||
const result = url({ date, channel })
|
||||
expect(result).toBe(
|
||||
'https://epg.beinsports.com/utctime_ar.php?mins=00&serviceidentity=beinsports.com&cdate=2022-05-08'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve('sites/beinsports.com/__data__/content.html'))
|
||||
const results = parser({ date, channel, content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-05-07T19:30:00.000Z',
|
||||
stop: '2022-05-07T21:20:00.000Z',
|
||||
title: 'Lorient vs Marseille',
|
||||
category: ['Ligue 1 2021/22']
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response for tomorrow', () => {
|
||||
const date = dayjs.utc('2022-05-09', 'YYYY-MM-DD').startOf('d')
|
||||
const content = fs.readFileSync(
|
||||
path.resolve('sites/beinsports.com/__data__/content_tomorrow.html')
|
||||
)
|
||||
const results = parser({ date, channel, content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-05-08T21:20:00.000Z',
|
||||
stop: '2022-05-08T23:10:00.000Z',
|
||||
title: 'Celtic vs Hearts',
|
||||
category: ['SPFL Premiership 2021/22']
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse US response', () => {
|
||||
const content = fs.readFileSync(path.resolve('sites/beinsports.com/__data__/content_us.html'))
|
||||
const results = parser({ date, channel, content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-05-07T20:00:00.000Z',
|
||||
stop: '2022-05-07T22:00:00.000Z',
|
||||
title: 'Basaksehir vs. Galatasaray',
|
||||
category: ['Fútbol Turco Superliga', 'Soccer']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const noContent = fs.readFileSync(path.resolve('sites/beinsports.com/__data__/no-content.html'))
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: noContent
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user