mirror of
https://github.com/iptv-org/epg
synced 2026-05-01 23:17:00 -04:00
Fix linter issues in sites/
This commit is contained in:
@@ -1,101 +1,105 @@
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
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: '<!DOCTYPE html><html><head></head><body></body></html>'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
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: '<!DOCTYPE html><html><head></head><body></body></html>'
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user