1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
package files;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
public class Parser {
public static Document getPage(String url) throws IOException {
return Jsoup.parse(new URL(url), 5000);
}
public static byte getSizeOfSearchedAnime(String page) throws IOException {
Element animeList = Parser.getPage(page).select("div[id=dle-content]").first();
if (animeList == null) return 0;
Elements anime = animeList.select("div[class=th-item]");
return (byte) anime.size();
}
public static Anime[] getAnime(String page) throws IOException {
String typeOfAnime = Anime.typeOfAnime;
Element animeList = Parser.getPage(page).select("div[id=dle-content]").first();
assert animeList != null;
Elements namesTemp = animeList.select("div[class=th-title]");
Elements descriptionsTemp = animeList.select("div[class=th-tip-text]");
Elements yearsTemp = null;
if (typeOfAnime != null && !typeOfAnime.equals("Ongoing"))
yearsTemp = animeList.select("div[class=th-tip-meta fx-row fx-middle fx-start]");
Elements genresTemp= animeList.select("ul[class=th-tip-list]");
Elements seriesTemp = null;
if (typeOfAnime != null && !typeOfAnime.equals("Films"))
seriesTemp = animeList.select("div[class=th-title]");
Elements ratingsTemp = animeList.select("div[class=th-rating]");
Elements imagesTemp = animeList.select("div[class=th-img img-resp-vert img-fit]");
Elements urlsTemp = animeList.select("div[class=th-itemb]").select("a[class=th-in]");
byte countOfAnime = (byte) namesTemp.size();
Anime.size = countOfAnime;
ArrayList<String> names = new ArrayList<>();
for (Element name : namesTemp) {
if (typeOfAnime != null && !typeOfAnime.equals("Films")) {
String text = Jsoup.parse(String.valueOf(name)).text();
int start = 0;
int end = text.indexOf(" [");
char[] dst = new char[end - start];
text.getChars(start, end, dst, 0);
names.add(String.valueOf(dst));
} else {
names.add(Jsoup.parse(String.valueOf(name)).text());
}
}
ArrayList<String> descriptions = new ArrayList<>();
for (Element description : descriptionsTemp) {
descriptions.add(Jsoup.parse(String.valueOf(description)).text());
}
ArrayList<String> years = new ArrayList<>();
if (typeOfAnime != null && !typeOfAnime.equals("Ongoing") && !Anime.isSearching) {
for (Element year : yearsTemp) {
Element yearTemp = year.child(0);
years.add(Jsoup.parse(String.valueOf(yearTemp)).text());
}
}
ArrayList<String> genres = new ArrayList<>();
for (Element oneGenres : genresTemp) {
Element genre = oneGenres.child(2);
String text = Jsoup.parse(String.valueOf(genre)).text();
int start = 6;
int end = text.length();
char[] dst = new char[end - start];
text.getChars(start, end, dst, 0);
genres.add(String.valueOf(dst));
}
ArrayList<String> series = new ArrayList<>();
if (typeOfAnime != null && !typeOfAnime.equals("Films") && !Anime.isSearching) {
for (Element oneSeries : seriesTemp) {
String text = oneSeries.toString();
int start = text.indexOf("[") + 1;
int end = text.indexOf("]");
char[] dst = new char[end - start];
text.getChars(start, end, dst, 0);
series.add(String.valueOf(dst));
}
}
ArrayList<String> ratings = new ArrayList<>();
for (Element rating : ratingsTemp) {
ratings.add(Jsoup.parse(String.valueOf(rating)).text());
}
ArrayList<String> images = new ArrayList<>();
for (Element image : imagesTemp) {
String text = image.toString();
int start = text.indexOf("data-src=\"") + 11;
int end = text.indexOf(".jpg") + 4;
if (end == 3) {
end = text.indexOf(".png") + 4;
}
char[] dst = new char[end - start];
text.getChars(start, end, dst, 0);
if (!String.valueOf(dst).contains("statics")) {
images.add("https://online.anidub.com/" + String.valueOf(dst));
} else {
images.add("h" + String.valueOf(dst));
}
}
ArrayList<String> urls = new ArrayList<>();
for (Element url : urlsTemp) {
String text = url.toString();
int start = text.indexOf("href=\"") + 6;
int end = text.indexOf("\">");
char[] dst = new char[end - start];
text.getChars(start, end, dst, 0);
urls.add(String.valueOf(dst));
}
Anime[] anime = new Anime[countOfAnime];
for (int i = 0; i < countOfAnime; i++) {
if (typeOfAnime != null && typeOfAnime.equals("Films")) {
anime[i] = new Anime(names.get(i), descriptions.get(i), genres.get(i), years.get(i), ratings.get(i), images.get(i), urls.get(i));
} else if (typeOfAnime != null && typeOfAnime.equals("Ongoing")) {
anime[i] = new Anime(names.get(i), descriptions.get(i), genres.get(i), null, series.get(i), ratings.get(i), images.get(i), urls.get(i));
} else if (typeOfAnime != null && typeOfAnime.equals("Serials")) {
anime[i] = new Anime(names.get(i), descriptions.get(i), genres.get(i), years.get(i), series.get(i), ratings.get(i), images.get(i), urls.get(i));
} else if (Anime.isSearching) {
anime[i] = new Anime(names.get(i), descriptions.get(i), genres.get(i), null, null, ratings.get(i), images.get(i), urls.get(i));
}
}
return anime;
}
}
|