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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
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 Parse {
public static Document getPage(String url) throws IOException {
return Jsoup.parse(new URL(url), 3000);
}
public static Anime[] getAnimeAtMainMenu(String page, String typeOfAnime) throws IOException {
Element animeList = Parse.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.equals("Ongoing")) yearsTemp = animeList.select("div[class=th-tip-meta fx-row fx-middle fx-start]");
// Elements genresTemp = animeList.select("span[class=anime-genre d-none d-sm-inline]").select("a[class=mb-2 text-link-gray text-underline]");
Elements seriesTemp = null;
if (!typeOfAnime.equals("AnimeFilms")) {
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();
ArrayList<String> names = new ArrayList<>();
for (Element name : namesTemp) {
if (!typeOfAnime.equals("AnimeFilms")) {
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.equals("Ongoing")) {
for (Element year : yearsTemp) {
Element yearTemp = year.child(0);
years.add(Jsoup.parse(String.valueOf(yearTemp)).text());
}
}
ArrayList<String> series = new ArrayList<>();
if (!typeOfAnime.equals("AnimeFilms")) {
for (Element oneSeries : seriesTemp) {
String text = oneSeries.toString();
int start = text.indexOf("из ") + 3;
if (start == 2) start = text.indexOf("ИЗ ") + 3;
int end = text.indexOf("]");
if (start == 2) {
start = text.indexOf("[") + 1;
end = text.indexOf(" по") + 1;
}
char[] dst = new char[end - start];
text.getChars(start, end, dst, 0);
if (String.valueOf(dst).equals("ххх")) {
start = text.indexOf("[") + 1;
end = text.indexOf(" из") - 1;
}
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.equals("AnimeFilms")) {
anime[i] = new Anime(names.get(i), descriptions.get(i), null, years.get(i), ratings.get(i), images.get(i), urls.get(i));
} else if (typeOfAnime.equals("Ongoing")) {
anime[i] = new Anime(names.get(i), descriptions.get(i), null, null, series.get(i), ratings.get(i), images.get(i), urls.get(i));
} else {
anime[i] = new Anime(names.get(i), descriptions.get(i), null, years.get(i), series.get(i), ratings.get(i), images.get(i), urls.get(i));
}
}
return anime;
}
public static Anime[] getAnimeAtSearch(String page) throws IOException {
Element animeList = Parse.getPage(page).select("div[class=animes-grid position-relative]").first();
assert animeList != null;
Elements namesTemp = animeList.select("div[class=h5 font-weight-normal mb-2 card-title text-truncate]").select("a");
Elements descriptionsTemp = animeList.select("div[class=anime-small-description read-more-container]");
Elements yearsTemp = animeList.select("span[class=anime-year]").select("a");
Elements seriesTemp = animeList.select("div[class=th-title]");
Elements maxSeriesTemp = animeList.select("div[class=th-title]");
Elements ratingsTemp = animeList.select("div[class=th-rating]");
Elements imagesTemp = animeList.select("div[class=anime-grid-lazy lazy]");
Elements urlsTemp = animeList.select("div[class=h5 font-weight-normal mb-2 card-title text-truncate]").select("a");
byte countOfAnime = (byte) namesTemp.size();
ArrayList<String> names = new ArrayList<>();
for (Element name : namesTemp) {
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<>();
for (Element year : yearsTemp) {
years.add(Jsoup.parse(String.valueOf(year)).text());
}
ArrayList<String> series = new ArrayList<>();
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> maxSeries = new ArrayList<>();
for (Element oneMaxSeries : maxSeriesTemp) {
String text = oneMaxSeries.toString();
int start = text.indexOf("из ") + 1;
int end = text.indexOf("]");
char[] dst = new char[end - start];
text.getChars(start, end, dst, 0);
maxSeries.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-original=") + 15;
int end = text.indexOf(">") - 1;
char[] dst = new char[end - start];
text.getChars(start, end, dst, 0);
images.add(String.valueOf(dst));
}
ArrayList<String> urls = new ArrayList<>();
for (Element url : urlsTemp) {
String text = url.toString();
int start = text.indexOf("=\"") + 2;
int end = text.indexOf("\" title") - 1;
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++) {
anime[i] = new Anime(names.get(i), null, null, years.get(i), series.get(i), ratings.get(i), images.get(i), urls.get(i));
}
return anime;
}
public static byte getAnimeAtSearchSize(String page) throws IOException {
Element animeList = Parse.getPage(page).select("div[class=animes-grid position-relative]").first();
assert animeList != null;
if (animeList == null) return 0;
Elements namesTemp = animeList.select("div[class=h5 font-weight-normal mb-2 card-title text-truncate]").select("a");
byte countOfAnime = (byte) namesTemp.size();
return countOfAnime;
}
}
|