diff --git a/src/main/java/de/mediathekview/mserver/crawler/ard/ArdConstants.java b/src/main/java/de/mediathekview/mserver/crawler/ard/ArdConstants.java index 9dda8bea8..1a632a9ca 100644 --- a/src/main/java/de/mediathekview/mserver/crawler/ard/ArdConstants.java +++ b/src/main/java/de/mediathekview/mserver/crawler/ard/ArdConstants.java @@ -1,5 +1,10 @@ package de.mediathekview.mserver.crawler.ard; +import java.util.HashMap; +import java.util.Map; + +import de.mediathekview.mlib.daten.Sender; + public class ArdConstants { public static final String API_URL = "https://api.ardmediathek.de"; @@ -38,6 +43,28 @@ public class ArdConstants { "arte" }; + public static final Map PARTNER_TO_SENDER = new HashMap<>(); + + static { + PARTNER_TO_SENDER.put("rbb", Sender.RBB); + PARTNER_TO_SENDER.put("swr", Sender.SWR); + PARTNER_TO_SENDER.put("mdr", Sender.MDR); + PARTNER_TO_SENDER.put("ndr", Sender.NDR); + PARTNER_TO_SENDER.put("wdr", Sender.WDR); + PARTNER_TO_SENDER.put("hr", Sender.HR); + PARTNER_TO_SENDER.put("br", Sender.BR); + PARTNER_TO_SENDER.put("radio_bremen", Sender.RBTV); + PARTNER_TO_SENDER.put("tagesschau24", Sender.ARD); + PARTNER_TO_SENDER.put("das_erste", Sender.ARD); + PARTNER_TO_SENDER.put("one", Sender.ONE); // ONE + PARTNER_TO_SENDER.put("ard-alpha", Sender.ARD_ALPHA); // ARD-alpha + PARTNER_TO_SENDER.put("funk", Sender.FUNK); // Funk.net + PARTNER_TO_SENDER.put("sr", Sender.SR); + PARTNER_TO_SENDER.put("phoenix", Sender.PHOENIX); + PARTNER_TO_SENDER.put("ard", Sender.ARD); + //IGNORED_SENDER "zdf", "kika", "3sat", "arte" + } + public static final String WEBSITE_URL = "https://www.ardmediathek.de/video/%s"; public static final String BASE_URL_SUBTITLES = "https://classic.ardmediathek.de"; diff --git a/src/main/java/de/mediathekview/mserver/crawler/ard/json/ArdFilmDeserializer.java b/src/main/java/de/mediathekview/mserver/crawler/ard/json/ArdFilmDeserializer.java index 79d3f499a..4c7dd8beb 100644 --- a/src/main/java/de/mediathekview/mserver/crawler/ard/json/ArdFilmDeserializer.java +++ b/src/main/java/de/mediathekview/mserver/crawler/ard/json/ArdFilmDeserializer.java @@ -167,12 +167,30 @@ public List deserialize( JsonUtils.getAttributeAsString(itemObject, ATTRIBUTE_SYNOPSIS); final Optional date = parseDate(itemObject); final Optional duration = parseDuration(itemObject); - final Sender sender = determinePartner(itemObject); - final Optional videoInfo = parseVideos(itemObject); - + //final Sender sender = determinePartner(itemObject); + final Optional partner = parsePartner(itemObject); + final Sender sender = ArdConstants.PARTNER_TO_SENDER.get(partner.orElse("")); + final Optional videoInfo = parseVideos(itemObject, title.orElse("")); + + if(title.orElse("").contains("- Die Antwort auf fast")) { + + System.out.println("stop"); + } + if (title.isEmpty() || topic.isEmpty() || videoInfo.isEmpty()) { return films; } + + if (sender == null) { + LOG.error("Missing Partner {}", partner.orElse("")); + if (partner.isEmpty()) { + LOG.error("Missing Partner Element {}", jsonElement); + } + + return films; + } + + // add film to ARD final ArdFilmDto filmDto = new ArdFilmDto( @@ -215,19 +233,26 @@ private Optional parseTitle(final JsonObject playerPageObject) { return title.map(nonNullTitle -> nonNullTitle.replace("Hörfassung", "Audiodeskription")); } - + /* private Sender determinePartner(JsonObject playerPageObject) { final Optional partner = parsePartner(playerPageObject); - final Sender sender; // If partner is present and an existing sender set it. Like for RBB + Sender partnerSender = null; if (partner.isPresent()) { - final Optional additionalSender = Sender.getSenderByName(partner.get()); - sender = additionalSender.orElse(Sender.ARD); + partnerSender = ArdConstants.PARTNER_TO_SENDER.get(partner.get()); + if (partnerSender != null) { + return partnerSender; + } else { + partnerSender = Sender.ARD; + LOG.info("unkown partner {}", partner.get() ); + } } else { - sender = Sender.ARD; + partnerSender = Sender.ARD; + LOG.info("missing partner {}", playerPageObject); } - return sender; - } + return partnerSender; + + } */ private Optional parsePartner(final JsonObject playerPageObject) { if (playerPageObject.has(ELEMENT_PUBLICATION_SERVICE)) { @@ -344,7 +369,7 @@ private void addDGSUrls(final Film film, final Map videoUrls } } - private Optional parseVideos(final JsonObject playerPageObject) { + private Optional parseVideos(final JsonObject playerPageObject, final String title) { ArdVideoInfoDto allVideoUrls = new ArdVideoInfoDto(); // final Optional> videoInfoStandard = parseVideoUrls(playerPageObject, MARKER_VIDEO_CATEGORY_MAIN, MARKER_VIDEO_STANDARD, MARKER_VIDEO_MP4); @@ -362,9 +387,10 @@ private Optional parseVideos(final JsonObject playerPageObject) if (videoInfoDGS.isPresent()) { allVideoUrls.putAllDGS(videoInfoDGS.get()); } - if (videoInfoStandard.isPresent()) { + // Sometimes we have DGS & standard + if (videoInfoStandard.isPresent() && !(videoInfoDGS.isPresent() && title.contains("Gebärdensprache"))) { allVideoUrls.putAll(videoInfoStandard.get()); - } else if (videoInfoAdaptive.isPresent()) { + } else if (videoInfoAdaptive.isPresent() && !(videoInfoDGS.isPresent() && title.contains("Gebärdensprache"))) { ArdVideoInfoDto fallbackM3UUrl = new ArdVideoInfoDto(); fallbackM3UUrl.putAll(videoInfoAdaptive.get()); Optional> fallback = fallbackToM3U(Optional.of(fallbackM3UUrl)); @@ -410,10 +436,15 @@ private Optional> parseVideoUrls(final JsonObject player } } } - if (videoInfo.size() > 0) { - return Optional.of(videoInfo); - } else { + if (videoInfo.size() == 0) { return Optional.empty(); } + // TODO: FIX ME + if (!videoInfo.containsKey(Resolution.NORMAL)) { + Resolution r = videoInfo.keySet().stream().findFirst().get(); + videoInfo.put(Resolution.NORMAL, videoInfo.get(r)); + videoInfo.remove(r); + } + return Optional.of(videoInfo); } }