Fix beinsports.com

This commit is contained in:
Aleksandr Statciuk 2022-05-09 15:02:48 +03:00
parent 71c8b659a5
commit 227bf6df78
3 changed files with 1246 additions and 20 deletions

File diff suppressed because it is too large Load diff

View file

@ -11,6 +11,12 @@ dayjs.extend(customParseFormat)
module.exports = {
site: 'beinsports.com',
request: {
cache: {
ttl: 60 * 60 * 1000, // 1h
interpretHeader: false
}
},
url: function ({ date, channel }) {
let [region] = channel.site_id.split('#')
region = region ? `_${region}` : ''
@ -19,7 +25,7 @@ module.exports = {
'YYYY-MM-DD'
)}`
},
parser: function ({ content, channel, date }) {
parser: function ({ content, channel, date, cached }) {
let programs = []
const items = parseItems(content, channel)
date = date.subtract(1, 'd')
@ -41,12 +47,8 @@ module.exports = {
if (stop.isBefore(start)) {
stop = stop.add(1, 'd')
}
programs.push({
title,
category,
start,
stop
})
programs.push({ title, category, start, stop })
})
return programs
@ -85,27 +87,33 @@ function parseTitle($item) {
}
function parseCategory($item) {
return $item('.format').text()
return $item('.format')
.map(function () {
return $item(this).text()
})
.get()
}
function parseStart($item, date) {
let [_, time] = $item('.time')
.text()
.match(/^(\d{2}:\d{2})/) || [null, null]
let time = $item('.time').text()
if (!time) return null
time = `${date.format('YYYY-MM-DD')} ${time}`
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(time, 'YYYY-MM-DD HH:mm', 'Asia/Qatar')
return dayjs.tz(start, format, 'Asia/Qatar')
}
function parseStop($item, date) {
let [_, time] = $item('.time')
.text()
.match(/(\d{2}:\d{2})$/) || [null, null]
let time = $item('.time').text()
if (!time) return null
time = `${date.format('YYYY-MM-DD')} ${time}`
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(time, 'YYYY-MM-DD HH:mm', 'Asia/Qatar')
return dayjs.tz(stop, format, 'Asia/Qatar')
}
function parseItems(content, channel) {

View file

@ -1,6 +1,6 @@
// 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
// npx epg-grabber --config=sites/beinsports.com/beinsports.com.config.js --channels=sites/beinsports.com/beinsports.com_qa-en.channels.xml --output=guide.xml --timeout=30000 --days=2
// npx epg-grabber --config=sites/beinsports.com/beinsports.com.config.js --channels=sites/beinsports.com/beinsports.com_qa-ar.channels.xml --output=guide.xml --timeout=30000 --days=2
// npx epg-grabber --config=sites/beinsports.com/beinsports.com.config.js --channels=sites/beinsports.com/beinsports.com_us-en.channels.xml --output=guide.xml --timeout=30000 --days=2
const { parser, url } = require('./beinsports.com.config.js')
const fs = require('fs')
@ -41,7 +41,23 @@ it('can parse response', () => {
start: '2022-05-07T19:45:00.000Z',
stop: '2022-05-07T21:30:00.000Z',
title: 'Al Arabi vs Al Khor - Qatar Stars League 2021/2022',
category: 'Qatar Stars League'
category: ['Qatar Stars League']
})
})
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-07T19:30:00.000Z',
stop: '2022-05-07T21:30:00.000Z',
title: 'Basaksehir vs. Galatasaray',
category: ['Turkish Super Lig Soccer', 'Soccer']
})
})