mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 10:26:41 -05:00
It is now derived from tvarenasport.com. 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.391 s) √ can generate valid url (3 ms) √ can parse response (877 ms) √ can handle empty guide (1 ms) Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 0 total Time: 5.555 s, estimated 6 s Ran all test suites matching /tvarenasport.com/i. ``` ```sh npm test -- tvarenasport.hr > test > run-script-os tvarenasport.hr > test:win32 > SET "TZ=Pacific/Nauru" && npx jest --runInBand tvarenasport.hr PASS sites/tvarenasport.hr/tvarenasport.hr.test.js (5.578 s) √ can generate valid url (4 ms) √ can parse response (327 ms) √ can handle empty guide (1 ms) Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 0 total Time: 5.774 s Ran all test suites matching /tvarenasport.hr/i. ``` Grab: ```sh npm run grab -- --site=tvarenasport.hr > grab > npx tsx scripts/commands/epg/grab.ts --site=tvarenasport.hr starting... config: output: guide.xml maxConnections: 1 gzip: false site: tvarenasport.hr loading channels... found 10 channel(s) run #1: [1/20] tvarenasport.hr (hr) - ArenaSport1.hr - Dec 10, 2024 (17 programs) [2/20] tvarenasport.hr (hr) - ArenaSport1.hr - Dec 11, 2024 (17 programs) ... [19/20] tvarenasport.hr (hr) - ArenaSport2.hr - Dec 11, 2024 (12 programs) [20/20] tvarenasport.hr (hr) - ArenaSport2.hr - Dec 10, 2024 (12 programs) saving to "guide.xml"... done in 00h 00m 11s ``` Signed-off-by: Toha <tohenk@yahoo.com>
124 lines
3.6 KiB
JavaScript
124 lines
3.6 KiB
JavaScript
const cheerio = require('cheerio')
|
|
const axios = require('axios')
|
|
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: 'tvarenasport.com',
|
|
tz: 'Europe/Belgrade',
|
|
lang: 'sr',
|
|
days: 2,
|
|
request: {
|
|
cache: {
|
|
ttl: 24 * 60 * 60 * 1000 // 1 day
|
|
}
|
|
},
|
|
url: 'https://www.tvarenasport.com/tv-scheme',
|
|
parser({ content, channel, date }) {
|
|
const programs = []
|
|
const expectedDate = date.format('YYYY-MM-DD')
|
|
if (content) {
|
|
const dates = []
|
|
const $ = cheerio.load(content)
|
|
const parent = $(`.tv-scheme-chanel-header img[src*="chanel-${channel.site_id}.png"]`)
|
|
.parents('div')
|
|
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], module.exports.tz))
|
|
})
|
|
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
|
|
.filter(p => p.start.format('YYYY-MM-DD') === expectedDate || p.stop.format('YYYY-MM-DD') === expectedDate)
|
|
},
|
|
async channels() {
|
|
const channels = []
|
|
const data = await axios
|
|
.get(this.url)
|
|
.then(r => r.data)
|
|
.catch(console.error)
|
|
|
|
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: this.lang,
|
|
site_id: id,
|
|
name: names(id)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
return channels
|
|
}
|
|
}
|
|
|
|
function parseSchedules($s, date, tz) {
|
|
const schedules = []
|
|
const $ = $s._make
|
|
$s.find('.slider-content').toArray()
|
|
.forEach(el => {
|
|
schedules.push(parseSchedule($(el), date, tz))
|
|
})
|
|
|
|
return schedules
|
|
}
|
|
|
|
function parseSchedule($s, date, tz) {
|
|
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
|
|
}
|
|
}
|