mirror of
https://github.com/iptv-org/epg
synced 2026-05-07 01:46:59 -04:00
Fixes linter errors
This commit is contained in:
@@ -1,169 +1,169 @@
|
||||
require('dayjs/locale/es')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const cheerio = require('cheerio')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const _ = require('lodash')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'reportv.com.ar',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
},
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
data({ channel, date }) {
|
||||
const formData = new URLSearchParams()
|
||||
formData.append('idSenial', channel.site_id)
|
||||
formData.append('Alineacion', '2694')
|
||||
formData.append('DiaDesde', date.format('YYYY/MM/DD'))
|
||||
formData.append('HoraDesde', '00:00:00')
|
||||
|
||||
return formData
|
||||
}
|
||||
},
|
||||
url: 'https://www.reportv.com.ar/buscador/ProgXSenial.php',
|
||||
parser: async function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, date)
|
||||
for (let item of items) {
|
||||
const $item = cheerio.load(item)
|
||||
const start = parseStart($item, date)
|
||||
const duration = parseDuration($item)
|
||||
const stop = start.add(duration, 's')
|
||||
const details = await loadProgramDetails($item)
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
category: parseCategory($item),
|
||||
icon: details.icon,
|
||||
description: details.description,
|
||||
directors: details.directors,
|
||||
actors: details.actors,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const content = await axios
|
||||
.get('https://www.reportv.com.ar/buscador/Buscador.php?aid=2694')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
const $ = cheerio.load(content)
|
||||
const items = $('#tr_home_2 > td:nth-child(1) > select > option').toArray()
|
||||
|
||||
return items.map(item => {
|
||||
return {
|
||||
site_id: $(item).attr('value'),
|
||||
name: $(item).text()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function loadProgramDetails($item) {
|
||||
const onclick = $item('*').attr('onclick')
|
||||
const regexp = /detallePrograma\((\d+),(\d+),(\d+),(\d+),'([^']+)'\);/g
|
||||
const match = [...onclick.matchAll(regexp)]
|
||||
const [, id, idc, id_alineacion, idp, title] = match[0]
|
||||
if (!id || !idc || !id_alineacion || !idp || !title) return Promise.resolve({})
|
||||
const formData = new URLSearchParams()
|
||||
formData.append('id', id)
|
||||
formData.append('idc', idc)
|
||||
formData.append('id_alineacion', id_alineacion)
|
||||
formData.append('idp', idp)
|
||||
formData.append('title', title)
|
||||
const content = await axios
|
||||
.post('https://www.reportv.com.ar/buscador/DetallePrograma.php', formData)
|
||||
.then(r => r.data.toString())
|
||||
.catch(console.error)
|
||||
if (!content) return Promise.resolve({})
|
||||
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return Promise.resolve({
|
||||
icon: parseIcon($),
|
||||
actors: parseActors($),
|
||||
directors: parseDirectors($),
|
||||
description: parseDescription($)
|
||||
})
|
||||
}
|
||||
|
||||
function parseActors($) {
|
||||
const section = $('#Ficha > div')
|
||||
.html()
|
||||
.split('<br>')
|
||||
.find(str => str.includes('Actores:'))
|
||||
if (!section) return null
|
||||
const $section = cheerio.load(section)
|
||||
|
||||
return $section('span')
|
||||
.map((i, el) => $(el).text().trim())
|
||||
.get()
|
||||
}
|
||||
|
||||
function parseDirectors($) {
|
||||
const section = $('#Ficha > div')
|
||||
.html()
|
||||
.split('<br>')
|
||||
.find(str => str.includes('Directores:'))
|
||||
if (!section) return null
|
||||
const $section = cheerio.load(section)
|
||||
|
||||
return $section('span')
|
||||
.map((i, el) => $(el).text().trim())
|
||||
.get()
|
||||
}
|
||||
|
||||
function parseDescription($) {
|
||||
return $('#Sinopsis > div').text().trim()
|
||||
}
|
||||
|
||||
function parseIcon($) {
|
||||
const src = $('#ImgProg').attr('src')
|
||||
const url = new URL(src, 'https://www.reportv.com.ar/buscador/')
|
||||
|
||||
return url.href
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
const [, title] = $item('div:nth-child(1) > span').text().split(' - ')
|
||||
|
||||
return title
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('div:nth-child(3) > span').text()
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const [time] = $item('div:nth-child(1) > span').text().split(' - ')
|
||||
|
||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'America/Caracas')
|
||||
}
|
||||
|
||||
function parseDuration($item) {
|
||||
const [hh, mm, ss] = $item('div:nth-child(4) > span').text().split(':')
|
||||
|
||||
return parseInt(hh) * 3600 + parseInt(mm) * 60 + parseInt(ss)
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
if (!content) return []
|
||||
const $ = cheerio.load(content)
|
||||
const d = _.startCase(date.locale('es').format('DD MMMM YYYY'))
|
||||
|
||||
return $(`.trProg[title*="${d}"]`).toArray()
|
||||
}
|
||||
require('dayjs/locale/es')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const cheerio = require('cheerio')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const _ = require('lodash')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'reportv.com.ar',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
},
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
data({ channel, date }) {
|
||||
const formData = new URLSearchParams()
|
||||
formData.append('idSenial', channel.site_id)
|
||||
formData.append('Alineacion', '2694')
|
||||
formData.append('DiaDesde', date.format('YYYY/MM/DD'))
|
||||
formData.append('HoraDesde', '00:00:00')
|
||||
|
||||
return formData
|
||||
}
|
||||
},
|
||||
url: 'https://www.reportv.com.ar/buscador/ProgXSenial.php',
|
||||
parser: async function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, date)
|
||||
for (let item of items) {
|
||||
const $item = cheerio.load(item)
|
||||
const start = parseStart($item, date)
|
||||
const duration = parseDuration($item)
|
||||
const stop = start.add(duration, 's')
|
||||
const details = await loadProgramDetails($item)
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
category: parseCategory($item),
|
||||
icon: details.icon,
|
||||
description: details.description,
|
||||
directors: details.directors,
|
||||
actors: details.actors,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const content = await axios
|
||||
.get('https://www.reportv.com.ar/buscador/Buscador.php?aid=2694')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
const $ = cheerio.load(content)
|
||||
const items = $('#tr_home_2 > td:nth-child(1) > select > option').toArray()
|
||||
|
||||
return items.map(item => {
|
||||
return {
|
||||
site_id: $(item).attr('value'),
|
||||
name: $(item).text()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function loadProgramDetails($item) {
|
||||
const onclick = $item('*').attr('onclick')
|
||||
const regexp = /detallePrograma\((\d+),(\d+),(\d+),(\d+),'([^']+)'\);/g
|
||||
const match = [...onclick.matchAll(regexp)]
|
||||
const [, id, idc, id_alineacion, idp, title] = match[0]
|
||||
if (!id || !idc || !id_alineacion || !idp || !title) return Promise.resolve({})
|
||||
const formData = new URLSearchParams()
|
||||
formData.append('id', id)
|
||||
formData.append('idc', idc)
|
||||
formData.append('id_alineacion', id_alineacion)
|
||||
formData.append('idp', idp)
|
||||
formData.append('title', title)
|
||||
const content = await axios
|
||||
.post('https://www.reportv.com.ar/buscador/DetallePrograma.php', formData)
|
||||
.then(r => r.data.toString())
|
||||
.catch(console.error)
|
||||
if (!content) return Promise.resolve({})
|
||||
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return Promise.resolve({
|
||||
icon: parseIcon($),
|
||||
actors: parseActors($),
|
||||
directors: parseDirectors($),
|
||||
description: parseDescription($)
|
||||
})
|
||||
}
|
||||
|
||||
function parseActors($) {
|
||||
const section = $('#Ficha > div')
|
||||
.html()
|
||||
.split('<br>')
|
||||
.find(str => str.includes('Actores:'))
|
||||
if (!section) return null
|
||||
const $section = cheerio.load(section)
|
||||
|
||||
return $section('span')
|
||||
.map((i, el) => $(el).text().trim())
|
||||
.get()
|
||||
}
|
||||
|
||||
function parseDirectors($) {
|
||||
const section = $('#Ficha > div')
|
||||
.html()
|
||||
.split('<br>')
|
||||
.find(str => str.includes('Directores:'))
|
||||
if (!section) return null
|
||||
const $section = cheerio.load(section)
|
||||
|
||||
return $section('span')
|
||||
.map((i, el) => $(el).text().trim())
|
||||
.get()
|
||||
}
|
||||
|
||||
function parseDescription($) {
|
||||
return $('#Sinopsis > div').text().trim()
|
||||
}
|
||||
|
||||
function parseIcon($) {
|
||||
const src = $('#ImgProg').attr('src')
|
||||
const url = new URL(src, 'https://www.reportv.com.ar/buscador/')
|
||||
|
||||
return url.href
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
const [, title] = $item('div:nth-child(1) > span').text().split(' - ')
|
||||
|
||||
return title
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('div:nth-child(3) > span').text()
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const [time] = $item('div:nth-child(1) > span').text().split(' - ')
|
||||
|
||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'America/Caracas')
|
||||
}
|
||||
|
||||
function parseDuration($item) {
|
||||
const [hh, mm, ss] = $item('div:nth-child(4) > span').text().split(':')
|
||||
|
||||
return parseInt(hh) * 3600 + parseInt(mm) * 60 + parseInt(ss)
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
if (!content) return []
|
||||
const $ = cheerio.load(content)
|
||||
const d = _.startCase(date.locale('es').format('DD MMMM YYYY'))
|
||||
|
||||
return $(`.trProg[title*="${d}"]`).toArray()
|
||||
}
|
||||
|
||||
@@ -1,114 +1,114 @@
|
||||
// npm run grab -- --site=reportv.com.ar
|
||||
// npm run channels:parse -- --config=./sites/reportv.com.ar/reportv.com.ar.config.js --output=./sites/reportv.com.ar/reportv.com.ar.channels.xml
|
||||
|
||||
const { parser, url, request } = require('./reportv.com.ar.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 axios = require('axios')
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2022-10-03', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '914',
|
||||
xmltv_id: 'VePlusVenezuela.ve'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url).toBe('https://www.reportv.com.ar/buscador/ProgXSenial.php')
|
||||
})
|
||||
|
||||
it('can generate valid request method', () => {
|
||||
expect(request.method).toBe('POST')
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
})
|
||||
|
||||
it('can generate valid request data', () => {
|
||||
const result = request.data({ channel, date })
|
||||
expect(result.get('idSenial')).toBe('914')
|
||||
expect(result.get('Alineacion')).toBe('2694')
|
||||
expect(result.get('DiaDesde')).toBe('2022/10/03')
|
||||
expect(result.get('HoraDesde')).toBe('00:00:00')
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
|
||||
axios.post.mockImplementation((url, data) => {
|
||||
if (
|
||||
url === 'https://www.reportv.com.ar/buscador/DetallePrograma.php' &&
|
||||
data.get('id') == '286096'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/program1.html'))
|
||||
})
|
||||
} else if (
|
||||
url === 'https://www.reportv.com.ar/buscador/DetallePrograma.php' &&
|
||||
data.get('id') == '392803'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/program2.html'))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/no_program.html'))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-10-03T04:00:00.000Z',
|
||||
stop: '2022-10-03T05:00:00.000Z',
|
||||
title: '¿Quién tiene la razón?',
|
||||
category: 'Talk Show',
|
||||
icon: 'https://www.reportv.com.ar/buscador/img/Programas/4401882.jpg',
|
||||
actors: ['Nancy Álvarez'],
|
||||
description:
|
||||
'Espacio que dará de qué hablar cuando la doctora Nancy Álvarez y Carmen Jara, acompañadas de un jurado implacable, lleguen a escuchar y a resolver los problemas de las partes en conflicto para luego decidir quién tiene la razón.'
|
||||
})
|
||||
|
||||
expect(results[21]).toMatchObject({
|
||||
start: '2022-10-04T03:00:00.000Z',
|
||||
stop: '2022-10-04T04:00:00.000Z',
|
||||
title: 'Valeria',
|
||||
category: 'Comedia',
|
||||
icon: 'https://www.reportv.com.ar/buscador/img/Programas/18788047.jpg',
|
||||
directors: ['Inma Torrente'],
|
||||
actors: [
|
||||
'Diana Gómez',
|
||||
'Silma López',
|
||||
'Paula Malia',
|
||||
'Teresa Riott',
|
||||
'Maxi Iglesias',
|
||||
'Juanlu González',
|
||||
'Aitor Luna',
|
||||
'Lauren McFall',
|
||||
'Éva Martin',
|
||||
'Raquel Ventosa'
|
||||
],
|
||||
description:
|
||||
'Valeria es una escritora que no está pasando por su mejor momento a nivel profesional y sentimental. La distancia emocional que la separa de su marido la lleva a refugiarse en sus tres mejores amigas: Carmen, Lola y Nerea. Valeria y sus amigas están inmersas en un torbellino de emociones de amor, amistad, celos, infidelidad, dudas, desamor, secretos, trabajo, preocupaciones, alegrías y sueños sobre el futuro.'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const result = await parser({ content, date })
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
// npm run grab -- --site=reportv.com.ar
|
||||
// npm run channels:parse -- --config=./sites/reportv.com.ar/reportv.com.ar.config.js --output=./sites/reportv.com.ar/reportv.com.ar.channels.xml
|
||||
|
||||
const { parser, url, request } = require('./reportv.com.ar.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 axios = require('axios')
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2022-10-03', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '914',
|
||||
xmltv_id: 'VePlusVenezuela.ve'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url).toBe('https://www.reportv.com.ar/buscador/ProgXSenial.php')
|
||||
})
|
||||
|
||||
it('can generate valid request method', () => {
|
||||
expect(request.method).toBe('POST')
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
})
|
||||
|
||||
it('can generate valid request data', () => {
|
||||
const result = request.data({ channel, date })
|
||||
expect(result.get('idSenial')).toBe('914')
|
||||
expect(result.get('Alineacion')).toBe('2694')
|
||||
expect(result.get('DiaDesde')).toBe('2022/10/03')
|
||||
expect(result.get('HoraDesde')).toBe('00:00:00')
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
|
||||
axios.post.mockImplementation((url, data) => {
|
||||
if (
|
||||
url === 'https://www.reportv.com.ar/buscador/DetallePrograma.php' &&
|
||||
data.get('id') == '286096'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/program1.html'))
|
||||
})
|
||||
} else if (
|
||||
url === 'https://www.reportv.com.ar/buscador/DetallePrograma.php' &&
|
||||
data.get('id') == '392803'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/program2.html'))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/no_program.html'))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-10-03T04:00:00.000Z',
|
||||
stop: '2022-10-03T05:00:00.000Z',
|
||||
title: '¿Quién tiene la razón?',
|
||||
category: 'Talk Show',
|
||||
icon: 'https://www.reportv.com.ar/buscador/img/Programas/4401882.jpg',
|
||||
actors: ['Nancy Álvarez'],
|
||||
description:
|
||||
'Espacio que dará de qué hablar cuando la doctora Nancy Álvarez y Carmen Jara, acompañadas de un jurado implacable, lleguen a escuchar y a resolver los problemas de las partes en conflicto para luego decidir quién tiene la razón.'
|
||||
})
|
||||
|
||||
expect(results[21]).toMatchObject({
|
||||
start: '2022-10-04T03:00:00.000Z',
|
||||
stop: '2022-10-04T04:00:00.000Z',
|
||||
title: 'Valeria',
|
||||
category: 'Comedia',
|
||||
icon: 'https://www.reportv.com.ar/buscador/img/Programas/18788047.jpg',
|
||||
directors: ['Inma Torrente'],
|
||||
actors: [
|
||||
'Diana Gómez',
|
||||
'Silma López',
|
||||
'Paula Malia',
|
||||
'Teresa Riott',
|
||||
'Maxi Iglesias',
|
||||
'Juanlu González',
|
||||
'Aitor Luna',
|
||||
'Lauren McFall',
|
||||
'Éva Martin',
|
||||
'Raquel Ventosa'
|
||||
],
|
||||
description:
|
||||
'Valeria es una escritora que no está pasando por su mejor momento a nivel profesional y sentimental. La distancia emocional que la separa de su marido la lleva a refugiarse en sus tres mejores amigas: Carmen, Lola y Nerea. Valeria y sus amigas están inmersas en un torbellino de emociones de amor, amistad, celos, infidelidad, dudas, desamor, secretos, trabajo, preocupaciones, alegrías y sueños sobre el futuro.'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const result = await parser({ content, date })
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user