Merge pull request #2410 from ToRvaLDz/master

Adding subtitle, catgory, season, episode,  thumb to mediasetinfinity.mediaset.it
This commit is contained in:
PopeyeTheSai10r 2024-08-13 17:00:41 -07:00 committed by GitHub
commit 270e85cfae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 79 additions and 31 deletions

View file

@ -12,39 +12,82 @@ module.exports = {
days: 2,
url: function ({date, channel}) {
// Get the epoch timestamp
const todayEpoch = date.startOf('day').utc().valueOf();
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();
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 data = JSON.parse(content);
parser: function ({content}) {
const programs = []
const data = JSON.parse(content)
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;
return programs
}
const listings = data.response.entries[0].listings;
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);
const title = listing.mediasetlisting$epgTitle
const subTitle = listing.program.title
const season = parseSeason(listing)
const episode = parseEpisode(listing)
if (listing.program.title && listing.startTime && listing.endTime) {
programs.push({
title: listing.program.title,
description: listing.program.description,
start,
stop
});
title: title || subTitle,
sub_title: title && title != subTitle ? subTitle : null,
description: listing.program.description || null,
category: listing.program.mediasetprogram$skyGenre || null,
season: episode && !season ? '0' : season,
episode: episode,
start: parseTime(listing.startTime),
stop: parseTime(listing.endTime),
image: getMaxResolutionThumbnails(listing)
})
}
});
return programs;
})
return programs
}
}
function parseTime(timestamp) {
return dayjs(timestamp).utc().format('YYYY-MM-DD HH:mm');
return dayjs(timestamp).utc().format('YYYY-MM-DD HH:mm')
}
function parseSeason(item) {
if (!item.mediasetlisting$shortDescription) return null
const season = item.mediasetlisting$shortDescription.match(/S(\d+)\s/)
return season ? season[1] : null
}
function parseEpisode(item) {
if (!item.mediasetlisting$shortDescription) return null
const episode = item.mediasetlisting$shortDescription.match(/Ep(\d+)\s/)
return episode ? episode[1] : null
}
function getMaxResolutionThumbnails(item) {
const thumbnails = item.program.thumbnails || null
const maxResolutionThumbnails = {}
for (const key in thumbnails) {
const type = key.split('-')[0] // Estrarre il tipo di thumbnail
const {width, height, url, title} = thumbnails[key]
if (!maxResolutionThumbnails[type] ||
(width * height > maxResolutionThumbnails[type].width * maxResolutionThumbnails[type].height)) {
maxResolutionThumbnails[type] = {width, height, url, title}
}
}
if (maxResolutionThumbnails.image_keyframe_poster)
return maxResolutionThumbnails.image_keyframe_poster.url
else if (maxResolutionThumbnails.image_header_poster)
return maxResolutionThumbnails.image_header_poster.url
else
return null
}

View file

@ -9,14 +9,14 @@ dayjs.extend(utc)
const date = dayjs.utc('2024-01-20', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'LB',
xmltv_id: '20.it'
site_id: 'LB', xmltv_id: '20.it'
}
it('can generate valid url', () => {
expect(url({ channel, date })).toBe(
'https://api-ott-prod-fe.mediaset.net/PROD/play/feed/allListingFeedEpg/v2.0?byListingTime=1705708800000~1705795200000&byCallSign=LB'
)
expect(url({
channel,
date
})).toBe('https://api-ott-prod-fe.mediaset.net/PROD/play/feed/allListingFeedEpg/v2.0?byListingTime=1705708800000~1705795200000&byCallSign=LB')
})
it('can parse response', () => {
@ -25,11 +25,16 @@ it('can parse response', () => {
return p
})
expect(results[0]).toMatchObject({
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.',
expect(results[3]).toMatchObject({
start: '2024-01-20 02:14',
stop: '2024-01-20 02:54',
title: 'Chicago Fire',
sub_title: 'Ep. 22 - Io non ti lascio',
description: 'Severide e Kidd continuano a indagare su un vecchio caso doloso di Benny. Notizie inaspettate portano Brett a meditare su una grande decisione.',
category: 'Intrattenimento',
season: '7',
episode: '22',
image: 'https://static2.mediasetplay.mediaset.it/Mediaset_Italia_Production_-_Main/F309370301002204/media/0/0/1ef76b73-3173-43bd-9c16-73986a0ec131/46896726-11e7-4438-b947-d2ae53f58c0b.jpg'
})
})