Fixes linter errors

This commit is contained in:
freearhey
2023-10-15 14:08:23 +03:00
parent 57e508fc3b
commit 63c86a2b30
393 changed files with 28447 additions and 28443 deletions

View File

@@ -1,100 +1,100 @@
const axios = require('axios')
const cheerio = require('cheerio')
const url = require('url')
const path = require('path')
const { DateTime } = require('luxon')
module.exports = {
site: 'gatotv.com',
days: 2,
url({ channel, date }) {
return `https://www.gatotv.com/canal/${channel.site_id}/${date.format('YYYY-MM-DD')}`
},
parser({ content, date }) {
let programs = []
const items = parseItems(content)
date = date.subtract(1, 'd')
items.forEach((item, i) => {
const $item = cheerio.load(item)
let start = parseStart($item, date)
if (i === 0 && start.hour >= 5) {
start = start.plus({ days: 1 })
date = date.add(1, 'd')
}
let stop = parseStop($item, date)
if (stop < start) {
stop = stop.plus({ days: 1 })
date = date.add(1, 'd')
}
programs.push({
title: parseTitle($item),
description: parseDescription($item),
icon: parseIcon($item),
start,
stop
})
})
return programs
},
async channels() {
const data = await axios
.get('https://www.gatotv.com/guia_tv/completa')
.then(response => response.data)
.catch(console.log)
const $ = cheerio.load(data)
const items = $('.tbl_EPG_row,.tbl_EPG_rowAlternate').toArray()
return items.map(item => {
const $item = cheerio.load(item)
const link = $item('td:nth-child(1) > div:nth-child(2) > a:nth-child(3)').attr('href')
const parsed = url.parse(link)
return {
lang: 'es',
site_id: path.basename(parsed.pathname),
name: $item('td:nth-child(1) > div:nth-child(2) > a:nth-child(3)').text()
}
})
}
}
function parseTitle($item) {
return $item('td:nth-child(4) > div > div > a > span,td:nth-child(3) > div > div > span,td:nth-child(3) > div > div > a > span').text()
}
function parseDescription($item) {
return $item('td:nth-child(4) > div').clone().children().remove().end().text().trim()
}
function parseIcon($item) {
return $item('td:nth-child(3) > a > img').attr('src')
}
function parseStart($item, date) {
const time = $item('td:nth-child(1) > div > time').attr('datetime')
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
zone: 'EST'
}).toUTC()
}
function parseStop($item, date) {
const time = $item('td:nth-child(2) > div > time').attr('datetime')
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
zone: 'EST'
}).toUTC()
}
function parseItems(content) {
const $ = cheerio.load(content)
return $(
'body > div.div_content > table:nth-child(8) > tbody > tr:nth-child(2) > td:nth-child(1) > table.tbl_EPG'
)
.find('.tbl_EPG_row,.tbl_EPG_rowAlternate,.tbl_EPG_row_selected')
.toArray()
}
const axios = require('axios')
const cheerio = require('cheerio')
const url = require('url')
const path = require('path')
const { DateTime } = require('luxon')
module.exports = {
site: 'gatotv.com',
days: 2,
url({ channel, date }) {
return `https://www.gatotv.com/canal/${channel.site_id}/${date.format('YYYY-MM-DD')}`
},
parser({ content, date }) {
let programs = []
const items = parseItems(content)
date = date.subtract(1, 'd')
items.forEach((item, i) => {
const $item = cheerio.load(item)
let start = parseStart($item, date)
if (i === 0 && start.hour >= 5) {
start = start.plus({ days: 1 })
date = date.add(1, 'd')
}
let stop = parseStop($item, date)
if (stop < start) {
stop = stop.plus({ days: 1 })
date = date.add(1, 'd')
}
programs.push({
title: parseTitle($item),
description: parseDescription($item),
icon: parseIcon($item),
start,
stop
})
})
return programs
},
async channels() {
const data = await axios
.get('https://www.gatotv.com/guia_tv/completa')
.then(response => response.data)
.catch(console.log)
const $ = cheerio.load(data)
const items = $('.tbl_EPG_row,.tbl_EPG_rowAlternate').toArray()
return items.map(item => {
const $item = cheerio.load(item)
const link = $item('td:nth-child(1) > div:nth-child(2) > a:nth-child(3)').attr('href')
const parsed = url.parse(link)
return {
lang: 'es',
site_id: path.basename(parsed.pathname),
name: $item('td:nth-child(1) > div:nth-child(2) > a:nth-child(3)').text()
}
})
}
}
function parseTitle($item) {
return $item('td:nth-child(4) > div > div > a > span,td:nth-child(3) > div > div > span,td:nth-child(3) > div > div > a > span').text()
}
function parseDescription($item) {
return $item('td:nth-child(4) > div').clone().children().remove().end().text().trim()
}
function parseIcon($item) {
return $item('td:nth-child(3) > a > img').attr('src')
}
function parseStart($item, date) {
const time = $item('td:nth-child(1) > div > time').attr('datetime')
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
zone: 'EST'
}).toUTC()
}
function parseStop($item, date) {
const time = $item('td:nth-child(2) > div > time').attr('datetime')
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
zone: 'EST'
}).toUTC()
}
function parseItems(content) {
const $ = cheerio.load(content)
return $(
'body > div.div_content > table:nth-child(8) > tbody > tr:nth-child(2) > td:nth-child(1) > table.tbl_EPG'
)
.find('.tbl_EPG_row,.tbl_EPG_rowAlternate,.tbl_EPG_row_selected')
.toArray()
}

