@@ -10,41 +10,84 @@ dayjs.extend(timezone)
10
10
module . exports = {
11
11
site : 'mediasetinfinity.mediaset.it' ,
12
12
days : 2 ,
13
- url : function ( { date, channel } ) {
13
+ url : function ( { date, channel} ) {
14
14
// Get the epoch timestamp
15
- const todayEpoch = date . startOf ( 'day' ) . utc ( ) . valueOf ( ) ;
15
+ const todayEpoch = date . startOf ( 'day' ) . utc ( ) . valueOf ( )
16
16
// Get the epoch timestamp for the next day
17
- const nextDayEpoch = date . add ( 1 , 'day' ) . startOf ( 'day' ) . utc ( ) . valueOf ( ) ;
17
+ const nextDayEpoch = date . add ( 1 , 'day' ) . startOf ( 'day' ) . utc ( ) . valueOf ( )
18
18
return `https://api-ott-prod-fe.mediaset.net/PROD/play/feed/allListingFeedEpg/v2.0?byListingTime=${ todayEpoch } ~${ nextDayEpoch } &byCallSign=${ channel . site_id } `
19
19
} ,
20
- parser : function ( { content, date } ) {
21
- const programs = [ ] ;
22
- const data = JSON . parse ( content ) ;
20
+ parser : function ( { content} ) {
21
+ const programs = [ ]
22
+ const data = JSON . parse ( content )
23
23
24
24
if ( ! data . response || ! data . response . entries || ! data . response . entries [ 0 ] || ! data . response . entries [ 0 ] . listings ) {
25
25
// If the structure is not as expected, return an empty array
26
- return programs ;
26
+ return programs
27
27
}
28
28
29
- const listings = data . response . entries [ 0 ] . listings ;
29
+ const listings = data . response . entries [ 0 ] . listings
30
30
31
31
listings . forEach ( ( listing ) => {
32
- if ( listing . program . title && listing . startTime && listing . endTime ) {
33
- const start = parseTime ( listing . startTime ) ;
34
- const stop = parseTime ( listing . endTime ) ;
32
+ const title = listing . mediasetlisting$epgTitle
33
+ const subTitle = listing . program . title
34
+ const season = parseSeason ( listing )
35
+ const episode = parseEpisode ( listing )
36
+
35
37
38
+ if ( listing . program . title && listing . startTime && listing . endTime ) {
36
39
programs . push ( {
37
- title : listing . program . title ,
38
- description : listing . program . description ,
39
- start,
40
- stop
41
- } ) ;
40
+ title : title || subTitle ,
41
+ sub_title : title && title != subTitle ? subTitle : null ,
42
+ description : listing . program . description || null ,
43
+ category : listing . program . mediasetprogram$skyGenre || null ,
44
+ season : episode && ! season ? '0' : season ,
45
+ episode : episode ,
46
+ start : parseTime ( listing . startTime ) ,
47
+ stop : parseTime ( listing . endTime ) ,
48
+ image : getMaxResolutionThumbnails ( listing )
49
+ } )
42
50
}
43
- } ) ;
44
- return programs ;
51
+ } )
52
+
53
+ return programs
45
54
}
46
55
}
47
56
57
+
48
58
function parseTime ( timestamp ) {
49
- return dayjs ( timestamp ) . utc ( ) . format ( 'YYYY-MM-DD HH:mm' ) ;
59
+ return dayjs ( timestamp ) . utc ( ) . format ( 'YYYY-MM-DD HH:mm' )
60
+ }
61
+
62
+ function parseSeason ( item ) {
63
+ if ( ! item . mediasetlisting$shortDescription ) return null
64
+ const season = item . mediasetlisting$shortDescription . match ( / S ( \d + ) \s / )
65
+ return season ? season [ 1 ] : null
66
+ }
67
+
68
+ function parseEpisode ( item ) {
69
+ if ( ! item . mediasetlisting$shortDescription ) return null
70
+ const episode = item . mediasetlisting$shortDescription . match ( / E p ( \d + ) \s / )
71
+ return episode ? episode [ 1 ] : null
72
+ }
73
+
74
+ function getMaxResolutionThumbnails ( item ) {
75
+ const thumbnails = item . program . thumbnails || null
76
+ const maxResolutionThumbnails = { }
77
+
78
+ for ( const key in thumbnails ) {
79
+ const type = key . split ( '-' ) [ 0 ] // Estrarre il tipo di thumbnail
80
+ const { width, height, url, title} = thumbnails [ key ]
81
+
82
+ if ( ! maxResolutionThumbnails [ type ] ||
83
+ ( width * height > maxResolutionThumbnails [ type ] . width * maxResolutionThumbnails [ type ] . height ) ) {
84
+ maxResolutionThumbnails [ type ] = { width, height, url, title}
85
+ }
86
+ }
87
+ if ( maxResolutionThumbnails . image_keyframe_poster )
88
+ return maxResolutionThumbnails . image_keyframe_poster . url
89
+ else if ( maxResolutionThumbnails . image_header_poster )
90
+ return maxResolutionThumbnails . image_header_poster . url
91
+ else
92
+ return null
50
93
}
0 commit comments