From 1e7c4d76a1b8cff1b3ef4867a27b8807640d967b Mon Sep 17 00:00:00 2001 From: Toha Date: Wed, 22 Nov 2023 02:16:03 +0700 Subject: [PATCH] Add meuguia.tv. Signed-off-by: Toha --- sites/meuguia.tv/__data__/content.html | 318 +++++++++++++++++++++++ sites/meuguia.tv/meuguia.tv.channels.xml | 105 ++++++++ sites/meuguia.tv/meuguia.tv.config.js | 101 +++++++ sites/meuguia.tv/meuguia.tv.test.js | 62 +++++ 4 files changed, 586 insertions(+) create mode 100644 sites/meuguia.tv/__data__/content.html create mode 100644 sites/meuguia.tv/meuguia.tv.channels.xml create mode 100644 sites/meuguia.tv/meuguia.tv.config.js create mode 100644 sites/meuguia.tv/meuguia.tv.test.js diff --git a/sites/meuguia.tv/__data__/content.html b/sites/meuguia.tv/__data__/content.html new file mode 100644 index 00000000..a1364e9f --- /dev/null +++ b/sites/meuguia.tv/__data__/content.html @@ -0,0 +1,318 @@ + + + + + + + + + + + + + + + Programação AXN + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+
+ +
+
+
+
+ PROGRAMAÇÃO +

AXN

