mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
commit
380bf5f8d9
6 changed files with 1488 additions and 0 deletions
1320
sites/tvi.iol.pt/__data__/content.html
Normal file
1320
sites/tvi.iol.pt/__data__/content.html
Normal file
File diff suppressed because it is too large
Load diff
2
sites/tvi.iol.pt/__data__/no_content.html
Normal file
2
sites/tvi.iol.pt/__data__/no_content.html
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<div class="guiatv-dia-label">Seg, 26 jan</div>
|
||||||
|
Brevemene Disponível
|
15
sites/tvi.iol.pt/readme.md
Normal file
15
sites/tvi.iol.pt/readme.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# tvi.iol.pt [Geo-blocked]
|
||||||
|
|
||||||
|
https://tvi.iol.pt/guiatv
|
||||||
|
|
||||||
|
### Download the guide
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run grab --- --site=tvi.iol.pt
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm test --- tvi.iol.pt
|
||||||
|
```
|
9
sites/tvi.iol.pt/tvi.iol.pt.channels.xml
Normal file
9
sites/tvi.iol.pt/tvi.iol.pt.channels.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<channels>
|
||||||
|
<channel site="tvi.iol.pt" lang="pt" xmltv_id="TVI.pt" site_id="tvi">TVI</channel>
|
||||||
|
<channel site="tvi.iol.pt" lang="pt" xmltv_id="CNNPortugal.pt" site_id="cnn">CNN Portugal</channel>
|
||||||
|
<channel site="tvi.iol.pt" lang="pt" xmltv_id="VPlusTVI.pt" site_id="vmais">V+ TVI</channel>
|
||||||
|
<channel site="tvi.iol.pt" lang="pt" xmltv_id="TVIReality.pt" site_id="tvireality">TVI Reality</channel>
|
||||||
|
<channel site="tvi.iol.pt" lang="pt" xmltv_id="TVIInternacional.pt" site_id="tviinternacional">TVI Internacional</channel>
|
||||||
|
<channel site="tvi.iol.pt" lang="pt" xmltv_id="TVIAfrica.pt" site_id="tviafrica">TVI África</channel>
|
||||||
|
</channels>
|
76
sites/tvi.iol.pt/tvi.iol.pt.config.js
Normal file
76
sites/tvi.iol.pt/tvi.iol.pt.config.js
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
const cheerio = require('cheerio')
|
||||||
|
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: 'tvi.iol.pt',
|
||||||
|
url({ channel, date }) {
|
||||||
|
return `https://tvi.iol.pt/emissao/dia/${channel.site_id}?data=${date.format('YYYY-MM-DD')}`
|
||||||
|
},
|
||||||
|
parser({ content, date }) {
|
||||||
|
let programs = []
|
||||||
|
|
||||||
|
const items = parseItems(content)
|
||||||
|
items.forEach(item => {
|
||||||
|
const prev = programs[programs.length - 1]
|
||||||
|
const $item = cheerio.load(item)
|
||||||
|
|
||||||
|
let start = parseStart($item, date)
|
||||||
|
if (prev) {
|
||||||
|
if (start.isBefore(prev.start)) {
|
||||||
|
start = start.add(1, 'd')
|
||||||
|
date = date.add(1, 'd')
|
||||||
|
}
|
||||||
|
prev.stop = start
|
||||||
|
}
|
||||||
|
|
||||||
|
const stop = start.add(30, 'm')
|
||||||
|
|
||||||
|
programs.push({
|
||||||
|
title: parseTitle($item),
|
||||||
|
description: parseDescription($item),
|
||||||
|
icon: parseIcon($item),
|
||||||
|
start,
|
||||||
|
stop
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return programs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseTitle($item) {
|
||||||
|
return $item('.guiatv-programa > h2').text().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseDescription($item) {
|
||||||
|
return $item('.guiatv-programa > .texto, .guiatv-programa > .texto2').text().trim() || null
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseIcon($item) {
|
||||||
|
const backgroundImage = $item('.picture16x9').css('background-image')
|
||||||
|
if (!backgroundImage) return null
|
||||||
|
const [, imageUrl] = backgroundImage.match(/url\((.*)\)/) || [null, null]
|
||||||
|
if (!imageUrl) return null
|
||||||
|
|
||||||
|
return imageUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseStart($item, date) {
|
||||||
|
const timezone = 'Europe/Madrid'
|
||||||
|
const time = $item('.hora').text().trim()
|
||||||
|
|
||||||
|
return dayjs.tz(`${date.tz(timezone).format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', timezone)
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseItems(content) {
|
||||||
|
const $ = cheerio.load(content)
|
||||||
|
|
||||||
|
return $('.guiatv-linha').toArray()
|
||||||
|
}
|
66
sites/tvi.iol.pt/tvi.iol.pt.test.js
Normal file
66
sites/tvi.iol.pt/tvi.iol.pt.test.js
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
const { parser, url } = require('./tvi.iol.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-26', 'YYYY-MM-DD').startOf('d')
|
||||||
|
const channel = { site_id: 'tvi', xmltv_id: 'TVI.pt' }
|
||||||
|
|
||||||
|
it('can generate valid url', () => {
|
||||||
|
expect(url({ channel, date })).toBe('https://tvi.iol.pt/emissao/dia/tvi?data=2025-01-26')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can parse response', () => {
|
||||||
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||||
|
|
||||||
|
let results = parser({ content, date })
|
||||||
|
results = results.map(p => {
|
||||||
|
p.start = p.start.toJSON()
|
||||||
|
p.stop = p.stop.toJSON()
|
||||||
|
|
||||||
|
return p
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(results.length).toBe(16)
|
||||||
|
expect(results[0]).toMatchObject({
|
||||||
|
title: 'As aventuras do Gato das Botas',
|
||||||
|
description: null,
|
||||||
|
icon: 'https://img.iol.pt/image/id/66d6fb1ad34e94b82904c3ce/300.jpg',
|
||||||
|
start: '2025-01-26T05:15:00.000Z',
|
||||||
|
stop: '2025-01-26T05:45:00.000Z'
|
||||||
|
})
|
||||||
|
expect(results[5]).toMatchObject({
|
||||||
|
title: 'Missa',
|
||||||
|
description: 'Gondomar',
|
||||||
|
icon: 'https://img.iol.pt/image/id/6218de030cf21a10a4218ba3/300.jpg',
|
||||||
|
start: '2025-01-26T09:00:00.000Z',
|
||||||
|
stop: '2025-01-26T10:00:00.000Z'
|
||||||
|
})
|
||||||
|
expect(results[7]).toMatchObject({
|
||||||
|
title: 'Por um Triz',
|
||||||
|
description: 'Um segundo pode mudar tudo.',
|
||||||
|
icon: 'https://img.iol.pt/image/id/6777dcffd34e94b829094756/300.jpg',
|
||||||
|
start: '2025-01-26T11:00:00.000Z',
|
||||||
|
stop: '2025-01-26T11:58:00.000Z'
|
||||||
|
})
|
||||||
|
expect(results[15]).toMatchObject({
|
||||||
|
title: 'As aventuras do Gato das Botas',
|
||||||
|
description: null,
|
||||||
|
icon: 'https://img.iol.pt/image/id/66d6fb1ad34e94b82904c3ce/300.jpg',
|
||||||
|
start: '2025-01-27T04:50:00.000Z',
|
||||||
|
stop: '2025-01-27T05:20:00.000Z'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can handle empty guide', () => {
|
||||||
|
const results = parser({
|
||||||
|
date,
|
||||||
|
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(results).toMatchObject([])
|
||||||
|
})
|
Loading…
Add table
Add a link
Reference in a new issue