diff --git a/README.md b/README.md index dbcde88..2c95fde 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,4 @@ public class Main { } } } -} - -``` \ No newline at end of file +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 00d4081..7b47e1b 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,8 @@ plugins { mainClassName = "fr.minemobs.animes.Test" +sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' + group 'org.example' version '1.0-SNAPSHOT' @@ -14,9 +16,14 @@ repositories { mavenCentral() } +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' implementation 'com.google.code.gson:gson:2.8.6' compile "org.jsoup:jsoup:1.10.2" implementation 'com.squareup.okhttp3:okhttp:4.9.0' + compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.14.0' } diff --git a/src/main/java/fr/minemobs/animes/AnimeSearcherAPI.java b/src/main/java/fr/minemobs/animes/AnimeSearcherAPI.java index 73e0008..08d08ba 100644 --- a/src/main/java/fr/minemobs/animes/AnimeSearcherAPI.java +++ b/src/main/java/fr/minemobs/animes/AnimeSearcherAPI.java @@ -2,22 +2,20 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import okhttp3.*; -import okhttp3.OkHttpClient.Builder; +import okhttp3.OkHttpClient; +import okhttp3.Protocol; +import okhttp3.Request; +import okhttp3.Response; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; -import java.io.*; +import java.io.IOException; import java.lang.reflect.Type; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Logger; import java.util.stream.Collectors; public class AnimeSearcherAPI { @@ -25,7 +23,7 @@ public class AnimeSearcherAPI { String urlOfNekoSama = "http://neko-sama.fr"; String jsonUrl = urlOfNekoSama + "/animes-search.json"; - String userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"; + private static Logger LOGGER = Logger.getLogger(AnimeSearcherAPI.class.getName()); OkHttpClient httpClient = new OkHttpClient.Builder() .protocols(Collections.singletonList(Protocol.HTTP_1_1)) @@ -69,12 +67,13 @@ public List getJSONFromTitleContains(String animeTitle) { Type animeListType = new TypeToken>() { }.getType(); List animes = gson.fromJson(responseBody, animeListType); - List animes1 = animes.stream().filter(anime1 -> anime1.getTitle().toLowerCase().contains(animeTitle.toLowerCase())).collect(Collectors.toList()); + List animes1 = animes.stream() + .filter(anime1 -> anime1.getTitle().toLowerCase().contains(animeTitle.toLowerCase())).collect(Collectors.toList()); return animes1; } public AnimeHtml getHtmlPageOfTheAnime(Anime anime, int episodeSearched) throws Exception { - if(Jsoup.connect(anime.getUrl()).get() == null){ + if(anime.getUrl() == null || Jsoup.connect(anime.getUrl()).get() == null){ throw new NullPointerException("Cet anime n'a pas de page"); } Document doc = Jsoup.connect(anime.getUrl()).get(); @@ -111,4 +110,16 @@ public String getJsonUrl() { public String getUrlOfNekoSama() { return urlOfNekoSama; } + + public OkHttpClient getHttpClient() { + return httpClient; + } + + public Request getRequest() { + return request; + } + + public static Logger getLOGGER() { + return LOGGER; + } }