Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
Optimized getJSONFromTitle
Browse files Browse the repository at this point in the history
Added equalsTitle and containsTitle in Anime.java
Updated gson, jsoup and okhttp
Removed log4j dependency and AnimeList.java
  • Loading branch information
Minemobs committed Dec 18, 2021
1 parent dc00405 commit 202b9f5
Show file tree
Hide file tree
Showing 31 changed files with 152 additions and 221 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/build/
/gradle/
/.gradle/
/.gradle/6.5/
/.gradle/6.5.1/
/.gradle/buildOutputCleanup/
/.gradle/checksums/
/.gradle/vcs-1/
/.idea/
Binary file removed .gradle/6.5.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file removed .gradle/6.5.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file removed .gradle/6.5.1/fileChanges/last-build.bin
Binary file not shown.
Binary file removed .gradle/6.5.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file removed .gradle/6.5.1/fileHashes/fileHashes.lock
Binary file not shown.
Empty file removed .gradle/6.5.1/gc.properties
Empty file.
Binary file removed .gradle/6.5/executionHistory/executionHistory.bin
Binary file not shown.
Binary file removed .gradle/6.5/executionHistory/executionHistory.lock
Binary file not shown.
Binary file removed .gradle/6.5/fileChanges/last-build.bin
Binary file not shown.
Binary file removed .gradle/6.5/fileContent/fileContent.lock
Binary file not shown.
Binary file removed .gradle/6.5/fileHashes/fileHashes.bin
Binary file not shown.
Binary file removed .gradle/6.5/fileHashes/fileHashes.lock
Binary file not shown.
Empty file removed .gradle/6.5/gc.properties
Empty file.
Binary file removed .gradle/6.5/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file removed .gradle/6.5/javaCompile/javaCompile.lock
Binary file not shown.
Binary file removed .gradle/6.5/javaCompile/taskHistory.bin
Binary file not shown.
Binary file removed .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 0 additions & 2 deletions .gradle/buildOutputCleanup/cache.properties

This file was deleted.

Binary file removed .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file removed .gradle/checksums/checksums.lock
Binary file not shown.
Binary file removed .gradle/checksums/md5-checksums.bin
Binary file not shown.
Binary file removed .gradle/checksums/sha1-checksums.bin
Binary file not shown.
Empty file removed .gradle/vcs-1/gc.properties
Empty file.
79 changes: 46 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ You just need to add jitpack as a repository

Like this:

