Skip to content

Commit

Permalink
Merge pull request #233 from JasonHHouse/improvement/genres
Browse files Browse the repository at this point in the history
Improvement/genres
  • Loading branch information
JasonHHouse authored Jun 1, 2021
2 parents ee25711 + 9ae174e commit 9e39165
Show file tree
Hide file tree
Showing 28 changed files with 160 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>Gaps</artifactId>
<groupId>com.jasonhhouse</groupId>
<version>0.9.3</version>
<version>0.9.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
33 changes: 28 additions & 5 deletions Core/src/main/java/com/jasonhhouse/gaps/BasicMovie.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -64,7 +66,8 @@ private BasicMovie(@NotNull String name,
@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;
Expand All @@ -79,6 +82,7 @@ private BasicMovie(@NotNull String name,
this.moviesInCollection = moviesInCollection;
this.ratingKey = ratingKey;
this.key = key;
this.genres = genres;
}

public @NotNull Integer getCollectionId() {
Expand Down Expand Up @@ -137,12 +141,20 @@ public void setTmdbId(@NotNull Integer tmdbId) {
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
Expand Down Expand Up @@ -198,7 +210,6 @@ public String toString() {
", year=" + year +
", nameWithoutBadCharacters='" + nameWithoutBadCharacters + '\'' +
", posterUrl='" + posterUrl + '\'' +
", backdropPathUrl='" + backdropPathUrl + '\'' +
", language='" + language + '\'' +
", overview='" + overview + '\'' +
", moviesInCollection=" + moviesInCollection +
Expand All @@ -207,7 +218,9 @@ public String toString() {
", imdbId='" + imdbId + '\'' +
", collectionTitle='" + collectionTitle + '\'' +
", collectionId=" + collectionId +
", backdropPathUrl='" + backdropPathUrl + '\'' +
", tmdbId=" + tmdbId +
", genres=" + genres +
'}';
}

Expand Down Expand Up @@ -268,6 +281,10 @@ public static class Builder {
@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) {
Expand All @@ -284,10 +301,11 @@ public Builder(@JsonProperty(value = "name") @NotNull String name,
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) {
Expand Down Expand Up @@ -344,5 +362,10 @@ public Builder(@JsonProperty(value = "name") @NotNull String name,
this.key = key;
return this;
}

public @NotNull Builder setGenres(@NotNull List<String> genres) {
this.genres = genres;
return this;
}
}
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN mkdir -p /usr/app && chmod 777 /usr/data

WORKDIR /usr/app

COPY GapsWeb/target/GapsWeb-0.9.3.jar /usr/app/gaps.jar
COPY GapsWeb/target/GapsWeb-0.9.4.jar /usr/app/gaps.jar

COPY start.sh /usr/app/

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN mkdir -p /usr/app && chmod 777 /usr/data

WORKDIR /usr/app

COPY GapsWeb/target/GapsWeb-0.9.3.jar /usr/app/gaps.jar
COPY GapsWeb/target/GapsWeb-0.9.4.jar /usr/app/gaps.jar

COPY start.sh /usr/app/

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.ppc64le
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN mkdir -p /usr/app && chmod 777 /usr/data

WORKDIR /usr/app

COPY GapsWeb/target/GapsWeb-0.9.3.jar /usr/app/gaps.jar
COPY GapsWeb/target/GapsWeb-0.9.4.jar /usr/app/gaps.jar

COPY start.sh /usr/app/

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.raspbian
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN mkdir -p /usr/app && chmod 777 /usr/data

WORKDIR /usr/app

COPY GapsWeb/target/GapsWeb-0.9.3.jar /usr/app/gaps.jar
COPY GapsWeb/target/GapsWeb-0.9.4.jar /usr/app/gaps.jar

COPY start.sh /usr/app/

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.riscv64
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RUN mkdir -p /usr/app && chmod 777 /usr/data

WORKDIR /usr/app

COPY GapsWeb/target/GapsWeb-0.9.3.jar /usr/app/gaps.jar
COPY GapsWeb/target/GapsWeb-0.9.4.jar /usr/app/gaps.jar

COPY start.sh /usr/app/

Expand Down
2 changes: 1 addition & 1 deletion GapsAsJar/gaps.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ RMDIR /r $INSTDIR
SectionEnd

# name the installer
OutFile "gaps-0.9.3-installer.exe"
OutFile "gaps-0.9.4-installer.exe"
2 changes: 1 addition & 1 deletion GapsWeb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>Gaps</artifactId>
<groupId>com.jasonhhouse</groupId>
<version>0.9.3</version>
<version>0.9.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
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;
Expand Down Expand Up @@ -71,13 +73,15 @@ 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";
public static final String RELEASE_DATE = "release_date";
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();

Expand All @@ -95,8 +99,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;
Expand All @@ -108,7 +114,7 @@ public GapsSearchService(@Qualifier("real") UrlGenerator urlGenerator, SimpMessa
}

@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();
Expand Down Expand Up @@ -228,7 +234,6 @@ private void searchForMovies(PlexProperties plexProperties, String machineIdenti
}

for (BasicMovie basicMovie : ownedBasicMovies) {
String languageCode = "en-US";

//Cancel search if needed
if (cancelSearch.get()) {
Expand Down Expand Up @@ -397,20 +402,25 @@ private void searchMovieDetails(PlexProperties plexProperties, String machineIde
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");
everyBasicMovie.get(indexOfMovie).setTmdbId(basicMovie.getTmdbId());
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())
.setImdbId(basicMovie.getImdbId())
.setCollectionTitle(basicMovie.getCollectionTitle())
.setCollectionId(basicMovie.getCollectionId())
.setBackdropPathUrl(basicMovie.getBackdropPathUrl())
.setGenres(basicMovie.getGenres())
.build();
everyBasicMovie.add(newBasicMovie);
}
Expand All @@ -422,6 +432,19 @@ private void searchMovieDetails(PlexProperties plexProperties, String machineIde
}
}

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()");
Expand Down Expand Up @@ -506,6 +529,7 @@ private void handleCollection(PlexProperties plexProperties, String machineIdent
.setOverview(basicMovie.getOverview())
.setPosterUrl(basicMovie.getPosterUrl())
.setBackdropPathUrl(basicMovie.getBackdropPathUrl())
.setGenres(basicMovie.getGenres())
.build();
everyBasicMovie.add(newBasicMovie);

Expand Down Expand Up @@ -547,6 +571,7 @@ private void handleCollection(PlexProperties plexProperties, String machineIdent
.setPosterUrl(posterUrl)
.setMoviesInCollection(moviesInCollection)
.setBackdropPathUrl(basicMovie.getBackdropPathUrl())
.setGenres(basicMovie.getGenres())
.build();

if (ownedBasicMovies.contains(basicMovieFromCollection)) {
Expand Down Expand Up @@ -608,6 +633,8 @@ private void handleCollection(PlexProperties plexProperties, String machineIdent
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())
Expand All @@ -618,6 +645,7 @@ private void handleCollection(PlexProperties plexProperties, String machineIdent
.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)) {
Expand Down
Loading

0 comments on commit 9e39165

Please sign in to comment.