mirror of
https://github.com/iptv-org/epg
synced 2026-04-30 22:46:58 -04:00
Fixes linter errors
This commit is contained in:
@@ -1,117 +1,117 @@
|
||||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
const { DateTime } = require('luxon')
|
||||
|
||||
module.exports = {
|
||||
site: 'superguidatv.it',
|
||||
days: 3,
|
||||
url({ channel, date }) {
|
||||
let diff = date.diff(DateTime.now().toUTC().startOf('day'), 'd')
|
||||
let day = {
|
||||
0: 'oggi',
|
||||
1: 'domani',
|
||||
2: 'dopodomani'
|
||||
}
|
||||
|
||||
return `https://www.superguidatv.it/programmazione-canale/${day[diff]}/guida-programmi-tv-${channel.site_id}/`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart($item, date)
|
||||
if (prev) {
|
||||
if (start < prev.start) {
|
||||
start = start.plus({ days: 1 })
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.plus({ minutes: 30 })
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
category: parseCategory($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const providers = [
|
||||
'',
|
||||
'premium/',
|
||||
'sky-intrattenimento/',
|
||||
'sky-sport/',
|
||||
'sky-cinema/',
|
||||
'sky-doc-e-lifestyle/',
|
||||
'sky-news/',
|
||||
'sky-bambini/',
|
||||
'sky-musica/',
|
||||
'sky-primafila/',
|
||||
'dazn/',
|
||||
'rsi/'
|
||||
]
|
||||
const promises = providers.map(p => axios.get(`https://www.superguidatv.it/canali/${p}`))
|
||||
|
||||
const channels = []
|
||||
await Promise.all(promises)
|
||||
.then(responses => {
|
||||
responses.forEach(r => {
|
||||
const $ = cheerio.load(r.data)
|
||||
|
||||
$('.sgtvchannellist_mainContainer .sgtvchannel_divCell a').each((i, link) => {
|
||||
let [, site_id] = $(link)
|
||||
.attr('href')
|
||||
.match(/guida-programmi-tv-(.*)\/$/) || [null, null]
|
||||
let name = $(link).find('.pchannel').text().trim()
|
||||
|
||||
channels.push({
|
||||
lang: 'it',
|
||||
site_id,
|
||||
name
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(console.log)
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const hours = $item('.sgtvchannelplan_hoursCell')
|
||||
.clone()
|
||||
.children('.sgtvOnairSpan')
|
||||
.remove()
|
||||
.end()
|
||||
.text()
|
||||
.trim()
|
||||
|
||||
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${hours}`, 'yyyy-MM-dd HH:mm', {
|
||||
zone: 'Europe/Rome'
|
||||
}).toUTC()
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.sgtvchannelplan_spanInfoNextSteps').text().trim()
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
const eventType = $item('.sgtvchannelplan_spanEventType').text().trim()
|
||||
const [, category] = eventType.match(/(^[^(]+)/) || [null, '']
|
||||
|
||||
return category.trim()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('.sgtvchannelplan_divContainer > .sgtvchannelplan_divTableRow')
|
||||
.has('#containerInfoEvent')
|
||||
.toArray()
|
||||
}
|
||||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
const { DateTime } = require('luxon')
|
||||
|
||||
module.exports = {
|
||||
site: 'superguidatv.it',
|
||||
days: 3,
|
||||
url({ channel, date }) {
|
||||
let diff = date.diff(DateTime.now().toUTC().startOf('day'), 'd')
|
||||
let day = {
|
||||
0: 'oggi',
|
||||
1: 'domani',
|
||||
2: 'dopodomani'
|
||||
}
|
||||
|
||||
return `https://www.superguidatv.it/programmazione-canale/${day[diff]}/guida-programmi-tv-${channel.site_id}/`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart($item, date)
|
||||
if (prev) {
|
||||
if (start < prev.start) {
|
||||
start = start.plus({ days: 1 })
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.plus({ minutes: 30 })
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
category: parseCategory($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const providers = [
|
||||
'',
|
||||
'premium/',
|
||||
'sky-intrattenimento/',
|
||||
'sky-sport/',
|
||||
'sky-cinema/',
|
||||
'sky-doc-e-lifestyle/',
|
||||
'sky-news/',
|
||||
'sky-bambini/',
|
||||
'sky-musica/',
|
||||
'sky-primafila/',
|
||||
'dazn/',
|
||||
'rsi/'
|
||||
]
|
||||
const promises = providers.map(p => axios.get(`https://www.superguidatv.it/canali/${p}`))
|
||||
|
||||
const channels = []
|
||||
await Promise.all(promises)
|
||||
.then(responses => {
|
||||
responses.forEach(r => {
|
||||
const $ = cheerio.load(r.data)
|
||||
|
||||
$('.sgtvchannellist_mainContainer .sgtvchannel_divCell a').each((i, link) => {
|
||||
let [, site_id] = $(link)
|
||||
.attr('href')
|
||||
.match(/guida-programmi-tv-(.*)\/$/) || [null, null]
|
||||
let name = $(link).find('.pchannel').text().trim()
|
||||
|
||||
channels.push({
|
||||
lang: 'it',
|
||||
site_id,
|
||||
name
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(console.log)
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const hours = $item('.sgtvchannelplan_hoursCell')
|
||||
.clone()
|
||||
.children('.sgtvOnairSpan')
|
||||
.remove()
|
||||
.end()
|
||||
.text()
|
||||
.trim()
|
||||
|
||||
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${hours}`, 'yyyy-MM-dd HH:mm', {
|
||||
zone: 'Europe/Rome'
|
||||
}).toUTC()
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.sgtvchannelplan_spanInfoNextSteps').text().trim()
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
const eventType = $item('.sgtvchannelplan_spanEventType').text().trim()
|
||||
const [, category] = eventType.match(/(^[^(]+)/) || [null, '']
|
||||
|
||||
return category.trim()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('.sgtvchannelplan_divContainer > .sgtvchannelplan_divTableRow')
|
||||
.has('#containerInfoEvent')
|
||||
.toArray()
|
||||
}
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
// npm run channels:parse -- --config=sites/superguidatv.it/superguidatv.it.config.js --output=sites/superguidatv.it/superguidatv.it.channels.xml
|
||||
// npm run grab -- --site=superguidatv.it
|
||||
|
||||
const { parser, url } = require('./superguidatv.it.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-01-11', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'virgin-radio/461',
|
||||
xmltv_id: 'VirginRadioTV.it'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date: dayjs.utc().startOf('d') })).toBe(
|
||||
'https://www.superguidatv.it/programmazione-canale/oggi/guida-programmi-tv-virgin-radio/461/'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for tomorrow', () => {
|
||||
expect(url({ channel, date: dayjs.utc().startOf('d').add(1, 'd') })).toBe(
|
||||
'https://www.superguidatv.it/programmazione-canale/domani/guida-programmi-tv-virgin-radio/461/'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for after tomorrow', () => {
|
||||
expect(url({ channel, date: dayjs.utc().startOf('d').add(2, 'd') })).toBe(
|
||||
'https://www.superguidatv.it/programmazione-canale/dopodomani/guida-programmi-tv-virgin-radio/461/'
|
||||
)
|
||||
})
|
||||
|
||||
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[0]).toMatchObject({
|
||||
start: '2023-01-11T01:00:00.000Z',
|
||||
stop: '2023-01-11T05:00:00.000Z',
|
||||
title: 'All Nite Rock',
|
||||
category: 'Musica'
|
||||
})
|
||||
|
||||
expect(results[13]).toMatchObject({
|
||||
start: '2023-01-12T05:00:00.000Z',
|
||||
stop: '2023-01-12T05:30:00.000Z',
|
||||
title: 'Free Rock',
|
||||
category: 'Musica'
|
||||
})
|
||||
})
|
||||
|
||||
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/superguidatv.it/superguidatv.it.config.js --output=sites/superguidatv.it/superguidatv.it.channels.xml
|
||||
// npm run grab -- --site=superguidatv.it
|
||||
|
||||
const { parser, url } = require('./superguidatv.it.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-01-11', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'virgin-radio/461',
|
||||
xmltv_id: 'VirginRadioTV.it'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date: dayjs.utc().startOf('d') })).toBe(
|
||||
'https://www.superguidatv.it/programmazione-canale/oggi/guida-programmi-tv-virgin-radio/461/'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for tomorrow', () => {
|
||||
expect(url({ channel, date: dayjs.utc().startOf('d').add(1, 'd') })).toBe(
|
||||
'https://www.superguidatv.it/programmazione-canale/domani/guida-programmi-tv-virgin-radio/461/'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for after tomorrow', () => {
|
||||
expect(url({ channel, date: dayjs.utc().startOf('d').add(2, 'd') })).toBe(
|
||||
'https://www.superguidatv.it/programmazione-canale/dopodomani/guida-programmi-tv-virgin-radio/461/'
|
||||
)
|
||||
})
|
||||
|
||||
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[0]).toMatchObject({
|
||||
start: '2023-01-11T01:00:00.000Z',
|
||||
stop: '2023-01-11T05:00:00.000Z',
|
||||
title: 'All Nite Rock',
|
||||
category: 'Musica'
|
||||
})
|
||||
|
||||
expect(results[13]).toMatchObject({
|
||||
start: '2023-01-12T05:00:00.000Z',
|
||||
stop: '2023-01-12T05:30:00.000Z',
|
||||
title: 'Free Rock',
|
||||
category: 'Musica'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8')
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user