@@ -19,37 +19,46 @@ public function __construct(Client $client, ?float $priority = null)
19
19
20
20
public function constructEPG (string $ channel , string $ date ): Channel |bool
21
21
{
22
- $ timestamps = array_map (function ($ hour ) use ($ date ) { return strtotime ("$ date $ hour:00:00 UTC " ); }, [0 , 6 , 12 , 18 ]);
22
+ $ dateObj = new \DateTimeImmutable ($ date .' 00:00 +00:00 ' );
23
+ $ timestamps = array_map (function ($ hour ) use ($ dateObj ) { return $ dateObj ->modify ("$ hour hours " ); }, ['-6 ' , '+0 ' , '+6 ' , '+12 ' , '+18 ' , '+24 ' ]);
23
24
24
25
$ channelObj = parent ::constructEPG ($ channel , $ date );
25
26
if (!$ this ->channelExists ($ channel )) {
26
27
return false ;
27
28
}
28
29
30
+ [$ minDate , $ maxDate ] = $ this ->getMinMaxDate ($ date );
29
31
foreach ($ timestamps as $ times ) {
30
32
$ json = json_decode ($ this ->getContentFromURL ($ this ->generateUrl ($ channelObj , $ times )), true );
31
33
if (empty ($ json ['result ' ]['entries ' ])) {
32
34
return false ;
33
35
}
34
36
35
37
foreach ($ json ['result ' ]['entries ' ] as $ entrie ) {
38
+ $ startDate = new \DateTimeImmutable ('@ ' .$ entrie ['live ' ]['start ' ]);
39
+ if ($ startDate < $ minDate ) {
40
+ continue ;
41
+ } elseif ($ startDate > $ maxDate ) {
42
+ return $ channelObj ;
43
+ }
36
44
$ program = new Program (date ('YmdHis O ' , $ entrie ['live ' ]['start ' ]), date ('YmdHis O ' , $ entrie ['live ' ]['end ' ]));
37
45
$ program ->addTitle ($ entrie ['live ' ]['title ' ]);
38
46
$ program ->addSubtitle ($ entrie ['live ' ]['sub_title ' ]);
39
47
$ program ->addDesc ($ entrie ['live ' ]['description ' ]);
40
48
$ program ->addCategory ($ entrie ['live ' ]['category ' ]);
41
49
$ program ->addCategory ($ entrie ['live ' ]['sub_category ' ]);
42
- $ icon = str_replace (" h%d " , " h1080 " , $ entrie ['pictures ' ]['main ' ]);
50
+ $ icon = str_replace (' h%d ' , ' h1080 ' , $ entrie ['pictures ' ]['main ' ]);
43
51
$ program ->setIcon ($ icon );
44
- $ program ->setRating (" - " . $ entrie ['live ' ]['parental_rating ' ]);
52
+ $ program ->setRating (' - ' . $ entrie ['live ' ]['parental_rating ' ]);
45
53
$ channelObj ->addProgram ($ program );
46
54
}
47
55
}
56
+
48
57
return $ channelObj ;
49
58
}
50
59
51
- public function generateUrl (Channel $ channel , $ time ): string
60
+ public function generateUrl (Channel $ channel , $ date ): string
52
61
{
53
- return 'https://api.oqee.net/api/v1/epg/by_channel/ ' . $ this ->channelsList [$ channel ->getId ()] .'/ ' .$ time ;
62
+ return 'https://api.oqee.net/api/v1/epg/by_channel/ ' . $ this ->channelsList [$ channel ->getId ()] .'/ ' .$ date -> getTimestamp () ;
54
63
}
55
64
}
0 commit comments