Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding backend support #180

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
5 changes: 3 additions & 2 deletions GapsWeb/src/main/java/com/jasonhhouse/gaps/UrlGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
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;
import com.jasonhhouse.gaps.service.SchedulerService;
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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -135,7 +143,8 @@ public ResponseEntity<String> 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
Expand All @@ -157,7 +166,8 @@ public ResponseEntity<String> 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);
Expand Down Expand Up @@ -193,4 +203,12 @@ public ResponseEntity<Payload> postSaveTmdbKey(@PathVariable("tmdbKey") final St
return ResponseEntity.ok().body(payload);
}

@PutMapping(value = "/update/plex/library",
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<Payload> putPlexLibrary(final Object object) {
LOGGER.info("putPlexLibrary( {} )", object);

return ResponseEntity.ok().body(Payload.PLEX_CONNECTION_SUCCEEDED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, PlexServer> plexServerMap = plexProperties.getPlexServers().stream().collect(Collectors.toMap(PlexServer::getMachineIdentifier, Function.identity()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading