mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Fixes linter errors
This commit is contained in:
parent
57e508fc3b
commit
63c86a2b30
393 changed files with 28447 additions and 28443 deletions
|
@ -1,133 +1,133 @@
|
|||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
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)
|
||||
|
||||
const API_ENDPOINT = 'https://www.reportv.com.ar/finder'
|
||||
|
||||
module.exports = {
|
||||
site: 'cableplus.com.uy',
|
||||
days: 2,
|
||||
url: `${API_ENDPOINT}/channel`,
|
||||
request: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||
},
|
||||
data({ date, channel }) {
|
||||
const params = new URLSearchParams()
|
||||
params.append('idAlineacion', '3017')
|
||||
params.append('idSenial', channel.site_id)
|
||||
params.append('fecha', date.format('YYYY-MM-DD'))
|
||||
params.append('hora', '00:00')
|
||||
|
||||
return params
|
||||
}
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
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),
|
||||
categories: parseCategories($item),
|
||||
icon: parseIcon($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const params = new URLSearchParams({ idAlineacion: '3017' })
|
||||
const data = await axios
|
||||
.post(`${API_ENDPOINT}/channelGrid`, params, {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
|
||||
})
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
const $ = cheerio.load(data)
|
||||
|
||||
return $('.senial')
|
||||
.map(function () {
|
||||
return {
|
||||
lang: 'es',
|
||||
site_id: $(this).attr('id'),
|
||||
name: $(this).find('img').attr('alt')
|
||||
}
|
||||
})
|
||||
.get()
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('p.evento_titulo.texto_a_continuacion.dotdotdot,.programa-titulo > span:first-child')
|
||||
.text()
|
||||
.trim()
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
return $item('img').data('src') || $item('img').attr('src') || null
|
||||
}
|
||||
|
||||
function parseCategories($item) {
|
||||
return $item('p.evento_genero')
|
||||
.map(function () {
|
||||
return $item(this).text().trim()
|
||||
})
|
||||
.toArray()
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
let time = $item('.grid_fecha_hora').text().trim()
|
||||
|
||||
if (time) {
|
||||
return dayjs.tz(`${date.format('YYYY')} ${time}`, 'YYYY DD-MM HH:mm[hs.]', 'America/Montevideo')
|
||||
}
|
||||
|
||||
time = $item('.fechaHora').text().trim()
|
||||
|
||||
return time
|
||||
? dayjs.tz(`${date.format('YYYY')} ${time}`, 'YYYY DD/MM HH:mm[hs.]', 'America/Montevideo')
|
||||
: null
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
let featuredItems = $('.vista-pc > .programacion-fila > .channel-programa')
|
||||
.filter(function () {
|
||||
return $(this).find('.grid_fecha_hora').text().indexOf(date.format('DD-MM')) > -1
|
||||
})
|
||||
.toArray()
|
||||
let otherItems = $('#owl-pc > .item-program')
|
||||
.filter(function () {
|
||||
return (
|
||||
$(this)
|
||||
.find('.evento_titulo > .horario > p.fechaHora')
|
||||
.text()
|
||||
.indexOf(date.format('DD/MM')) > -1
|
||||
)
|
||||
})
|
||||
.toArray()
|
||||
|
||||
return featuredItems.concat(otherItems)
|
||||
}
|
||||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
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)
|
||||
|
||||
const API_ENDPOINT = 'https://www.reportv.com.ar/finder'
|
||||
|
||||
module.exports = {
|
||||
site: 'cableplus.com.uy',
|
||||
days: 2,
|
||||
url: `${API_ENDPOINT}/channel`,
|
||||
request: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||
},
|
||||
data({ date, channel }) {
|
||||
const params = new URLSearchParams()
|
||||
params.append('idAlineacion', '3017')
|
||||
params.append('idSenial', channel.site_id)
|
||||
params.append('fecha', date.format('YYYY-MM-DD'))
|
||||
params.append('hora', '00:00')
|
||||
|
||||
return params
|
||||
}
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
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),
|
||||
categories: parseCategories($item),
|
||||
icon: parseIcon($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const params = new URLSearchParams({ idAlineacion: '3017' })
|
||||
const data = await axios
|
||||
.post(`${API_ENDPOINT}/channelGrid`, params, {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
|
||||
})
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
const $ = cheerio.load(data)
|
||||
|
||||
return $('.senial')
|
||||
.map(function () {
|
||||
return {
|
||||
lang: 'es',
|
||||
site_id: $(this).attr('id'),
|
||||
name: $(this).find('img').attr('alt')
|
||||
}
|
||||
})
|
||||
.get()
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('p.evento_titulo.texto_a_continuacion.dotdotdot,.programa-titulo > span:first-child')
|
||||
.text()
|
||||
.trim()
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
return $item('img').data('src') || $item('img').attr('src') || null
|
||||
}
|
||||
|
||||
function parseCategories($item) {
|
||||
return $item('p.evento_genero')
|
||||
.map(function () {
|
||||
return $item(this).text().trim()
|
||||
})
|
||||
.toArray()
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
let time = $item('.grid_fecha_hora').text().trim()
|
||||
|
||||
if (time) {
|
||||
return dayjs.tz(`${date.format('YYYY')} ${time}`, 'YYYY DD-MM HH:mm[hs.]', 'America/Montevideo')
|
||||
}
|
||||
|
||||
time = $item('.fechaHora').text().trim()
|
||||
|
||||
return time
|
||||
? dayjs.tz(`${date.format('YYYY')} ${time}`, 'YYYY DD/MM HH:mm[hs.]', 'America/Montevideo')
|
||||
: null
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
let featuredItems = $('.vista-pc > .programacion-fila > .channel-programa')
|
||||
.filter(function () {
|
||||
return $(this).find('.grid_fecha_hora').text().indexOf(date.format('DD-MM')) > -1
|
||||
})
|
||||
.toArray()
|
||||
let otherItems = $('#owl-pc > .item-program')
|
||||
.filter(function () {
|
||||
return (
|
||||
$(this)
|
||||
.find('.evento_titulo > .horario > p.fechaHora')
|
||||
.text()
|
||||
.indexOf(date.format('DD/MM')) > -1
|
||||
)
|
||||
})
|
||||
.toArray()
|
||||
|
||||
return featuredItems.concat(otherItems)
|
||||
}
|
||||
|
|
|
@ -1,76 +1,76 @@
|
|||
// npm run channels:parse -- --config=./sites/cableplus.com.uy/cableplus.com.uy.config.js --output=./sites/cableplus.com.uy/cableplus.com.uy.channels.xml
|
||||
// npm run grab -- --site=cableplus.com.uy
|
||||
|
||||
const { parser, url, request } = require('./cableplus.com.uy.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-02-12', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '2035',
|
||||
xmltv_id: 'APlusV.uy'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url).toBe('https://www.reportv.com.ar/finder/channel')
|
||||
})
|
||||
|
||||
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; charset=UTF-8'
|
||||
})
|
||||
})
|
||||
|
||||
it('can generate valid request data', () => {
|
||||
const params = request.data({ date, channel })
|
||||
|
||||
expect(params.get('idAlineacion')).toBe('3017')
|
||||
expect(params.get('idSenial')).toBe('2035')
|
||||
expect(params.get('fecha')).toBe('2023-02-12')
|
||||
expect(params.get('hora')).toBe('00:00')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'), 'utf8')
|
||||
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(21)
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-02-12T09:30:00.000Z',
|
||||
stop: '2023-02-12T10:30:00.000Z',
|
||||
title: 'Revista agropecuaria',
|
||||
icon: 'https://www.reportv.com.ar/buscador/img/Programas/2797844.jpg',
|
||||
categories: []
|
||||
})
|
||||
|
||||
expect(results[4]).toMatchObject({
|
||||
start: '2023-02-12T12:30:00.000Z',
|
||||
stop: '2023-02-12T13:30:00.000Z',
|
||||
title: 'De pago en pago',
|
||||
icon: 'https://www.reportv.com.ar/buscador/img/Programas/3772835.jpg',
|
||||
categories: ['Cultural']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8')
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
// npm run channels:parse -- --config=./sites/cableplus.com.uy/cableplus.com.uy.config.js --output=./sites/cableplus.com.uy/cableplus.com.uy.channels.xml
|
||||
// npm run grab -- --site=cableplus.com.uy
|
||||
|
||||
const { parser, url, request } = require('./cableplus.com.uy.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-02-12', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '2035',
|
||||
xmltv_id: 'APlusV.uy'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url).toBe('https://www.reportv.com.ar/finder/channel')
|
||||
})
|
||||
|
||||
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; charset=UTF-8'
|
||||
})
|
||||
})
|
||||
|
||||
it('can generate valid request data', () => {
|
||||
const params = request.data({ date, channel })
|
||||
|
||||
expect(params.get('idAlineacion')).toBe('3017')
|
||||
expect(params.get('idSenial')).toBe('2035')
|
||||
expect(params.get('fecha')).toBe('2023-02-12')
|
||||
expect(params.get('hora')).toBe('00:00')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'), 'utf8')
|
||||
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(21)
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-02-12T09:30:00.000Z',
|
||||
stop: '2023-02-12T10:30:00.000Z',
|
||||
title: 'Revista agropecuaria',
|
||||
icon: 'https://www.reportv.com.ar/buscador/img/Programas/2797844.jpg',
|
||||
categories: []
|
||||
})
|
||||
|
||||
expect(results[4]).toMatchObject({
|
||||
start: '2023-02-12T12:30:00.000Z',
|
||||
stop: '2023-02-12T13:30:00.000Z',
|
||||
title: 'De pago en pago',
|
||||
icon: 'https://www.reportv.com.ar/buscador/img/Programas/3772835.jpg',
|
||||
categories: ['Cultural']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8')
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue