Skip to content

Commit

Permalink
two digit season and episode
Browse files Browse the repository at this point in the history
  • Loading branch information
codingPF committed May 8, 2024
1 parent 5972cac commit a0e81cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/main/java/mServer/crawler/sender/base/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ public static boolean hasElements(
return true;
}

public static Optional<Integer> getElementValueAsInteger(final JsonElement aJsonElement, final String... aElementIds) {
Optional<JsonElement> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ private Optional<String> parseTitle(final JsonObject aRootNode, final JsonObject
resultingTitle = formatTitle(targetTitle, targetSubtitle);
}
if (resultingTitle.isPresent()) {
final Optional<String> season = JsonUtils.getElementValueAsString(aTarget, SEASONNUMBER);
final Optional<String> episode = JsonUtils.getElementValueAsString(aTarget, EPISODENUMBER);
final Optional<Integer> season = JsonUtils.getElementValueAsInteger(aTarget, SEASONNUMBER);
final Optional<Integer> episode = JsonUtils.getElementValueAsInteger(aTarget, EPISODENUMBER);
final Optional<String> seasonEpisodeTitle = formatEpisodeTitle(season, episode);
final Optional<String> title = cleanupTitle((resultingTitle.get() + " " + seasonEpisodeTitle.orElse("")).trim());
return title;
Expand All @@ -244,23 +244,23 @@ private Optional<String> formatTitle(Optional<String> title, Optional<String> 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<String> formatEpisodeTitle(Optional<String> season, Optional<String> episode) {
private Optional<String> formatEpisodeTitle(Optional<Integer> season, Optional<Integer> 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+")");
}
Expand Down

0 comments on commit a0e81cb

Please sign in to comment.