1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import java
.util
.ArrayList
;
8 import java
.util
.Map
.Entry
;
9 import java
.util
.Scanner
;
11 import be
.nikiroo
.fanfix
.Instance
;
12 import be
.nikiroo
.fanfix
.data
.Chapter
;
13 import be
.nikiroo
.fanfix
.data
.Story
;
14 import be
.nikiroo
.utils
.StringUtils
;
17 * Support class for <a href="http://e621.net/">e621.net</a> and <a
18 * href="http://e926.net/">e926.net</a>, a Furry website supporting comics,
19 * including some of MLP.
21 * <a href="http://e926.net/">e926.net</a> only shows the "clean" images and
22 * comics, but it can be difficult to browse.
26 class E621
extends BasicSupport
{
28 public String
getSourceName() {
33 public boolean isImageDocument(URL source
, InputStream in
) {
38 public Story
process(URL url
) throws IOException
{
39 // There is no chapters on e621, just pagination...
40 Story story
= super.process(url
);
42 Chapter only
= new Chapter(1, null);
43 for (Chapter chap
: story
) {
44 only
.getParagraphs().addAll(chap
.getParagraphs());
47 story
.getChapters().clear();
48 story
.getChapters().add(only
);
54 protected boolean supports(URL url
) {
55 String host
= url
.getHost();
56 if (host
.startsWith("www.")) {
57 host
= host
.substring("www.".length());
60 return ("e621.net".equals(host
) || "e926.net".equals(host
))
61 && url
.getPath().startsWith("/pool/");
65 protected boolean isHtml() {
70 protected String
getAuthor(URL source
, InputStream in
) throws IOException
{
71 String author
= getLine(in
, "href=\"/post/show/", 0);
73 String key
= "href=\"";
74 int pos
= author
.indexOf(key
);
76 author
= author
.substring(pos
+ key
.length());
77 pos
= author
.indexOf("\"");
79 author
= author
.substring(0, pos
- 1);
80 String page
= source
.getProtocol() + "://"
81 + source
.getHost() + author
;
82 InputStream pageIn
= Instance
.getCache().open(
83 new URL(page
), this, false);
85 key
= "class=\"tag-type-artist\"";
86 author
= getLine(pageIn
, key
, 0);
88 pos
= author
.indexOf("<a href=\"");
90 author
= author
.substring(pos
);
91 pos
= author
.indexOf("</a>");
93 author
= author
.substring(0, pos
);
94 return StringUtils
.unhtml(author
);
109 protected String
getDate(URL source
, InputStream in
) throws IOException
{
114 protected String
getSubject(URL source
, InputStream in
) throws IOException
{
119 protected URL
getCover(URL source
, InputStream in
) throws IOException
{
124 protected String
getTitle(URL source
, InputStream in
) throws IOException
{
125 String title
= getLine(in
, "<title>", 0);
127 int pos
= title
.indexOf('>');
129 title
= title
.substring(pos
+ 1);
130 pos
= title
.indexOf('<');
132 title
= title
.substring(0, pos
);
136 if (title
.startsWith("Pool:")) {
137 title
= title
.substring("Pool:".length());
140 title
= title
.trim();
147 protected String
getDesc(URL source
, InputStream in
) throws IOException
{
148 String desc
= getLine(in
, "margin-bottom: 2em;", 0);
151 StringBuilder builder
= new StringBuilder();
153 boolean inTags
= false;
154 for (char car
: desc
.toCharArray()) {
155 if ((inTags
&& car
== '>') || (!inTags
&& car
== '<')) {
164 return builder
.toString().trim();
171 protected List
<Entry
<String
, URL
>> getChapters(URL source
, InputStream in
)
173 List
<Entry
<String
, URL
>> urls
= new ArrayList
<Entry
<String
, URL
>>();
174 int last
= 1; // no pool/show when only one page
176 @SuppressWarnings("resource")
177 Scanner scan
= new Scanner(in
, "UTF-8");
178 scan
.useDelimiter("\\n");
179 while (scan
.hasNext()) {
180 String line
= scan
.next();
181 for (int pos
= line
.indexOf(source
.getPath()); pos
>= 0; pos
= line
182 .indexOf(source
.getPath(), pos
+ source
.getPath().length())) {
183 int equalPos
= line
.indexOf("=", pos
);
184 int quotePos
= line
.indexOf("\"", pos
);
185 if (equalPos
>= 0 && quotePos
> equalPos
) {
186 String snum
= line
.substring(equalPos
+ 1, quotePos
);
188 int num
= Integer
.parseInt(snum
);
192 } catch (NumberFormatException e
) {
198 for (int i
= 1; i
<= last
; i
++) {
199 final String key
= Integer
.toString(i
);
200 final URL value
= new URL(source
.toString() + "?page=" + i
);
201 urls
.add(new Entry
<String
, URL
>() {
202 public URL
setValue(URL value
) {
206 public URL
getValue() {
210 public String
getKey() {
220 protected String
getChapterContent(URL source
, InputStream in
, int number
)
222 StringBuilder builder
= new StringBuilder();
223 String staticSite
= "https://static1.e621.net";
224 if (source
.getHost().contains("e926")) {
225 staticSite
= staticSite
.replace("e621", "e926");
228 String key
= staticSite
+ "/data/preview/";
230 @SuppressWarnings("resource")
231 Scanner scan
= new Scanner(in
, "UTF-8");
232 scan
.useDelimiter("\\n");
233 while (scan
.hasNext()) {
234 String line
= scan
.next();
235 if (line
.contains("class=\"preview\"")) {
236 for (int pos
= line
.indexOf(key
); pos
>= 0; pos
= line
.indexOf(
237 key
, pos
+ key
.length())) {
238 int endPos
= line
.indexOf("\"", pos
);
240 String id
= line
.substring(pos
+ key
.length(), endPos
);
241 id
= staticSite
+ "/data/" + id
;
243 int dotPos
= id
.lastIndexOf(".");
245 id
= id
.substring(0, dotPos
);
248 builder
.append("]\n");
255 return builder
.toString();