X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFimfictionApi.java;h=6c6d7ba31caf2197356b68168447c7871b257a52;hb=7345d22206e6ff1571dfaef6795aff7007e50bcb;hp=f31f8566e2460b581dfaf78d2ee7509b2eb6a542;hpb=826e45696764433b7b46e83143c2259f416c3b61;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/FimfictionApi.java b/src/be/nikiroo/fanfix/supported/FimfictionApi.java index f31f856..6c6d7ba 100644 --- a/src/be/nikiroo/fanfix/supported/FimfictionApi.java +++ b/src/be/nikiroo/fanfix/supported/FimfictionApi.java @@ -37,22 +37,17 @@ class FimfictionApi extends BasicSupport { private Map chapterContents; public FimfictionApi() throws IOException { - if (Instance.getConfig().getBoolean( - Config.LOGIN_FIMFICTION_APIKEY_FORCE_HTML, false)) { - throw new IOException( - "Configuration is set to force HTML scrapping"); + if (Instance.getInstance().getConfig().getBoolean(Config.LOGIN_FIMFICTION_APIKEY_FORCE_HTML, false)) { + throw new IOException("Configuration is set to force HTML scrapping"); } - String oauth = Instance.getConfig().getString( - Config.LOGIN_FIMFICTION_APIKEY_TOKEN); + String oauth = Instance.getInstance().getConfig().getString(Config.LOGIN_FIMFICTION_APIKEY_TOKEN); if (oauth == null || oauth.isEmpty()) { - String clientId = Instance.getConfig().getString( - Config.LOGIN_FIMFICTION_APIKEY_CLIENT_ID) - + ""; - String clientSecret = Instance.getConfig().getString( - Config.LOGIN_FIMFICTION_APIKEY_CLIENT_SECRET) + String clientId = Instance.getInstance().getConfig().getString(Config.LOGIN_FIMFICTION_APIKEY_CLIENT_ID) + ""; + String clientSecret = Instance.getInstance().getConfig() + .getString(Config.LOGIN_FIMFICTION_APIKEY_CLIENT_SECRET) + ""; if (clientId.trim().isEmpty() || clientSecret.trim().isEmpty()) { throw new IOException("API key required for the beta API v2"); @@ -60,9 +55,8 @@ class FimfictionApi extends BasicSupport { oauth = generateOAuth(clientId, clientSecret); - Instance.getConfig().setString( - Config.LOGIN_FIMFICTION_APIKEY_TOKEN, oauth); - Instance.getConfig().updateFile(); + Instance.getInstance().getConfig().setString(Config.LOGIN_FIMFICTION_APIKEY_TOKEN, oauth); + Instance.getInstance().getConfig().updateFile(); } this.oauth = oauth; @@ -84,11 +78,6 @@ class FimfictionApi extends BasicSupport { return true; } - @Override - public String getSourceName() { - return "FimFiction.net"; - } - /** * Extract the full JSON data we will later use to build the {@link Story}. * @@ -121,7 +110,7 @@ class FimfictionApi extends BasicSupport { urlString = urlString.replace("[", "%5B").replace("]", "%5D"); URL url = new URL(urlString); - InputStream jsonIn = Instance.getCache().open(url, this, false); + InputStream jsonIn = Instance.getInstance().getCache().open(url, this, false); try { return IOUtils.readSmallStream(jsonIn); } finally { @@ -137,9 +126,9 @@ class FimfictionApi extends BasicSupport { meta.setAuthor(getKeyJson(json, 0, "type", "user", "name")); meta.setDate(getKeyJson(json, 0, "type", "story", "date_published")); meta.setTags(getTags()); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(getSource().toString()); - meta.setPublisher(getSourceName()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(getSource().toString()); meta.setLuid(""); meta.setLang("en"); @@ -150,13 +139,20 @@ class FimfictionApi extends BasicSupport { String coverImageLink = getKeyJson(json, 0, "type", "story", "cover_image", "full"); if (!coverImageLink.trim().isEmpty()) { - InputStream in = null; + URL coverImageUrl = new URL(coverImageLink.trim()); + + // No need to use the oauth, cookies... for the cover + // Plus: it crashes on Android because of the referer try { - URL coverImageUrl = new URL(coverImageLink.trim()); - in = Instance.getCache().open(coverImageUrl, this, true); - meta.setCover(new Image(in)); - } finally { - in.close(); + InputStream in = Instance.getInstance().getCache().open(coverImageUrl, null, true); + try { + meta.setCover(new Image(in)); + } finally { + in.close(); + } + } catch (IOException e) { + Instance.getInstance().getTraceHandler() + .error(new IOException("Cannot get the story cover, ignoring...", e)); } } @@ -212,7 +208,7 @@ class FimfictionApi extends BasicSupport { List> urls = new ArrayList>(); for (String title : chapterNames.values()) { - urls.add(new AbstractMap.SimpleEntry(title, null)); + urls.add(new AbstractMap.SimpleEntry(title, null)); } return urls; @@ -254,8 +250,7 @@ class FimfictionApi extends BasicSupport { params.put("client_id", clientId); params.put("client_secret", clientSecret); params.put("grant_type", "client_credentials"); - InputStream in = Instance.getCache().openNoCache(url, null, params, - null, null); + InputStream in = Instance.getInstance().getCache().openNoCache(url, null, params, null, null); String jsonToken = IOUtils.readSmallStream(in); in.close();