mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update tvarenasport.com guide.
Test: ```sh npm test -- tvarenasport.com > test > run-script-os tvarenasport.com > test:win32 > SET "TZ=Pacific/Nauru" && npx jest --runInBand tvarenasport.com PASS sites/tvarenasport.com/tvarenasport.com.test.js (5.89 s) √ can parse response (977 ms) √ can handle empty guide Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 0 total Time: 6.097 s Ran all test suites matching /tvarenasport.com/i. ``` Grab: ```sh npm run grab -- --site=tvarenasport.com > grab > npx tsx scripts/commands/epg/grab.ts --site=tvarenasport.com starting... config: output: guide.xml maxConnections: 1 gzip: false site: tvarenasport.com loading channels... found 14 channel(s) run #1: [1/28] tvarenasport.com (sr) - ArenaSport1.rs - Dec 7, 2024 (16 programs) [2/28] tvarenasport.com (sr) - ArenaSport1.rs - Dec 8, 2024 (14 programs) ... [27/28] tvarenasport.com (sr) - ArenaSport1Premium.rs - Dec 8, 2024 (17 programs) [28/28] tvarenasport.com (sr) - ArenaSport1Premium.rs - Dec 7, 2024 (19 programs) saving to "guide.xml"... done in 00h 00m 29s ``` Signed-off-by: Toha <tohenk@yahoo.com>
This commit is contained in:
parent
ce4f3e6935
commit
34da0a19eb
4 changed files with 21106 additions and 61 deletions
20968
sites/tvarenasport.com/__data__/content.html
Normal file
20968
sites/tvarenasport.com/__data__/content.html
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,15 +1,17 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<channels>
|
<channels>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport1Premium.rs" site_id="5710">Arena Sport Premium 1 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport1.rs" site_id="01">Arena Sport 1</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport1.rs" site_id="380">Arena Sport 1 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport1Premium.rs" site_id="a1p">Arena 1 Premium</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport1x2.rs" site_id="5347">Arena Sport 1x2 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport1x2.rs" site_id="1x2">Arena Sport 1x2</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport2Premium.rs" site_id="5711">Arena Sport Premium 2 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport2.rs" site_id="02">Arena Sport 2</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport2.rs" site_id="381">Arena Sport 2 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport2Premium.rs" site_id="a2p">Arena 2 Premium</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport3Premium.rs" site_id="5712">Arena Sport Premium 3 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport3.rs" site_id="03">Arena Sport 3</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport3.rs" site_id="382">Arena Sport 3 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport3Premium.rs" site_id="a3p">Arena 3 Premium</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport4.rs" site_id="383">Arena Sport 4 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport4.rs" site_id="04">Arena Sport 4</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport5.rs" site_id="384">Arena Sport 5 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport5.rs" site_id="05">Arena Sport 5</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport6.rs" site_id="5594">Arena Sport 6 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport6.rs" site_id="06">Arena Sport 6</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport7.rs" site_id="5595">Arena Sport 7 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport7.rs" site_id="07">Arena Sport 7</channel>
|
||||||
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport8.rs" site_id="5596">Arena Sport 8 Serbia</channel>
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport8.rs" site_id="08">Arena Sport 8</channel>
|
||||||
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport9.rs" site_id="09">Arena Sport 9</channel>
|
||||||
|
<channel site="tvarenasport.com" lang="sr" xmltv_id="ArenaSport10.rs" site_id="10">Arena Sport 10</channel>
|
||||||
</channels>
|
</channels>
|
||||||
|
|
|
@ -1,50 +1,123 @@
|
||||||
|
const cheerio = require('cheerio')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const dayjs = require('dayjs')
|
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)
|
||||||
|
|
||||||
|
const tz = 'Europe/Belgrade'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'tvarenasport.com',
|
site: 'tvarenasport.com',
|
||||||
days: 2,
|
days: 2,
|
||||||
url: function ({ date }) {
|
request: {
|
||||||
return `https://www.tvarenasport.com/api/schedule?date=${date.format('DD-MM-YYYY')}`
|
cache: {
|
||||||
|
ttl: 24 * 60 * 60 * 1000 // 1 day
|
||||||
|
}
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel }) {
|
url: 'https://www.tvarenasport.com/tv-scheme',
|
||||||
let programs = []
|
parser({ content, channel, date }) {
|
||||||
const items = parseItems(content, channel)
|
const programs = []
|
||||||
items.forEach(item => {
|
const expectedDate = date.format('YYYY-MM-DD')
|
||||||
programs.push({
|
if (content) {
|
||||||
title: item.title.trim(),
|
const dates = []
|
||||||
category: item.league,
|
const $ = cheerio.load(content)
|
||||||
description: item.sport.trim(),
|
const parent = $(`.tv-scheme-chanel-header img[src*="chanel-${channel.site_id}.png"]`)
|
||||||
start: dayjs(item.start),
|
.parents('div')
|
||||||
stop: dayjs(item.end)
|
parent
|
||||||
|
.siblings('.tv-scheme-days')
|
||||||
|
.find('a').toArray()
|
||||||
|
.forEach(el => {
|
||||||
|
const a = $(el)
|
||||||
|
const dt = a.find('span:nth-child(3)').text()
|
||||||
|
dates.push(dayjs(dt + date.year(), 'DD.MM.YYYY'))
|
||||||
|
})
|
||||||
|
parent
|
||||||
|
.siblings('.tv-scheme-new-slider-wrapper')
|
||||||
|
.find('.tv-scheme-new-slider-item').toArray()
|
||||||
|
.forEach((el, i) => {
|
||||||
|
programs.push(...parseSchedules($(el), dates[i]))
|
||||||
|
})
|
||||||
|
programs.forEach((s, i) => {
|
||||||
|
if (i < programs.length - 2) {
|
||||||
|
s.stop = programs[i + 1].start
|
||||||
|
} else {
|
||||||
|
s.stop = s.start.startOf('d').add(1, 'd')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
|
.filter(p => p.start.format('YYYY-MM-DD') === expectedDate || p.stop.format('YYYY-MM-DD') === expectedDate)
|
||||||
},
|
},
|
||||||
async channels() {
|
async channels() {
|
||||||
const data = await axios
|
|
||||||
.get('https://www.tvarenasport.com/api/schedule')
|
|
||||||
.then(r => r.data)
|
|
||||||
.catch(console.log)
|
|
||||||
|
|
||||||
const channels = []
|
const channels = []
|
||||||
for (let id in data.channels) {
|
const data = await axios
|
||||||
const item = data.channels[id]
|
.get('https://www.tvarenasport.com/tv-scheme')
|
||||||
channels.push({
|
.then(r => r.data)
|
||||||
lang: 'sr',
|
.catch(console.error)
|
||||||
site_id: id,
|
|
||||||
name: item.name
|
if (data) {
|
||||||
})
|
// channel naming rule
|
||||||
|
const names = id => {
|
||||||
|
let match = id.match(/^\d+$/)
|
||||||
|
if (match) {
|
||||||
|
return `Arena Sport ${parseInt(id)}`
|
||||||
|
}
|
||||||
|
match = id.match(/^\d/)
|
||||||
|
if (match) {
|
||||||
|
return `Arena Sport ${id}`
|
||||||
|
}
|
||||||
|
match = id.match(/^a(\d+)(p)?/)
|
||||||
|
if (match) {
|
||||||
|
return `Arena ${parseInt(match[1])}${match[2] === 'p' ? ' Premium' : ''}`
|
||||||
|
}
|
||||||
|
return `Arena ${id}`
|
||||||
|
}
|
||||||
|
const $ = cheerio.load(data)
|
||||||
|
const items = $('.tv-scheme-chanel-header img').toArray()
|
||||||
|
for (const item of items) {
|
||||||
|
const [, id] = $(item).attr('src').match(/chanel-([a-z0-9]+)\.png/) || [null, null]
|
||||||
|
if (id) {
|
||||||
|
channels.push({
|
||||||
|
lang: 'sr',
|
||||||
|
site_id: id,
|
||||||
|
name: names(id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return channels
|
return channels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, channel) {
|
function parseSchedules($s, date) {
|
||||||
const data = JSON.parse(content)
|
const schedules = []
|
||||||
if (!data || !Array.isArray(data.items)) return []
|
const $ = $s._make
|
||||||
|
$s.find('.slider-content').toArray()
|
||||||
|
.forEach(el => {
|
||||||
|
schedules.push(parseSchedule($(el), date))
|
||||||
|
})
|
||||||
|
|
||||||
return data.items.filter(i => i.group === channel.site_id)
|
return schedules
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseSchedule($s, date) {
|
||||||
|
const time = $s.find('.slider-content-top span').text()
|
||||||
|
const start = dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', tz)
|
||||||
|
const category = $s.find('.slider-content-middle span').text()
|
||||||
|
const title = $s.find('.slider-content-bottom p').text()
|
||||||
|
const description = $s.find('.slider-content-bottom span:first').text()
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: description ? description : title,
|
||||||
|
description: description ? title : description,
|
||||||
|
category,
|
||||||
|
start
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +1,47 @@
|
||||||
const { parser, url } = require('./tvarenasport.com.config.js')
|
const { parser, url } = require('./tvarenasport.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-11-17', 'YYYY-MM-DD').startOf('d')
|
const date = dayjs.utc('2024-12-07', 'YYYY-MM-DD').startOf('d')
|
||||||
const channel = {
|
const channel = {
|
||||||
site_id: '380',
|
site_id: 'a1p',
|
||||||
xmltv_id: 'ArenaSport1.rs'
|
xmltv_id: 'ArenaSport1Premium.rs'
|
||||||
}
|
}
|
||||||
|
|
||||||
it('can generate valid url', () => {
|
|
||||||
expect(url({ channel, date })).toBe('https://www.tvarenasport.com/api/schedule?date=17-11-2021')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', () => {
|
||||||
const content =
|
const content = fs.readFileSync(path.join(__dirname, '__data__', 'content.html'))
|
||||||
'{"items":[{"id":2857,"title":"Crvena zvezda mts - Partizan NIS","start":"2021-11-16T23:30:00Z","end":"2021-11-17T01:30:00Z","sport":"ABA LIGA","league":"Ko\u0161arka","group":"380","isLive":false,"doNotMiss":false,"domain":"srb"},{"id":3155,"title":"Sao Paulo - Flamengo","start":"2021-11-17T00:00:00Z","end":"2021-11-17T02:00:00Z","sport":"BRAZILSKA LIGA","league":"Fudbal","group":"381","isLive":false,"doNotMiss":false,"domain":"srb"}]}'
|
const result = parser({ channel, date, content }).map(p => {
|
||||||
const result = parser({ channel, content }).map(p => {
|
|
||||||
p.start = p.start.toJSON()
|
p.start = p.start.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
return p
|
return p
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result).toMatchObject([
|
expect(result.length).toBe(19)
|
||||||
{
|
expect(result[4]).toMatchObject({
|
||||||
start: '2021-11-16T23:30:00.000Z',
|
start: '2024-12-07T03:30:00.000Z',
|
||||||
stop: '2021-11-17T01:30:00.000Z',
|
stop: '2024-12-07T05:00:00.000Z',
|
||||||
title: 'Crvena zvezda mts - Partizan NIS',
|
title: 'EVROPSKO PRVENSTVO Ž',
|
||||||
category: 'Ko\u0161arka',
|
description: 'Francuska - Crna Gora',
|
||||||
description: 'ABA LIGA'
|
category: 'Rukomet',
|
||||||
}
|
})
|
||||||
])
|
expect(result[8]).toMatchObject({
|
||||||
|
start: '2024-12-07T11:00:00.000Z',
|
||||||
|
stop: '2024-12-07T11:05:00.000Z',
|
||||||
|
title: 'Arena News',
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can handle empty guide', () => {
|
it('can handle empty guide', () => {
|
||||||
const result = parser({
|
const result = parser({
|
||||||
date,
|
date,
|
||||||
channel,
|
channel,
|
||||||
content: '{"channels":[]}'
|
content: ''
|
||||||
})
|
})
|
||||||
expect(result).toMatchObject([])
|
expect(result).toMatchObject([])
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue