mirror of
https://github.com/JasonHHouse/gaps.git
synced 2026-05-12 20:39:36 -05:00
Fixing double searching
This commit is contained in:
@@ -32,8 +32,6 @@ public final class BasicMovie implements Comparable<BasicMovie> {
|
||||
@NotNull
|
||||
private final String posterUrl;
|
||||
@NotNull
|
||||
private String imdbId;
|
||||
@NotNull
|
||||
private final String language;
|
||||
@NotNull
|
||||
private final String overview;
|
||||
@@ -44,6 +42,8 @@ public final class BasicMovie implements Comparable<BasicMovie> {
|
||||
@NotNull
|
||||
private final String key;
|
||||
@NotNull
|
||||
private String imdbId;
|
||||
@NotNull
|
||||
private String collectionTitle;
|
||||
@NotNull
|
||||
private Integer collectionId;
|
||||
@@ -85,10 +85,6 @@ public final class BasicMovie implements Comparable<BasicMovie> {
|
||||
this.collectionId = collectionId;
|
||||
}
|
||||
|
||||
public void setTmdbId(int tmdbId) {
|
||||
this.tmdbId = tmdbId;
|
||||
}
|
||||
|
||||
public @NotNull String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -117,6 +113,10 @@ public final class BasicMovie implements Comparable<BasicMovie> {
|
||||
return tmdbId;
|
||||
}
|
||||
|
||||
public void setTmdbId(int tmdbId) {
|
||||
this.tmdbId = tmdbId;
|
||||
}
|
||||
|
||||
public void setTmdbId(@NotNull Integer tmdbId) {
|
||||
this.tmdbId = tmdbId;
|
||||
}
|
||||
@@ -287,7 +287,7 @@ public final class BasicMovie implements Comparable<BasicMovie> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NotNull Builder setTmdbId(@NotNull Integer tmdbId) {
|
||||
public @NotNull Builder setTmdbId(@NotNull Integer tmdbId) {
|
||||
this.tmdbId = tmdbId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.jasonhhouse.gaps.PlexServer;
|
||||
import com.jasonhhouse.gaps.Schedule;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -26,7 +28,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
public final class PlexProperties {
|
||||
|
||||
@NotNull
|
||||
private final Set<PlexServer> plexServers;
|
||||
private final List<PlexServer> plexServers;
|
||||
@NotNull
|
||||
private String movieDbApiKey;
|
||||
@NotNull
|
||||
@@ -49,7 +51,7 @@ public final class PlexProperties {
|
||||
private Schedule schedule;
|
||||
|
||||
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||
public PlexProperties(@JsonProperty(value = "plexServers") @Nullable Set<PlexServer> plexServers,
|
||||
public PlexProperties(@JsonProperty(value = "plexServers") @Nullable List<PlexServer> plexServers,
|
||||
@JsonProperty(value = "telegramProperties") @Nullable TelegramProperties telegramProperties,
|
||||
@JsonProperty(value = "pushBulletProperties") @Nullable PushBulletProperties pushBulletProperties,
|
||||
@JsonProperty(value = "emailProperties") @Nullable EmailProperties emailProperties,
|
||||
@@ -60,7 +62,7 @@ public final class PlexProperties {
|
||||
@JsonProperty(value = "movieDbApiKey") @Nullable String movieDbApiKey,
|
||||
@JsonProperty(value = "password") @Nullable String password,
|
||||
@JsonProperty(value = "schedule") @Nullable Schedule schedule) {
|
||||
this.plexServers = plexServers == null ? new HashSet<>() : plexServers;
|
||||
this.plexServers = plexServers == null ? new ArrayList<>() : plexServers;
|
||||
this.telegramProperties = telegramProperties == null ? TelegramProperties.getDefault() : telegramProperties;
|
||||
this.pushBulletProperties = pushBulletProperties == null ? PushBulletProperties.getDefault() : pushBulletProperties;
|
||||
this.emailProperties = emailProperties == null ? EmailProperties.getDefault() : emailProperties;
|
||||
@@ -74,7 +76,7 @@ public final class PlexProperties {
|
||||
}
|
||||
|
||||
public PlexProperties() {
|
||||
this.plexServers = new HashSet<>();
|
||||
this.plexServers = new ArrayList<>();
|
||||
this.telegramProperties = TelegramProperties.getDefault();
|
||||
this.pushBulletProperties = PushBulletProperties.getDefault();
|
||||
this.emailProperties = EmailProperties.getDefault();
|
||||
@@ -88,7 +90,7 @@ public final class PlexProperties {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<PlexServer> getPlexServers() {
|
||||
public List<PlexServer> getPlexServers() {
|
||||
return plexServers;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
package com.jasonhhouse.gaps.service;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Handles the process of searching, movies, counts, and canceling
|
||||
*/
|
||||
@@ -19,7 +21,7 @@ public interface GapsSearch {
|
||||
/**
|
||||
* Kicks of searching for all missing movies
|
||||
*/
|
||||
void run(String machineIdentifier, Integer key);
|
||||
void run(@NotNull String machineIdentifier, @NotNull Integer key);
|
||||
|
||||
/**
|
||||
* Cancel the current search
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
package com.jasonhhouse.gaps;
|
||||
|
||||
import com.jasonhhouse.gaps.properties.PlexProperties;
|
||||
import com.jasonhhouse.gaps.service.GapsSearch;
|
||||
import com.jasonhhouse.gaps.service.FileIoService;
|
||||
import com.jasonhhouse.gaps.service.GapsSearch;
|
||||
import com.jasonhhouse.gaps.service.NotificationService;
|
||||
import com.jasonhhouse.gaps.service.PlexQuery;
|
||||
import com.jasonhhouse.gaps.service.TmdbService;
|
||||
@@ -23,22 +23,34 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import okhttp3.HttpUrl;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
public class SearchGapsTask implements Runnable {
|
||||
public final class SearchGapsTask implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SearchGapsTask.class);
|
||||
|
||||
@NotNull
|
||||
private final GapsSearch gapsSearch;
|
||||
@NotNull
|
||||
private final TmdbService tmdbService;
|
||||
@NotNull
|
||||
private final FileIoService fileIoService;
|
||||
@NotNull
|
||||
private final PlexQuery plexQuery;
|
||||
@NotNull
|
||||
private final GapsUrlGenerator gapsUrlGenerator;
|
||||
@NotNull
|
||||
private final NotificationService notificationService;
|
||||
|
||||
public SearchGapsTask(GapsSearch gapsSearch, TmdbService tmdbService, FileIoService fileIoService, PlexQuery plexQuery, GapsUrlGenerator gapsUrlGenerator, NotificationService notificationService) {
|
||||
public SearchGapsTask(@NotNull GapsSearch gapsSearch,
|
||||
@NotNull TmdbService tmdbService,
|
||||
@NotNull FileIoService fileIoService,
|
||||
@NotNull PlexQuery plexQuery,
|
||||
@NotNull GapsUrlGenerator gapsUrlGenerator,
|
||||
@NotNull NotificationService notificationService) {
|
||||
this.gapsSearch = gapsSearch;
|
||||
this.tmdbService = tmdbService;
|
||||
this.fileIoService = fileIoService;
|
||||
@@ -71,7 +83,7 @@ public class SearchGapsTask implements Runnable {
|
||||
}
|
||||
|
||||
private boolean checkTmdbKey() {
|
||||
LOGGER.info("checkTmdbKey()");
|
||||
LOGGER.debug("checkTmdbKey()");
|
||||
|
||||
String tmdbKey = fileIoService.readProperties().getMovieDbApiKey();
|
||||
Payload payload = tmdbService.testTmdbKey(tmdbKey);
|
||||
@@ -85,9 +97,10 @@ public class SearchGapsTask implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPlexServers(PlexProperties plexProperties) {
|
||||
LOGGER.info("checkPlexServers()");
|
||||
private void checkPlexServers(@NotNull PlexProperties plexProperties) {
|
||||
LOGGER.debug("checkPlexServers()");
|
||||
|
||||
int counter = 0;
|
||||
for (PlexServer plexServer : plexProperties.getPlexServers()) {
|
||||
Payload payload = plexQuery.queryPlexServer(plexServer);
|
||||
if (payload.getCode() == Payload.PLEX_CONNECTION_SUCCEEDED.getCode()) {
|
||||
@@ -95,11 +108,15 @@ public class SearchGapsTask implements Runnable {
|
||||
} else {
|
||||
notificationService.plexServerConnectFailed(plexServer, payload.getReason());
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
LOGGER.info("checkPlexServers() executed {} times", counter);
|
||||
}
|
||||
|
||||
private void updatePlexLibraries(PlexProperties plexProperties) {
|
||||
LOGGER.info("updatePlexLibraries()");
|
||||
private void updatePlexLibraries(@NotNull PlexProperties plexProperties) {
|
||||
LOGGER.debug("updatePlexLibraries()");
|
||||
|
||||
int counter = 0;
|
||||
//Update each Plex Library from each Plex Server
|
||||
for (PlexServer plexServer : plexProperties.getPlexServers()) {
|
||||
Payload getLibrariesResults = plexQuery.getLibraries(plexServer);
|
||||
@@ -108,11 +125,15 @@ public class SearchGapsTask implements Runnable {
|
||||
} else {
|
||||
LOGGER.warn("Plex libraries not found for Plex Server {}", plexServer.getFriendlyName());
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
LOGGER.info("updatePlexLibraries() executed {} times", counter);
|
||||
}
|
||||
|
||||
private void updateLibraryMovies(PlexProperties plexProperties) {
|
||||
LOGGER.info("updateLibraryMovies()");
|
||||
private void updateLibraryMovies(@NotNull PlexProperties plexProperties) {
|
||||
LOGGER.debug("updateLibraryMovies()");
|
||||
|
||||
int counter = 0;
|
||||
for (PlexServer plexServer : plexProperties.getPlexServers()) {
|
||||
for (PlexLibrary plexLibrary : plexServer.getPlexLibraries()) {
|
||||
HttpUrl url = gapsUrlGenerator.generatePlexLibraryUrl(plexServer, plexLibrary);
|
||||
@@ -124,20 +145,25 @@ public class SearchGapsTask implements Runnable {
|
||||
} catch (ResponseStatusException e) {
|
||||
notificationService.plexLibraryScanFailed(plexServer, plexLibrary, e.getMessage());
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
LOGGER.info("updateLibraryMovies() executed {} times", counter);
|
||||
}
|
||||
|
||||
private void findRecommendedMovies(PlexProperties plexProperties) {
|
||||
LOGGER.info("findRecommendedMovies()");
|
||||
private void findRecommendedMovies(@NotNull PlexProperties plexProperties) {
|
||||
LOGGER.debug("updateLibraryMovies()");
|
||||
int counter =0;
|
||||
for (PlexServer plexServer : plexProperties.getPlexServers()) {
|
||||
for (PlexLibrary plexLibrary : plexServer.getPlexLibraries()) {
|
||||
gapsSearch.run(plexServer.getMachineIdentifier(), plexLibrary.getKey());
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
LOGGER.info("findRecommendedMovies() executed {} times", counter);
|
||||
}
|
||||
|
||||
private Map<Pair<String, Integer>, BasicMovie> generateOwnedMovieMap(PlexProperties plexProperties) {
|
||||
private @NotNull Map<Pair<String, Integer>, BasicMovie> generateOwnedMovieMap(@NotNull PlexProperties plexProperties) {
|
||||
Set<BasicMovie> everyBasicMovie = fileIoService.readMovieIdsFromFile();
|
||||
Map<Pair<String, Integer>, BasicMovie> previousMovies = new HashMap<>();
|
||||
|
||||
|
||||
@@ -90,11 +90,10 @@ public class ConfigurationController {
|
||||
Payload payload = plexQuery.getLibraries(plexServer);
|
||||
|
||||
if (payload.getCode() == Payload.PLEX_LIBRARIES_FOUND.getCode()) {
|
||||
int initialCount = plexProperties.getPlexServers().size();
|
||||
plexProperties.addPlexServer(plexServer);
|
||||
if (plexProperties.getPlexServers().size() == initialCount) {
|
||||
if (plexProperties.getPlexServers().contains(plexServer)) {
|
||||
template.convertAndSend(CONFIGURATION_PLEX + "/duplicate", Payload.DUPLICATE_PLEX_LIBRARY);
|
||||
} else {
|
||||
plexProperties.addPlexServer(plexServer);
|
||||
fileIoService.writeProperties(plexProperties);
|
||||
template.convertAndSend(CONFIGURATION_PLEX_COMPLETE, payload.setExtras(plexServer));
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -106,7 +107,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String machineIdentifier, Integer key) {
|
||||
public void run(@NotNull String machineIdentifier,@NotNull Integer key) {
|
||||
LOGGER.info("run( {}, {} )", machineIdentifier, key);
|
||||
|
||||
PlexProperties plexProperties = fileIoService.readProperties();
|
||||
@@ -186,11 +187,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
|
||||
template.convertAndSend(FINISHED_SEARCHING_URL, Payload.SEARCH_SUCCESSFUL);
|
||||
|
||||
LOGGER.info("Recommended");
|
||||
for (BasicMovie basicMovie : recommended) {
|
||||
String strMovie = basicMovie.toString();
|
||||
LOGGER.info(strMovie);
|
||||
}
|
||||
LOGGER.info("Recommending {} movies.", recommended.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,7 +213,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
|
||||
private void searchForMovies(PlexProperties plexProperties, String machineIdentifier, Integer key, List<BasicMovie> ownedBasicMovies, List<BasicMovie> everyBasicMovie, Set<BasicMovie> recommended, List<BasicMovie> searched,
|
||||
AtomicInteger searchedMovieCount) throws SearchCancelledException, IOException {
|
||||
LOGGER.info("searchForMovies()");
|
||||
LOGGER.debug("searchForMovies()");
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
if (StringUtils.isEmpty(plexProperties.getMovieDbApiKey())) {
|
||||
@@ -364,7 +361,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
|
||||
private void searchMovieDetails(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.info("searchMovieDetails()");
|
||||
LOGGER.debug("searchMovieDetails()");
|
||||
HttpUrl movieDetailUrl = urlGenerator.generateMovieDetailUrl(plexProperties.getMovieDbApiKey(), String.valueOf(basicMovie.getTmdbId()), languageCode);
|
||||
|
||||
Request request = new Request.Builder()
|
||||
@@ -422,7 +419,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
|
||||
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.info("handleCollection()");
|
||||
LOGGER.debug("handleCollection()");
|
||||
HttpUrl collectionUrl = urlGenerator.generateCollectionUrl(plexProperties.getMovieDbApiKey(), String.valueOf(basicMovie.getCollectionId()), languageCode);
|
||||
|
||||
Request request = new Request.Builder()
|
||||
|
||||
@@ -114,6 +114,7 @@ public class PlexQueryImpl implements PlexQuery {
|
||||
List<PlexLibrary> plexLibraries = mediaContainer.getPlexLibraries().stream().filter(plexLibrary -> plexLibrary.getType().equalsIgnoreCase("movie")).collect(Collectors.toList());
|
||||
|
||||
LOGGER.info("{} Plex libraries found", plexLibraries.size());
|
||||
plexServer.getPlexLibraries().clear();
|
||||
plexServer.getPlexLibraries().addAll(plexLibraries);
|
||||
return Payload.PLEX_LIBRARIES_FOUND.setExtras("size():" + plexLibraries.size());
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.jasonhhouse.gaps.properties.PlexProperties;
|
||||
import com.jasonhhouse.plex.libs.PlexLibrary;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.validation.constraints.NotNull;
|
||||
@@ -39,7 +40,7 @@ public class RssService {
|
||||
Map<PlexLibrary, PlexServer> plexServerMap = new HashMap<>();
|
||||
|
||||
PlexProperties plexProperties = fileIoService.readProperties();
|
||||
Set<PlexServer> plexServers = plexProperties.getPlexServers();
|
||||
List<PlexServer> plexServers = plexProperties.getPlexServers();
|
||||
if (CollectionUtils.isEmpty(plexServers)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user