mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Updating mediaset guide to use new endpoint and json structure
This commit is contained in:
parent
d86d0c8711
commit
5c52c4dd14
1 changed files with 25 additions and 34 deletions
|
@ -11,49 +11,40 @@ module.exports = {
|
||||||
site: 'mediasetinfinity.mediaset.it',
|
site: 'mediasetinfinity.mediaset.it',
|
||||||
days: 2,
|
days: 2,
|
||||||
url: function ({ date, channel }) {
|
url: function ({ date, channel }) {
|
||||||
return `http://www.mediaset.it/guidatv/inc/canali/${date.format('YYYYMM')}/${date.format(
|
// Get the epoch timestamp
|
||||||
'YYYYMMDD'
|
const todayEpoch = date.startOf('day').utc().valueOf();
|
||||||
)}_${channel.site_id}.sjson`
|
// 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 }) {
|
parser: function ({ content, date }) {
|
||||||
const programs = []
|
const programs = [];
|
||||||
const items = getItems(content)
|
const data = JSON.parse(content);
|
||||||
|
|
||||||
items.forEach(item => {
|
if (!data.response || !data.response.entries || !data.response.entries[0] || !data.response.entries[0].listings) {
|
||||||
if (item.title && item.startTime && item.duration) {
|
// If the structure is not as expected, return an empty array
|
||||||
const start = parseStart(item, date)
|
return programs;
|
||||||
const duration = parseInt(item.duration)
|
}
|
||||||
const stop = start.add(duration, 'm')
|
|
||||||
|
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({
|
programs.push({
|
||||||
title: item.displayTitle || item.title,
|
title: listing.program.title,
|
||||||
description: item.description,
|
description: listing.program.description,
|
||||||
category: item.genere,
|
|
||||||
start,
|
start,
|
||||||
stop
|
stop
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
return programs;
|
||||||
return programs
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item, date) {
|
function parseTime(timestamp) {
|
||||||
return dayjs.tz(
|
return dayjs(timestamp).utc().format('YYYY-MM-DD HH:mm');
|
||||||
`${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 : []
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue