Merge pull request #2539 from iptv-org/add-sporttv.pt

Add sporttv.pt
This commit is contained in:
PopeyeTheSai10r 2024-12-26 17:54:46 -08:00 committed by GitHub
commit f2b46645ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 61820 additions and 0 deletions

View file

@ -130,6 +130,7 @@
| [sky.com](sites/sky.com) | 🟡 | https://github.com/iptv-org/epg/issues/2325 |
| [sky.de](sites/sky.de) | 🟢 | |
| [skylife.co.kr](sites/skylife.co.kr) | 🟢 | |
| [sporttv.pt](sites/sporttv.pt) | 🟢 | |
| [starhubtvplus.com](sites/starhubtvplus.com) | 🔴 | https://github.com/iptv-org/epg/issues/2365 |
| [startimestv.com](sites/startimestv.com) | 🔴 | https://github.com/iptv-org/epg/issues/2296 |
| [streamingtvguides.com](sites/streamingtvguides.com) | 🟢 | |

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,15 @@
# sporttv.pt
https://www.sporttv.pt/guia
### Download the guide
```sh
npm run grab --- --site=sporttv.pt
```
### Test
```sh
npm test --- sporttv.pt
```

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<channels>
<channel site="sporttv.pt" lang="pt" xmltv_id="SportTVPlus.pt" site_id="7133">SPORT.TV +</channel>
<channel site="sporttv.pt" lang="pt" xmltv_id="SportTV1.pt" site_id="727">SPORT.TV1</channel>
<channel site="sporttv.pt" lang="pt" xmltv_id="SportTV2.pt" site_id="728">SPORT.TV2</channel>
<channel site="sporttv.pt" lang="pt" xmltv_id="SportTV3.pt" site_id="729">SPORT.TV3</channel>
<channel site="sporttv.pt" lang="pt" xmltv_id="SportTV4.pt" site_id="5406">SPORT.TV4</channel>
<channel site="sporttv.pt" lang="pt" xmltv_id="SportTV5.pt" site_id="5422">SPORT.TV5</channel>
<channel site="sporttv.pt" lang="pt" xmltv_id="SportTV6.pt" site_id="7577">SPORT.TV6</channel>
<channel site="sporttv.pt" lang="pt" xmltv_id="SportTV7.pt" site_id="7600">SPORT.TV7</channel>
<channel site="sporttv.pt" lang="pt" xmltv_id="NBATVInternational.us" site_id="7386">NBA TV</channel>
</channels>

View file

@ -0,0 +1,63 @@
const dayjs = require('dayjs')
const cheerio = require('cheerio')
module.exports = {
site: 'sporttv.pt',
days: 2,
url: 'https://www.sporttv.pt/guia',
parser({ content, date, channel }) {
let programs = []
const items = parseItems(content, channel, date)
items.forEach(item => {
const start = dayjs(item.data)
const stop = start.add(item.duracao, 'ms')
programs.push({
title: item.descricao,
description: item?.evento?.nome,
image: item.imagem,
category: item?.modalidade?.nomeModalidade,
start,
stop
})
})
return programs
}
}
function parseItems(content, channel, date) {
const $ = cheerio.load(content)
const nuxtData = $('#__NUXT_DATA__').html()
if (!nuxtData) return []
const parsed = JSON.parse(nuxtData)
const dataIndex = parsed[1].data
const epgIndex = Object.values(parsed[dataIndex])[3] // 1611
const epg = parsed[epgIndex].map(i => parsed[i]).map(obj => dataMapper(obj, parsed))
if (!Array.isArray(epg)) return []
return epg
.filter(
item => item.canal.id === parseInt(channel.site_id) && date.isSame(dayjs(item.data), 'd')
)
.sort((a, b) => {
if (a < b) return -1
if (a > b) return 1
return 0
})
}
function dataMapper(object, parsed) {
let output = {}
for (let key in object) {
const value = parsed[object[key]]
if (typeof value === 'object') {
output[key] = dataMapper(value, parsed)
} else {
output[key] = value
}
}
return output
}

View file

@ -0,0 +1,54 @@
const { parser, url } = require('./sporttv.pt.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('2024-12-23', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 727,
xmltv_id: 'SportTV1.pt'
}
it('can generate valid url', () => {
expect(url).toBe('https://www.sporttv.pt/guia')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
const results = parser({ content, date, channel }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(19)
expect(results[0]).toMatchObject({
start: '2024-12-23T01:00:00.000Z',
stop: '2024-12-23T01:30:00.000Z',
description: 'LIGA PORTUGAL BETCLIC',
category: 'FUTEBOL',
title: 'RESUMOS DA JORNADA 15',
image: 'https://www.sporttv.pt/default/0001/11/08cb25f0b9b427e0bb83179309074632410f536b.jpg'
})
expect(results[1]).toMatchObject({
start: '2024-12-23T01:30:00.000Z',
stop: '2024-12-23T02:00:00.000Z',
description: 'LIGA ITALIANA',
category: 'FUTEBOL',
title: 'RESUMOS DA JORNADA 17',
image:
'https://www.sporttv.pt/cms_media/default/0001/11/56ab6bb72a00c8a9543eff35f90f57c07fb0ff87.jpg'
})
})
it('can handle empty guide', () => {
const content = ''
const result = parser({ content, date })
expect(result).toMatchObject([])
})