mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 09:30:06 -04:00
Add a test
This commit is contained in:
parent
47b06eb9f3
commit
9f811c9497
4 changed files with 76 additions and 4 deletions
2
sites/mediaset.it/__data__/content.json
Normal file
2
sites/mediaset.it/__data__/content.json
Normal file
File diff suppressed because one or more lines are too long
10
sites/mediaset.it/__data__/no_content.html
Normal file
10
sites/mediaset.it/__data__/no_content.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>301 Moved Permanently</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Moved Permanently</h1>
|
||||
<p>The document has moved <a href="https://mediasetinfinity.mediaset.it/">here</a>.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -17,10 +17,9 @@ module.exports = {
|
|||
},
|
||||
parser: function ({ content, date }) {
|
||||
const programs = []
|
||||
const data = JSON.parse(content)
|
||||
if (!data.events) return programs
|
||||
const items = getItems(content)
|
||||
|
||||
data.events.forEach(item => {
|
||||
items.forEach(item => {
|
||||
if (item.title && item.startTime && item.duration) {
|
||||
const start = parseStart(item, date)
|
||||
const duration = parseInt(item.duration)
|
||||
|
@ -41,5 +40,20 @@ module.exports = {
|
|||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${item.startTime}`, 'YYYY-MM-DD HH:mm', 'Europe/Rome')
|
||||
return dayjs.tz(
|
||||
`${date.format('YYYY-MM-DD')} ${item.startTime}`,
|
||||
'YYYY-MM-DD HH:mm',
|
||||
'Europe/Rome'
|
||||
)
|
||||
}
|
||||
|
||||
function getItems(content) {
|
||||
let data
|
||||
try {
|
||||
data = JSON.parse(content)
|
||||
} catch (err) {
|
||||
return []
|
||||
}
|
||||
|
||||
return data && Array.isArray(data.events) ? data.events : []
|
||||
}
|
||||
|
|
46
sites/mediaset.it/mediaset.it.test.js
Normal file
46
sites/mediaset.it/mediaset.it.test.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
// npm run grab -- --site=mediaset.it
|
||||
|
||||
const { parser, url } = require('./mediaset.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-10-20', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'LB',
|
||||
xmltv_id: '20.it'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'http://www.mediaset.it/guidatv/inc/canali/202310/20231020_LB.sjson'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'), 'utf8')
|
||||
const results = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-10-20T04:10:00.000Z',
|
||||
stop: '2023-10-20T05:07:00.000Z',
|
||||
title: 'Showreel',
|
||||
description: 'INTRATTENIMENTO 15 - Italia, 2023',
|
||||
category: 'INTRATTENIMENTO'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
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