View File

@@ -1,82 +1,82 @@
// npm run channels:parse -- --config=./sites/gatotv.com/gatotv.com.config.js --output=./sites/gatotv.com/gatotv.com.channels.xml
// npm run grab -- --site=gatotv.com
const { parser, url } = require('./gatotv.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)
let date = dayjs.utc('2023-06-13', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'm_0',
xmltv_id: '0porMovistarPlus.es'
}
it('can generate valid url', () => {
expect(url({ channel, date })).toBe('https://www.gatotv.com/canal/m_0/2023-06-13')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_0.html'), 'utf8')
const results = parser({ date, channel, content }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2023-06-13T04:30:00.000Z',
stop: '2023-06-13T05:32:00.000Z',
title: 'Supergarcía'
})
expect(results[1]).toMatchObject({
start: '2023-06-13T05:32:00.000Z',
stop: '2023-06-13T06:59:00.000Z',
title: 'La resistencia'
})
expect(results[25]).toMatchObject({
start: '2023-06-14T04:46:00.000Z',
stop: '2023-06-14T05:00:00.000Z',
title: 'Una familia absolutamente normal'
})
})
it('can parse response when the guide starts from midnight', () => {
date = date.add(1, 'd')
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_1.html'), 'utf8')
const results = parser({ date, channel, content }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2023-06-14T05:00:00.000Z',
stop: '2023-06-14T05:32:00.000Z',
title: 'Ilustres Ignorantes'
})
expect(results[26]).toMatchObject({
start: '2023-06-15T04:30:00.000Z',
stop: '2023-06-15T05:30:00.000Z',
title: 'Showriano'
})
})
it('can handle empty guide', () => {
const results = parser({
date,
channel,
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8')
})
expect(results).toMatchObject([])
})
// npm run channels:parse -- --config=./sites/gatotv.com/gatotv.com.config.js --output=./sites/gatotv.com/gatotv.com.channels.xml
// npm run grab -- --site=gatotv.com
const { parser, url } = require('./gatotv.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)
let date = dayjs.utc('2023-06-13', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'm_0',
xmltv_id: '0porMovistarPlus.es'
}
it('can generate valid url', () => {
expect(url({ channel, date })).toBe('https://www.gatotv.com/canal/m_0/2023-06-13')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_0.html'), 'utf8')
const results = parser({ date, channel, content }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2023-06-13T04:30:00.000Z',
stop: '2023-06-13T05:32:00.000Z',
title: 'Supergarcía'
})
expect(results[1]).toMatchObject({
start: '2023-06-13T05:32:00.000Z',
stop: '2023-06-13T06:59:00.000Z',
title: 'La resistencia'
})
expect(results[25]).toMatchObject({
start: '2023-06-14T04:46:00.000Z',
stop: '2023-06-14T05:00:00.000Z',
title: 'Una familia absolutamente normal'
})
})
it('can parse response when the guide starts from midnight', () => {
date = date.add(1, 'd')
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_1.html'), 'utf8')
const results = parser({ date, channel, content }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2023-06-14T05:00:00.000Z',
stop: '2023-06-14T05:32:00.000Z',
title: 'Ilustres Ignorantes'
})
expect(results[26]).toMatchObject({
start: '2023-06-15T04:30:00.000Z',
stop: '2023-06-15T05:30:00.000Z',
title: 'Showriano'
})
})
it('can handle empty guide', () => {
const results = parser({
date,
channel,
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8')
})
expect(results).toMatchObject([])
})