+
+
+ + + + + + + +
+
+ + + + + + + + + \ No newline at end of file diff --git a/sites/meuguia.tv/meuguia.tv.channels.xml b/sites/meuguia.tv/meuguia.tv.channels.xml new file mode 100644 index 00000000..4e209f84 --- /dev/null +++ b/sites/meuguia.tv/meuguia.tv.channels.xml @@ -0,0 +1,105 @@ + + + AMC + Animal Planet + Arte 1 + AXN + Baby TV + Band + Band News + Band Sports + BBC World News + Bis + Bloomberg + Rede Boa Vontade + Canal 21 + Canal Brasil + Canal do Boi + Futura + OFF HD + Canal Rural + Viva + Cartoon Network + Cinemax + Climatempo + CNN International + Combate + Comedy Central + Discovery Channel + Discovery Science + Discovery HD Theater + Discovery Turbo + Discovery World + Disney Channel + Deutsche Welle + E! Entertainment Television + ESPN Brasil + ESPN + Eurochannel + Fox Sports 2 + Fox Sports + FX + Globo + Globo News + Gloob + GNT + HBO 2 + HBO + HBO Family + HBO Plus + HBO Signature + Lifetime + Megapix + MTV + Multishow + National Geographic + NHK World + Nickelodeon + Nick Jr. + Paramount Channel + Premiere Clubes + RAI International + Record TV + Record News + Rede TV + Rede Vida + SBT + Shoptime + SIC International + Sony + SPACE + SporTV 2 + SporTV 3 + SporTV + Studio Universal + SyFy + TBS + TCM - Turner Classic + Telecine Action + Telecine Cult + Telecine Fun + Telecine Pipoca + Telecine Premium + Telecine Touch + Terra Viva + TLC + TNT + TNT Séries + Tooncast + Travel Box Brazil + TV5 Monde + TV Aparecida (aberta) + TV Brasil + TV Câmara + Canção Nova + TV Cultura + TV Escola + TV Espanha + TV Gazeta + TV Justiça + TV Rá-tim-bum + TV Senado + Universal Channel + Warner Channel + Woohoo + diff --git a/sites/meuguia.tv/meuguia.tv.config.js b/sites/meuguia.tv/meuguia.tv.config.js new file mode 100644 index 00000000..c877a08f --- /dev/null +++ b/sites/meuguia.tv/meuguia.tv.config.js @@ -0,0 +1,101 @@ +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: 'meuguia.tv', + days: 2, + url({ channel }) { + return `https://meuguia.tv/programacao/canal/${channel.site_id}` + }, + parser({ content, date }) { + const programs = [] + parseItems(content, date).forEach(item => { + if (dayjs.utc(item.start).isSame(date, 'day')) { + programs.push(item) + } + }) + + return programs + }, + async channels() { + const channels = [] + const axios = require('axios') + const baseUrl = 'https://meuguia.tv' + + let seq = 0 + const queues = [baseUrl] + while (true) { + if (!queues.length) { + break + } + const url = queues.shift() + const content = await axios + .get(url) + .then(response => response.data) + .catch(console.error) + + if (content) { + const [ $, items ] = getItems(content) + if (seq === 0) { + queues.push(...items.map(category => baseUrl + $(category).attr('href'))) + } else { + items.forEach(item => { + const href = $(item).attr('href') + channels.push({ + lang: 'pt', + site_id: href.substr(href.lastIndexOf('/') + 1), + name: $(item).find('.licontent h2').text().trim() + }) + }) + } + } + seq++ + } + + return channels + } +} + +function getItems(content) { + const $ = cheerio.load(content) + return [$, $('div.mw ul li a').toArray()] +} + +function parseItems(content, date) { + const result = [] + const $ = cheerio.load(content) + + let lastDate + for (const item of $('ul.mw li').toArray()) { + const $item = $(item) + if ($item.hasClass('subheader')) { + lastDate = `${$item.text().split(', ')[1]}/${date.format('YYYY')}` + } else if ($item.hasClass('divider')) { + // ignore + } else if (lastDate) { + const data = { title: $item.find('a').attr('title').trim() } + const ep = data.title.match(/T(\d+) EP(\d+)/) + if (ep) { + data.season = parseInt(ep[1]) + data.episode = parseInt(ep[2]) + } + data.start = dayjs.tz(`${lastDate} ${$item.find('.time').text()}`, 'DD/MM/YYYY HH:mm', 'America/Sao_Paulo') + result.push(data) + } + } + // use stop time from next item + if (result.length > 1) { + for (let i = 0; i < result.length - 1; i++) { + result[i].stop = result[i + 1].start + } + } + + return result +} \ No newline at end of file diff --git a/sites/meuguia.tv/meuguia.tv.test.js b/sites/meuguia.tv/meuguia.tv.test.js new file mode 100644 index 00000000..b3e7cb54 --- /dev/null +++ b/sites/meuguia.tv/meuguia.tv.test.js @@ -0,0 +1,62 @@ +// npm run channels:parse -- --config=./sites/meuguia.tv/meuguia.tv.config.js --output=./sites/meuguia.tv/meuguia.tv.channels.xml +// npm run grab -- --site=meuguia.tv + +const { parser, url } = require('./meuguia.tv.config.js') +const fs = require('fs') +const path = require('path') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') + +dayjs.extend(utc) + +const date = dayjs.utc('2023-11-21').startOf('d') +const channel = { + site_id: 'AXN', + xmltv_id: 'AXN.id' +} +it('can generate valid url', () => { + expect(url({ channel })).toBe('https://meuguia.tv/programacao/canal/AXN') +}) + +it('can parse response', () => { + const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html')) + const result = parser({ content, channel, date }).map(p => { + p.start = p.start.toJSON() + if (p.stop) { + p.stop = p.stop.toJSON() + } + return p + }) + + expect(result).toMatchObject([ + { + title: 'Hawaii Five-0 : T10 EP4 - Tiny Is the Flower, Yet It Scents the Grasses Around It', + start: '2023-11-21T21:20:00.000Z', + stop: '2023-11-21T22:15:00.000Z', + season: 10, + episode: 4 + }, + { + title: 'Hawaii Five-0 : T10 EP5 - Don\'t Blame Ghosts and Spirits for One\'s Troubles; A Human Is Responsible', + start: '2023-11-21T22:15:00.000Z', + stop: '2023-11-21T23:10:00.000Z', + season: 10, + episode: 5 + }, + { + title: 'NCIS : T5 EP15 - In the Zone', + start: '2023-11-21T23:10:00.000Z', + season: 5, + episode: 15 + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: '' + }) + expect(result).toMatchObject([]) +})