Adding genres to recommended movies

This commit is contained in:
Jason
2021-05-31 21:16:09 +09:00
parent ee25711057
commit 3410b0470e
3 changed files with 63 additions and 16 deletions
@@ -51,6 +51,8 @@ public final class BasicMovie implements Comparable<BasicMovie> {
private String backdropPathUrl;
@NotNull
private Integer tmdbId;
@NotNull
private List<String> genres;
private BasicMovie(@NotNull String name,
@NotNull Integer year,
@@ -64,7 +66,8 @@ public final class BasicMovie implements Comparable<BasicMovie> {
@NotNull String overview,
@NotNull List<MovieFromCollection> moviesInCollection,
@NotNull Integer ratingKey,
@NotNull String key) {
@NotNull String key,
@NotNull List<String> genres) {
this.name = name;
this.nameWithoutBadCharacters = name.replaceAll("[<>`~\\[\\]()*&^%$#@!|{}.,?\\-_=+:;]", "");
this.year = year;
@@ -79,6 +82,7 @@ public final class BasicMovie implements Comparable<BasicMovie> {
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<BasicMovie> {
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<String> getGenres() {
return genres;
}
public void setGenres(@NotNull List<String> genres) {
this.genres = genres;
}
@JsonIgnore
@@ -198,7 +210,6 @@ public final class BasicMovie implements Comparable<BasicMovie> {
", year=" + year +
", nameWithoutBadCharacters='" + nameWithoutBadCharacters + '\'' +
", posterUrl='" + posterUrl + '\'' +
", backdropPathUrl='" + backdropPathUrl + '\'' +
", language='" + language + '\'' +
", overview='" + overview + '\'' +
", moviesInCollection=" + moviesInCollection +
@@ -207,7 +218,9 @@ public final class BasicMovie implements Comparable<BasicMovie> {
", imdbId='" + imdbId + '\'' +
", collectionTitle='" + collectionTitle + '\'' +
", collectionId=" + collectionId +
", backdropPathUrl='" + backdropPathUrl + '\'' +
", tmdbId=" + tmdbId +
", genres=" + genres +
'}';
}
@@ -268,6 +281,10 @@ public final class BasicMovie implements Comparable<BasicMovie> {
@JsonProperty
private String key;
@NotNull
@JsonProperty
private List<String> 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<BasicMovie> {
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<BasicMovie> {
this.key = key;
return this;
}
public @NotNull Builder setGenres(@NotNull List<String> genres) {
this.genres = genres;
return this;
}
}
}
@@ -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<String> 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<String> getGenres(@NotNull JsonNode movieDetails) {
List<String> genres = new ArrayList<>();
Iterator<JsonNode> 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<BasicMovie> ownedBasicMovies, List<BasicMovie> everyBasicMovie, Set<BasicMovie> recommended, List<BasicMovie> 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<String> 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)) {
@@ -137,7 +137,11 @@
<h5 class="card-title">{{name}} ({{year}})</h5>
<h6 class="card-title">{{collectionTitle}}</h6>
<p class="card-text">{{overview}}</p>
<p class="card-text"><small class="text-info">English</small></p>
<p class="card-text">
{{#each genres}}
<small class="text-info">{{this}}</small>
{{/each}}
</p>
</div>
</div>
</div>
@@ -148,17 +152,10 @@
<div class="list-group">
{{#each moviesInCollection}}
{{#if this.owned}}
{{#if (isEqual this.tmdbId @root.tmdbId)}}
<a data-cy="{{@root.imdbId}}-{{this.tmdbId}}"
href="https://www.themoviedb.org/movie/{{this.tmdbId}}" target="_blank"
class="list-group-item list-group-item-action active"
rel="noopener noreferrer">{{this.title}}</a>
{{else}}
<a data-cy="{{@root.imdbId}}-{{this.tmdbId}}"
href="https://www.themoviedb.org/movie/{{this.tmdbId}}" target="_blank"
class="list-group-item list-group-item-action"
rel="noopener noreferrer">{{this.title}}</a>
{{/if}}
{{/if}}
{{/each}}
</div>