diff --git a/Core/src/main/java/com/jasonhhouse/gaps/BasicMovie.java b/Core/src/main/java/com/jasonhhouse/gaps/BasicMovie.java index e8cc4bc..bdee30c 100755 --- a/Core/src/main/java/com/jasonhhouse/gaps/BasicMovie.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/BasicMovie.java @@ -51,6 +51,8 @@ public final class BasicMovie implements Comparable { private String backdropPathUrl; @NotNull private Integer tmdbId; + @NotNull + private List genres; private BasicMovie(@NotNull String name, @NotNull Integer year, @@ -64,7 +66,8 @@ public final class BasicMovie implements Comparable { @NotNull String overview, @NotNull List moviesInCollection, @NotNull Integer ratingKey, - @NotNull String key) { + @NotNull String key, + @NotNull List genres) { this.name = name; this.nameWithoutBadCharacters = name.replaceAll("[<>`~\\[\\]()*&^%$#@!|{}.,?\\-_=+:;]", ""); this.year = year; @@ -79,6 +82,7 @@ public final class BasicMovie implements Comparable { this.moviesInCollection = moviesInCollection; this.ratingKey = ratingKey; this.key = key; + this.genres = genres; } public @NotNull Integer getCollectionId() { @@ -137,12 +141,20 @@ public final class BasicMovie implements Comparable { return moviesInCollection; } + public @NotNull String getBackdropPathUrl() { + return backdropPathUrl; + } + public void setBackdropPathUrl(@NotNull String backdropPathUrl) { this.backdropPathUrl = backdropPathUrl; } - public @NotNull String getBackdropPathUrl() { - return backdropPathUrl; + public @NotNull List getGenres() { + return genres; + } + + public void setGenres(@NotNull List genres) { + this.genres = genres; } @JsonIgnore @@ -198,7 +210,6 @@ public final class BasicMovie implements Comparable { ", year=" + year + ", nameWithoutBadCharacters='" + nameWithoutBadCharacters + '\'' + ", posterUrl='" + posterUrl + '\'' + - ", backdropPathUrl='" + backdropPathUrl + '\'' + ", language='" + language + '\'' + ", overview='" + overview + '\'' + ", moviesInCollection=" + moviesInCollection + @@ -207,7 +218,9 @@ public final class BasicMovie implements Comparable { ", imdbId='" + imdbId + '\'' + ", collectionTitle='" + collectionTitle + '\'' + ", collectionId=" + collectionId + + ", backdropPathUrl='" + backdropPathUrl + '\'' + ", tmdbId=" + tmdbId + + ", genres=" + genres + '}'; } @@ -268,6 +281,10 @@ public final class BasicMovie implements Comparable { @JsonProperty private String key; + @NotNull + @JsonProperty + private List genres; + @JsonCreator public Builder(@JsonProperty(value = "name") @NotNull String name, @JsonProperty(value = "year") @NotNull Integer year) { @@ -284,10 +301,11 @@ public final class BasicMovie implements Comparable { this.moviesInCollection = new ArrayList<>(); this.ratingKey = -1; this.key = ""; + this.genres = new ArrayList<>(); } public @NotNull BasicMovie build() { - return new BasicMovie(name, year, posterUrl, backdropPathUrl, collectionTitle, collectionId, tmdbId, imdbId, language, overview, moviesInCollection, ratingKey, key); + return new BasicMovie(name, year, posterUrl, backdropPathUrl, collectionTitle, collectionId, tmdbId, imdbId, language, overview, moviesInCollection, ratingKey, key, genres); } public @NotNull Builder setPosterUrl(@NotNull String posterUrl) { @@ -344,5 +362,10 @@ public final class BasicMovie implements Comparable { this.key = key; return this; } + + public @NotNull Builder setGenres(@NotNull List genres) { + this.genres = genres; + return this; + } } } diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/GapsSearchService.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/GapsSearchService.java index 8325b40..14e3b0e 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/GapsSearchService.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/GapsSearchService.java @@ -39,6 +39,7 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; @@ -71,6 +72,7 @@ public class GapsSearchService implements GapsSearch { public static final String COLLECTION_ID = "belongs_to_collection"; public static final String BACKDROP_PATH = "backdrop_path"; + public static final String GENRES = "genres"; public static final String TITLE = "title"; public static final String NAME = "name"; public static final String ID = "id"; @@ -78,6 +80,7 @@ public class GapsSearchService implements GapsSearch { public static final String PARTS = "parts"; public static final String MOVIE_RESULTS = "movie_results"; public static final String FINISHED_SEARCHING_URL = "/finishedSearching"; + private static final String languageCode = "en-US"; private static final Logger LOGGER = LoggerFactory.getLogger(GapsSearchService.class); private static final ObjectMapper objectMapper = new ObjectMapper(); @@ -95,8 +98,10 @@ public class GapsSearchService implements GapsSearch { private final NotificationService notificationService; + @Autowired - public GapsSearchService(@Qualifier("real") UrlGenerator urlGenerator, SimpMessagingTemplate template, FileIoService fileIoService, TmdbService tmdbService, NotificationService notificationService) { + public GapsSearchService(@Qualifier("real") UrlGenerator urlGenerator, + SimpMessagingTemplate template, FileIoService fileIoService, TmdbService tmdbService, NotificationService notificationService) { this.template = template; this.tmdbService = tmdbService; this.urlGenerator = urlGenerator; @@ -108,7 +113,7 @@ public class GapsSearchService implements GapsSearch { } @Override - public void run(@NotNull String machineIdentifier,@NotNull Integer key) { + public void run(@NotNull String machineIdentifier, @NotNull Integer key) { LOGGER.info("run( {}, {} )", machineIdentifier, key); PlexProperties plexProperties = fileIoService.readProperties(); @@ -228,7 +233,6 @@ public class GapsSearchService implements GapsSearch { } for (BasicMovie basicMovie : ownedBasicMovies) { - String languageCode = "en-US"; //Cancel search if needed if (cancelSearch.get()) { @@ -397,6 +401,9 @@ public class GapsSearchService implements GapsSearch { basicMovie.setCollectionTitle(collectionName); basicMovie.setBackdropPathUrl(backdropPath); + List genres = getGenres(movieDetails); + basicMovie.setGenres(genres); + int indexOfMovie = everyBasicMovie.indexOf(basicMovie); if (indexOfMovie != -1) { LOGGER.info("Merging movie data"); @@ -404,6 +411,7 @@ public class GapsSearchService implements GapsSearch { everyBasicMovie.get(indexOfMovie).setCollectionId(basicMovie.getCollectionId()); everyBasicMovie.get(indexOfMovie).setCollectionTitle(basicMovie.getCollectionTitle()); everyBasicMovie.get(indexOfMovie).setBackdropPathUrl(basicMovie.getBackdropPathUrl()); + everyBasicMovie.get(indexOfMovie).setGenres(genres); } else { BasicMovie newBasicMovie = new BasicMovie.Builder(basicMovie.getName(), basicMovie.getYear()) .setTmdbId(basicMovie.getTmdbId()) @@ -411,6 +419,7 @@ public class GapsSearchService implements GapsSearch { .setCollectionTitle(basicMovie.getCollectionTitle()) .setCollectionId(basicMovie.getCollectionId()) .setBackdropPathUrl(basicMovie.getBackdropPathUrl()) + .setGenres(basicMovie.getGenres()) .build(); everyBasicMovie.add(newBasicMovie); } @@ -422,6 +431,19 @@ public class GapsSearchService implements GapsSearch { } } + private @NotNull List getGenres(@NotNull JsonNode movieDetails) { + List genres = new ArrayList<>(); + + Iterator jsonNodeIterator = movieDetails.get(GENRES).elements(); + + while (jsonNodeIterator.hasNext()) { + JsonNode genre = jsonNodeIterator.next(); + genres.add(genre.get(NAME).textValue()); + } + + return genres; + } + private void handleCollection(PlexProperties plexProperties, String machineIdentifier, Integer key, List ownedBasicMovies, List everyBasicMovie, Set recommended, List searched, AtomicInteger searchedMovieCount, BasicMovie basicMovie, OkHttpClient client, String languageCode) { LOGGER.debug("handleCollection()"); @@ -506,6 +528,7 @@ public class GapsSearchService implements GapsSearch { .setOverview(basicMovie.getOverview()) .setPosterUrl(basicMovie.getPosterUrl()) .setBackdropPathUrl(basicMovie.getBackdropPathUrl()) + .setGenres(basicMovie.getGenres()) .build(); everyBasicMovie.add(newBasicMovie); @@ -547,6 +570,7 @@ public class GapsSearchService implements GapsSearch { .setPosterUrl(posterUrl) .setMoviesInCollection(moviesInCollection) .setBackdropPathUrl(basicMovie.getBackdropPathUrl()) + .setGenres(basicMovie.getGenres()) .build(); if (ownedBasicMovies.contains(basicMovieFromCollection)) { @@ -608,6 +632,8 @@ public class GapsSearchService implements GapsSearch { basicMovieFromCollection.setCollectionTitle(collection.get(NAME).textValue()); } + List genres = getGenres(movieDet); + // Add movie with imbd_id and other details for RSS to recommended list BasicMovie recommendedBasicMovie = new BasicMovie.Builder(movieDet.get(TITLE).textValue(), year) .setTmdbId(movieDet.get(ID).intValue()) @@ -618,6 +644,7 @@ public class GapsSearchService implements GapsSearch { .setBackdropPathUrl("https://image.tmdb.org/t/p/original/" + movieDet.get(COLLECTION_ID).get(BACKDROP_PATH).textValue()) .setOverview(movieDet.get("overview").textValue()) .setMoviesInCollection(moviesInCollection) + .setGenres(genres) .build(); if (ownedBasicMovies.contains(recommendedBasicMovie)) { diff --git a/GapsWeb/src/main/resources/templates/recommended.html b/GapsWeb/src/main/resources/templates/recommended.html index 3fd38fb..52deeda 100755 --- a/GapsWeb/src/main/resources/templates/recommended.html +++ b/GapsWeb/src/main/resources/templates/recommended.html @@ -137,7 +137,11 @@
{{name}} ({{year}})
{{collectionTitle}}

{{overview}}

-

English

+

+ {{#each genres}} + {{this}} + {{/each}} +

@@ -148,17 +152,10 @@
{{#each moviesInCollection}} {{#if this.owned}} - {{#if (isEqual this.tmdbId @root.tmdbId)}} - {{this.title}} - {{else}} {{this.title}} - {{/if}} {{/if}} {{/each}}