```
```GROOVY
repositories {
maven { url 'https://jitpack.io' }
maven { url 'https://jitpack.io' }
}
```

And add in your dependencies this :

(Replace v1.0 by the release you want)

`implementation 'com.github.Minemobs:VostFrAnimeSearcher:v1.0'`
`implementation 'com.github.Minemobs:VostFrAnimeSearcher:v1.2'`

- ### How do I use the API ?

Expand All @@ -31,99 +31,112 @@ One example of a possible use.
* @version v1.1
*/

public class Main {
public class Test {

static Main main = new Main();
private static final Logger logger = Logger.getLogger("Test NekoSama API");

public static void main(String[] args) {
System.out.println("Choose what anime you want to search.");
logger.info("Choose what anime you want to search.");
Scanner scanner = new Scanner(System.in);
//Instantiate the class AnimeSearcherAPI
AnimeSearcherAPI animes = new AnimeSearcherAPI();
//Set the name of the anime
String animeTitle = scanner.nextLine();
System.out.println("Equals or contains this string ? \n" +
logger.info("Equals or contains this string ? \n" +
"[YES] or [No]");
scanner = new Scanner(System.in);
switch (scanner.nextLine().toLowerCase()) {
switch (scanner.nextLine().toLowerCase()){
case "yes":
/**
* Call the function animeSearchEquals()
* @param animes the variable AnimeSearcherAPI
* @param animeTitle the name of the anime
*/
main.animeSearchEquals(animes, animeTitle);
animeSearchEquals(animes, animeTitle);
break;
case "no":
/**
* Call the function animeSearchEquals()
* @param animes the variable AnimeSearcherAPI
* @param animeTitle the name of the anime
*/
main.animeSearchContains(animes, animeTitle);
animeSearchContains(animes, animeTitle);
break;
default:
System.out.println("Please relaunch the code because i don't want to relaunch the function myself.");
logger.severe("Please relaunch the code because I don't want to relaunch the function myself.");
break;
}
}
private void animeSearchEquals(AnimeSearcherAPI animes, String animeTitle) {

private static void animeSearchEquals(AnimeSearcherAPI animes, String animeTitle) {
//Create the variable anime which get the result of the function getJSONFromTitle()
if (animes.getJSONFromTitle(animeTitle) == null) {
Optional<Anime> anime = animes.getJSONFromTitle(animeTitle);
if (!anime.isPresent()) {
throw new NullPointerException("This anime is not on NekoSama");
}
Anime anime = animes.getJSONFromTitle(animeTitle);
try {
//Create the variable animeHtml and
//Specify the episode searched
AnimeHtml animeHtml = animes.getHtmlPageOfTheAnime(anime, 12);
AnimeHtml animeHtml;
if(anime.get().getType().equalsIgnoreCase("tv")){
animeHtml = animes.getHtmlPageOfTheAnime(anime.get(), 12);
}else{
animeHtml = animes.getHtmlPageOfTheAnime(anime.get(), 1);
}
//Print the link of the episode
System.out.println(animeHtml.getLinkOfTheEpisode());
logger.info(animeHtml.getLinkOfTheEpisode());
//Print the synopsis of the anime
System.out.println(animeHtml.getSynop());
logger.info(animeHtml.getSynop());
} catch (Exception e) {
//If there is an exception, print the error
e.printStackTrace();
}
}

private void animeSearchContains(AnimeSearcherAPI animes, String animeTitle) {
private static void animeSearchContains(AnimeSearcherAPI animes, String animeTitle) {
//Create the variable anime which get the result of the function getJSONFromTitle()
if (animes.getJSONFromTitleContains(animeTitle) == null) {
throw new NullPointerException("This anime is not on NekoSama");
}
List<Anime> animeList = animes.getJSONFromTitleContains(animeTitle);
AnimeHtml animeHtml = null;
AnimeHtml animeHtml;
for (Anime anime : animeList) {
try {
//Create the variable animeHtml and
//Specify the episode searched
int episodeSearched;
if (anime.getType().equalsIgnoreCase("tv")) {
System.out.println("Please specify the episode wanted \n" +
if(anime.getType().equalsIgnoreCase("tv")){
logger.info("Please specify the episode wanted \n" +
"if you don't want to search an episode please write 1 (it will search the episode 1 anyways)");
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextInt()) {
if (scanner.hasNextInt()){
episodeSearched = scanner.nextInt();
animeHtml = animes.getHtmlPageOfTheAnime(anime, episodeSearched);
} else {
System.out.println("I want a number!");
}else{
logger.severe("I want a number!");
break;
}
} else {
}else{
animeHtml = animes.getHtmlPageOfTheAnime(anime, 1);
}
if(animeHtml == null) {
throw new NullPointerException("The episode does not exist!");
}
//Print everything
System.out.println(
logger.info(
"-------------------------------------------------------------" + "\n" +
"Title: " + anime.getTitle() + "\n" +
"Url:" + anime.getUrl() + "\n" +
"Synopsis: " + animeHtml.getSynop() + "\n" +
"Url of episode: " + animeHtml.getLinkOfTheEpisode() + "\n" +
"-------------------------------------------------------------");
} catch (Exception e) {
"Title: " + anime.getTitle() + "\n" +
"Url:" + anime.getUrl() + "\n" +
"Synopsis: " + animeHtml.getSynop() + "\n" +
"Url of episode: " + animeHtml.getLinkOfTheEpisode() + "\n" +
"Url of the cover: " + animeHtml.getUrlOfTheCover() + "\n" +
"-------------------------------------------------------------"
);
} catch (IOException e) {
//If there is an error, print the error
e.printStackTrace();
}
}
}
}
}
```
15 changes: 8 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ plugins {
id "com.github.johnrengelman.shadow" version "6.1.0"
}

mainClassName = "fr.minemobs.animes.Test"

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'

group 'org.example'
Expand All @@ -16,14 +14,17 @@ repositories {
mavenCentral()
}

