diff --git a/sites/guida.tv/__data__/content.html b/sites/guida.tv/__data__/content.html new file mode 100644 index 00000000..731ff49d --- /dev/null +++ b/sites/guida.tv/__data__/content.html @@ -0,0 +1,1068 @@ + + + Programmi TV RAI 1 - Stasera in TV | guida.tv + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
+
+ +
+
+ RAI 1 +
+

RAI 1

+
+
+ Scopri i programmi TV di stasera su RAI 1 con + Guida TV +
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
Orario
+
+
Programma TV
+
+
01:10
+
+
+ + Viva Rai2! +
+
+
02:05
+
+
+ + Che tempo fa +
+
+
02:10
+
+
+ + Cinematografo +
+
+
03:10
+
+
+ + RAInews24 +
+
+
06:00
+
+
+ + RAInews24 +
+
+
06:28
+
+
+ + Previsioni sulla viabilità +
+
+
06:30
+
+
+ + TG1 +
+
+
06:35
+
+
+ + Tg uno mattina +
+
+
07:00
+
+
+ + TG1 +
+
+
07:10
+
+
+ + Che tempo fa +
+
+
07:15
+
+
+ + Tg uno mattina +
+
+
08:00
+
+
+ + TG1 +
+
+
08:30
+
+
+ + Che tempo fa +
+
+
08:35
+
+
+ + Unomattina +
+
+
08:55
+
+
+ + Rai Parlamento Telegiornale +
+
+
09:00
+
+
+ + TG1 L.I.S. +
+
+
09:50
+
+
+ + Storie italiane +
+
+
11:55
+
+
+ + È sempre mezzogiorno +
+
+
13:30
+
+
+ + Telegiornale +
+
+
14:05
+
+
+ + La volta buona +
+
+
16:00
+
+
+ + Il paradiso delle signore +
+
+
16:52
+
+
+ + Previsioni sulla viabilità +
+
+
16:55
+
+
+ + TG1 +
+
+
17:05
+
+
+ + La vita in diretta +
+
+
18:45
+
+
+ + Reazione a catena +
+
+
20:00
+
+
+ + Telegiornale +
+
+
20:30
+
+
+ + Cinque Minuti +
+
+
20:35
+
+
+ + Affari tuoi +
+
+
21:30
+
+
+ + The Voice Kids +
+
+
23:55
+
+
+ + TG1 Sera +
+
+
00:00
+
+
+ + TV 7 +
+
+
+
+ Altri canali su Guida TV.. +
+
+

