33import com .google .gson .*;
44import de .mediathekview .mserver .daten .Film ;
55import de .mediathekview .mserver .daten .FilmUrl ;
6+ import de .mediathekview .mserver .daten .GeoLocations ;
67import de .mediathekview .mserver .daten .Resolution ;
78import de .mediathekview .mserver .daten .Sender ;
89import de .mediathekview .mserver .base .utils .GeoLocationGuesser ;
910import de .mediathekview .mserver .base .utils .JsonUtils ;
1011import de .mediathekview .mserver .base .utils .UrlUtils ;
1112import de .mediathekview .mserver .crawler .ard .ArdConstants ;
1213import de .mediathekview .mserver .crawler .ard .ArdFilmDto ;
13- import de .mediathekview .mserver .crawler .ard .ArdFilmInfoDto ;
1414import de .mediathekview .mserver .crawler .ard .UrlOptimizer ;
1515import de .mediathekview .mserver .crawler .basic .AbstractCrawler ;
1616import org .apache .logging .log4j .LogManager ;
@@ -41,7 +41,6 @@ public class ArdFilmDeserializer implements JsonDeserializer<List<ArdFilmDto>> {
4141 private static final String ELEMENT_MEDIA_COLLECTION = "mediaCollection" ;
4242 private static final String ELEMENT_PUBLICATION_SERVICE = "publicationService" ;
4343 private static final String ELEMENT_SHOW = "show" ;
44- private static final String ELEMENT_TEASERS = "teasers" ;
4544 private static final String ELEMENT_WIDGETS = "widgets" ;
4645 private static final String [] ELEMENT_SUBTITLES = {ELEMENT_MEDIA_COLLECTION ,ELEMENT_EMBEDDED ,"subtitles" };
4746 private static final String ELEMENT_SOURCES = "sources" ;
@@ -53,7 +52,6 @@ public class ArdFilmDeserializer implements JsonDeserializer<List<ArdFilmDto>> {
5352 private static final String ATTRIBUTE_BROADCAST = "broadcastedOn" ;
5453 private static final String [] ATTRIBUTE_DURATION = {"meta" ,"duration" };
5554 private static final String [] ATTRIBUTE_DURATION_SEC = {"meta" ,"durationSeconds" };
56- private static final String ATTRIBUTE_ID = "id" ;
5755 private static final String ATTRIBUTE_NAME = "name" ;
5856 private static final String ATTRIBUTE_PARTNER = "partner" ;
5957 private static final String ATTRIBUTE_SYNOPSIS = "synopsis" ;
@@ -63,6 +61,7 @@ public class ArdFilmDeserializer implements JsonDeserializer<List<ArdFilmDto>> {
6361 private static final String ATTRIBUTE_MIME = "mimeType" ;
6462 private static final String ATTRIBUTE_KIND = "kind" ;
6563 private static final String ATTRIBUTE_ADUIO_LANG = "languageCode" ;
64+ private static final String ATTRIBUTE_GEO_BLOCKED = "isGeoBlocked" ;
6665
6766 private static final String MARKER_VIDEO_MP4 = "video/mp4" ;
6867 private static final String MARKER_VIDEO_STANDARD = "standard" ;
@@ -179,6 +178,7 @@ public List<ArdFilmDto> deserialize(
179178 final Optional <LocalDateTime > date = parseDate (itemObject );
180179 final Optional <Duration > duration = parseDuration (itemObject );
181180 final Optional <String > partner = parsePartner (itemObject );
181+ final Optional <Boolean > geoBlocked = parseGeoBlocked (itemObject );
182182 final Sender sender = ArdConstants .PARTNER_TO_SENDER .get (partner .orElse ("" ));
183183 final Optional <ArdVideoInfoDto > videoInfo = parseVideos (itemObject , titleOriginal .orElse ("" ));
184184
@@ -209,7 +209,8 @@ public List<ArdFilmDto> deserialize(
209209 description .orElse (null ),
210210 date .orElse (null ),
211211 duration .orElse (null ),
212- videoInfo .get ()));
212+ videoInfo .get (),
213+ geoBlocked ));
213214 films .add (filmDto );
214215 }
215216 // OV - long term this should go into Film as "OV"
@@ -227,7 +228,8 @@ public List<ArdFilmDto> deserialize(
227228 description .orElse (null ),
228229 date .orElse (null ),
229230 duration .orElse (null ),
230- allVideoUrlsOV ));
231+ allVideoUrlsOV ,
232+ geoBlocked ));
231233 films .add (filmDtoOV );
232234 }
233235
@@ -294,6 +296,19 @@ private Optional<String> parsePartner(final JsonObject playerPageObject) {
294296 return Optional .empty ();
295297 }
296298
299+ private Optional <Boolean > parseGeoBlocked (final JsonObject playerPageObject ) {
300+ final Optional <JsonObject > mediaCollectionObject = getMediaCollectionObject (playerPageObject );
301+ if (mediaCollectionObject .isEmpty ()) {
302+ return Optional .empty ();
303+ }
304+ final Optional <JsonElement > geoBlockedElement =
305+ JsonUtils .getElement (mediaCollectionObject .get (), ATTRIBUTE_GEO_BLOCKED );
306+ if (geoBlockedElement .isPresent () && geoBlockedElement .get ().isJsonPrimitive ()) {
307+ return Optional .of (geoBlockedElement .get ().getAsBoolean ());
308+ }
309+ return Optional .empty ();
310+ }
311+
297312 private Film createFilm (
298313 final String id ,
299314 final Sender sender ,
@@ -302,7 +317,8 @@ private Film createFilm(
302317 @ Nullable final String description ,
303318 @ Nullable final LocalDateTime date ,
304319 @ Nullable final Duration duration ,
305- final ArdVideoInfoDto videoInfo ) {
320+ final ArdVideoInfoDto videoInfo ,
321+ final Optional <Boolean > geoBlocked ) {
306322
307323 final Film film =
308324 new Film (
@@ -315,8 +331,18 @@ private Film createFilm(
315331
316332 Optional .ofNullable (description ).ifPresent (film ::setBeschreibung );
317333 film .setId (id );
318- film .setGeoLocations (GeoLocationGuesser .getGeoLocations (Sender .ARD , videoInfo .getDefaultVideoUrl ()));
319-
334+
335+ // Set GeoLocations based on isGeoBlocked flag
336+ if (geoBlocked .isPresent ()) {
337+ if (geoBlocked .get ()) {
338+ film .addGeolocation (GeoLocations .GEO_DE );
339+ } else {
340+ film .addGeolocation (GeoLocations .GEO_NONE );
341+ }
342+ } else {
343+ film .setGeoLocations (GeoLocationGuesser .getGeoLocations (Sender .ARD , videoInfo .getDefaultVideoUrl ()));
344+ }
345+
320346 if (!videoInfo .getSubtitleUrl ().isEmpty ()) {
321347 for (String subtitleUrl : videoInfo .getSubtitleUrl ()) {
322348 try {
0 commit comments