diff --git a/src/main/java/de/mediathekview/mserver/base/utils/JsonUtils.java b/src/main/java/de/mediathekview/mserver/base/utils/JsonUtils.java index 00f8fcff..0eb02818 100644 --- a/src/main/java/de/mediathekview/mserver/base/utils/JsonUtils.java +++ b/src/main/java/de/mediathekview/mserver/base/utils/JsonUtils.java @@ -86,7 +86,7 @@ public static Optional getElementValueAsString(final JsonElement aJsonEl public static Optional getElement(final JsonElement aJsonElement, final String... aElementIds) { Optional rs = Optional.empty(); - if (aElementIds == null || aElementIds.length == 0) { + if (aElementIds == null || aElementIds.length == 0 || aJsonElement == null || !aJsonElement.isJsonObject()) { return rs; } JsonObject aJsonObject = aJsonElement.getAsJsonObject(); diff --git a/src/main/java/de/mediathekview/mserver/crawler/zdf/json/ZdfFilmDetailDeserializer.java b/src/main/java/de/mediathekview/mserver/crawler/zdf/json/ZdfFilmDetailDeserializer.java index b2fb9662..9cbe959c 100644 --- a/src/main/java/de/mediathekview/mserver/crawler/zdf/json/ZdfFilmDetailDeserializer.java +++ b/src/main/java/de/mediathekview/mserver/crawler/zdf/json/ZdfFilmDetailDeserializer.java @@ -59,8 +59,13 @@ public class ZdfFilmDetailDeserializer implements JsonDeserializer deserialize( final Optional website = parseWebsiteUrl(rootNode); final Optional time = parseAirtime(rootNode, programItemTarget); final Optional duration = parseDuration(mainVideoTarget); - + final Map downloadUrl = parseDownloadUrls(mainVideoTarget); - + if (title.isPresent()) { final Optional film = createFilm(topic, title.get(), description, website, time, duration); @@ -260,36 +265,51 @@ private Optional parseDescription(final JsonObject aRootNode) { } private Optional parseTitle(final JsonObject aRootNode, final JsonObject aTarget) { - final Optional title = parseTitleValue(aRootNode, aTarget); - return title.map(s -> s.replaceAll("\\(CC.*\\) - .* Creative Commons.*", "")); + final Optional programmTitle = JsonUtils.getElementValueAsString(aRootNode, JSON_ELEMENT_TITLE); + final Optional programmSubtitle = JsonUtils.getElementValueAsString(aRootNode, JSON_ELEMENT_SUBTITLE); + Optional resultingTitle = formatTitle(programmTitle, programmSubtitle); + if (resultingTitle.isEmpty()) { + final Optional targetTitle = JsonUtils.getElementValueAsString(aTarget, JSON_ELEMENT_TITLE); + final Optional targetSubtitle = JsonUtils.getElementValueAsString(aTarget, JSON_ELEMENT_SUBTITLE); + resultingTitle = formatTitle(targetTitle, targetSubtitle); + } + if (resultingTitle.isPresent()) { + final Optional season = JsonUtils.getElementValueAsString(aTarget, SEASONNUMBER); + final Optional episode = JsonUtils.getElementValueAsString(aTarget, EPISODENUMBER); + final Optional seasonEpisodeTitle = formatEpisodeTitle(season, episode); + final Optional title = cleanupTitle((resultingTitle.get() + " " + seasonEpisodeTitle.orElse("")).trim()); + return title; + } + return Optional.empty(); } - - private Optional parseTitleValue(final JsonObject aRootNode, final JsonObject aTarget) { - // use property "title" if found - final JsonElement titleElement = aRootNode.get(JSON_ELEMENT_TITLE); - if (titleElement != null) { - final JsonElement subTitleElement = aRootNode.get(JSON_ELEMENT_SUBTITLE); - if (subTitleElement != null && !subTitleElement.getAsString().isBlank()) { - return Optional.of( - titleElement.getAsString().trim() + " - " + subTitleElement.getAsString()); - } else { - return Optional.of(titleElement.getAsString()); - } + + private Optional cleanupTitle(String title) { + return Optional.of(title.replaceAll("\\(CC.*\\) - .* Creative Commons.*", "")); + } + + private Optional formatTitle(Optional title, Optional sub) { + if (title.isEmpty()) { + return Optional.empty(); + } + if (sub.isPresent()) { + return Optional.of(title.get().trim() + " - " + sub.get().trim()); } else { - // programmItem target required to determine title - if (aTarget != null && aTarget.has(JSON_ELEMENT_TITLE)) { - final String title = aTarget.get(JSON_ELEMENT_TITLE).getAsString(); - final String subTitle = aTarget.get(JSON_ELEMENT_SUBTITLE).getAsString(); - - if (subTitle.isEmpty()) { - return Optional.of(title); - } else { - return Optional.of(title.trim() + " - " + subTitle); - } - } + return Optional.of(title.get().trim()); } - - return Optional.empty(); + } + + private Optional formatEpisodeTitle(Optional season, Optional episode) { + if (season.isEmpty() && episode.isEmpty()) { + return Optional.empty(); + } + String result = ""; + if (season.isPresent()) { + result += "S"+season.get(); + } + if (episode.isPresent()) { + result += "E"+episode.get(); + } + return Optional.of("("+result+")"); } private Optional parseTopic(final JsonObject aRootNode) { diff --git a/src/main/java/de/mediathekview/mserver/crawler/zdf/parser/ZdfTopicsPageHtmlDeserializer.java b/src/main/java/de/mediathekview/mserver/crawler/zdf/parser/ZdfTopicsPageHtmlDeserializer.java index 12fee71d..ac159733 100644 --- a/src/main/java/de/mediathekview/mserver/crawler/zdf/parser/ZdfTopicsPageHtmlDeserializer.java +++ b/src/main/java/de/mediathekview/mserver/crawler/zdf/parser/ZdfTopicsPageHtmlDeserializer.java @@ -39,6 +39,6 @@ private boolean isRelevant(Element teaserElement) { if (teaserElement == null) { return true; } - return !("ARD".equalsIgnoreCase(teaserElement.text())); + return !("ARD".equalsIgnoreCase(teaserElement.text()) || "funk".equalsIgnoreCase(teaserElement.text())); } }