diff --git a/Core/src/main/java/com/jasonhhouse/gaps/properties/PlexProperties.java b/Core/src/main/java/com/jasonhhouse/gaps/properties/PlexProperties.java index 67527d83..2d9fb173 100755 --- a/Core/src/main/java/com/jasonhhouse/gaps/properties/PlexProperties.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/properties/PlexProperties.java @@ -14,7 +14,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.Schedule; import java.util.HashSet; import java.util.Set; diff --git a/Core/src/main/java/com/jasonhhouse/gaps/service/PlexQuery.java b/Core/src/main/java/com/jasonhhouse/gaps/service/PlexQuery.java index ec25042e..74578443 100755 --- a/Core/src/main/java/com/jasonhhouse/gaps/service/PlexQuery.java +++ b/Core/src/main/java/com/jasonhhouse/gaps/service/PlexQuery.java @@ -14,10 +14,10 @@ import com.jasonhhouse.gaps.BasicMovie; import com.jasonhhouse.gaps.Pair; import com.jasonhhouse.gaps.Payload; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.properties.PlexProperties; -import com.jasonhhouse.plex.libs.PlexLibrary; -import com.jasonhhouse.plex.video.MediaContainer; +import com.jasonhhouse.gaps.plex.PlexLibrary; +import com.jasonhhouse.gaps.plex.video.MediaContainer; import java.util.List; import java.util.Map; import okhttp3.HttpUrl; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsApplication.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsApplication.java index b29c867a..561c5526 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsApplication.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsApplication.java @@ -34,7 +34,7 @@ * Search for all missing movies in your plex collection by MovieDB collection. */ @SpringBootApplication -@EntityScan("com.jasonhhouse.plex") +@EntityScan("com.jasonhhouse.gaps.plex") @EnableAsync @EnableConfigurationProperties @ConfigurationPropertiesScan diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsUrlGenerator.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsUrlGenerator.java index 3b01ca50..9d78f97e 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsUrlGenerator.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/GapsUrlGenerator.java @@ -10,7 +10,8 @@ package com.jasonhhouse.gaps; -import com.jasonhhouse.plex.libs.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexServer; import okhttp3.HttpUrl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -103,7 +104,7 @@ public class GapsUrlGenerator implements UrlGenerator { } @Override - public @Nullable HttpUrl generatePlexLibraryUrl(@NotNull PlexServer plexServer,@NotNull PlexLibrary plexLibrary) { + public @Nullable HttpUrl generatePlexLibraryUrl(@NotNull PlexServer plexServer, @NotNull PlexLibrary plexLibrary) { return new HttpUrl.Builder() .scheme(HTTP) .host(plexServer.getAddress()) diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/PlexServerToStringConverter.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/PlexServerToStringConverter.java index 01555454..3a904697 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/PlexServerToStringConverter.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/PlexServerToStringConverter.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.jasonhhouse.gaps.plex.PlexServer; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/SearchGapsTask.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/SearchGapsTask.java index 28ff20bc..c1d2a782 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/SearchGapsTask.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/SearchGapsTask.java @@ -10,13 +10,14 @@ package com.jasonhhouse.gaps; +import com.jasonhhouse.gaps.plex.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.properties.PlexProperties; import com.jasonhhouse.gaps.service.GapsSearch; import com.jasonhhouse.gaps.service.FileIoService; import com.jasonhhouse.gaps.service.NotificationService; import com.jasonhhouse.gaps.service.PlexQuery; import com.jasonhhouse.gaps.service.TmdbService; -import com.jasonhhouse.plex.libs.PlexLibrary; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -91,7 +92,8 @@ private void checkPlexServers(PlexProperties plexProperties) { for (PlexServer plexServer : plexProperties.getPlexServers()) { Payload payload = plexQuery.queryPlexServer(plexServer); if (payload.getCode() == Payload.PLEX_CONNECTION_SUCCEEDED.getCode()) { - notificationService.plexServerConnectSuccessful(plexServer); + plexProperties.addPlexServer((PlexServer) payload.getExtras()); + notificationService.plexServerConnectSuccessful((PlexServer) payload.getExtras()); } else { notificationService.plexServerConnectFailed(plexServer, payload.getReason()); } diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/UrlGenerator.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/UrlGenerator.java index d16d2282..85502436 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/UrlGenerator.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/UrlGenerator.java @@ -9,7 +9,8 @@ */ package com.jasonhhouse.gaps; -import com.jasonhhouse.plex.libs.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexServer; import okhttp3.HttpUrl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -70,7 +71,7 @@ public interface UrlGenerator { * @param plexLibrary The PlexLibrary to query * @return query */ - @Nullable HttpUrl generatePlexLibraryUrl(@NotNull PlexServer plexServer,@NotNull PlexLibrary plexLibrary); + @Nullable HttpUrl generatePlexLibraryUrl(@NotNull PlexServer plexServer, @NotNull PlexLibrary plexLibrary); @NotNull HttpUrl generatePlexMetadataUrl(@NotNull PlexServer plexServer, @NotNull PlexLibrary plexLibrary,@NotNull Integer ratingKey); diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/ConfigurationController.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/ConfigurationController.java index 316a1c16..5cb2e9aa 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/ConfigurationController.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/ConfigurationController.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.jasonhhouse.gaps.Payload; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.properties.PlexProperties; import com.jasonhhouse.gaps.service.FileIoService; import com.jasonhhouse.gaps.service.PlexQueryImpl; @@ -20,6 +20,7 @@ import com.jasonhhouse.gaps.service.TmdbService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import java.util.Collections; import javax.validation.Valid; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -80,13 +81,20 @@ public ModelAndView getConfiguration() { @PostMapping(value = "/add/plex", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) @ResponseStatus(value = HttpStatus.OK) - public void postAddPlexServer(@Parameter(description = "The details of the Plex Server to add.") @Valid final PlexServer plexServer) { - LOGGER.info("postAddPlexServer( {} )", plexServer); + public void postAddPlexServer(@Parameter(description = "The details of the Plex Server to add.") @Valid final PlexServer sentPlexServer) { + LOGGER.info("postAddPlexServer( {} )", sentPlexServer); PlexProperties plexProperties = fileIoService.readProperties(); try { - plexQuery.queryPlexServer(plexServer); + PlexServer plexServer; + Payload plexServerPayload = plexQuery.queryPlexServer(sentPlexServer); + if (plexServerPayload.getCode() == Payload.PLEX_CONNECTION_SUCCEEDED.getCode()) { + plexServer = (PlexServer) plexServerPayload.getExtras(); + } else { + plexServer = sentPlexServer; + } + Payload payload = plexQuery.getLibraries(plexServer); if (payload.getCode() == Payload.PLEX_LIBRARIES_FOUND.getCode()) { @@ -135,7 +143,8 @@ public ResponseEntity putTestPlexServerByMachineId(@PathVariable("machin PlexProperties plexProperties = fileIoService.readProperties(); ObjectNode objectNode = objectMapper.createObjectNode(); - PlexServer returnedPlexServer = plexProperties.getPlexServers().stream().filter(plexServer -> plexServer.getMachineIdentifier().equals(machineIdentifier)).findFirst().orElse(new PlexServer()); + PlexServer returnedPlexServer = plexProperties.getPlexServers().stream().filter(plexServer -> + plexServer.getMachineIdentifier().equals(machineIdentifier)).findFirst().orElse(new PlexServer("", "", "", "", -1, Collections.emptySet())); if (StringUtils.isEmpty(returnedPlexServer.getMachineIdentifier())) { //Failed to find and delete @@ -157,7 +166,8 @@ public ResponseEntity deletePlexServer(@PathVariable("machineIdentifier" PlexProperties plexProperties = fileIoService.readProperties(); ObjectNode objectNode = objectMapper.createObjectNode(); - PlexServer returnedPlexServer = plexProperties.getPlexServers().stream().filter(plexServer -> plexServer.getMachineIdentifier().equals(machineIdentifier)).findFirst().orElse(new PlexServer()); + PlexServer returnedPlexServer = plexProperties.getPlexServers().stream().filter(plexServer -> + plexServer.getMachineIdentifier().equals(machineIdentifier)).findFirst().orElse(new PlexServer("", "", "", "", -1, Collections.emptySet())); if (StringUtils.isEmpty(returnedPlexServer.getMachineIdentifier())) { //Failed to find and delete objectNode.put(SUCCESS, false); @@ -193,4 +203,12 @@ public ResponseEntity postSaveTmdbKey(@PathVariable("tmdbKey") final St return ResponseEntity.ok().body(payload); } + @PutMapping(value = "/update/plex/library", + produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody + public ResponseEntity putPlexLibrary(final Object object) { + LOGGER.info("putPlexLibrary( {} )", object); + + return ResponseEntity.ok().body(Payload.PLEX_CONNECTION_SUCCEEDED); + } } diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/LibraryController.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/LibraryController.java index 3e911f44..1e10da92 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/LibraryController.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/LibraryController.java @@ -11,10 +11,11 @@ import com.jasonhhouse.gaps.BasicMovie; import com.jasonhhouse.gaps.Payload; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.properties.PlexProperties; import com.jasonhhouse.gaps.service.FileIoService; -import com.jasonhhouse.plex.libs.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexLibrary; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -56,12 +57,12 @@ public ModelAndView getLibraries() { PlexLibrary plexLibrary; if (CollectionUtils.isNotEmpty(plexProperties.getPlexServers())) { //Read first plex servers movies - plexServer = plexProperties.getPlexServers().stream().findFirst().orElse(new PlexServer()); - plexLibrary = plexServer.getPlexLibraries().stream().findFirst().orElse(new PlexLibrary()); + plexServer = plexProperties.getPlexServers().stream().findFirst().orElse(new PlexServer("", "","", "",-1, Collections.emptySet())); + plexLibrary = plexServer.getPlexLibraries().stream().findFirst().orElse(new PlexLibrary(-1, "","","",false, false)); plexServersFound = true; } else { - plexServer = new PlexServer(); - plexLibrary = new PlexLibrary(); + plexServer = new PlexServer("", "","", "",-1, Collections.emptySet()); + plexLibrary = new PlexLibrary(-1, "","","",false, false); plexServersFound = false; } diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/MislabeledController.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/MislabeledController.java index b472353f..3af2d58a 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/MislabeledController.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/MislabeledController.java @@ -15,7 +15,7 @@ import com.jasonhhouse.gaps.service.FileIoService; import com.jasonhhouse.gaps.service.MediaContainerService; import com.jasonhhouse.gaps.service.MislabeledService; -import com.jasonhhouse.plex.video.MediaContainer; +import com.jasonhhouse.gaps.plex.video.MediaContainer; import java.util.List; import org.apache.commons.lang3.time.StopWatch; import org.slf4j.Logger; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/PlexMovieListController.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/PlexMovieListController.java index 19f7e902..1b89344a 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/PlexMovieListController.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/PlexMovieListController.java @@ -13,11 +13,11 @@ import com.jasonhhouse.gaps.GapsUrlGenerator; import com.jasonhhouse.gaps.BasicMovie; import com.jasonhhouse.gaps.Pair; +import com.jasonhhouse.gaps.plex.PlexLibrary; import com.jasonhhouse.gaps.service.PlexQuery; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.properties.PlexProperties; import com.jasonhhouse.gaps.service.FileIoService; -import com.jasonhhouse.plex.libs.PlexLibrary; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/RSSController.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/RSSController.java index 4e0f3c4a..850fff3b 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/RSSController.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/RSSController.java @@ -10,11 +10,11 @@ package com.jasonhhouse.gaps.controller; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.properties.PlexProperties; import com.jasonhhouse.gaps.service.FileIoService; import com.jasonhhouse.gaps.service.RssService; -import com.jasonhhouse.plex.libs.PlexLibrary; import java.util.Map; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/RecommendedController.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/RecommendedController.java index 12cca699..af874c89 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/RecommendedController.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/controller/RecommendedController.java @@ -12,10 +12,11 @@ import com.jasonhhouse.gaps.service.GapsSearch; import com.jasonhhouse.gaps.BasicMovie; import com.jasonhhouse.gaps.Payload; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.properties.PlexProperties; import com.jasonhhouse.gaps.service.FileIoService; -import com.jasonhhouse.plex.libs.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexLibrary; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -63,11 +64,11 @@ public ModelAndView getRecommended() { if (CollectionUtils.isNotEmpty(plexProperties.getPlexServers())) { //Read first plex servers movies - plexServer = plexProperties.getPlexServers().stream().findFirst().orElse(new PlexServer()); - plexLibrary = plexServer.getPlexLibraries().stream().findFirst().orElse(new PlexLibrary()); + plexServer = plexProperties.getPlexServers().stream().findFirst().orElse(new PlexServer("", "","", "",-1, Collections.emptySet())); + plexLibrary = plexServer.getPlexLibraries().stream().findFirst().orElse(new PlexLibrary(-1, "","","",false, false)); } else { - plexServer = new PlexServer(); - plexLibrary = new PlexLibrary(); + plexServer = new PlexServer("", "","", "",-1, Collections.emptySet()); + plexLibrary = new PlexLibrary(-1, "","","",false, false); } Map plexServerMap = plexProperties.getPlexServers().stream().collect(Collectors.toMap(PlexServer::getMachineIdentifier, Function.identity())); 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 e3d961da..35f42cb9 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/GapsSearchService.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/GapsSearchService.java @@ -18,12 +18,12 @@ import com.jasonhhouse.gaps.BasicMovie; import com.jasonhhouse.gaps.MovieFromCollection; import com.jasonhhouse.gaps.Payload; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.SearchCancelledException; import com.jasonhhouse.gaps.SearchResults; import com.jasonhhouse.gaps.UrlGenerator; import com.jasonhhouse.gaps.properties.PlexProperties; -import com.jasonhhouse.plex.libs.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexLibrary; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.net.URLEncoder; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/MediaContainerService.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/MediaContainerService.java index f26c5b24..1998d8ee 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/MediaContainerService.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/MediaContainerService.java @@ -1,7 +1,7 @@ package com.jasonhhouse.gaps.service; import com.jasonhhouse.gaps.sql.MediaContainerRepository; -import com.jasonhhouse.plex.video.MediaContainer; +import com.jasonhhouse.gaps.plex.video.MediaContainer; import java.util.List; import org.springframework.stereotype.Service; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/MislabeledService.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/MislabeledService.java index 45719810..43e7ddee 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/MislabeledService.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/MislabeledService.java @@ -10,8 +10,8 @@ package com.jasonhhouse.gaps.service; import com.jasonhhouse.gaps.Mislabeled; -import com.jasonhhouse.plex.video.MediaContainer; -import com.jasonhhouse.plex.video.Video; +import com.jasonhhouse.gaps.plex.video.MediaContainer; +import com.jasonhhouse.gaps.plex.video.Video; import java.util.ArrayList; import java.util.List; import org.apache.commons.text.similarity.LevenshteinDistance; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/Notification.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/Notification.java index ae31cec2..536b1fee 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/Notification.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/Notification.java @@ -1,7 +1,7 @@ package com.jasonhhouse.gaps.service; -import com.jasonhhouse.gaps.PlexServer; -import com.jasonhhouse.plex.libs.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexServer; +import com.jasonhhouse.gaps.plex.PlexLibrary; public interface Notification { diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/NotificationService.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/NotificationService.java index 68624749..c883d80b 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/NotificationService.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/NotificationService.java @@ -10,10 +10,10 @@ package com.jasonhhouse.gaps.service; import com.jasonhhouse.gaps.NotificationType; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.notifications.NotificationAgent; import com.jasonhhouse.gaps.properties.NotificationProperties; -import com.jasonhhouse.plex.libs.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexLibrary; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/PlexQueryImpl.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/PlexQueryImpl.java index d7510375..c95d8ba4 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/PlexQueryImpl.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/PlexQueryImpl.java @@ -13,11 +13,10 @@ import com.jasonhhouse.gaps.BasicMovie; import com.jasonhhouse.gaps.Pair; import com.jasonhhouse.gaps.Payload; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.UrlGenerator; import com.jasonhhouse.gaps.properties.PlexProperties; -import com.jasonhhouse.plex.libs.MediaContainer; -import com.jasonhhouse.plex.libs.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexLibrary; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -26,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; @@ -60,8 +58,6 @@ @Service public class PlexQueryImpl implements PlexQuery { - public static final String ID_IDX_START = "://"; - public static final String ID_IDX_END = "?"; private static final long TIMEOUT = 2500; private static final Logger LOGGER = LoggerFactory.getLogger(PlexQueryImpl.class); @@ -76,6 +72,8 @@ public PlexQueryImpl(@Qualifier("real") UrlGenerator urlGenerator) { public @NotNull Payload getLibraries(@NotNull PlexServer plexServer) { LOGGER.info("queryPlexLibraries()"); + List plexLibraries = new ArrayList<>(); + HttpUrl url = new HttpUrl.Builder() .scheme("http") .host(plexServer.getAddress()) @@ -97,22 +95,53 @@ public PlexQueryImpl(@Qualifier("real") UrlGenerator urlGenerator) { .build(); try (Response response = client.newCall(request).execute()) { - String body = response.body() != null ? response.body().string() : null; + NodeList directories = parseXml(response, url, "/MediaContainer/Directory"); - if (StringUtils.isBlank(body)) { - String reason = "Body returned empty from Plex"; - LOGGER.error(reason); - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, reason); + if (directories.getLength() == 0) { + LOGGER.warn("No movies found in url: {}", url); + return Payload.PARSING_PLEX_FAILED.setExtras("url:" + url); } - InputStream inputStream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)); - JAXBContext jaxbContext = JAXBContext.newInstance(MediaContainer.class); - Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); - MediaContainer mediaContainer = (MediaContainer) jaxbUnmarshaller.unmarshal(inputStream); + for (int i = 0; i < directories.getLength(); i++) { + Node directory = directories.item(i); - //Remove everything except movie folders - List plexLibraries = mediaContainer.getPlexLibraries().stream().filter(plexLibrary -> plexLibrary.getType().equalsIgnoreCase("movie")).collect(Collectors.toList()); + Node nodeKey = directory.getAttributes().getNamedItem("key"); + Node nodeScanner = directory.getAttributes().getNamedItem("scanner"); + Node nodeTitle = directory.getAttributes().getNamedItem("title"); + Node nodeType = directory.getAttributes().getNamedItem("type"); + + if (nodeTitle == null) { + String reason = "Missing title from Video element in Plex"; + LOGGER.warn(reason); + continue; + } + if(nodeType == null || !"movie".equalsIgnoreCase(nodeType.getNodeValue())) { + LOGGER.info("Skipping library {}, not of type movie",nodeTitle.getNodeValue()); + continue; + } + + if(nodeKey == null) { + LOGGER.warn("Skipping library {}, key missing",nodeTitle.getNodeValue()); + continue; + } + + if(nodeScanner == null) { + LOGGER.warn("Skipping library {}, scanner missing",nodeTitle.getNodeValue()); + continue; + } + + Integer key = Integer.valueOf(nodeKey.getNodeValue()); + String scanner = nodeScanner.getNodeValue(); + String title = nodeTitle.getNodeValue(); + String type = nodeType.getNodeValue(); + + PlexLibrary plexLibrary = new PlexLibrary(key, scanner, title, type, true, false); + plexLibraries.add(plexLibrary); + } + LOGGER.info("{} libraries found on server", plexLibraries.size()); + + //Remove everything except movie folders LOGGER.info("{} Plex libraries found", plexLibraries.size()); plexServer.getPlexLibraries().addAll(plexLibraries); return Payload.PLEX_LIBRARIES_FOUND.setExtras("size():" + plexLibraries.size()); @@ -120,7 +149,7 @@ public PlexQueryImpl(@Qualifier("real") UrlGenerator urlGenerator) { String reason = String.format("Error connecting to Plex to get library list: %s", url); LOGGER.error(reason, e); return Payload.PLEX_CONNECTION_FAILED.setExtras("url:" + url); - } catch (JAXBException e) { + } catch (SAXException|XPathExpressionException|ParserConfigurationException e) { String reason = "Error parsing XML from Plex: " + url; LOGGER.error(reason, e); return Payload.PARSING_PLEX_FAILED.setExtras("url:" + url); @@ -188,10 +217,16 @@ public PlexQueryImpl(@Qualifier("real") UrlGenerator urlGenerator) { String machineIdentifier = machineIdentifierNode.getNodeValue().trim(); LOGGER.info("machineIdentifier:{}", machineIdentifier); - plexServer.setFriendlyName(friendlyName); - plexServer.setMachineIdentifier(machineIdentifier); + //ToDo + //Do I need this anymore + plexServer = new PlexServer(friendlyName, + machineIdentifier, + plexServer.getPlexToken(), + plexServer.getAddress(), + plexServer.getPort(), + plexServer.getPlexLibraries()); - return Payload.PLEX_CONNECTION_SUCCEEDED.setExtras("url:" + url); + return Payload.PLEX_CONNECTION_SUCCEEDED.setExtras(plexServer); } catch (IOException e) { String reason = String.format("Error connecting to Plex to get library list: %s", url); LOGGER.error(reason, e); @@ -209,7 +244,7 @@ public PlexQueryImpl(@Qualifier("real") UrlGenerator urlGenerator) { } @Override - public @NotNull com.jasonhhouse.plex.video.MediaContainer findAllPlexVideos(@NotNull String url) { + public @NotNull com.jasonhhouse.gaps.plex.video.MediaContainer findAllPlexVideos(@NotNull String url) { LOGGER.info("findAllPlexVideos()"); OkHttpClient client = new OkHttpClient.Builder() @@ -220,10 +255,10 @@ public PlexQueryImpl(@Qualifier("real") UrlGenerator urlGenerator) { if (StringUtils.isEmpty(url)) { LOGGER.info("No URL added to findAllPlexVideos()."); - return new com.jasonhhouse.plex.video.MediaContainer(); + return new com.jasonhhouse.gaps.plex.video.MediaContainer(); } - com.jasonhhouse.plex.video.MediaContainer mediaContainer; + com.jasonhhouse.gaps.plex.video.MediaContainer mediaContainer; try { HttpUrl httpUrl = urlGenerator.generatePlexUrl(url); @@ -241,9 +276,9 @@ public PlexQueryImpl(@Qualifier("real") UrlGenerator urlGenerator) { } InputStream inputStream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)); - JAXBContext jaxbContext = JAXBContext.newInstance(com.jasonhhouse.plex.video.MediaContainer.class); + JAXBContext jaxbContext = JAXBContext.newInstance(com.jasonhhouse.gaps.plex.video.MediaContainer.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); - mediaContainer = (com.jasonhhouse.plex.video.MediaContainer) jaxbUnmarshaller.unmarshal(inputStream); + mediaContainer = (com.jasonhhouse.gaps.plex.video.MediaContainer) jaxbUnmarshaller.unmarshal(inputStream); } catch (IOException e) { String reason = String.format("Error connecting to Plex to get Movie list: %s", url); diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/RssService.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/RssService.java index 3e5af1ce..7d20e441 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/RssService.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/RssService.java @@ -9,9 +9,9 @@ */ package com.jasonhhouse.gaps.service; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexLibrary; +import com.jasonhhouse.gaps.plex.PlexServer; import com.jasonhhouse.gaps.properties.PlexProperties; -import com.jasonhhouse.plex.libs.PlexLibrary; import java.util.Collections; import java.util.HashMap; import java.util.Map; diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/sql/MediaContainerRepository.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/sql/MediaContainerRepository.java index 670e1b54..6e679652 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/sql/MediaContainerRepository.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/sql/MediaContainerRepository.java @@ -1,6 +1,6 @@ package com.jasonhhouse.gaps.sql; -import com.jasonhhouse.plex.video.MediaContainer; +import com.jasonhhouse.gaps.plex.video.MediaContainer; import org.springframework.data.jpa.repository.JpaRepository; public interface MediaContainerRepository extends JpaRepository { diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/validator/PlexServerValidator.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/validator/PlexServerValidator.java index 0d4e783a..914a0736 100755 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/validator/PlexServerValidator.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/validator/PlexServerValidator.java @@ -10,7 +10,7 @@ package com.jasonhhouse.gaps.validator; -import com.jasonhhouse.gaps.PlexServer; +import com.jasonhhouse.gaps.plex.PlexServer; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; diff --git a/GapsWeb/src/main/resources/static/css/input.css b/GapsWeb/src/main/resources/static/css/input.css index 40a03f68..d5e38421 100755 --- a/GapsWeb/src/main/resources/static/css/input.css +++ b/GapsWeb/src/main/resources/static/css/input.css @@ -71,6 +71,14 @@ margin-right: auto; } +.material-icons.green600 { + color: #43A047; +} + +.skip-searching-library { + text-decoration: line-through; +} + .list-ul-default { background-color: #fafafa; /* defines the background color of the image */ mask: url(/images/list-ul.svg) no-repeat center / contain; diff --git a/GapsWeb/src/main/resources/static/js/configuration.js b/GapsWeb/src/main/resources/static/js/configuration.js index 93f640d9..f6c1c824 100755 --- a/GapsWeb/src/main/resources/static/js/configuration.js +++ b/GapsWeb/src/main/resources/static/js/configuration.js @@ -20,6 +20,7 @@ import {saveEmailNotifications, testEmailNotifications} from "./modules/email-no import {saveSchedule} from "./modules/schedule.min.js"; import {getSoundOptions, savePushOverNotifications, testPushOverNotifications} from "./modules/push-over-notifications.min.js"; import {saveDiscordNotifications, testDiscordNotifications} from "./modules/discord-notifications.min.js"; +import {openPlexLibraryConfigurationModel, savePlexLibraryConfiguration} from "./modules/plex-configuration.min.js" let plexSpinner, plexSaveSuccess, plexSaveError, plexTestSuccess, plexTestError, plexDeleteSuccess, plexDeleteError, plexDuplicateError; @@ -44,6 +45,21 @@ window.addEventListener('load', function () { document.addEventListener('DOMContentLoaded', function () { + Handlebars.registerHelper({ + isEnabled: function (value) { + return value.enabled && !value.defaultLibrary; + }, + isDefaultLibrary: function (value) { + return !value.enabled && value.defaultLibrary; + }, + isBoth: function (value) { + return value.enabled && value.defaultLibrary; + }, + isNone: function (value) { + return !value.enabled && !value.defaultLibrary; + } + }); + plexSpinner = $('#plexSpinner'); plexSaveSuccess = $('#plexSaveSuccess'); plexSaveError = $('#plexSaveError'); @@ -122,6 +138,8 @@ document.addEventListener('DOMContentLoaded', function () { window.testPushOver = testPushOverNotifications; window.savePushOver = savePushOverNotifications; window.saveSchedule = saveSchedule; + window.openPlexLibraryConfigurationModel = openPlexLibraryConfigurationModel; + window.savePlexLibraryConfiguration = savePlexLibraryConfiguration; getSoundOptions(); }); diff --git a/GapsWeb/src/main/resources/static/js/modules/plex-configuration.js b/GapsWeb/src/main/resources/static/js/modules/plex-configuration.js new file mode 100644 index 00000000..5498c5be --- /dev/null +++ b/GapsWeb/src/main/resources/static/js/modules/plex-configuration.js @@ -0,0 +1,50 @@ +/* + * Copyright 2020 Jason H House + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +export function openPlexLibraryConfigurationModel(title, machineIdentifier, key) { + const obj = { + 'title':title, + 'machineIdentifier': machineIdentifier, + 'key': key + } + const plexLibraryModalTemplate = $("#plexLibraryModalTemplate").html(); + const theTemplate = Handlebars.compile(plexLibraryModalTemplate); + const theCompiledHtml = theTemplate(obj); + const plexLibraryConfigurationModal = document.getElementById('plexLibraryConfigurationModal'); + plexLibraryConfigurationModal.innerHTML = theCompiledHtml; + $('#plexLibraryConfigurationModal').modal('show'); +} + +export async function savePlexLibraryConfiguration(machineIdentifier, key) { + const obj = { + 'machineIdentifier': machineIdentifier, + 'key': key, + 'enabled': document.getElementById('libraryEnabled').value, + 'defaultLibrary': document.getElementById('defaultLibrary').value + } + + let response = await fetch(`/configuration/update/plex/library`, { + method: 'put', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify(obj) + }) + const put = await response.json(); + /*if (put.code && put.code === Payload.SCHEDULE_UPDATED) { + hideAllAlertsAndSpinners(); + document.getElementById('scheduleSaveSuccess').style.display = 'block'; + } else { + hideAllAlertsAndSpinners(); + document.getElementById('scheduleSaveError').style.display = 'block'; + }*/ +} \ No newline at end of file diff --git a/GapsWeb/src/main/resources/templates/configuration.html b/GapsWeb/src/main/resources/templates/configuration.html index 4fb658f1..415d469b 100755 --- a/GapsWeb/src/main/resources/templates/configuration.html +++ b/GapsWeb/src/main/resources/templates/configuration.html @@ -16,6 +16,7 @@ + @@ -414,6 +415,40 @@

Success!

+ + + +