tasks.withType(JavaCompile) {
application {
mainClassName = "fr.minemobs.animes.Test"
}

compileJava {
options.encoding = 'UTF-8'
}

dependencies {
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'org.jsoup:jsoup:1.14.3'
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
testCompile group: 'junit', name: 'junit', version: '4.13.2'
implementation 'com.google.code.gson:gson:2.8.6'
compile "org.jsoup:jsoup:1.13.1"
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.14.1'
}
78 changes: 45 additions & 33 deletions src/main/java/fr/minemobs/animes/Anime.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
package fr.minemobs.animes;

import com.google.gson.annotations.SerializedName;

import java.util.Arrays;

public class Anime {

private String title;
private String title_english;
private String title_romanji;
private int id;
private String other;
private String[] genres;
private String url;
private String nbrOfEps;
private String type;

public Anime(String title, String title_english, String title_romanji, int id, String other, String[] genres, String url, String nbrOfEps,
String type) {
this.title = title;
this.title_english = title_english;
this.title_romanji = title_romanji;
this.id = id;
this.other = other;
this.genres = genres;
this.url = url;
this.nbrOfEps = nbrOfEps;
this.type = type;
private final String title;
@SerializedName("title_english") private final String titleEnglish;
@SerializedName("title_romanji") private final String titleRomanji;
private final int id;
private final String others;
private final String[] genres;
private final String url;
@SerializedName("nb_eps") private final String nbrOfEps;
private final String type;

private Anime() {
this.title = "";
this.titleEnglish = "";
this.titleRomanji = null;
this.id = 0;
this.others = "";
this.genres = new String[0];
this.url = "";
this.nbrOfEps = "";
this.type = "";
}

public boolean containsTitle(String title) {
return this.title.toLowerCase().contains(title.toLowerCase()) ||
this.titleEnglish.toLowerCase().contains(title.toLowerCase()) ||
(this.titleRomanji != null && this.titleRomanji.toLowerCase().contains(title.toLowerCase())) ||
this.others.toLowerCase().contains(title.toLowerCase());
}

public boolean equalsTitle(String title) {
return this.title.equalsIgnoreCase(title) || this.titleEnglish.equalsIgnoreCase(title) ||
(this.titleRomanji != null && this.titleRomanji.equalsIgnoreCase(title)) ||
Arrays.stream(this.others.split(",")).anyMatch(t -> t.equalsIgnoreCase(title));
}

public String getType() {
Expand All @@ -36,9 +50,7 @@ public String getNbrOfEps() {
}

public int getNbrOfEpsAsInt(){
String epsString = nbrOfEps.replace(" ", "").replace("Eps", "");
int episodes = Integer.getInteger(epsString);
return episodes;
return Integer.getInteger(nbrOfEps.replace(" ", "").replace("Eps", ""));
}

public String getUrl() {
Expand All @@ -49,20 +61,20 @@ public String getTitle() {
return title;
}

public String getTitle_english() {
return title_english;
public String getTitleEnglish() {
return titleEnglish;
}

public String getTitle_romanji() {
return title_romanji;
public String getTitleRomanji() {
return titleRomanji;
}

public int getId() {
return id;
}

public String getOther() {
return other;
public String getOthers() {
return others;
}

public String[] getGenres() {
Expand All @@ -73,10 +85,10 @@ public String[] getGenres() {
public String toString() {
return "Anime{" +
"title='" + title + '\'' +
", title_english='" + title_english + '\'' +
", title_romanji='" + title_romanji + '\'' +
", title_english='" + titleEnglish + '\'' +
", title_romanji='" + titleRomanji + '\'' +
", id=" + id +
", other='" + other + '\'' +
", others='" + others + '\'' +
", genres=" + Arrays.toString(genres) +
", url='" + url + '\'' +
", nbrOfEps='" + nbrOfEps + '\'' +
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/fr/minemobs/animes/AnimeHtml.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

public class AnimeHtml {

private String synop;
private String linkOfTheEpisode;
private int nbrOfEps;
private String urlOfTheCover;
private final String synop;
private final String linkOfTheEpisode;
private final int nbrOfEps;
private final String urlOfTheCover;

public AnimeHtml(String synop, String linkOfTheEpisode, int nbrOfEps, String urlOfTheCover) {
this.synop = synop;
Expand Down
Loading

0 comments on commit 202b9f5

Please sign in to comment.