diff --git a/src/main/java/mServer/crawler/sender/base/JsonUtils.java b/src/main/java/mServer/crawler/sender/base/JsonUtils.java index 296b87f59..3b0566f7e 100644 --- a/src/main/java/mServer/crawler/sender/base/JsonUtils.java +++ b/src/main/java/mServer/crawler/sender/base/JsonUtils.java @@ -113,6 +113,13 @@ public static boolean hasElements( return true; } + public static Optional getElementValueAsInteger(final JsonElement aJsonElement, final String... aElementIds) { + Optional rs = JsonUtils.getElement(aJsonElement, aElementIds); + if (rs.isPresent()) { + return Optional.of(rs.get().getAsInt()); + } + return Optional.empty(); + } /** * Checks if the {@link JsonObject} has all given elements and if no element * is null or empty. diff --git a/src/main/java/mServer/crawler/sender/zdf/json/ZdfFilmDetailDeserializer.java b/src/main/java/mServer/crawler/sender/zdf/json/ZdfFilmDetailDeserializer.java index 0a2eb1abf..3c63ec63e 100644 --- a/src/main/java/mServer/crawler/sender/zdf/json/ZdfFilmDetailDeserializer.java +++ b/src/main/java/mServer/crawler/sender/zdf/json/ZdfFilmDetailDeserializer.java @@ -227,8 +227,8 @@ private Optional parseTitle(final JsonObject aRootNode, final JsonObject resultingTitle = formatTitle(targetTitle, targetSubtitle); } if (resultingTitle.isPresent()) { - final Optional season = JsonUtils.getElementValueAsString(aTarget, SEASONNUMBER); - final Optional episode = JsonUtils.getElementValueAsString(aTarget, EPISODENUMBER); + final Optional season = JsonUtils.getElementValueAsInteger(aTarget, SEASONNUMBER); + final Optional episode = JsonUtils.getElementValueAsInteger(aTarget, EPISODENUMBER); final Optional seasonEpisodeTitle = formatEpisodeTitle(season, episode); final Optional title = cleanupTitle((resultingTitle.get() + " " + seasonEpisodeTitle.orElse("")).trim()); return title; @@ -244,23 +244,23 @@ private Optional formatTitle(Optional title, Optional su if (title.isEmpty()) { return Optional.empty(); } - if (sub.isPresent()) { + if (sub.isPresent() && !sub.get().isBlank()) { return Optional.of(title.get().trim() + " - " + sub.get().trim()); } else { return Optional.of(title.get().trim()); } } - private Optional formatEpisodeTitle(Optional season, Optional episode) { + private Optional formatEpisodeTitle(Optional season, Optional episode) { if (season.isEmpty() && episode.isEmpty()) { return Optional.empty(); } String result = ""; if (season.isPresent()) { - result += "S"+season.get(); + result += String.format("S%02d", season.get()); } if (episode.isPresent()) { - result += "E"+episode.get(); + result += String.format("E%02d", episode.get()); } return Optional.of("("+result+")"); }