Merge pull request #2607 from iptv-org/add-opto.sic.pt

Add opto.sic.pt
This commit is contained in:
PopeyeTheSai10r 2025-01-17 20:41:59 -08:00 committed by GitHub
commit 7ca923b753
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 134 additions and 0 deletions

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<channels>
<channel site="opto.sic.pt" lang="pt" xmltv_id="SIC.pt" site_id="14229a5c-765a-46ab-a43b-56822565e5b3">SIC</channel>
<channel site="opto.sic.pt" lang="pt" xmltv_id="" site_id="549519c3-31fa-42de-a621-15e981082fd9">SIC Alta Definição</channel>
<channel site="opto.sic.pt" lang="pt" xmltv_id="SICNoticias.pt" site_id="38719848-2a57-42e3-8640-63a9aa39f107">SIC Notícias</channel>
<channel site="opto.sic.pt" lang="pt" xmltv_id="" site_id="d47400e0-19d9-4f71-94f4-2b4cfdc1a2ca">SIC Replay</channel>
</channels>

View file

@ -0,0 +1,53 @@
const axios = require('axios')
const dayjs = require('dayjs')
module.exports = {
site: 'opto.sic.pt',
days: 2,
url({ date, channel }) {
const startDate = date.unix()
const endDate = date.add(1, 'd').unix()
return `https://opto.sic.pt/api/v1/content/epg?startDate=${startDate}&endDate=${endDate}&channels=${channel.site_id}`
},
parser({ content }) {
let programs = []
let items = parseItems(content)
items.forEach(item => {
programs.push({
title: item.title,
episode: item.episode_number || null,
season: item.season_number || null,
start: dayjs.unix(item.start_time),
stop: dayjs.unix(item.end_time)
})
})
return programs
},
async channels() {
const data = await axios
.get('https://opto.sic.pt/api/v1/content/channel')
.then(r => r.data)
.catch(console.error)
return data.map(channel => {
return {
lang: 'pt',
site_id: channel.id,
name: channel.name
}
})
}
}
function parseItems(content) {
try {
const data = JSON.parse(content)
if (!Array.isArray(data)) return []
return data
} catch {
return []
}
}

View file

@ -0,0 +1,52 @@
const { parser, url } = require('./opto.sic.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('2025-01-17', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '38719848-2a57-42e3-8640-63a9aa39f107',
xmltv_id: 'SICNoticias.pt'
}
it('can generate valid url', () => {
expect(url({ date, channel })).toBe(
'https://opto.sic.pt/api/v1/content/epg?startDate=1737072000&endDate=1737158400&channels=38719848-2a57-42e3-8640-63a9aa39f107'
)
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'), 'utf8')
let results = parser({ content })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(17)
expect(results[0]).toMatchObject({
start: '2025-01-17T00:00:00.000Z',
stop: '2025-01-17T01:45:00.000Z',
title: 'JORNAL DA MEIA-NOITE',
episode: 16,
season: null
})
expect(results[16]).toMatchObject({
start: '2025-01-17T23:00:00.000Z',
stop: '2025-01-18T00:00:00.000Z',
title: 'EXPRESSO DA MEIA-NOITE',
episode: 2,
season: null
})
})
it('can handle empty guide', () => {
const results = parser({ content: '' })
expect(results).toMatchObject([])
})

View file

@ -0,0 +1,21 @@
# opto.sic.pt
https://opto.sic.pt/guia-tv
### Download the guide
```sh
npm run grab --- --site=opto.sic.pt
```
### Update channel list
```sh
npm run channels:parse --- --config=./sites/opto.sic.pt/opto.sic.pt.config.js --output=./sites/opto.sic.pt/opto.sic.pt.channels.xml
```
### Test
```sh
npm test --- opto.sic.pt
```