Merge pull request #782 from iptv-org/fix-beinsports.com

Fix beinsports.com
This commit is contained in:
Aleksandr Statciuk 2022-05-08 16:53:08 +03:00 committed by GitHub
commit fa62083c87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 3150 additions and 131 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,28 @@
<script>
currenthour="13";
</script>
<div class=container>
<div class='row no-gutter'>
<div class='col-xs-12 col-sm-12 col-md-12 col-lg-12'>
</div></div><div class='row no-gutter'>
<div class='col-xs-12 col-sm-12 col-md-12 col-lg-12'>
<table width=100% border=0 class=day_table><tr><td><span id=day1t1 style=width:100% class=day_item><a href=javascript:selectday('day1');loaders('utctime.php?cdate=2022-05-08&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>Sun</a></span><span id=day1t2 style=width:100% class=day_item1><a href=javascript:selectday('day1');loaders('utctime.php?cdate=2022-05-08&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>08</a></div></td><td><span id=day2t1 style=width:100% class=day_item><a href=javascript:selectday('day2');loaders('utctime.php?cdate=2022-05-09&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>Mon</a></span><span id=day2t2 style=width:100% class=day_item1><a href=javascript:selectday('day2');loaders('utctime.php?cdate=2022-05-09&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>09</a></div></td><td><span id=day3t1 style=width:100% class=day_item><a href=javascript:selectday('day3');loaders('utctime.php?cdate=2022-05-10&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>Tue</a></span><span id=day3t2 style=width:100% class=day_item1><a href=javascript:selectday('day3');loaders('utctime.php?cdate=2022-05-10&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>10</a></div></td><td><span id=day4t1 style=width:100% class=day_item><a href=javascript:selectday('day4');loaders('utctime.php?cdate=2022-05-11&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>Wed</a></span><span id=day4t2 style=width:100% class=day_item1><a href=javascript:selectday('day4');loaders('utctime.php?cdate=2022-05-11&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>11</a></div></td><td><span id=day5t1 style=width:100% class=day_item><a href=javascript:selectday('day5');loaders('utctime.php?cdate=2022-05-12&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>Thu</a></span><span id=day5t2 style=width:100% class=day_item1><a href=javascript:selectday('day5');loaders('utctime.php?cdate=2022-05-12&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>12</a></div></td><td><span id=day6t1 style=width:100% class=day_item><a href=javascript:selectday('day6');loaders('utctime.php?cdate=2022-05-13&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>Fri</a></span><span id=day6t2 style=width:100% class=day_item1><a href=javascript:selectday('day6');loaders('utctime.php?cdate=2022-05-13&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>13</a></div></td><td><span id=day7t1 style=width:100% class=day_item><a href=javascript:selectday('day7');loaders('utctime.php?cdate=2022-05-14&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>Sat</a></span><span id=day7t2 style=width:100% class=day_item1><a href=javascript:selectday('day7');loaders('utctime.php?cdate=2022-05-14&offset=0&mins=00&category=sports&serviceidentity=beinsports.com',2)>14</a></div></td></table></div>
</div><div class='row no-gutter'>
<div class='col-xs-12 col-sm-12 col-md-12 col-lg-12'>
<div style='background-color:#d1d0de;margin:0px auto;text-align:center;display:flex;width:100%'><div id=left style=width:25px;background-color:red;height:50px;padding-top:13px;background-color:#d1d0de;><img src=ico/left.png onclick=ptime()></div><div id='slider_timer' class='slider_time'>
<ul id='timer'></ul></div><div id=left style=width:25px;background-color:red;height:50px;padding-top:13px;background-color:#d1d0de><img src=ico/right.png onclick=ntime()></div></div>
</div>
</div><div class='row no-gutter' style='height:10px'></div>
<div class='row no-gutter'>
<div class='col-xs-7 col-xs-offset-5 col-sm-4 col-sm-offset-8 col-md-2 col-md-offset-10 col-lg-2 col-lg-offset-10'>
<div style='position:absolute;font-size:18px;margin-top:5px'>Live Events</div><div class="onoffswitch" style='left:120px'><input onchange=showhides() type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" tabindex="0"><label class="onoffswitch-label" for="myonoffswitch"><span class="onoffswitch-inner"></span><span class="onoffswitch-switch"></span></label></div></div></div><div class='row no-gutter' style='height:10px'></div>
<div class='row no-gutter'>
<div class='col-xs-12 col-sm-12 col-md-12 col-lg-12'>
<div id='loader_inner' style='display:none;margin:0 auto;width:100%;margin-top:5px;margin-bottom:5px;text-align:center'>
<div style='text-align:center;margin:auto 0;'><img src='images/ajax-loader.gif'></div>
</div>
</div>
</div>
</div><div class='container'><div class='row no-gutter' id='cta_row'><div id='cta' class='col-xs-12 col-sm-12 col-md-12 col-lg-12'><img style=cursor:pointer onclick=gobein('entertainment','e') class='img-responsive' src=images/entertain_cta_en.png></div><div></div>
</div>
<div id="immobile" style="display:'none'"></div><div id="imtablet" style="display:'none'"></div><div id="imdesktop" style="display:'none'"></div>

View file

@ -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()
} }

View file

@ -1,86 +1,46 @@
// npx epg-grabber --config=sites/beinsports.com/beinsports.com.config.js --channels=sites/beinsports.com/beinsports.com_qa.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-en.channels.xml --output=guide.xml --timeout=30000 --days=2
const { parser, url } = require('./beinsports.com.config.js') const { parser, url } = require('./beinsports.com.config.js')
const fs = require('fs')
const path = require('path')
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat') const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
dayjs.extend(utc) dayjs.extend(utc)
const date = dayjs.utc('2021-10-24', 'YYYY-MM-DD').startOf('d') const date = dayjs.utc('2022-05-08', 'YYYY-MM-DD').startOf('d')
const channel = { site_id: '1', xmltv_id: 'BeInSports.qa' } const channel = { site_id: '#1', xmltv_id: 'BeINSports.qa' }
const content = `<script>
currenthour="10";
</script>
<div class=containertop>
<div class='row no-gutter'>
<div class='col-xs-12 col-sm-12 col-md-12 col-lg-12'>
</div></div><div class='row no-gutter'>
<div class='col-xs-12 col-sm-12 col-md-12 col-lg-12'>
</div>
</div><div class='row no-gutter'>
<div class='col-xs-12 col-sm-12 col-md-12 col-lg-12'>
<div style='background-color:#d1d0de;margin:0px auto;text-align:center;display:flex;width:100%'><div id=left style=width:25px;background-color:red;height:50px;padding-top:13px;background-color:#d1d0de;><img src=ico/left.png onclick=ptime()></div><div id='slider_timer' class='slider_time'>
<ul id='timer'></ul></div><div id=left style=width:25px;background-color:red;height:50px;padding-top:13px;background-color:#d1d0de><img src=ico/right.png onclick=ntime()></div></div>
</div>
</div><div class='row no-gutter' style='height:15px'></div>
<div class='row no-gutter'>
<div class='col-xs-7 col-xs-offset-5 col-sm-4 col-sm-offset-8 col-md-2 col-md-offset-10 col-lg-2 col-lg-offset-10'>
<div class="onoffswitch" style=float:left><input onchange=showhides() type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" tabindex="0"><label class="onoffswitch-label" for="myonoffswitch"><span class="onoffswitch-inner"></span><span class="onoffswitch-switch"></span></label></div><div style='position:relative;float:left;font-size:18px;margin-top:5px;left:30px'>Live Events</div></div></div><div class='row no-gutter' style='height:10px'></div>
<div class='row no-gutter'>
<div class='col-xs-12 col-sm-12 col-md-12 col-lg-12'>
<div id='loader_inner' style='display:none;margin:0 auto;width:100%;margin-top:5px;margin-bottom:5px;text-align:center'>
<div style='text-align:center;margin:auto 0'><img align=center src='images/ajax-loader.gif'></div>
</div>
</div>
</div>
</div><div class='container'><div class='row no-gutter' id=channels_1>
<div class='col-xs-3 col-sm-2 col-md-2 col-lg-1'>
<div style='width:100%;text-align:center;'>
<div class=channel>
<div class=centered>
<img style=width:70%;height:auto onclick=getconnect('channel_19_global') align=center src='https://assets.bein.com/mena/sites/3/2015/06/bein_SPORTS_FTA_DIGITAL_Mono.png'>
</div>
</div>
</div>
</div>
<div class='col-xs-8 col-sm-9 col-md-9 col-lg-10'>
<div id='slider_1' class=slider><ul id='ul_slider_1'><li live='0' id='slider_1_item1' data-id='slider_1_item1' data-index='1' data-start='0' data-start-m='0' data-end='00' data-end-m='40' data-img='mena_sports/https://assets.bein.com/mena/sites/3/2015/06/bein_SPORTS_FTA_DIGITAL_Mono.png' data-desc='' parent='slider_1' category='MotorSports'>
<div class=onecontent>
<p class=title>Red Bull Car Park Drift 2021</p>
<p class=format>MotorSports</p>
</div>
<div class=timer><p class=time>21:45&nbsp;-&nbsp;00:40</p>
<div class='progress'><div id=teas class='progress-bar progress-bar-custom' role='progressbar' aria-valuenow='0' aria-valuemin='0' aria-valuemax='100'> <span class='sr-only'>70% Complete</span></div></div></div> </li>
<div><ul><li class=item_normal></li><li class=item_normal></li></ul> </ul></div>
</div>
<div class='col-xs-1 nextarrow col-sm-1 nextarrow col-md-1 nextarrow col-lg-1 nextarrow'>
<div class='centered'>
<img align=center width=15 height=15 src=images/nextarrow_en.svg style=cursor:pointer onclick=action('slider_22')>
</div>
</div>
</div>
<div class='row no-gutter' style='height:15px' id='ruler_channels_22'></div>
<div class='row no-gutter' id='cta_row'><div id='cta' class='col-xs-12 col-sm-12 col-md-12 col-lg-12'><img style=cursor:pointer onclick=gobein('entertainment','a') class='img-responsive' src=images/entertain_cta_ar.png></div><div></div></div>
<div id="immobile" style="display:'none'"></div><div id="imtablet" style="display:'none'"></div><div id="imdesktop" style="display:'none'"></div>
`
it('can generate valid url', () => { it('can generate valid url', () => {
const result = url({ date }) const result = url({ date })
expect(result).toBe( expect(result).toBe(
'https://epg.beinsports.com/utctime.php?mins=00&serviceidentity=beinsports.com&cdate=2021-10-24' 'https://epg.beinsports.com/utctime.php?mins=00&serviceidentity=beinsports.com&cdate=2022-05-08'
) )
}) })
it('can parse response', () => { it('can parse response', () => {
const result = parser({ date, channel, content }) const content = fs.readFileSync(path.resolve('sites/beinsports.com/__data__/content.html'))
expect(result).toMatchObject([ const results = parser({ date, channel, content }).map(p => {
{ p.start = p.start.toJSON()
start: 'Sat, 23 Oct 2021 21:45:00 GMT', p.stop = p.stop.toJSON()
stop: 'Sun, 24 Oct 2021 00:40:00 GMT', return p
title: 'Red Bull Car Park Drift 2021', })
category: 'MotorSports'
} expect(results[0]).toMatchObject({
]) 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'
})
})
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([])
}) })

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<site site="beinsports.com">
<channels>
<channel lang="en" xmltv_id="BeINSports.qa" site_id="#1">BeIn Sports</channel>
<channel lang="en" xmltv_id="BeINSportsNews.qa" site_id="#2">BeIn Sports News</channel>
<channel lang="en" xmltv_id="BeINSports2.qa" site_id="#3">BeIn Sports 2</channel>
<channel lang="en" xmltv_id="BeINSports3.qa" site_id="#4">BeIn Sports 3</channel>
<channel lang="en" xmltv_id="BeINSports4.qa" site_id="#5">BeIn Sports 4</channel>
<channel lang="en" xmltv_id="BeINSports5.qa" site_id="#6">BeIn Sports 5</channel>
<channel lang="en" xmltv_id="BeINSports6.qa" site_id="#7">BeIn Sports 6</channel>
<channel lang="en" xmltv_id="BeINSports7.qa" site_id="#8">BeIn Sports 7</channel>
<channel lang="en" xmltv_id="BeINSportsPremium3.qa" site_id="#9">BeIn Sports Premium 3</channel>
<channel lang="en" xmltv_id="BeINSportsXtra1.qa" site_id="#10">BeIn Sports Xtra 1</channel>
<channel lang="en" xmltv_id="BeINSportsXtra2.qa" site_id="#11">BeIn Sports Xtra 2</channel>
<channel lang="en" xmltv_id="BeIN4K.qa" site_id="#12">BeIn 4K</channel>
<channel lang="en" xmltv_id="BeINSportsNBA.qa" site_id="#13">BeIn NBA</channel>
<channel lang="en" xmltv_id="BeINSportsEnglish1.qa" site_id="#14">BeIn Sports English 1</channel>
<channel lang="en" xmltv_id="BeINSportsEnglish2.qa" site_id="#15">BeIn Sports English 2</channel>
<channel lang="en" xmltv_id="BeINSportsEnglish3.qa" site_id="#16">BeIn Sports English 3</channel>
<channel lang="en" xmltv_id="BeINSportsFrench1.qa" site_id="#17">BeIn Sports French 1</channel>
<channel lang="en" xmltv_id="BeINSportsFrench2.qa" site_id="#18">BeIn Sports French 2</channel>
<channel lang="en" xmltv_id="BeINSportsFrench3.qa" site_id="#19">BeIn Sports French 3</channel>
</channels>
</site>

View file

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<site site="beinsports.com">
<channels>
<channel lang="en" xmltv_id="BeINSports.qa" site_id="1">BeIn Sports</channel>
<channel lang="en" xmltv_id="BeINSportsNews.qa" site_id="2">BeIn Sports News</channel>
<channel lang="en" xmltv_id="BeINSports1.qa" site_id="3">BeIn Sports 1</channel>
<channel lang="en" xmltv_id="BeINSports2.qa" site_id="4">BeIn Sports 2</channel>
<channel lang="en" xmltv_id="BeINSports3.qa" site_id="5">BeIn Sports 3</channel>
<channel lang="en" xmltv_id="BeINSports4.qa" site_id="6">BeIn Sports 4</channel>
<channel lang="en" xmltv_id="BeINSports5.qa" site_id="7">BeIn Sports 5</channel>
<channel lang="en" xmltv_id="BeINSports6.qa" site_id="8">BeIn Sports 6</channel>
<channel lang="en" xmltv_id="BeINSports7.qa" site_id="9">BeIn Sports 7</channel>
<channel lang="en" xmltv_id="BeINSportsPremium1.qa" site_id="10">BeIn Sports Premium 1</channel>
<channel lang="en" xmltv_id="BeINSportsPremium2.qa" site_id="11">BeIn Sports Premium 2</channel>
<channel lang="en" xmltv_id="BeINSportsPremium3.qa" site_id="12">BeIn Sports Premium 3</channel>
<channel lang="en" xmltv_id="BeINSportsXtra1.qa" site_id="13">BeIn Sports Xtra 1</channel>
<channel lang="en" xmltv_id="BeINSportsXtra2.qa" site_id="14">BeIn Sports Xtra 2</channel>
<channel lang="en" xmltv_id="BeIN4K.qa" site_id="15">BeIn 4K</channel>
<channel lang="en" xmltv_id="BeINSportsNBA.qa" site_id="16">BeIn NBA</channel>
<channel lang="en" xmltv_id="BeINSportsEnglish1.qa" site_id="17">BeIn Sports English 1</channel>
<channel lang="en" xmltv_id="BeINSportsEnglish2.qa" site_id="18">BeIn Sports English 2</channel>
<channel lang="en" xmltv_id="BeINSportsEnglish3.qa" site_id="19">BeIn Sports English 3</channel>
<channel lang="en" xmltv_id="BeINSportsFrench1.qa" site_id="20">BeIn Sports French 1</channel>
<channel lang="en" xmltv_id="BeINSportsFrench2.qa" site_id="21">BeIn Sports French 2</channel>
<channel lang="en" xmltv_id="BeINSportsFrench3.qa" site_id="22">BeIn Sports French 3</channel>
</channels>
</site>