diff --git a/sites/tvi.iol.pt/__data__/content.html b/sites/tvi.iol.pt/__data__/content.html new file mode 100644 index 00000000..0fb36bc1 --- /dev/null +++ b/sites/tvi.iol.pt/__data__/content.html @@ -0,0 +1,1320 @@ +
Dom, 26 jan
+ +
+
+
+
+
+
06:15
+

As aventuras do Gato das Botas

+ +
+
+ +
+ +
+
+
+
+
+
06:45
+

Diário da Manhã

+ +
+
+ +
+ +
+
+
+
+
+
07:15
+

Campeões e Detectives

+ +
+
+ +
+ +
+
+
+
+
+
08:00
+

Inspetor Max

+ +
+
+ +
+ +
+
+
+
+
+
09:00
+

Ilhas - Os segredos da Natureza

+ +
+
+ +
+ +
+
+
+
+
+
10:00
+

Missa

+
Gondomar
+ +
+
+ +
+ +
+
+
+
+
+
11:00
+

Querido, Mudei a Casa!

+ +
+
+ +
+ +
+
+
+
+
+
12:00
+

Por um Triz

+ +
Um segundo pode mudar tudo.
+
+ +
+ +
+
+
+
+
+
12:58
+

TVI Jornal

+ +
+
+ +
+ +
+
+
+
+
+
14:00
+

Funtástico

+ +
+
+ +
+ +
+
+
+
+
+
19:57
+

Jornal Nacional

+ +
+
+ +
+ +
+
+
+
+
+
21:30
+

Secret Story

+
Desafio Final - Gala
+ +
+
+ +
+ +
+
+
+
+
+
01:30
+

Jardins Proibidos

+ +
+
+ +
+ +
+
+
+
+
+
03:45
+

TV Shop

+ +
+
+ +
+ +
+
+
+
+
+
05:30
+

Batanetes

+ +
+
+ +
+ +
+
+
+
+
+
05:50
+

As aventuras do Gato das Botas

+ +
+
+ +
diff --git a/sites/tvi.iol.pt/__data__/no_content.html b/sites/tvi.iol.pt/__data__/no_content.html new file mode 100644 index 00000000..5b4d3371 --- /dev/null +++ b/sites/tvi.iol.pt/__data__/no_content.html @@ -0,0 +1,2 @@ +
Seg, 26 jan
+Brevemene Disponível diff --git a/sites/tvi.iol.pt/readme.md b/sites/tvi.iol.pt/readme.md new file mode 100644 index 00000000..67b51e6b --- /dev/null +++ b/sites/tvi.iol.pt/readme.md @@ -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 +``` diff --git a/sites/tvi.iol.pt/tvi.iol.pt.channels.xml b/sites/tvi.iol.pt/tvi.iol.pt.channels.xml new file mode 100644 index 00000000..86dc32a1 --- /dev/null +++ b/sites/tvi.iol.pt/tvi.iol.pt.channels.xml @@ -0,0 +1,9 @@ + + + TVI + CNN Portugal + V+ TVI + TVI Reality + TVI Internacional + TVI África + diff --git a/sites/tvi.iol.pt/tvi.iol.pt.config.js b/sites/tvi.iol.pt/tvi.iol.pt.config.js new file mode 100644 index 00000000..fce6b7dc --- /dev/null +++ b/sites/tvi.iol.pt/tvi.iol.pt.config.js @@ -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() +} diff --git a/sites/tvi.iol.pt/tvi.iol.pt.test.js b/sites/tvi.iol.pt/tvi.iol.pt.test.js new file mode 100644 index 00000000..4ca367a4 --- /dev/null +++ b/sites/tvi.iol.pt/tvi.iol.pt.test.js @@ -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([]) +})