X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FBasicSupport.java;h=b528cac819acea887acfc28f861b9c32221d1971;hb=6e06d2cc9bf068a8ec4ad105aaef955a6eb509a1;hp=2b4715ab0beec0af04f5d52a70f88f55a61193fd;hpb=2284842831ea46e89b97dd22b6e294caad361f30;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/BasicSupport.java b/src/be/nikiroo/fanfix/supported/BasicSupport.java index 2b4715a..b528cac 100644 --- a/src/be/nikiroo/fanfix/supported/BasicSupport.java +++ b/src/be/nikiroo/fanfix/supported/BasicSupport.java @@ -59,6 +59,8 @@ public abstract class BasicSupport { MANGAFOX, /** Furry website with comics support */ E621, + /** Furry website with stories */ + YIFFSTAR, /** CBZ files */ CBZ, /** HTML files */ @@ -241,6 +243,16 @@ public abstract class BasicSupport { protected abstract String getChapterContent(URL source, InputStream in, int number) throws IOException; + /** + * Log into the support (can be a no-op depending upon the support). + * + * @throws IOException + * in case of I/O error + */ + public void login() throws IOException { + + } + /** * Return the list of cookies (values included) that must be used to * correctly fetch the resources. @@ -249,11 +261,29 @@ public abstract class BasicSupport { * it. * * @return the cookies + * + * @throws IOException + * in case of I/O error */ - public Map getCookies() { + public Map getCookies() throws IOException { return new HashMap(); } + /** + * Return the canonical form of the main {@link URL}. + * + * @param source + * the source {@link URL} + * + * @return the canonical form of this {@link URL} + * + * @throws IOException + * in case of I/O error + */ + public URL getCanonicalUrl(URL source) throws IOException { + return source; + } + /** * Process the given story resource into a partially filled {@link Story} * object containing the name and metadata, except for the description. @@ -287,6 +317,12 @@ public abstract class BasicSupport { */ protected Story processMeta(URL url, boolean close, boolean getDesc) throws IOException { + login(); + + url = getCanonicalUrl(url); + + setCurrentReferer(url); + in = openInput(url); if (in == null) { return null; @@ -324,6 +360,8 @@ public abstract class BasicSupport { in.close(); } } + + setCurrentReferer(null); } } @@ -348,8 +386,7 @@ public abstract class BasicSupport { pg.setMinMax(0, 100); } - setCurrentReferer(url); - + url = getCanonicalUrl(url); pg.setProgress(1); try { Story story = processMeta(url, false, true); @@ -359,6 +396,8 @@ public abstract class BasicSupport { return null; } + setCurrentReferer(url); + story.setChapters(new ArrayList()); List> chapters = getChapters(url, getInput()); @@ -400,12 +439,12 @@ public abstract class BasicSupport { in.close(); } - currentReferer = null; + setCurrentReferer(null); } } /** - * The support type.$ + * The support type. * * @return the type */ @@ -661,6 +700,11 @@ public abstract class BasicSupport { /** * Return the list of supported image extensions. * + * @param emptyAllowed + * TRUE to allow an empty extension on first place, which can be + * used when you may already have an extension in your input but + * are not sure about it + * * @return the extensions */ static String[] getImageExt(boolean emptyAllowed) { @@ -671,6 +715,18 @@ public abstract class BasicSupport { } } + /** + * Check if the given resource can be a local image or a remote image, then + * refresh the cache with it if it is. + * + * @param source + * the story source + * @param line + * the resource to check + * + * @return the image if found, or NULL + * + */ static BufferedImage getImage(BasicSupport support, URL source, String line) { URL url = getImageUrl(support, source, line); if (url != null) { @@ -782,6 +838,14 @@ public abstract class BasicSupport { return Instance.getCache().open(source, this, false); } + /** + * Reset the given {@link InputStream} and return it. + * + * @param in + * the {@link InputStream} to reset + * + * @return the same {@link InputStream} after reset + */ protected InputStream reset(InputStream in) { try { in.reset(); @@ -834,7 +898,7 @@ public abstract class BasicSupport { * paragraphs (quotes or not)). * * @param para - * the paragraph to requotify (not necessaraly a quote) + * the paragraph to requotify (not necessarily a quote) * * @return the correctly (or so we hope) quotified paragraphs */ @@ -1111,7 +1175,7 @@ public abstract class BasicSupport { } /** - * Remove the HTML from the inpit if {@link BasicSupport#isHtml()} is + * Remove the HTML from the input if {@link BasicSupport#isHtml()} is * true. * * @param input @@ -1186,6 +1250,8 @@ public abstract class BasicSupport { return new MangaFox().setType(type); case E621: return new E621().setType(type); + case YIFFSTAR: + return new YiffStar().setType(type); case CBZ: return new Cbz().setType(type); case HTML: