Merge pull request #2313 from Sicilykill/issue_2312

Resolves #2312
This commit is contained in:
PopeyeTheSai10r 2024-02-05 06:12:28 -08:00 committed by GitHub
commit 58987b81a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 35 additions and 57 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,10 +0,0 @@
<!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>

View file

@ -12,4 +12,5 @@
<channel site="mediasetinfinity.mediaset.it" lang="it" xmltv_id="MediasetExtra.it" site_id="KQ">Mediaset Extra</channel>
<channel site="mediasetinfinity.mediaset.it" lang="it" xmltv_id="Rete4.it" site_id="R4">Rete 4</channel>
<channel site="mediasetinfinity.mediaset.it" lang="it" xmltv_id="TopCrime.it" site_id="LT">Top Crime</channel>
</channels>
<channel site="mediasetinfinity.mediaset.it" lang="it" xmltv_id="TGCom24.it" site_id="KF">TGCom 24</channel>
</channels>

View file

@ -11,49 +11,40 @@ module.exports = {
site: 'mediasetinfinity.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`
// Get the epoch timestamp
const todayEpoch = date.startOf('day').utc().valueOf();
// Get the epoch timestamp for the next day
const nextDayEpoch = date.add(1, 'day').startOf('day').utc().valueOf();
return `https://api-ott-prod-fe.mediaset.net/PROD/play/feed/allListingFeedEpg/v2.0?byListingTime=${todayEpoch}~${nextDayEpoch}&byCallSign=${channel.site_id}`
},
parser: function ({ content, date }) {
const programs = []
const items = getItems(content)
const programs = [];
const data = JSON.parse(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')
if (!data.response || !data.response.entries || !data.response.entries[0] || !data.response.entries[0].listings) {
// If the structure is not as expected, return an empty array
return programs;
}
const listings = data.response.entries[0].listings;
listings.forEach((listing) => {
if (listing.program.title && listing.startTime && listing.endTime) {
const start = parseTime(listing.startTime);
const stop = parseTime(listing.endTime);
programs.push({
title: item.displayTitle || item.title,
description: item.description,
category: item.genere,
title: listing.program.title,
description: listing.program.description,
start,
stop
})
});
}
})
return programs
});
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 : []
function parseTime(timestamp) {
return dayjs(timestamp).utc().format('YYYY-MM-DD HH:mm');
}

View file

@ -7,7 +7,7 @@ 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 date = dayjs.utc('2024-01-20', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'LB',
xmltv_id: '20.it'
@ -15,30 +15,27 @@ const channel = {
it('can generate valid url', () => {
expect(url({ channel, date })).toBe(
'http://www.mediaset.it/guidatv/inc/canali/202310/20231020_LB.sjson'
'https://api-ott-prod-fe.mediaset.net/PROD/play/feed/allListingFeedEpg/v2.0?byListingTime=1705708800000~1705795200000&byCallSign=LB'
)
})
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'
start: '2024-01-19 22:37',
stop: '2024-01-20 00:54',
title: 'Independence day: Rigenerazione',
description: 'Sequel del film di fantascienza Independence Day, con L. Hemsworth e B. Pullman. Dopo 20 anni la Terra si prepara a subire un secondo, terrificante attacco alieno.',
})
})
it('can handle empty guide', () => {
const result = parser({
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8')
content: '[]'
})
expect(result).toMatchObject([])
})