Cleaning up imports and other small bugs

This commit is contained in:
Jason House
2020-07-30 16:44:07 +09:00
parent 591bb42876
commit 15bca7bce3
13 changed files with 31 additions and 46 deletions

View File

@@ -14,13 +14,9 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.jasonhhouse.gaps.json.MovieDeserializer;
import com.jasonhhouse.gaps.json.MovieSerializer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -67,14 +63,14 @@ public final class Movie implements Comparable<Movie> {
private final String language;
@Nullable
private final String overview;
@NotNull
private final List<MovieFromCollection> moviesInCollection;
@Nullable
private String collection;
@NotNull
private Integer collectionId;
@NotNull
private Integer tvdbId;
@NotNull
private final List<MovieFromCollection> moviesInCollection;
private Movie(@NotNull String name, @NotNull Integer year, @Nullable String posterUrl, @Nullable String collection, @NotNull Integer collectionId, @NotNull Integer tvdbId,
@Nullable String imdbId, @Nullable String language, @Nullable String overview, @NotNull List<MovieFromCollection> moviesInCollection) {

View File

@@ -15,12 +15,12 @@ import java.util.TreeSet;
public final class PlexServer {
private final Set<PlexLibrary> plexLibraries;
private String friendlyName;
private String machineIdentifier;
private String plexToken;
private String address;
private Integer port;
private final Set<PlexLibrary> plexLibraries;
public PlexServer() {
plexLibraries = new TreeSet<>();

View File

@@ -17,11 +17,8 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.MovieFromCollection;
import com.jasonhhouse.gaps.Pair;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class MovieDeserializer extends StdDeserializer<Movie> {

View File

@@ -15,8 +15,6 @@ import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.MovieFromCollection;
import com.jasonhhouse.gaps.Pair;
import java.io.IOException;
public class MovieSerializer extends StdSerializer<Movie> {

View File

@@ -31,7 +31,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

View File

@@ -24,7 +24,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

View File

@@ -10,7 +10,11 @@
package com.jasonhhouse.gaps.controller;
import com.jasonhhouse.gaps.*;
import com.jasonhhouse.gaps.GapsService;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.Pair;
import com.jasonhhouse.gaps.PlexLibrary;
import com.jasonhhouse.gaps.PlexQuery;
import com.jasonhhouse.gaps.service.IoService;
import java.util.HashMap;
import java.util.List;

View File

@@ -24,8 +24,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

View File

@@ -16,16 +16,11 @@ import com.jasonhhouse.gaps.Payload;
import com.jasonhhouse.gaps.PlexLibrary;
import com.jasonhhouse.gaps.PlexServer;
import com.jasonhhouse.gaps.service.IoService;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -10,7 +10,6 @@
package com.jasonhhouse.gaps.controller;
import com.jasonhhouse.gaps.GapsSearch;
import com.jasonhhouse.gaps.service.IoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -24,20 +24,26 @@ import com.jasonhhouse.gaps.SearchCancelledException;
import com.jasonhhouse.gaps.SearchResults;
import com.jasonhhouse.gaps.UrlGenerator;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Year;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
@@ -227,11 +233,11 @@ public class GapsSearchService implements GapsSearch {
continue;
} else if (StringUtils.isNotBlank(movie.getImdbId())) {
LOGGER.info("Used 'find' to search for " + movie.getName());
String imdbId = URLEncoder.encode(movie.getImdbId(), "UTF-8");
String imdbId = URLEncoder.encode(movie.getImdbId(), StandardCharsets.UTF_8);
searchMovieUrl = urlGenerator.generateFindMovieUrl(gapsService.getPlexSearch().getMovieDbApiKey(), imdbId, languageCode);
} else {
LOGGER.info("Used 'search' to search for " + movie.getName());
String name = URLEncoder.encode(movie.getName(), "UTF-8");
String name = URLEncoder.encode(movie.getName(), StandardCharsets.UTF_8);
searchMovieUrl = urlGenerator.generateSearchMovieUrl(gapsService.getPlexSearch().getMovieDbApiKey(), name, String.valueOf(movie.getYear()), languageCode);
}
@@ -300,32 +306,25 @@ public class GapsSearchService implements GapsSearch {
searchMovieDetails(machineIdentifier, key, ownedMovies, everyMovie, recommended, searched, searchedMovieCount, movie, client, languageCode);
} catch (JsonProcessingException e) {
LOGGER.error("Error parsing movie " + movie + ". " + e.getMessage());
LOGGER.error("Error parsing movie " + movie + ". ", e);
LOGGER.error("URL: " + searchMovieUrl);
e.printStackTrace();
} catch (IOException e) {
LOGGER.error("Error searching for movie " + movie, e);
LOGGER.error("URL: " + searchMovieUrl);
e.printStackTrace();
} finally {
try {
//can't have too many connections to the movie database in a specific time, have to wait
Thread.sleep(700);
} catch (InterruptedException e) {
LOGGER.error("Error sleeping", e);
e.printStackTrace();
}
}
} catch (UnsupportedEncodingException e) {
LOGGER.error("Error parsing movie URL " + movie, e);
e.printStackTrace();
} finally {
try {
//can't have too many connections to the movie database in a specific time, have to wait
Thread.sleep(350);
} catch (InterruptedException e) {
LOGGER.error("Error sleeping", e);
e.printStackTrace();
}
}
}

View File

@@ -26,7 +26,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -68,13 +67,9 @@ public class IoService {
if (os.contains("Windows")) {
//Default to the same folder as the jar
String decodedPath = "";
try {
String path = new File(new File(new File(IoService.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent()).getParent()).getParent();
decodedPath = URLDecoder.decode(path, "UTF-8");
decodedPath = decodedPath.startsWith("file:\\") ? decodedPath.substring("file:\\".length()) : decodedPath;
} catch (UnsupportedEncodingException e) {
//Do nothing
}
String path = new File(new File(new File(IoService.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent()).getParent()).getParent();
decodedPath = URLDecoder.decode(path, StandardCharsets.UTF_8);
decodedPath = decodedPath.startsWith("file:\\") ? decodedPath.substring("file:\\".length()) : decodedPath;
STORAGE_FOLDER = decodedPath + "\\";
} else {
STORAGE_FOLDER = "/usr/data/";

View File

@@ -10,7 +10,13 @@
package com.jasonhhouse.gaps.service;
import com.jasonhhouse.gaps.*;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.Pair;
import com.jasonhhouse.gaps.Payload;
import com.jasonhhouse.gaps.PlexLibrary;
import com.jasonhhouse.gaps.PlexQuery;
import com.jasonhhouse.gaps.PlexServer;
import com.jasonhhouse.gaps.UrlGenerator;
import com.jasonhhouse.plex.MediaContainer;
import java.io.ByteArrayInputStream;
import java.io.IOException;