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 dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
dayjs.extend(utc)
|
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(customParseFormat)
|
||||||
module.exports = {
|
dayjs.extend(timezone)
|
||||||
site: 'mediaset.it',
|
|
||||||
days: 2,
|
module.exports = {
|
||||||
url: function ({ date, channel }) {
|
site: 'mediaset.it',
|
||||||
return `http://www.mediaset.it/guidatv/inc/canali/${date.format('YYYYMM')}/${date.format(
|
days: 2,
|
||||||
'YYYYMMDD'
|
url: function ({ date, channel }) {
|
||||||
)}_${channel.site_id}.sjson`
|
return `http://www.mediaset.it/guidatv/inc/canali/${date.format('YYYYMM')}/${date.format(
|
||||||
},
|
'YYYYMMDD'
|
||||||
parser: function ({ content, date }) {
|
)}_${channel.site_id}.sjson`
|
||||||
const programs = []
|
},
|
||||||
const data = JSON.parse(content)
|
parser: function ({ content, date }) {
|
||||||
if (!data.events) return programs
|
const programs = []
|
||||||
|
const items = getItems(content)
|
||||||
data.events.forEach(item => {
|
|
||||||
if (item.title && item.startTime && item.endTime) {
|
items.forEach(item => {
|
||||||
const start = dayjs
|
if (item.title && item.startTime && item.duration) {
|
||||||
.utc(item.startTime, 'HH:mm')
|
const start = parseStart(item, date)
|
||||||
.set('D', date.get('D'))
|
const duration = parseInt(item.duration)
|
||||||
.set('M', date.get('M'))
|
const stop = start.add(duration, 'm')
|
||||||
.set('y', date.get('y'))
|
|
||||||
.toString()
|
programs.push({
|
||||||
|
title: item.displayTitle || item.title,
|
||||||
const stop = dayjs
|
description: item.description,
|
||||||
.utc(item.endTime, 'HH:mm')
|
category: item.genere,
|
||||||
.set('D', date.get('D'))
|
start,
|
||||||
.set('M', date.get('M'))
|
stop
|
||||||
.set('y', date.get('y'))
|
})
|
||||||
.toString()
|
}
|
||||||
|
})
|
||||||
programs.push({
|
|
||||||
title: item.displayTitle || item.title,
|
return programs
|
||||||
description: item.description,
|
}
|
||||||
category: item.genere,
|
}
|
||||||
start,
|
|
||||||
stop
|
function parseStart(item, date) {
|
||||||
})
|
return dayjs.tz(
|
||||||
}
|
`${date.format('YYYY-MM-DD')} ${item.startTime}`,
|
||||||
})
|
'YYYY-MM-DD HH:mm',
|
||||||
|
'Europe/Rome'
|
||||||
return programs
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
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