61f61d2f5856c4732c87f27df1f00b96e7f6f0f2
1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.io
.InputStream
;
4 import java
.net
.MalformedURLException
;
6 import java
.util
.ArrayList
;
7 import java
.util
.HashMap
;
10 import java
.util
.Map
.Entry
;
11 import java
.util
.Scanner
;
13 import be
.nikiroo
.fanfix
.Instance
;
16 * Support class for <a href="http://www.fimfiction.net/">FimFiction.net</a>
17 * stories, a website dedicated to My Little Pony.
21 class Fimfiction
extends BasicSupport
{
23 protected boolean isHtml() {
28 public String
getSourceName() {
29 return "FimFiction.net";
33 protected String
getSubject(URL source
, InputStream in
) {
38 public Map
<String
, String
> getCookies() {
39 Map
<String
, String
> cookies
= new HashMap
<String
, String
>();
40 cookies
.put("view_mature", "true");
45 protected List
<String
> getTags(URL source
, InputStream in
) {
46 List
<String
> tags
= new ArrayList
<String
>();
49 @SuppressWarnings("resource")
50 Scanner scan
= new Scanner(in
, "UTF-8");
51 scan
.useDelimiter("\\n");
52 while (scan
.hasNext()) {
53 String line
= scan
.next();
54 if (line
.contains("story_category") && !line
.contains("title=")) {
55 int pos
= line
.indexOf('>');
57 line
= line
.substring(pos
+ 1);
58 pos
= line
.indexOf('<');
60 line
= line
.substring(0, pos
);
65 if (!tags
.contains(line
)) {
75 protected String
getTitle(URL source
, InputStream in
) {
76 String line
= getLine(in
, " property=\"og:title\"", 0);
79 for (int i
= 0; i
< 3; i
++) {
80 pos
= line
.indexOf('"', pos
+ 1);
84 line
= line
.substring(pos
+ 1);
85 pos
= line
.indexOf('"');
87 return line
.substring(0, pos
);
96 protected String
getAuthor(URL source
, InputStream in
) {
97 String line
= getLine(in
, " href=\"/user/", 0);
99 int pos
= line
.indexOf('"');
101 line
= line
.substring(pos
+ 1);
102 pos
= line
.indexOf('"');
104 line
= line
.substring(0, pos
);
105 pos
= line
.lastIndexOf('/');
107 line
= line
.substring(pos
+ 1);
108 return line
.replace('+', ' ');
118 protected String
getDate(URL source
, InputStream in
) {
119 String line
= getLine(in
, "<span class=\"date\">", 0);
122 for (int i
= 0; i
< 3; i
++) {
123 pos
= line
.indexOf('>', pos
+ 1);
127 line
= line
.substring(pos
+ 1);
128 pos
= line
.indexOf('<');
130 return line
.substring(0, pos
).trim();
139 protected String
getDesc(URL source
, InputStream in
) {
140 // the og: meta version is the SHORT resume, this is the LONG resume
141 return getLine(in
, "class=\"more_button hidden\"", -1);
145 protected URL
getCover(URL url
, InputStream in
) {
146 // Note: the 'og:image' is the SMALL cover, not the full version
147 String cover
= getLine(in
, "<div class=\"story_image\">", 1);
149 int pos
= cover
.indexOf('"');
151 cover
= cover
.substring(pos
+ 1);
152 pos
= cover
.indexOf('"');
154 cover
= cover
.substring(0, pos
);
161 return new URL(cover
);
162 } catch (MalformedURLException e
) {
171 protected List
<Entry
<String
, URL
>> getChapters(URL source
, InputStream in
) {
172 List
<Entry
<String
, URL
>> urls
= new ArrayList
<Entry
<String
, URL
>>();
173 @SuppressWarnings("resource")
174 Scanner scan
= new Scanner(in
, "UTF-8");
175 scan
.useDelimiter("\\n");
176 while (scan
.hasNext()) {
177 String line
= scan
.next();
178 if (line
.contains("class=\"chapter_link\"")
179 || line
.contains("class='chapter_link'")) {
182 int pos
= name
.indexOf('>');
184 name
= name
.substring(pos
+ 1);
185 pos
= name
.indexOf('<');
187 name
= name
.substring(0, pos
);
191 pos
= line
.indexOf('/');
193 line
= line
.substring(pos
); // we take the /, not +1
194 pos
= line
.indexOf('"');
196 line
= line
.substring(0, pos
);
201 final String key
= name
;
202 final URL value
= new URL("http://www.fimfiction.net"
204 urls
.add(new Entry
<String
, URL
>() {
205 public URL
setValue(URL value
) {
209 public String
getKey() {
213 public URL
getValue() {
217 } catch (MalformedURLException e
) {
227 protected String
getChapterContent(URL source
, InputStream in
, int number
) {
228 return getLine(in
, "<div id=\"chapter_container\">", 1);
232 protected boolean supports(URL url
) {
233 return "fimfiction.net".equals(url
.getHost())
234 || "www.fimfiction.net".equals(url
.getHost());