mirror of
https://github.com/iptv-org/epg
synced 2026-05-01 06:56:59 -04:00
Fixes linter errors
This commit is contained in:
@@ -1,95 +1,95 @@
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
const { DateTime } = require('luxon')
|
||||
|
||||
module.exports = {
|
||||
site: 'entertainment.ie',
|
||||
days: 2,
|
||||
url: function ({ date, channel }) {
|
||||
return `https://entertainment.ie/tv/${channel.site_id}/?date=${date.format(
|
||||
'DD-MM-YYYY'
|
||||
)}&time=all-day`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date)
|
||||
if (!start) return
|
||||
if (prev && start < prev.start) {
|
||||
start = start.plus({ days: 1 })
|
||||
}
|
||||
const duration = parseDuration($item)
|
||||
const stop = start.plus({ minutes: duration })
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
categories: parseCategories($item),
|
||||
icon: parseIcon($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://entertainment.ie/tv/all-channels/')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
const $ = cheerio.load(data)
|
||||
let channels = $('.tv-filter-container > tv-filter').attr(':channels')
|
||||
channels = JSON.parse(channels)
|
||||
|
||||
return channels.map(c => {
|
||||
return {
|
||||
site_id: c.slug,
|
||||
name: c.name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
return $item('.text-holder > .btn-hold > .btn-wrap > a.btn-share').data('img')
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.text-holder h3').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.text-holder > .btn-hold > .btn-wrap > a.btn-share').data('description')
|
||||
}
|
||||
|
||||
function parseCategories($item) {
|
||||
const genres = $item('.text-holder > .btn-hold > .btn-wrap > a.btn-share').data('genres')
|
||||
|
||||
return genres ? genres.split(', ') : []
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
let d = $item('.text-holder > .btn-hold > .btn-wrap > a.btn-share').data('time')
|
||||
let [, time] = d ? d.split(', ') : [null, null]
|
||||
|
||||
return time
|
||||
? DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
|
||||
zone: 'UTC'
|
||||
}).toUTC()
|
||||
: null
|
||||
}
|
||||
|
||||
function parseDuration($item) {
|
||||
const duration = $item('.text-holder > .btn-hold > .btn-wrap > a.btn-share').data('duration')
|
||||
|
||||
return parseInt(duration)
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('.info-list > li').toArray()
|
||||
}
|
||||
const axios = require('axios')
|
||||
const cheerio = require('cheerio')
|
||||
const { DateTime } = require('luxon')
|
||||
|
||||
module.exports = {
|
||||
site: 'entertainment.ie',
|
||||
days: 2,
|
||||
url: function ({ date, channel }) {
|
||||
return `https://entertainment.ie/tv/${channel.site_id}/?date=${date.format(
|
||||
'DD-MM-YYYY'
|
||||
)}&time=all-day`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date)
|
||||
if (!start) return
|
||||
if (prev && start < prev.start) {
|
||||
start = start.plus({ days: 1 })
|
||||
}
|
||||
const duration = parseDuration($item)
|
||||
const stop = start.plus({ minutes: duration })
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
categories: parseCategories($item),
|
||||
icon: parseIcon($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://entertainment.ie/tv/all-channels/')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
const $ = cheerio.load(data)
|
||||
let channels = $('.tv-filter-container > tv-filter').attr(':channels')
|
||||
channels = JSON.parse(channels)
|
||||
|
||||
return channels.map(c => {
|
||||
return {
|
||||
site_id: c.slug,
|
||||
name: c.name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
return $item('.text-holder > .btn-hold > .btn-wrap > a.btn-share').data('img')
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.text-holder h3').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.text-holder > .btn-hold > .btn-wrap > a.btn-share').data('description')
|
||||
}
|
||||
|
||||
function parseCategories($item) {
|
||||
const genres = $item('.text-holder > .btn-hold > .btn-wrap > a.btn-share').data('genres')
|
||||
|
||||
return genres ? genres.split(', ') : []
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
let d = $item('.text-holder > .btn-hold > .btn-wrap > a.btn-share').data('time')
|
||||
let [, time] = d ? d.split(', ') : [null, null]
|
||||
|
||||
return time
|
||||
? DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
|
||||
zone: 'UTC'
|
||||
}).toUTC()
|
||||
: null
|
||||
}
|
||||
|
||||
function parseDuration($item) {
|
||||
const duration = $item('.text-holder > .btn-hold > .btn-wrap > a.btn-share').data('duration')
|
||||
|
||||
return parseInt(duration)
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('.info-list > li').toArray()
|
||||
}
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
// npm run channels:parse -- --config=./sites/entertainment.ie/entertainment.ie.config.js --output=./sites/entertainment.ie/entertainment.ie.channels.xml
|
||||
// npm run grab -- --site=entertainment.ie
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { parser, url } = require('./entertainment.ie.config.js')
|
||||
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-06-29', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = { site_id: 'rte2', xmltv_id: 'RTE2.ie' }
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://entertainment.ie/tv/rte2/?date=29-06-2023&time=all-day'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ date, content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(51)
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-06-29T06:00:00.000Z',
|
||||
stop: '2023-06-29T08:00:00.000Z',
|
||||
title: 'EuroNews',
|
||||
description: 'European and international headlines live via satellite',
|
||||
icon: 'https://img.resized.co/entertainment/eyJkYXRhIjoie1widXJsXCI6XCJodHRwczpcXFwvXFxcL3R2LmFzc2V0cy5wcmVzc2Fzc29jaWF0aW9uLmlvXFxcLzcxZDdkYWY2LWQxMjItNTliYy1iMGRjLTFkMjc2ODg1MzhkNC5qcGdcIixcIndpZHRoXCI6NDgwLFwiaGVpZ2h0XCI6Mjg4LFwiZGVmYXVsdFwiOlwiaHR0cHM6XFxcL1xcXC9lbnRlcnRhaW5tZW50LmllXFxcL2ltYWdlc1xcXC9uby1pbWFnZS5wbmdcIn0iLCJoYXNoIjoiZDhjYzA0NzFhMGZhOTI1Yjc5ODI0M2E3OWZjMGI2ZGJmMDIxMjllNyJ9/71d7daf6-d122-59bc-b0dc-1d27688538d4.jpg',
|
||||
categories: ['Factual']
|
||||
})
|
||||
|
||||
expect(results[50]).toMatchObject({
|
||||
start: '2023-06-30T02:25:00.000Z',
|
||||
stop: '2023-06-30T06:00:00.000Z',
|
||||
title: 'EuroNews',
|
||||
description: 'European and international headlines live via satellite',
|
||||
icon: 'https://img.resized.co/entertainment/eyJkYXRhIjoie1widXJsXCI6XCJodHRwczpcXFwvXFxcL3R2LmFzc2V0cy5wcmVzc2Fzc29jaWF0aW9uLmlvXFxcLzcxZDdkYWY2LWQxMjItNTliYy1iMGRjLTFkMjc2ODg1MzhkNC5qcGdcIixcIndpZHRoXCI6NDgwLFwiaGVpZ2h0XCI6Mjg4LFwiZGVmYXVsdFwiOlwiaHR0cHM6XFxcL1xcXC9lbnRlcnRhaW5tZW50LmllXFxcL2ltYWdlc1xcXC9uby1pbWFnZS5wbmdcIn0iLCJoYXNoIjoiZDhjYzA0NzFhMGZhOTI1Yjc5ODI0M2E3OWZjMGI2ZGJmMDIxMjllNyJ9/71d7daf6-d122-59bc-b0dc-1d27688538d4.jpg',
|
||||
categories: ['Factual']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no-content.html'))
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
// npm run channels:parse -- --config=./sites/entertainment.ie/entertainment.ie.config.js --output=./sites/entertainment.ie/entertainment.ie.channels.xml
|
||||
// npm run grab -- --site=entertainment.ie
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { parser, url } = require('./entertainment.ie.config.js')
|
||||
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-06-29', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = { site_id: 'rte2', xmltv_id: 'RTE2.ie' }
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://entertainment.ie/tv/rte2/?date=29-06-2023&time=all-day'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ date, content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(51)
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-06-29T06:00:00.000Z',
|
||||
stop: '2023-06-29T08:00:00.000Z',
|
||||
title: 'EuroNews',
|
||||
description: 'European and international headlines live via satellite',
|
||||
icon: 'https://img.resized.co/entertainment/eyJkYXRhIjoie1widXJsXCI6XCJodHRwczpcXFwvXFxcL3R2LmFzc2V0cy5wcmVzc2Fzc29jaWF0aW9uLmlvXFxcLzcxZDdkYWY2LWQxMjItNTliYy1iMGRjLTFkMjc2ODg1MzhkNC5qcGdcIixcIndpZHRoXCI6NDgwLFwiaGVpZ2h0XCI6Mjg4LFwiZGVmYXVsdFwiOlwiaHR0cHM6XFxcL1xcXC9lbnRlcnRhaW5tZW50LmllXFxcL2ltYWdlc1xcXC9uby1pbWFnZS5wbmdcIn0iLCJoYXNoIjoiZDhjYzA0NzFhMGZhOTI1Yjc5ODI0M2E3OWZjMGI2ZGJmMDIxMjllNyJ9/71d7daf6-d122-59bc-b0dc-1d27688538d4.jpg',
|
||||
categories: ['Factual']
|
||||
})
|
||||
|
||||
expect(results[50]).toMatchObject({
|
||||
start: '2023-06-30T02:25:00.000Z',
|
||||
stop: '2023-06-30T06:00:00.000Z',
|
||||
title: 'EuroNews',
|
||||
description: 'European and international headlines live via satellite',
|
||||
icon: 'https://img.resized.co/entertainment/eyJkYXRhIjoie1widXJsXCI6XCJodHRwczpcXFwvXFxcL3R2LmFzc2V0cy5wcmVzc2Fzc29jaWF0aW9uLmlvXFxcLzcxZDdkYWY2LWQxMjItNTliYy1iMGRjLTFkMjc2ODg1MzhkNC5qcGdcIixcIndpZHRoXCI6NDgwLFwiaGVpZ2h0XCI6Mjg4LFwiZGVmYXVsdFwiOlwiaHR0cHM6XFxcL1xcXC9lbnRlcnRhaW5tZW50LmllXFxcL2ltYWdlc1xcXC9uby1pbWFnZS5wbmdcIn0iLCJoYXNoIjoiZDhjYzA0NzFhMGZhOTI1Yjc5ODI0M2E3OWZjMGI2ZGJmMDIxMjllNyJ9/71d7daf6-d122-59bc-b0dc-1d27688538d4.jpg',
|
||||
categories: ['Factual']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no-content.html'))
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user