diff --git a/src/main/java/xyz/vallat/louis/MoviesQuoteBot.java b/src/main/java/xyz/vallat/louis/MoviesQuoteBot.java index 74431f1..4400d4d 100644 --- a/src/main/java/xyz/vallat/louis/MoviesQuoteBot.java +++ b/src/main/java/xyz/vallat/louis/MoviesQuoteBot.java @@ -11,7 +11,7 @@ public class MoviesQuoteBot { public static final String PREFIX = "!"; public static final String NAME = "Movies Quote Bot"; public static final String DESCRIPTION = "I may know some quotes from some movies."; - public static final String VERSION = "0.3.2-SNAPSHOT"; + public static final String VERSION = "0.3.3-SNAPSHOT"; private static final Logger logger = LoggerFactory.getLogger(MoviesQuoteBot.class.getCanonicalName()); public static void main(String[] args) { diff --git a/src/main/java/xyz/vallat/louis/omdb/OMDBClient.java b/src/main/java/xyz/vallat/louis/omdb/OMDBClient.java index edb49a7..03f17b3 100644 --- a/src/main/java/xyz/vallat/louis/omdb/OMDBClient.java +++ b/src/main/java/xyz/vallat/louis/omdb/OMDBClient.java @@ -34,32 +34,6 @@ public final class OMDBClient { private OMDBClient() { } - public static List searchMoviesByTitle(String name) throws IOException, InterruptedException { - logger.debug("Searching for '{}'.", name); - List movies = new ArrayList<>(); - HttpRequest request = HttpRequest.newBuilder() - .GET() - .uri(URI.create(ENDPOINT + "?apikey=" + API_KEY + "&type=movie" + - "&s=" + URLEncoder.encode(name, StandardCharsets.UTF_8))) - .build(); - logger.debug("Calling url '{}'.", request.uri()); - HttpResponse response = getHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); - if (response.statusCode() == 200) { - JsonObject object = JsonParser.parseString(response.body()).getAsJsonObject(); - if (object.get("Response").getAsBoolean()) { - for (JsonElement jsonElement : object.get("Search").getAsJsonArray()) { - JsonObject jsonMovie = (JsonObject) jsonElement; - Movie movie = getMovieFromJson(jsonMovie); - if (movie == null) continue; - movies.add(movie); - } - } else - logger.error("OMDB API returned an error: {}", object.get("Error").getAsString()); - } else - logger.error("Querying the results gave this code: {}.", response.statusCode()); - return movies; - } - public static Movie getMovie(String value, boolean isId) throws IOException { logger.debug("Getting movie by title '{}'.", value); Movie movie = FilmManager.getMovieFromTitleOrImdbId(value, isId); @@ -90,7 +64,8 @@ public final class OMDBClient { private static Movie getMovieFromJson(JsonObject jsonMovie) { Movie movie = null; - if (jsonMovie.get(IMDB_KEY) != null && jsonMovie.get(TITLE_KEY) != null) { + if (jsonMovie.get(IMDB_KEY) != null && jsonMovie.get(TITLE_KEY) != null && + jsonMovie.get(TYPE_KEY) != null && jsonMovie.get(TYPE_KEY).getAsString().equalsIgnoreCase("movie")) { movie = new Movie( jsonMovie.get(TITLE_KEY).getAsString(), jsonMovie.get(IMDB_KEY).getAsString(),