X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFimfictionApi.java;h=59b593ec7aecedea5cb24c4f91b10f6819b172d6;hb=d9a94285b568e80cba1d5b85d67829839d1d5029;hp=591bbb08736c921333b885c19548c51e7d5c78c2;hpb=315f14ae3752d90c683a07fa20f1aa53f6010d6d;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/FimfictionApi.java b/src/be/nikiroo/fanfix/supported/FimfictionApi.java index 591bbb0..59b593e 100644 --- a/src/be/nikiroo/fanfix/supported/FimfictionApi.java +++ b/src/be/nikiroo/fanfix/supported/FimfictionApi.java @@ -159,7 +159,15 @@ class FimfictionApi extends BasicSupport { @Override protected String getDesc(URL source, InputStream in) { - return getKeyJson(json, 0, "type", "story", "description"); + 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; } @Override @@ -281,6 +289,34 @@ class FimfictionApi extends BasicSupport { return null; } - return getKeyText(json.substring(pos), "\"", null, "\""); + String result = null; + String wip = json.substring(pos); + + pos = nextUnescapedQuote(wip, 0); + if (pos >= 0) { + wip = wip.substring(pos + 1); + pos = nextUnescapedQuote(wip, 0); + if (pos >= 0) { + result = wip.substring(0, pos); + } + } + + return result; + } + + // next " but don't take \" into account + static private int nextUnescapedQuote(String result, int pos) { + while (pos >= 0) { + pos = result.indexOf("\"", pos); + if (pos == 0 || (pos > 0 && result.charAt(pos - 1) != '\\')) { + break; + } + + if (pos < result.length()) { + pos++; + } + } + + return pos; } }