1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import java
.util
.AbstractMap
;
7 import java
.util
.ArrayList
;
9 import java
.util
.Map
.Entry
;
10 import java
.util
.Scanner
;
12 import be
.nikiroo
.fanfix
.Instance
;
13 import be
.nikiroo
.fanfix
.data
.Chapter
;
14 import be
.nikiroo
.fanfix
.data
.MetaData
;
15 import be
.nikiroo
.fanfix
.data
.Story
;
16 import be
.nikiroo
.utils
.Image
;
17 import be
.nikiroo
.utils
.Progress
;
18 import be
.nikiroo
.utils
.StringUtils
;
21 * Support class for <a href="http://e621.net/">e621.net</a> and <a
22 * href="http://e926.net/">e926.net</a>, a Furry website supporting comics,
23 * including some of MLP.
25 * <a href="http://e926.net/">e926.net</a> only shows the "clean" images and
26 * comics, but it can be difficult to browse.
30 class E621
extends BasicSupport_Deprecated
{
32 public String
getSourceName() {
37 protected MetaData
getMeta(URL source
, InputStream in
) throws IOException
{
38 MetaData meta
= new MetaData();
40 meta
.setTitle(getTitle(reset(in
)));
41 meta
.setAuthor(getAuthor(source
, reset(in
)));
43 meta
.setTags(new ArrayList
<String
>()); // TODDO ???
44 meta
.setSource(getSourceName());
45 meta
.setUrl(source
.toString());
46 meta
.setPublisher(getSourceName());
47 meta
.setUuid(source
.toString());
50 meta
.setSubject("Furry");
51 meta
.setType(getType().toString());
52 meta
.setImageDocument(true);
53 meta
.setCover(getCover(source
));
54 meta
.setFakeCover(true);
60 public Story
process(URL url
, Progress pg
) throws IOException
{
61 // There is no chapters on e621, just pagination...
62 Story story
= super.process(url
, pg
);
64 Chapter only
= new Chapter(1, null);
65 for (Chapter chap
: story
) {
66 only
.getParagraphs().addAll(chap
.getParagraphs());
69 story
.getChapters().clear();
70 story
.getChapters().add(only
);
76 protected boolean supports(URL url
) {
77 String host
= url
.getHost();
78 if (host
.startsWith("www.")) {
79 host
= host
.substring("www.".length());
82 return ("e621.net".equals(host
) || "e926.net".equals(host
))
83 && url
.getPath().startsWith("/pool/");
87 protected boolean isHtml() {
91 private Image
getCover(URL source
) throws IOException
{
92 InputStream in
= Instance
.getCache().open(source
, this, true);
93 String images
= getChapterContent(new URL(source
.toString() + "?page="
95 if (!images
.isEmpty()) {
96 int pos
= images
.indexOf("<br/>");
98 images
= images
.substring(1, pos
- 1);
99 return getImage(this, null, images
);
106 private String
getAuthor(URL source
, InputStream in
) {
107 String author
= getLine(in
, "href=\"/post/show/", 0);
108 if (author
!= null) {
109 String key
= "href=\"";
110 int pos
= author
.indexOf(key
);
112 author
= author
.substring(pos
+ key
.length());
113 pos
= author
.indexOf("\"");
115 author
= author
.substring(0, pos
- 1);
116 String page
= source
.getProtocol() + "://"
117 + source
.getHost() + author
;
119 InputStream pageIn
= Instance
.getCache().open(
120 new URL(page
), this, false);
122 key
= "class=\"tag-type-artist\"";
123 author
= getLine(pageIn
, key
, 0);
124 if (author
!= null) {
125 pos
= author
.indexOf("<a href=\"");
127 author
= author
.substring(pos
);
128 pos
= author
.indexOf("</a>");
130 author
= author
.substring(0, pos
);
131 return StringUtils
.unhtml(author
);
138 } catch (Exception e
) {
148 private String
getTitle(InputStream in
) {
149 String title
= getLine(in
, "<title>", 0);
151 int pos
= title
.indexOf('>');
153 title
= title
.substring(pos
+ 1);
154 pos
= title
.indexOf('<');
156 title
= title
.substring(0, pos
);
160 if (title
.startsWith("Pool:")) {
161 title
= title
.substring("Pool:".length());
164 title
= StringUtils
.unhtml(title
).trim();
171 protected String
getDesc(URL source
, InputStream in
) throws IOException
{
172 String desc
= getLine(in
, "margin-bottom: 2em;", 0);
175 StringBuilder builder
= new StringBuilder();
177 boolean inTags
= false;
178 for (char car
: desc
.toCharArray()) {
179 if ((inTags
&& car
== '>') || (!inTags
&& car
== '<')) {
188 return builder
.toString().trim();
195 protected List
<Entry
<String
, URL
>> getChapters(URL source
, InputStream in
,
196 Progress pg
) throws IOException
{
197 List
<Entry
<String
, URL
>> urls
= new ArrayList
<Entry
<String
, URL
>>();
198 int last
= 1; // no pool/show when only one page
200 @SuppressWarnings("resource")
201 Scanner scan
= new Scanner(in
, "UTF-8");
202 scan
.useDelimiter("\\n");
203 while (scan
.hasNext()) {
204 String line
= scan
.next();
205 for (int pos
= line
.indexOf(source
.getPath()); pos
>= 0; pos
= line
206 .indexOf(source
.getPath(), pos
+ source
.getPath().length())) {
207 int equalPos
= line
.indexOf("=", pos
);
208 int quotePos
= line
.indexOf("\"", pos
);
209 if (equalPos
>= 0 && quotePos
> equalPos
) {
210 String snum
= line
.substring(equalPos
+ 1, quotePos
);
212 int num
= Integer
.parseInt(snum
);
216 } catch (NumberFormatException e
) {
222 for (int i
= 1; i
<= last
; i
++) {
223 urls
.add(new AbstractMap
.SimpleEntry
<String
, URL
>(Integer
224 .toString(i
), new URL(source
.toString() + "?page=" + i
)));
231 protected String
getChapterContent(URL source
, InputStream in
, int number
,
232 Progress pg
) throws IOException
{
233 StringBuilder builder
= new StringBuilder();
234 String staticSite
= "https://static1.e621.net";
235 if (source
.getHost().contains("e926")) {
236 staticSite
= staticSite
.replace("e621", "e926");
239 String key
= staticSite
+ "/data/preview/";
241 @SuppressWarnings("resource")
242 Scanner scan
= new Scanner(in
, "UTF-8");
243 scan
.useDelimiter("\\n");
244 while (scan
.hasNext()) {
245 String line
= scan
.next();
246 if (line
.contains("class=\"preview")) {
247 for (int pos
= line
.indexOf(key
); pos
>= 0; pos
= line
.indexOf(
248 key
, pos
+ key
.length())) {
249 int endPos
= line
.indexOf("\"", pos
);
251 String id
= line
.substring(pos
+ key
.length(), endPos
);
252 id
= staticSite
+ "/data/" + id
;
254 int dotPos
= id
.lastIndexOf(".");
256 id
= id
.substring(0, dotPos
);
259 builder
.append("]<br/>");
266 return builder
.toString();