X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFimfictionApi.java;h=9c3e71ddb00a1c4b7ad7f84ab7bc639401c539e1;hb=77e28d38d47dbfcf29030ee388854d59df3ef1d0;hp=59b593ec7aecedea5cb24c4f91b10f6819b172d6;hpb=d9a94285b568e80cba1d5b85d67829839d1d5029;p=fanfix.git
diff --git a/src/be/nikiroo/fanfix/supported/FimfictionApi.java b/src/be/nikiroo/fanfix/supported/FimfictionApi.java
index 59b593e..9c3e71d 100644
--- a/src/be/nikiroo/fanfix/supported/FimfictionApi.java
+++ b/src/be/nikiroo/fanfix/supported/FimfictionApi.java
@@ -87,19 +87,15 @@ class FimfictionApi extends BasicSupport {
// Selectors, so to download all I need and only what I need
String storyContent = "fields[story]=title,description,date_published,cover_image";
String authorContent = "fields[author]=name";
- String chapterContent = "fields[chapter]=chapter_number,title,content,authors_note";
- String contentContent = "fields[content]=html";
- String authorsNoteContent = "fields[authors_note]=html";
+ String chapterContent = "fields[chapter]=chapter_number,title,content_html,authors_note_html";
String includes = "author,chapters,tags";
String urlString = String.format(
"https://www.fimfiction.net/api/v2/stories/%s?" //
- + "%s&%s&"//
+ "%s&%s&%s&" //
+ "include=%s", //
storyId, //
- storyContent, authorContent, //
- chapterContent, contentContent, authorsNoteContent,//
+ storyContent, authorContent, chapterContent,//
includes);
// URL params must be URL-encoded: "[ ]" <-> "%5B %5D"
@@ -160,14 +156,7 @@ class FimfictionApi extends BasicSupport {
@Override
protected String getDesc(URL source, InputStream in) {
String desc = getKeyJson(json, 0, "type", "story", "description");
-
- // TODO: if the description becomes available in html, use it
- desc = desc.replace("\\r\\n", "
");
- desc = desc.replace("[i]", "_").replace("[/i]", "_")
- .replace("[b]", "*").replace("[/b]", "*");
- desc = desc.replaceAll("\\[[^\\]]*\\]", "");
-
- return desc;
+ return unbbcode(desc);
}
@Override
@@ -187,8 +176,8 @@ class FimfictionApi extends BasicSupport {
final int number = Integer.parseInt(json.substring(posNumber,
posComa).trim());
final String title = getKeyJson(json, pos, "title");
- String notes = getKeyJson(json, pos, "authors_note", "html");
- String content = getKeyJson(json, pos, "content", "html");
+ String notes = getKeyJson(json, pos, "authors_note_html");
+ String content = getKeyJson(json, pos, "content_html");
chapterNames.put(number, title);
chapterContents
@@ -228,6 +217,24 @@ class FimfictionApi extends BasicSupport {
|| "www.fimfiction.net".equals(url.getHost());
}
+ /**
+ * Generate a new token from the client ID and secret.
+ *
+ * Note that those tokens are long-lived, and it would be badly seen to + * create a lot of them without due cause. + *
+ * So, please cache and re-use them.
+ *
+ * @param clientId
+ * the client ID offered on FimFiction
+ * @param clientSecret
+ * the client secret that goes with it
+ *
+ * @return a new generated token linked to that client ID
+ *
+ * @throws IOException
+ * in case of I/O errors
+ */
static private String generateOAuth(String clientId, String clientSecret)
throws IOException {
URL url = new URL("https://www.fimfiction.net/api/v2/token");
@@ -241,18 +248,13 @@ class FimfictionApi extends BasicSupport {
String jsonToken = IOUtils.readSmallStream(in);
// Extract token type and token from: {
- // token_type = "bearer",
+ // token_type = "Bearer",
// access_token = "xxxxxxxxxxxxxx"
// }
String token = getKeyText(jsonToken, "\"access_token\"", "\"", "\"");
String tokenType = getKeyText(jsonToken, "\"token_type\"", "\"", "\"");
- // TODO: remove this once the bug is fixed on the server side
- if ("bearer".equals(tokenType)) {
- tokenType = "Bearer";
- }
-
return tokenType + " " + token;
}
@@ -319,4 +321,13 @@ class FimfictionApi extends BasicSupport {
return pos;
}
+
+ // quick & dirty filter
+ static private String unbbcode(String bbcode) {
+ String text = bbcode.replace("\\r\\n", "
") //
+ .replace("[i]", "_").replace("[/i]", "_") //
+ .replace("[b]", "*").replace("[/b]", "*") //
+ .replaceAll("\\[[^\\]]*\\]", "");
+ return text;
+ }
}