mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Merge pull request #2185 from Sicilykill/issue_2184
Fixes issue reported in #2184
This commit is contained in:
commit
d309a4acd9
4 changed files with 117 additions and 49 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>
|
|
@ -1,49 +1,59 @@
|
|||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'mediaset.it',
|
||||
days: 2,
|
||||
url: function ({ date, channel }) {
|
||||
return `http://www.mediaset.it/guidatv/inc/canali/${date.format('YYYYMM')}/${date.format(
|
||||
'YYYYMMDD'
|
||||
)}_${channel.site_id}.sjson`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
const programs = []
|
||||
const data = JSON.parse(content)
|
||||
if (!data.events) return programs
|
||||
|
||||
data.events.forEach(item => {
|
||||
if (item.title && item.startTime && item.endTime) {
|
||||
const start = dayjs
|
||||
.utc(item.startTime, 'HH:mm')
|
||||
.set('D', date.get('D'))
|
||||
.set('M', date.get('M'))
|
||||
.set('y', date.get('y'))
|
||||
.toString()
|
||||
|
||||
const stop = dayjs
|
||||
.utc(item.endTime, 'HH:mm')
|
||||
.set('D', date.get('D'))
|
||||
.set('M', date.get('M'))
|
||||
.set('y', date.get('y'))
|
||||
.toString()
|
||||
|
||||
programs.push({
|
||||
title: item.displayTitle || item.title,
|
||||
description: item.description,
|
||||
category: item.genere,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
module.exports = {
|
||||
site: 'mediaset.it',
|
||||
days: 2,
|
||||
url: function ({ date, channel }) {
|
||||
return `http://www.mediaset.it/guidatv/inc/canali/${date.format('YYYYMM')}/${date.format(
|
||||
'YYYYMMDD'
|
||||
)}_${channel.site_id}.sjson`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
const programs = []
|
||||
const items = getItems(content)
|
||||
|
||||
items.forEach(item => {
|
||||
if (item.title && item.startTime && item.duration) {
|
||||
const start = parseStart(item, date)
|
||||
const duration = parseInt(item.duration)
|
||||
const stop = start.add(duration, 'm')
|
||||
|
||||
programs.push({
|
||||
title: item.displayTitle || item.title,
|
||||
description: item.description,
|
||||
category: item.genere,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
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