mirror of
https://github.com/iptv-org/epg
synced 2026-04-30 14:36:58 -04:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,101 +1,101 @@
|
||||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
require('dayjs/locale/pt')
|
||||
|
||||
module.exports = {
|
||||
site: 'guiadetv.com',
|
||||
days: 2,
|
||||
url({ channel }) {
|
||||
return `https://www.guiadetv.com/canal/${channel.site_id}`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
const title = parseTitle($item)
|
||||
let start = parseStart($item)
|
||||
if (!start || !title) return
|
||||
if (prev) {
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.add(30, 'm')
|
||||
|
||||
programs.push({
|
||||
title,
|
||||
description: parseDescription($item),
|
||||
category: parseCategory($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const categories = [
|
||||
'variedades',
|
||||
'tv-aberta',
|
||||
'noticias',
|
||||
'infantil',
|
||||
'filmes-e-series',
|
||||
'esportes',
|
||||
'documentarios'
|
||||
]
|
||||
const promises = categories.map(category =>
|
||||
axios.get(`https://www.guiadetv.com/categorias/${category}.html`)
|
||||
)
|
||||
|
||||
const channels = []
|
||||
const results = await Promise.all(promises).catch(console.log)
|
||||
results.forEach(r => {
|
||||
const $ = cheerio.load(r.data)
|
||||
$('.cardchannel').each((i, el) => {
|
||||
const link = $(el).find('a')
|
||||
const name = link.attr('title')
|
||||
const url = link.attr('href')
|
||||
const site_id = url.replace('https://www.guiadetv.com/canal/', '')
|
||||
|
||||
channels.push({
|
||||
lang: 'pt',
|
||||
name,
|
||||
site_id
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('h3').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('p').clone().children().remove().end().text().trim() || null
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('p > i').text().trim() || null
|
||||
}
|
||||
|
||||
function parseStart($item) {
|
||||
const dt = $item('b span:nth-child(1)').data('dt') || $item('b').data('dt')
|
||||
if (!dt) return null
|
||||
|
||||
return dayjs(dt, 'YYYY-MM-DD HH:mm:ssZ')
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
const $ = cheerio.load(content)
|
||||
const localDate = date.locale('pt').format('D MMMM YYYY')
|
||||
|
||||
return $(`.row:contains(${localDate})`).nextUntil('.row:not(.mt-1)').toArray()
|
||||
}
|
||||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
require('dayjs/locale/pt')
|
||||
|
||||
module.exports = {
|
||||
site: 'guiadetv.com',
|
||||
days: 2,
|
||||
url({ channel }) {
|
||||
return `https://www.guiadetv.com/canal/${channel.site_id}`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
const title = parseTitle($item)
|
||||
let start = parseStart($item)
|
||||
if (!start || !title) return
|
||||
if (prev) {
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.add(30, 'm')
|
||||
|
||||
programs.push({
|
||||
title,
|
||||
description: parseDescription($item),
|
||||
category: parseCategory($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const categories = [
|
||||
'variedades',
|
||||
'tv-aberta',
|
||||
'noticias',
|
||||
'infantil',
|
||||
'filmes-e-series',
|
||||
'esportes',
|
||||
'documentarios'
|
||||
]
|
||||
const promises = categories.map(category =>
|
||||
axios.get(`https://www.guiadetv.com/categorias/${category}.html`)
|
||||
)
|
||||
|
||||
const channels = []
|
||||
const results = await Promise.all(promises).catch(console.log)
|
||||
results.forEach(r => {
|
||||
const $ = cheerio.load(r.data)
|
||||
$('.cardchannel').each((i, el) => {
|
||||
const link = $(el).find('a')
|
||||
const name = link.attr('title')
|
||||
const url = link.attr('href')
|
||||
const site_id = url.replace('https://www.guiadetv.com/canal/', '')
|
||||
|
||||
channels.push({
|
||||
lang: 'pt',
|
||||
name,
|
||||
site_id
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('h3').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('p').clone().children().remove().end().text().trim() || null
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('p > i').text().trim() || null
|
||||
}
|
||||
|
||||
function parseStart($item) {
|
||||
const dt = $item('b span:nth-child(1)').data('dt') || $item('b').data('dt')
|
||||
if (!dt) return null
|
||||
|
||||
return dayjs(dt, 'YYYY-MM-DD HH:mm:ssZ')
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
const $ = cheerio.load(content)
|
||||
const localDate = date.locale('pt').format('D MMMM YYYY')
|
||||
|
||||
return $(`.row:contains(${localDate})`).nextUntil('.row:not(.mt-1)').toArray()
|
||||
}
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
const { parser, url } = require('./guiadetv.com.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-18', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'canal-rural',
|
||||
xmltv_id: 'CanalRural.br'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel })).toBe('https://www.guiadetv.com/canal/canal-rural')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(16)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-01-18T03:00:00.000Z',
|
||||
stop: '2025-01-18T04:00:00.000Z',
|
||||
title: 'Leilão',
|
||||
description: null,
|
||||
category: null
|
||||
})
|
||||
expect(results[2]).toMatchObject({
|
||||
start: '2025-01-18T06:00:00.000Z',
|
||||
stop: '2025-01-18T09:00:00.000Z',
|
||||
title: 'TV Verdade',
|
||||
description: null,
|
||||
category: 'Jornalismo'
|
||||
})
|
||||
expect(results[15]).toMatchObject({
|
||||
start: '2025-01-19T00:00:00.000Z',
|
||||
stop: '2025-01-19T00:30:00.000Z',
|
||||
title: 'Leilão',
|
||||
description: null,
|
||||
category: null
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response for current day', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date: dayjs.utc('2025-01-15', 'YYYY-MM-DD').startOf('d') }).map(
|
||||
p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
}
|
||||
)
|
||||
|
||||
expect(results.length).toBe(7)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-01-15T21:15:00.000Z',
|
||||
stop: '2025-01-15T21:45:00.000Z',
|
||||
title: 'Planeta Campo Talks',
|
||||
description:
|
||||
'Grandes reportagens, notícias, entrevistas e debates com foco em ações de sustentabilidade e indicadores ESG. Informações para apoiar o produtor rural a plantar e criar com olhar para o futuro.',
|
||||
category: null
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({
|
||||
date,
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
})
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./guiadetv.com.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-18', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'canal-rural',
|
||||
xmltv_id: 'CanalRural.br'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel })).toBe('https://www.guiadetv.com/canal/canal-rural')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(16)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-01-18T03:00:00.000Z',
|
||||
stop: '2025-01-18T04:00:00.000Z',
|
||||
title: 'Leilão',
|
||||
description: null,
|
||||
category: null
|
||||
})
|
||||
expect(results[2]).toMatchObject({
|
||||
start: '2025-01-18T06:00:00.000Z',
|
||||
stop: '2025-01-18T09:00:00.000Z',
|
||||
title: 'TV Verdade',
|
||||
description: null,
|
||||
category: 'Jornalismo'
|
||||
})
|
||||
expect(results[15]).toMatchObject({
|
||||
start: '2025-01-19T00:00:00.000Z',
|
||||
stop: '2025-01-19T00:30:00.000Z',
|
||||
title: 'Leilão',
|
||||
description: null,
|
||||
category: null
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response for current day', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date: dayjs.utc('2025-01-15', 'YYYY-MM-DD').startOf('d') }).map(
|
||||
p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
}
|
||||
)
|
||||
|
||||
expect(results.length).toBe(7)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2025-01-15T21:15:00.000Z',
|
||||
stop: '2025-01-15T21:45:00.000Z',
|
||||
title: 'Planeta Campo Talks',
|
||||
description:
|
||||
'Grandes reportagens, notícias, entrevistas e debates com foco em ações de sustentabilidade e indicadores ESG. Informações para apoiar o produtor rural a plantar e criar com olhar para o futuro.',
|
||||
category: null
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({
|
||||
date,
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
})
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user