+
+
+ +
+ +
+ +
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sites/guida.tv/guida.tv.channels.xml b/sites/guida.tv/guida.tv.channels.xml new file mode 100644 index 00000000..a7c0eb47 --- /dev/null +++ b/sites/guida.tv/guida.tv.channels.xml @@ -0,0 +1,91 @@ + + + Mediaset 20 + 7 Gold + Alma + Boing + Sky Italian Boomerang + Caccia + Canale 5 + Cartoonito + Cartoon Network Italy + Cielo + Cine34 + Class CNBC + Comedy Central + Crime+Investigation + DEA JUNIOR + DeA Kids + Discovery Channel I + DMAX Italia + Donna TV + Euronews + Eurosport Italia + Eurosport 2 Italia + Focus + Food Network + Frisbee + Sky Italian Gambero Rosso HD + Giallo + HGTV IT + History + Inter TV + Iris + ITALIA 1 + ITALIA 2 + K2 + La 5 + LA 7 + La7d + Mediaset Extra + Milan TV + MTV Music + Nickelodeon + Nick Jr. + Nove + Pesca + Radionorba TV + RAI 1 + RAI 2 + RAI 3 + Rai 4 + Rai 5 + Rai gulp + RAI Movie + RAI 24 News + Rai Premium + Rai Scuola + Rai Sport HD + RAI STORIA + Rai YoYo + Real Time + RETE 4 + RTL 102.5 + Sky Italian San Marino RTV + Sky Arte HDTV + Sky Atlantic HDTV + Sky Cinema Action + Sky Cinema Collection + Sky Cinema Comedy + Sky Cinema Drama + Sky Cinema Due + Sky Cinema Family + Sky Cinema Romance + Sky Cinema Suspense + Sky Cinema Uno + SKY SPORT 24 + Sky Sport F1 + Sky Sport Football + Sky Moto GP + Sky Sport NBA + Sky Sport Tennis + Sky Sport Uno + Sky TG24 + Sky Uno + Sport Italia + Super! + Super Tennis HD + Top Calcio 24 + TV 2000 + TV8 + diff --git a/sites/guida.tv/guida.tv.config.js b/sites/guida.tv/guida.tv.config.js new file mode 100644 index 00000000..44402d16 --- /dev/null +++ b/sites/guida.tv/guida.tv.config.js @@ -0,0 +1,99 @@ +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: 'guida.tv', + days: 2, + url: function ({ date, channel }) { + return `https://www.guida.tv/programmi-tv/palinsesto/canale/${ + channel.site_id + }.html?dt=${date.format('YYYY-MM-DD')}` + }, + parser: function ({ content, date, channel }) { + const programs = [] + const items = parseItems(content) + items.forEach(item => { + const prev = programs[programs.length - 1] + const $item = cheerio.load(item) + let start = parseStart($item, date, channel) + 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), + start, + stop + }) + }) + + return programs + }, + async channels() { + const axios = require('axios') + const _ = require('lodash') + + const providers = ['-1', '-2', '-3'] + + const channels = [] + for (let provider of providers) { + const data = await axios + .post(`https://www.guida.tv/guide/schedule`, null, { + params: { + provider, + region: 'Italy', + TVperiod: 'Night', + date: dayjs().format('YYYY-MM-DD'), + st: 0, + u_time: 1429, + is_mobile: 1 + } + }) + .then(r => r.data) + .catch(console.log) + + const $ = cheerio.load(data) + $('.channelname').each((i, el) => { + const name = $(el).find('center > a:eq(1)').text() + const url = $(el).find('center > a:eq(1)').attr('href') + const [, number, slug] = url.match(/\/(\d+)\/(.*)\.html$/) + + channels.push({ + lang: 'it', + name, + site_id: `${number}/${slug}` + }) + }) + } + + return _.uniqBy(channels, 'site_id') + } +} + +function parseStart($item, date, channel) { + const timeString = $item('td:eq(0)').text().trim() + const dateString = `${date.format('YYYY-MM-DD')} ${timeString}` + + return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Europe/Rome') +} + +function parseTitle($item) { + return $item('td:eq(1)').text().trim() +} + +function parseItems(content) { + const $ = cheerio.load(content) + + return $('table.table > tbody > tr').toArray() +} diff --git a/sites/guida.tv/guida.tv.test.js b/sites/guida.tv/guida.tv.test.js new file mode 100644 index 00000000..859409b4 --- /dev/null +++ b/sites/guida.tv/guida.tv.test.js @@ -0,0 +1,53 @@ +// npm run channels:parse -- --config=./sites/guida.tv/guida.tv.config.js --output=./sites/guida.tv/guida.tv.channels.xml +// npm run grab -- --site=guida.tv + +const { parser, url } = require('./guida.tv.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('2023-11-24', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '826573/rai-1', + xmltv_id: 'Rai1.it' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://www.guida.tv/programmi-tv/palinsesto/canale/826573/rai-1.html?dt=2023-11-24' + ) +}) + +it('can parse response', () => { + const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html')) + const results = parser({ content, channel, date }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(results[0]).toMatchObject({ + start: '2023-11-24T00:10:00.000Z', + stop: '2023-11-24T01:05:00.000Z', + title: 'Viva Rai2!' + }) + + expect(results[30]).toMatchObject({ + start: '2023-11-24T23:00:00.000Z', + stop: '2023-11-24T23:30:00.000Z', + title: 'TV 7' + }) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: '' + }) + expect(result).toMatchObject([]) +})