1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
5 import java
.net
.MalformedURLException
;
7 import java
.util
.AbstractMap
;
8 import java
.util
.ArrayList
;
11 import java
.util
.Map
.Entry
;
12 import java
.util
.Scanner
;
14 import be
.nikiroo
.fanfix
.Instance
;
15 import be
.nikiroo
.fanfix
.data
.Chapter
;
16 import be
.nikiroo
.fanfix
.data
.MetaData
;
17 import be
.nikiroo
.fanfix
.data
.Story
;
18 import be
.nikiroo
.utils
.Image
;
19 import be
.nikiroo
.utils
.Progress
;
20 import be
.nikiroo
.utils
.StringUtils
;
23 * Support class for <a href="https://e-hentai.org/">e-hentai.org</a>, a website
24 * supporting mostly but not always NSFW comics, including some of MLP.
28 class EHentai
extends BasicSupport_Deprecated
{
30 public String
getSourceName() {
31 return "e-hentai.org";
35 protected MetaData
getMeta(URL source
, InputStream in
) throws IOException
{
36 MetaData meta
= new MetaData();
38 meta
.setTitle(getTitle(reset(in
)));
39 meta
.setAuthor(getAuthor(reset(in
)));
40 meta
.setDate(getDate(reset(in
)));
41 meta
.setTags(getTags(reset(in
)));
42 meta
.setSource(getSourceName());
43 meta
.setUrl(source
.toString());
44 meta
.setPublisher(getSourceName());
45 meta
.setUuid(source
.toString());
47 meta
.setLang(getLang(reset(in
)));
48 meta
.setSubject("Hentai");
49 meta
.setType(getType().toString());
50 meta
.setImageDocument(true);
51 meta
.setCover(getCover(source
, reset(in
)));
52 meta
.setFakeCover(true);
58 public Story
process(URL url
, Progress pg
) throws IOException
{
59 // There is no chapters on e621, just pagination...
60 Story story
= super.process(url
, pg
);
62 Chapter only
= new Chapter(1, null);
63 for (Chapter chap
: story
) {
64 only
.getParagraphs().addAll(chap
.getParagraphs());
67 story
.getChapters().clear();
68 story
.getChapters().add(only
);
74 protected boolean supports(URL url
) {
75 return "e-hentai.org".equals(url
.getHost());
79 protected boolean isHtml() {
84 public Map
<String
, String
> getCookies() {
85 // TODO Auto-generated method stub
86 Map
<String
, String
> cookies
= super.getCookies();
87 cookies
.put("nw", "1");
91 private Image
getCover(URL source
, InputStream in
) {
93 String coverLine
= getKeyLine(in
, "<div id=\"gd1\"", " url(", ")");
94 if (coverLine
!= null) {
95 coverLine
= StringUtils
.unhtml(coverLine
).trim();
96 author
= getImage(this, source
, coverLine
);
102 private String
getAuthor(InputStream in
) {
103 String author
= null;
105 List
<String
> tagsAuthor
= getTagsAuthor(in
);
106 if (!tagsAuthor
.isEmpty()) {
107 author
= tagsAuthor
.get(0);
113 private String
getLang(InputStream in
) {
116 String langLine
= getKeyLine(in
, "class=\"gdt1\">Language",
117 "class=\"gdt2\"", "</td>");
118 if (langLine
!= null) {
119 langLine
= StringUtils
.unhtml(langLine
).trim();
120 if (langLine
.equalsIgnoreCase("English")) {
122 } else if (langLine
.equalsIgnoreCase("Japanese")) {
124 } else if (langLine
.equalsIgnoreCase("French")) {
127 // TODO find the code?
135 private String
getDate(InputStream in
) {
138 String dateLine
= getKeyLine(in
, "class=\"gdt1\">Posted",
139 "class=\"gdt2\"", "</td>");
140 if (dateLine
!= null) {
141 dateLine
= StringUtils
.unhtml(dateLine
).trim();
142 if (dateLine
.length() > 10) {
143 dateLine
= dateLine
.substring(0, 10).trim();
152 private List
<String
> getTags(InputStream in
) {
153 List
<String
> tags
= new ArrayList
<String
>();
154 List
<String
> tagsAuthor
= getTagsAuthor(in
);
156 for (int i
= 1; i
< tagsAuthor
.size(); i
++) {
157 tags
.add(tagsAuthor
.get(i
));
163 private List
<String
> getTagsAuthor(InputStream in
) {
164 List
<String
> tags
= new ArrayList
<String
>();
165 String tagLine
= getKeyLine(in
, "<meta name=\"description\"", "Tags: ",
167 if (tagLine
!= null) {
168 for (String tag
: tagLine
.split(",")) {
169 String candi
= tag
.trim();
170 if (!candi
.isEmpty() && !tags
.contains(candi
)) {
179 private String
getTitle(InputStream in
) {
180 String siteName
= " - E-Hentai Galleries";
182 String title
= getLine(in
, "<title>", 0);
184 title
= StringUtils
.unhtml(title
).trim();
185 if (title
.endsWith(siteName
)) {
186 title
= title
.substring(0, title
.length() - siteName
.length())
195 protected String
getDesc(URL source
, InputStream in
) throws IOException
{
198 String descLine
= getKeyLine(in
, "Uploader Comment", null,
199 "<div class=\"c7\"");
200 if (descLine
!= null) {
201 desc
= StringUtils
.unhtml(descLine
);
208 protected List
<Entry
<String
, URL
>> getChapters(URL source
, InputStream in
,
209 Progress pg
) throws IOException
{
210 List
<Entry
<String
, URL
>> urls
= new ArrayList
<Entry
<String
, URL
>>();
211 int last
= 0; // no pool/show when only one page, first page == page 0
213 @SuppressWarnings("resource")
214 Scanner scan
= new Scanner(in
, "UTF-8");
215 scan
.useDelimiter(">");
216 while (scan
.hasNext()) {
217 String line
= scan
.next();
218 if (line
.contains(source
.toString())) {
219 String page
= line
.substring(line
.indexOf(source
.toString()));
221 if (page
.contains(pkey
)) {
222 page
= page
.substring(page
.indexOf(pkey
) + pkey
.length());
224 while (!page
.isEmpty() && page
.charAt(0) >= '0'
225 && page
.charAt(0) <= '9') {
226 number
+= page
.charAt(0);
227 page
= page
.substring(1);
229 if (number
.isEmpty()) {
233 int current
= Integer
.parseInt(number
);
234 if (last
< current
) {
241 for (int i
= 0; i
<= last
; i
++) {
242 urls
.add(new AbstractMap
.SimpleEntry
<String
, URL
>(Integer
243 .toString(i
+ 1), new URL(source
.toString() + "?p=" + i
)));
250 protected String
getChapterContent(URL source
, InputStream in
, int number
,
251 Progress pg
) throws IOException
{
252 String staticSite
= "https://e-hentai.org/s/";
253 List
<URL
> pages
= new ArrayList
<URL
>();
255 @SuppressWarnings("resource")
256 Scanner scan
= new Scanner(in
, "UTF-8");
257 scan
.useDelimiter("\"");
258 while (scan
.hasNext()) {
259 String line
= scan
.next();
260 if (line
.startsWith(staticSite
)) {
262 pages
.add(new URL(line
));
263 } catch (MalformedURLException e
) {
264 Instance
.getTraceHandler().error(
266 "Parsing error, a link is not correctly parsed: "
275 pg
.setMinMax(0, pages
.size());
278 StringBuilder builder
= new StringBuilder();
280 for (URL page
: pages
) {
281 InputStream pageIn
= Instance
.getCache().open(page
, this, false);
283 String link
= getKeyLine(pageIn
, "id=\"img\"", "src=\"", "\"");
284 if (link
!= null && !link
.isEmpty()) {
286 builder
.append(link
);
287 builder
.append("]<br/>");
291 if (pageIn
!= null) {
298 return builder
.toString();