From 78577e8fc035845faefb740a0b9df17bc37973e0 Mon Sep 17 00:00:00 2001
From: freearhey <7253922+freearhey@users.noreply.github.com>
Date: Fri, 24 Jan 2025 23:38:00 +0300
Subject: [PATCH 1/5] Create __data__
---
sites/tvi.iol.pt/__data__/content.html | 1320 +++++++++++++++++++++
sites/tvi.iol.pt/__data__/no_content.html | 2 +
2 files changed, 1322 insertions(+)
create mode 100644 sites/tvi.iol.pt/__data__/content.html
create mode 100644 sites/tvi.iol.pt/__data__/no_content.html
diff --git a/sites/tvi.iol.pt/__data__/content.html b/sites/tvi.iol.pt/__data__/content.html
new file mode 100644
index 000000000..0fb36bc1b
--- /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
+
+
+
+
+
+
+
+
+
+
+
+
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 000000000..5b4d3371a
--- /dev/null
+++ b/sites/tvi.iol.pt/__data__/no_content.html
@@ -0,0 +1,2 @@
+Seg, 26 jan
+Brevemene Disponível
From 504398f079bec437cd109e72491514e02f76d6e3 Mon Sep 17 00:00:00 2001
From: freearhey <7253922+freearhey@users.noreply.github.com>
Date: Fri, 24 Jan 2025 23:38:09 +0300
Subject: [PATCH 2/5] Create tvi.iol.pt.test.js
---
sites/tvi.iol.pt/tvi.iol.pt.test.js | 66 +++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
create mode 100644 sites/tvi.iol.pt/tvi.iol.pt.test.js
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 000000000..4ca367a4b
--- /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([])
+})
From 50dddecfe8de0bd238c383260a27322dca86f535 Mon Sep 17 00:00:00 2001
From: freearhey <7253922+freearhey@users.noreply.github.com>
Date: Fri, 24 Jan 2025 23:38:36 +0300
Subject: [PATCH 3/5] Create tvi.iol.pt.config.js
---
sites/tvi.iol.pt/tvi.iol.pt.config.js | 76 +++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 sites/tvi.iol.pt/tvi.iol.pt.config.js
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 000000000..fce6b7dcb
--- /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()
+}
From e6c63941217b4279c61da48fe311aa63c4daec55 Mon Sep 17 00:00:00 2001
From: freearhey <7253922+freearhey@users.noreply.github.com>
Date: Fri, 24 Jan 2025 23:38:47 +0300
Subject: [PATCH 4/5] Create tvi.iol.pt.channels.xml
---
sites/tvi.iol.pt/tvi.iol.pt.channels.xml | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 sites/tvi.iol.pt/tvi.iol.pt.channels.xml
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 000000000..86dc32a14
--- /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
+
From b4d776e152cedcf5d69a0f80b041b1fa9291c630 Mon Sep 17 00:00:00 2001
From: freearhey <7253922+freearhey@users.noreply.github.com>
Date: Fri, 24 Jan 2025 23:38:57 +0300
Subject: [PATCH 5/5] Create readme.md
---
sites/tvi.iol.pt/readme.md | 15 +++++++++++++++
1 file changed, 15 insertions(+)
create mode 100644 sites/tvi.iol.pt/readme.md
diff --git a/sites/tvi.iol.pt/readme.md b/sites/tvi.iol.pt/readme.md
new file mode 100644
index 000000000..67b51e6b7
--- /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
+```