X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFimfictionApi.java;h=52678e402a2e1c98b65560b12a0a8df825424252;hb=ce297a794b1b7d3aa4e9234a6511dd9fe7216656;hp=9c3e71ddb00a1c4b7ad7f84ab7bc639401c539e1;hpb=77e28d38d47dbfcf29030ee388854d59df3ef1d0;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/FimfictionApi.java b/src/be/nikiroo/fanfix/supported/FimfictionApi.java index 9c3e71d..52678e4 100644 --- a/src/be/nikiroo/fanfix/supported/FimfictionApi.java +++ b/src/be/nikiroo/fanfix/supported/FimfictionApi.java @@ -3,11 +3,13 @@ package be.nikiroo.fanfix.supported; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.bundles.Config; @@ -23,7 +25,7 @@ import be.nikiroo.utils.Progress; * * @author niki */ -class FimfictionApi extends BasicSupport { +class FimfictionApi extends BasicSupport_Deprecated { private String oauth; private String storyId; private String json; @@ -128,12 +130,16 @@ class FimfictionApi extends BasicSupport { meta.setPublisher(getSourceName()); meta.setUuid(source.toString()); meta.setLuid(""); - meta.setLang("EN"); + meta.setLang("en"); 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; } @@ -146,7 +152,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()); } } @@ -162,10 +168,8 @@ class FimfictionApi extends BasicSupport { @Override protected List> getChapters(URL source, InputStream in, Progress pg) { - List> urls = new ArrayList>(); - - chapterNames = new HashMap(); - chapterContents = new HashMap(); + chapterNames = new TreeMap(); + chapterContents = new TreeMap(); int pos = 0; while (pos >= 0) { @@ -179,29 +183,20 @@ class FimfictionApi extends BasicSupport { 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); - - urls.add(new Entry() { - @Override - public URL setValue(URL value) { - return null; - } - - @Override - public String getKey() { - return title; - } - - @Override - public URL getValue() { - return null; - } - }); + chapterContents.put(number, content + notes); } } + List> urls = new ArrayList>(); + for (String title : chapterNames.values()) { + urls.add(new AbstractMap.SimpleEntry(title, null)); + } + return urls; } @@ -246,6 +241,7 @@ class FimfictionApi extends BasicSupport { null, null); String jsonToken = IOUtils.readSmallStream(in); + in.close(); // Extract token type and token from: { // token_type = "Bearer", @@ -283,15 +279,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); @@ -303,6 +299,8 @@ class FimfictionApi extends BasicSupport { } } + result = result.replace("\\t", "\t").replace("\\\"", "\""); + return result; }