X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFimfictionApi.java;h=ee436f165851e64ecffc80eede9ba53651f1edfb;hb=581d42c09b2673025e719a25477565362ebf4482;hp=b2d75df98b9c06437c21bf776843f32ad75b2675;hpb=a8209dd0972f751e59153dd80a53f3062042897a;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/supported/FimfictionApi.java b/src/be/nikiroo/fanfix/supported/FimfictionApi.java index b2d75df..ee436f1 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" @@ -136,8 +132,12 @@ class FimfictionApi extends BasicSupport { meta.setSubject("MLP"); meta.setType(getType().toString()); meta.setImageDocument(false); - meta.setCover(getImage(this, null, - getKeyJson(json, 0, "type", "story", "cover_image", "full"))); + + String coverImageLink = + getKeyJson(json, 0, "type", "story", "cover_image", "full"); + if (!coverImageLink.trim().isEmpty()) { + meta.setCover(getImage(this, null, coverImageLink.trim())); + } return meta; } @@ -150,7 +150,7 @@ class FimfictionApi extends BasicSupport { while (pos >= 0) { pos = indexOfJsonAfter(json, pos, "type", "story_tag"); if (pos >= 0) { - tags.add(getKeyJson(json, pos, "name")); + tags.add(getKeyJson(json, pos, "name").trim()); } } @@ -180,12 +180,16 @@ 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"); + + if (!notes.trim().isEmpty()) { + notes = "
* * *
" + notes; + } + chapterNames.put(number, title); chapterContents - .put(number, content + "
* * *
" + notes); + .put(number, content + notes); urls.add(new Entry() { @Override @@ -250,6 +254,7 @@ class FimfictionApi extends BasicSupport { null, null); String jsonToken = IOUtils.readSmallStream(in); + in.close(); // Extract token type and token from: { // token_type = "Bearer", @@ -287,15 +292,15 @@ class FimfictionApi extends BasicSupport { } // afters: [name, value] pairs (or "" for any of them), can end without - // value + // value but will then be empty, not NULL static private String getKeyJson(String json, int startAt, String... afterKeys) { int pos = indexOfJsonAfter(json, startAt, afterKeys); if (pos < 0) { - return null; + return ""; } - String result = null; + String result = ""; String wip = json.substring(pos); pos = nextUnescapedQuote(wip, 0); @@ -306,7 +311,10 @@ class FimfictionApi extends BasicSupport { result = wip.substring(0, pos); } } - + + result = result.replace("\\t", "\t") + .replace("\\\"", "\""); + return result; }