Remove or move java.awt dependencies
authorNiki Roo <niki@nikiroo.be>
Sun, 3 Dec 2017 03:11:48 +0000 (04:11 +0100)
committerNiki Roo <niki@nikiroo.be>
Sun, 3 Dec 2017 03:11:48 +0000 (04:11 +0100)
37 files changed:
configure.sh
libs/nikiroo-utils-4.0.0-sources.jar [moved from libs/nikiroo-utils-3.1.6-sources.jar with 87% similarity]
src/be/nikiroo/fanfix/DataLoader.java
src/be/nikiroo/fanfix/data/MetaData.java
src/be/nikiroo/fanfix/data/Paragraph.java
src/be/nikiroo/fanfix/data/Story.java
src/be/nikiroo/fanfix/library/BasicLibrary.java
src/be/nikiroo/fanfix/library/CacheLibrary.java
src/be/nikiroo/fanfix/library/LocalLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibrary.java
src/be/nikiroo/fanfix/output/BasicOutput.java
src/be/nikiroo/fanfix/output/Epub.java
src/be/nikiroo/fanfix/output/Html.java
src/be/nikiroo/fanfix/output/InfoCover.java
src/be/nikiroo/fanfix/output/Text.java
src/be/nikiroo/fanfix/reader/BasicReader.java
src/be/nikiroo/fanfix/reader/Reader.java
src/be/nikiroo/fanfix/reader/cli/CliReader.java [moved from src/be/nikiroo/fanfix/reader/CliReader.java with 96% similarity]
src/be/nikiroo/fanfix/reader/tui/TuiReader.java [moved from src/be/nikiroo/fanfix/reader/TuiReader.java with 93% similarity]
src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java [moved from src/be/nikiroo/fanfix/reader/TuiReaderApplication.java with 94% similarity]
src/be/nikiroo/fanfix/reader/tui/TuiReaderMainWindow.java [moved from src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java with 98% similarity]
src/be/nikiroo/fanfix/reader/tui/TuiReaderStoryWindow.java [moved from src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java with 99% similarity]
src/be/nikiroo/fanfix/reader/ui/GuiReader.java [moved from src/be/nikiroo/fanfix/reader/GuiReader.java with 92% similarity]
src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java [moved from src/be/nikiroo/fanfix/reader/GuiReaderBook.java with 96% similarity]
src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java [moved from src/be/nikiroo/fanfix/reader/GuiReaderFrame.java with 98% similarity]
src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java [moved from src/be/nikiroo/fanfix/reader/GuiReaderGroup.java with 97% similarity]
src/be/nikiroo/fanfix/supported/BasicSupport.java
src/be/nikiroo/fanfix/supported/Cbz.java
src/be/nikiroo/fanfix/supported/E621.java
src/be/nikiroo/fanfix/supported/EHentai.java
src/be/nikiroo/fanfix/supported/Epub.java
src/be/nikiroo/fanfix/supported/Fanfiction.java
src/be/nikiroo/fanfix/supported/Fimfiction.java
src/be/nikiroo/fanfix/supported/InfoReader.java
src/be/nikiroo/fanfix/supported/MangaFox.java
src/be/nikiroo/fanfix/supported/Text.java
src/be/nikiroo/fanfix/supported/YiffStar.java

index 520afba9454ad0e7ad4ab8a3bb91152f549d7ae3..eb20f7d382b020f74550aeb80b508967ceb3b4ca 100755 (executable)
@@ -4,9 +4,9 @@
 PREFIX=/usr/local
 PROGS="java javac jar make sed"
 
-CLI=be/nikiroo/fanfix/reader/CliReader
+CLI=be/nikiroo/fanfix/reader/cli/CliReader
 TUI=
-GUI=be/nikiroo/fanfix/reader/GuiReader
+GUI=be/nikiroo/fanfix/reader/ui/GuiReader
 JCLI=
 JTUI=
 JGUI=
@@ -35,7 +35,7 @@ while [ "$*" != "" ]; do
        --tui) #=yes    Enable TUI support (Jexer, experimental)
                [ "$val" = no -o "$val" = false ] && TUI= && JTUI=
                if [ "$val" = yes -o "$val" = true ]; then
-                       TUI=be/nikiroo/fanfix/reader/TuiReader
+                       TUI=be/nikiroo/fanfix/reader/tui/TuiReader
                        JTUI="-C bin/ jexer"
                fi
        ;;
similarity index 87%
rename from libs/nikiroo-utils-3.1.6-sources.jar
rename to libs/nikiroo-utils-4.0.0-sources.jar
index 5f2dbae17e1ec5c599c565d6a1e040b0db80cfbc..72ad2349c73e1b4c1588223cf5403a3de34debf7 100644 (file)
Binary files a/libs/nikiroo-utils-3.1.6-sources.jar and b/libs/nikiroo-utils-4.0.0-sources.jar differ
index 395f68314cc7caf131295d899bb179167033c052..222c61463c815e8000b6e491fe0234598071a05b 100644 (file)
@@ -1,18 +1,16 @@
 package be.nikiroo.fanfix;
 
-import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Map;
 
-import javax.imageio.ImageIO;
-
 import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.supported.BasicSupport;
 import be.nikiroo.utils.Cache;
 import be.nikiroo.utils.Downloader;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.ImageUtils;
 
 /**
@@ -50,7 +48,9 @@ public class DataLoader {
        public DataLoader(File dir, String UA, int hoursChanging, int hoursStable)
                        throws IOException {
                cache = new Cache(dir, hoursChanging, hoursStable);
+               cache.setTraceHandler(Instance.getTraceHandler());
                downloader = new Downloader(UA);
+               downloader.setTraceHandler(Instance.getTraceHandler());
        }
 
        /**
@@ -216,64 +216,49 @@ public class DataLoader {
 
        /**
         * Save the given resource as an image on disk using the default image
-        * format for content.
+        * format for content or cover -- will automatically add the extension, too.
         * 
-        * @param url
+        * @param img
         *            the resource
         * @param target
-        *            the target file
+        *            the target file without extension
+        * @param cover
+        *            use the cover image format instead of the content image format
         * 
         * @throws IOException
         *             in case of I/O error
         */
-       public void saveAsImage(URL url, File target) throws IOException {
-               InputStream in = open(url, null, true);
-               try {
-                       saveAsImage(ImageUtils.fromStream(in), target);
-               } finally {
-                       in.close();
+       public void saveAsImage(Image img, File target, boolean cover)
+                       throws IOException {
+               String format;
+               if (cover) {
+                       format = Instance.getConfig().getString(Config.IMAGE_FORMAT_COVER)
+                                       .toLowerCase();
+               } else {
+                       format = Instance.getConfig()
+                                       .getString(Config.IMAGE_FORMAT_CONTENT).toLowerCase();
                }
+               saveAsImage(img, new File(target.toString() + "." + format), format);
        }
 
        /**
-        * Save the given resource as an image on disk using the default image
-        * format for content.
+        * Save the given resource as an image on disk using the given image format
+        * for content, or with "png" format if it fails.
         * 
-        * @param image
+        * @param img
         *            the resource
         * @param target
         *            the target file
+        * @param format
+        *            the file format ("png", "jpeg", "bmp"...)
         * 
         * @throws IOException
         *             in case of I/O error
         */
-       public void saveAsImage(BufferedImage image, File target)
+       public void saveAsImage(Image img, File target, String format)
                        throws IOException {
-               try {
-                       String format = Instance.getConfig()
-                                       .getString(Config.IMAGE_FORMAT_CONTENT).toLowerCase();
-
-                       boolean ok = false;
-                       try {
-                               ok = ImageIO.write(image, format, target);
-                       } catch (IOException e) {
-                               ok = false;
-                       }
-
-                       // Some formats are not reliable
-                       // Second change: PNG
-                       if (!ok && !format.equals("png")) {
-                               ok = ImageIO.write(image, "png", target);
-                       }
+               ImageUtils.getInstance().saveAsImage(img, target, format);
 
-                       if (!ok) {
-                               throw new IOException(
-                                               "Cannot find a writer for this image and format: "
-                                                               + format);
-                       }
-               } catch (IOException e) {
-                       throw new IOException("Cannot write image to " + target, e);
-               }
        }
 
        /**
index 8185ddd235340c07e814eae3665464a056762f3d..d72b55732adde9098b98914968f0196c3abc0562 100644 (file)
@@ -1,9 +1,10 @@
 package be.nikiroo.fanfix.data;
 
-import java.awt.image.BufferedImage;
 import java.util.ArrayList;
 import java.util.List;
 
+import be.nikiroo.utils.Image;
+
 /**
  * The meta data associated to a {@link Story} object.
  * 
@@ -15,7 +16,7 @@ public class MetaData implements Cloneable, Comparable<MetaData> {
        private String date;
        private Chapter resume;
        private List<String> tags;
-       private BufferedImage cover;
+       private Image cover;
        private String subject;
        private String source;
        private String url;
@@ -129,7 +130,7 @@ public class MetaData implements Cloneable, Comparable<MetaData> {
         * 
         * @return the cover
         */
-       public BufferedImage getCover() {
+       public Image getCover() {
                return cover;
        }
 
@@ -139,7 +140,7 @@ public class MetaData implements Cloneable, Comparable<MetaData> {
         * @param cover
         *            the cover to set
         */
-       public void setCover(BufferedImage cover) {
+       public void setCover(Image cover) {
                this.cover = cover;
        }
 
index 7a1a1c448322212cbd09cebdc7180b0f8912b6c4..91e95f8bd791f545ce185c5c194c843ff0e4dbe8 100644 (file)
@@ -1,6 +1,6 @@
 package be.nikiroo.fanfix.data;
 
-import java.awt.image.BufferedImage;
+import be.nikiroo.utils.Image;
 
 /**
  * A paragraph in a chapter of the story.
@@ -28,7 +28,7 @@ public class Paragraph implements Cloneable {
 
        private ParagraphType type;
        private String content;
-       private BufferedImage contentImage;
+       private Image contentImage;
        private long words;
 
        /**
@@ -45,7 +45,7 @@ public class Paragraph implements Cloneable {
         * @param contentImage
         *            the image
         */
-       public Paragraph(BufferedImage contentImage) {
+       public Paragraph(Image contentImage) {
                this(ParagraphType.IMAGE, null, 1);
                this.contentImage = contentImage;
        }
@@ -109,7 +109,7 @@ public class Paragraph implements Cloneable {
         * 
         * @return the content
         */
-       public BufferedImage getContentImage() {
+       public Image getContentImage() {
                return contentImage;
        }
 
index 7e585712c8db7d5001047c648045b0fb3f229635..fd4f2a8d15258f1f973b12252089d7bc52b24fda 100644 (file)
@@ -92,9 +92,22 @@ public class Story implements Iterable<Chapter>, Cloneable {
                        resume += "\n";
                }
 
-               String cover = (meta == null || meta.getCover() == null) ? "none"
-                               : meta.getCover().getWidth() + "x"
-                                               + meta.getCover().getHeight();
+               String cover = "none";
+               if (meta != null && meta.getCover() != null) {
+                       cover = " bytes";
+
+                       int size = meta.getCover().getData().length;
+                       if (size > 1000) {
+                               size /= 1000;
+                               cover = " kb";
+                               if (size > 1000) {
+                                       size /= 1000;
+                                       cover = " mb";
+                               }
+                       }
+
+                       cover = size + cover;
+               }
                return String.format(
                                "Title: [%s]\nAuthor: [%s]\nDate: [%s]\nTags: [%s]\n"
                                                + "Resume: [%s]\nCover: [%s]", title, meta == null ? ""
index 9e7d4644494e5b51d871091868c3c1e47d882f53..8c86fc90e5baf2449689f2857f1f86ff52877cd8 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.library;
 
-import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
@@ -16,6 +15,7 @@ import be.nikiroo.fanfix.output.BasicOutput;
 import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.fanfix.supported.BasicSupport;
 import be.nikiroo.fanfix.supported.BasicSupport.SupportType;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 
 /**
@@ -89,7 +89,7 @@ abstract public class BasicLibrary {
         * 
         * @return the cover image
         */
-       public abstract BufferedImage getCover(String luid);
+       public abstract Image getCover(String luid);
 
        /**
         * Return the cover image associated to this source.
@@ -101,7 +101,7 @@ abstract public class BasicLibrary {
         * 
         * @return the cover image or NULL
         */
-       public BufferedImage getSourceCover(String source) {
+       public Image getSourceCover(String source) {
                List<MetaData> metas = getListBySource(source);
                if (metas.size() > 0) {
                        return getCover(metas.get(0).getLuid());
index 7f4bb370d5a4fb0ad98e1c4c0882390cb5374512..26204156b4d587cb7353851de1a8ea8af7e12b84 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.library;
 
-import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
@@ -10,6 +9,7 @@ import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.UiConfig;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 
 /**
@@ -101,7 +101,7 @@ public class CacheLibrary extends BasicLibrary {
        }
 
        @Override
-       public BufferedImage getCover(final String luid) {
+       public Image getCover(final String luid) {
                if (isCached(luid)) {
                        return cacheLib.getCover(luid);
                }
@@ -111,7 +111,7 @@ public class CacheLibrary extends BasicLibrary {
        }
 
        @Override
-       public BufferedImage getSourceCover(String source) {
+       public Image getSourceCover(String source) {
                // no cache for the source cover
                return lib.getSourceCover(source);
        }
index 92676b3530288eac94244b9b84c4f23c24bd82c8..041db1013dbf85bfd0a41112676dcc6e4f31c055 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.library;
 
-import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileInputStream;
@@ -11,8 +10,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.imageio.ImageIO;
-
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.data.MetaData;
@@ -22,7 +19,7 @@ import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.fanfix.output.InfoCover;
 import be.nikiroo.fanfix.supported.InfoReader;
 import be.nikiroo.utils.IOUtils;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.MarkableFileInputStream;
 import be.nikiroo.utils.Progress;
 
@@ -34,7 +31,7 @@ import be.nikiroo.utils.Progress;
 public class LocalLibrary extends BasicLibrary {
        private int lastId;
        private Map<MetaData, File[]> stories; // Files: [ infoFile, TargetFile ]
-       private Map<String, BufferedImage> sourceCovers;
+       private Map<String, Image> sourceCovers;
 
        private File baseDir;
        private OutputType text;
@@ -90,7 +87,7 @@ public class LocalLibrary extends BasicLibrary {
 
                this.lastId = 0;
                this.stories = null;
-               this.sourceCovers = new HashMap<String, BufferedImage>();
+               this.sourceCovers = new HashMap<String, Image>();
 
                baseDir.mkdirs();
        }
@@ -111,7 +108,7 @@ public class LocalLibrary extends BasicLibrary {
        }
 
        @Override
-       public BufferedImage getCover(String luid) {
+       public Image getCover(String luid) {
                MetaData meta = getInfo(luid);
                if (meta != null) {
                        File[] files = getStories(null).get(meta);
@@ -133,7 +130,7 @@ public class LocalLibrary extends BasicLibrary {
        @Override
        protected void invalidateInfo(String luid) {
                stories = null;
-               sourceCovers = new HashMap<String, BufferedImage>();
+               sourceCovers = new HashMap<String, Image>();
        }
 
        @Override
@@ -197,7 +194,7 @@ public class LocalLibrary extends BasicLibrary {
        }
 
        @Override
-       public BufferedImage getSourceCover(String source) {
+       public Image getSourceCover(String source) {
                if (!sourceCovers.containsKey(source)) {
                        sourceCovers.put(source, super.getSourceCover(source));
                }
@@ -210,7 +207,8 @@ public class LocalLibrary extends BasicLibrary {
                sourceCovers.put(source, getCover(luid));
                File cover = new File(getExpectedDir(source), ".cover.png");
                try {
-                       ImageIO.write(sourceCovers.get(source), "png", cover);
+                       Instance.getCache().saveAsImage(sourceCovers.get(source), cover,
+                                       true);
                } catch (IOException e) {
                        Instance.getTraceHandler().error(e);
                        sourceCovers.remove(source);
@@ -487,10 +485,9 @@ public class LocalLibrary extends BasicLibrary {
                                File cover = new File(dir, ".cover.png");
                                if (cover.exists()) {
                                        try {
-                                               InputStream in = new MarkableFileInputStream(
-                                                               new FileInputStream(cover));
+                                               InputStream in = new FileInputStream(cover);
                                                try {
-                                                       sourceCovers.put(source, ImageUtils.fromStream(in));
+                                                       sourceCovers.put(source, new Image(in));
                                                } finally {
                                                        in.close();
                                                }
@@ -516,11 +513,12 @@ public class LocalLibrary extends BasicLibrary {
         * @param coverImage
         *            the cover image
         */
-       void setSourceCover(String source, BufferedImage coverImage) {
+       void setSourceCover(String source, Image coverImage) {
                sourceCovers.put(source, coverImage);
                File cover = new File(getExpectedDir(source), ".cover.png");
                try {
-                       ImageIO.write(sourceCovers.get(source), "png", cover);
+                       Instance.getCache().saveAsImage(sourceCovers.get(source), cover,
+                                       true);
                } catch (IOException e) {
                        Instance.getTraceHandler().error(e);
                        sourceCovers.remove(source);
index 326a488b1766a8fc9ddf5052dae8c8fdb32b11cc..5052fa279dd4cdcbe127a61edd8f2a00ca4bf9a6 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.library;
 
-import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
@@ -11,6 +10,7 @@ import java.util.List;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
 import be.nikiroo.utils.Version;
@@ -95,15 +95,15 @@ public class RemoteLibrary extends BasicLibrary {
        }
 
        @Override
-       public BufferedImage getCover(final String luid) {
-               final BufferedImage[] result = new BufferedImage[1];
+       public Image getCover(final String luid) {
+               final Image[] result = new Image[1];
 
                try {
                        new ConnectActionClientObject(host, port, true) {
                                @Override
                                public void action(Version serverVersion) throws Exception {
                                        Object rep = send(new Object[] { md5, "GET_COVER", luid });
-                                       result[0] = (BufferedImage) rep;
+                                       result[0] = (Image) rep;
                                }
 
                                @Override
@@ -119,8 +119,8 @@ public class RemoteLibrary extends BasicLibrary {
        }
 
        @Override
-       public BufferedImage getSourceCover(final String source) {
-               final BufferedImage[] result = new BufferedImage[1];
+       public Image getSourceCover(final String source) {
+               final Image[] result = new Image[1];
 
                try {
                        new ConnectActionClientObject(host, port, true) {
@@ -128,7 +128,7 @@ public class RemoteLibrary extends BasicLibrary {
                                public void action(Version serverVersion) throws Exception {
                                        Object rep = send(new Object[] { md5, "GET_SOURCE_COVER",
                                                        source });
-                                       result[0] = (BufferedImage) rep;
+                                       result[0] = (Image) rep;
                                }
 
                                @Override
index 97920cbecb9c4cbf57d2f0802729299fa5c11cef..5109cce61637a067bb6fc2bfaf38272f54c37c33 100644 (file)
@@ -376,13 +376,13 @@ public abstract class BasicOutput {
 
                int num = 0;
                String paragraphNumber = String.format("%04d", num++);
-               imageName = chapterNameNum + "_" + paragraphNumber + ".png";
+               imageName = chapterNameNum + "_" + paragraphNumber;
 
                writeChapterHeader(chap);
                int i = 1;
                for (Paragraph para : chap) {
                        paragraphNumber = String.format("%04d", num++);
-                       imageName = chapterNameNum + "_" + paragraphNumber + ".png";
+                       imageName = chapterNameNum + "_" + paragraphNumber;
                        writeParagraph(para);
                        if (chapPg != null) {
                                chapPg.setProgress(i++);
index 48da65a293704fc5eb13c9ee69ac17975b9d2f34..09a9944d78932b40c806a13a6f8b4fcef3d55ba8 100644 (file)
@@ -7,8 +7,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStreamWriter;
 
-import javax.imageio.ImageIO;
-
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.bundles.StringId;
@@ -26,6 +24,7 @@ class Epub extends BasicOutput {
        private boolean inDialogue = false;
        private boolean inNormal = false;
        private File images;
+       private boolean nextParaIsCover = true;
 
        @Override
        public File process(Story story, File targetDir, String targetName)
@@ -104,7 +103,8 @@ class Epub extends BasicOutput {
                        String format = Instance.getConfig()
                                        .getString(Config.IMAGE_FORMAT_COVER).toLowerCase();
                        File file = new File(images, "cover." + format);
-                       ImageIO.write(story.getMeta().getCover(), format, file);
+                       Instance.getCache().saveAsImage(story.getMeta().getCover(), file,
+                                       true);
                }
 
                // OPS/* except chapters
@@ -209,11 +209,14 @@ class Epub extends BasicOutput {
                        break;
                case IMAGE:
                        File file = new File(images, getCurrentImageBestName(false));
-                       Instance.getCache().saveAsImage(para.getContentImage(), file);
+                       Instance.getCache().saveAsImage(para.getContentImage(), file,
+                                       nextParaIsCover);
                        writer.write("                  <img class='page-image' src='images/"
                                        + getCurrentImageBestName(false) + "'/>");
                        break;
                }
+
+               nextParaIsCover = false;
        }
 
        @Override
index d1559b401326bbc1815b8743040e807c17290d27..e91c6f46bfe896b65024bb9f10d3d37abfc2732f 100644 (file)
@@ -7,8 +7,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStreamWriter;
 
-import javax.imageio.ImageIO;
-
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.data.Chapter;
@@ -51,11 +49,9 @@ class Html extends BasicOutput {
                        writer = null;
                }
 
-               String format = Instance.getConfig()
-                               .getString(Config.IMAGE_FORMAT_COVER).toLowerCase();
                if (story.getMeta().getCover() != null) {
-                       ImageIO.write(story.getMeta().getCover(), format, new File(dir,
-                                       "cover." + format));
+                       Instance.getCache().saveAsImage(story.getMeta().getCover(),
+                                       new File(dir, "cover"), true);
                }
 
                return target;
index a1b37913bc9e44789eb3d29801b88bc94362a0ad..1e6ccd3363f49cf210e45c28ea2a66d5fa3eae2e 100644 (file)
@@ -6,8 +6,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 
-import javax.imageio.ImageIO;
-
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.data.MetaData;
@@ -69,10 +67,8 @@ public class InfoCover {
                        MetaData meta) {
                if (meta != null && meta.getCover() != null) {
                        try {
-                               String format = Instance.getConfig()
-                                               .getString(Config.IMAGE_FORMAT_COVER).toLowerCase();
-                               ImageIO.write(meta.getCover(), format, new File(targetDir,
-                                               targetName + "." + format));
+                               Instance.getCache().saveAsImage(meta.getCover(),
+                                               new File(targetDir, targetName), true);
                        } catch (IOException e) {
                                // Allow to continue without cover
                                Instance.getTraceHandler().error(
index ee72385b32220c479e1e03ad2d8a378f59539e49..b45a51284bf913501bb0fa7fefd4c12a371c8bc8 100644 (file)
@@ -17,6 +17,7 @@ import be.nikiroo.fanfix.data.Story;
 class Text extends BasicOutput {
        protected BufferedWriter writer;
        protected File targetDir;
+       private boolean nextParaIsCover = true;
 
        @Override
        public File process(Story story, File targetDir, String targetName)
@@ -104,8 +105,11 @@ class Text extends BasicOutput {
        protected void writeParagraphHeader(Paragraph para) throws IOException {
                if (para.getType() == ParagraphType.IMAGE) {
                        File file = new File(targetDir, getCurrentImageBestName(true));
-                       Instance.getCache().saveAsImage(para.getContentImage(), file);
+                       Instance.getCache().saveAsImage(para.getContentImage(), file,
+                                       nextParaIsCover);
                }
+
+               nextParaIsCover = false;
        }
 
        @Override
index 0ea403c40f4fdf5af11da2d1345cf5184069b6fb..4b444940c11a07cfeb15a108171126c4bfe14baf 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.reader;
 
-import java.awt.Desktop;
 import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
@@ -133,8 +132,9 @@ public abstract class BasicReader implements Reader {
                                                .getTypeName());
                        }
                } catch (Exception e) {
-                       Instance.getTraceHandler().error(new Exception("Cannot create a reader of type: "
-                                       + defaultType + " (Not compiled in?)", e));
+                       Instance.getTraceHandler().error(
+                                       new Exception("Cannot create a reader of type: "
+                                                       + defaultType + " (Not compiled in?)", e));
                }
 
                return null;
@@ -212,8 +212,8 @@ public abstract class BasicReader implements Reader {
         * @throws IOException
         *             in case of I/O error
         */
-       public static void openExternal(BasicLibrary lib, String luid)
-                       throws IOException {
+       @Override
+       public void openExternal(BasicLibrary lib, String luid) throws IOException {
                MetaData meta = lib.getInfo(luid);
                File target = lib.getFile(luid, null);
 
@@ -232,8 +232,7 @@ public abstract class BasicReader implements Reader {
         * @throws IOException
         *             in case of I/O error
         */
-       protected static void openExternal(MetaData meta, File target)
-                       throws IOException {
+       protected void openExternal(MetaData meta, File target) throws IOException {
                String program = null;
                if (meta.isImageDocument()) {
                        program = Instance.getUiConfig().getString(
@@ -247,13 +246,35 @@ public abstract class BasicReader implements Reader {
                        program = null;
                }
 
-               if (program == null) {
-                       try {
-                               Desktop.getDesktop().browse(target.toURI());
-                       } catch (UnsupportedOperationException e) {
-                               Runtime.getRuntime().exec(
-                                               new String[] { "xdg-open", target.getAbsolutePath() });
+               start(target, program);
+       }
 
+       /**
+        * Start a file and open it with the given program if given or the first
+        * default system starter we can find.
+        * 
+        * @param target
+        *            the target to open
+        * @param program
+        *            the program to use or NULL for the default system starter
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        */
+       protected void start(File target, String program) throws IOException {
+               if (program == null) {
+                       boolean ok = false;
+                       for (String starter : new String[] { "xdg-open", "start", "run" }) {
+                               try {
+                                       Runtime.getRuntime().exec(
+                                                       new String[] { starter, target.getAbsolutePath() });
+                                       ok = true;
+                                       break;
+                               } catch (IOException e) {
+                               }
+                       }
+                       if (!ok) {
+                               throw new IOException("Cannot find a program to start the file");
                        }
                } else {
                        Runtime.getRuntime().exec(
index d540d39f9094edb4e9d1e08a16cedfe9b65a5298..f98f12c53f0c21b811341bc79703799bbc646080 100644 (file)
@@ -40,11 +40,11 @@ public interface Reader {
                        String pkg = "be.nikiroo.fanfix.reader.";
                        switch (this) {
                        case CLI:
-                               return pkg + "CliReader";
+                               return pkg + "cli.CliReader";
                        case TUI:
-                               return pkg + "TuiReader";
+                               return pkg + "tui.TuiReader";
                        case GUI:
-                               return pkg + "GuiReader";
+                               return pkg + "ui.GuiReader";
                        }
 
                        return null;
@@ -158,4 +158,18 @@ public interface Reader {
         *            all
         */
        public void browse(String source);
+
+       /**
+        * Open the {@link Story} with an external reader (the program will be
+        * passed the main file associated with this {@link Story}).
+        * 
+        * @param lib
+        *            the {@link BasicLibrary} to select the {@link Story} from
+        * @param luid
+        *            the {@link Story} LUID
+        * 
+        * @throws IOException
+        *             in case of I/O error
+        */
+       public void openExternal(BasicLibrary lib, String luid) throws IOException;
 }
similarity index 96%
rename from src/be/nikiroo/fanfix/reader/CliReader.java
rename to src/be/nikiroo/fanfix/reader/cli/CliReader.java
index 2f0b8cee32910ffae7e31374b807a3cd2d65f32c..b28d4d4e8987479b7936699e7db14368c947d691 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.cli;
 
 import java.io.IOException;
 import java.util.List;
@@ -9,6 +9,7 @@ import be.nikiroo.fanfix.data.Chapter;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Paragraph;
 import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.fanfix.reader.BasicReader;
 
 /**
  * Command line {@link Story} reader.
similarity index 93%
rename from src/be/nikiroo/fanfix/reader/TuiReader.java
rename to src/be/nikiroo/fanfix/reader/tui/TuiReader.java
index 30b9dce5962972b86eaf27aadb5f31e0b81d0aa8..7192854ea6fed7f07978427a9c6534fbeb07e74a 100644 (file)
@@ -1,10 +1,12 @@
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.tui;
 
 import java.io.IOException;
 
 import jexer.TApplication;
 import jexer.TApplication.BackendType;
 import be.nikiroo.fanfix.Instance;
+import be.nikiroo.fanfix.reader.BasicReader;
+import be.nikiroo.fanfix.reader.Reader;
 
 /**
  * This {@link Reader}is based upon the TUI widget library 'jexer'
similarity index 94%
rename from src/be/nikiroo/fanfix/reader/TuiReaderApplication.java
rename to src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java
index c1bba5a8220b49d0dfacdef1cca777a2e31ac5e8..9e991e4c743e7f31b24f0fee0f7370fd52476d03 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.tui;
 
 import java.awt.Toolkit;
 import java.awt.datatransfer.DataFlavor;
@@ -17,6 +17,8 @@ import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.library.BasicLibrary;
+import be.nikiroo.fanfix.reader.BasicReader;
+import be.nikiroo.fanfix.reader.Reader;
 import be.nikiroo.utils.Progress;
 
 /**
@@ -77,7 +79,7 @@ class TuiReaderApplication extends TApplication implements Reader {
                                        getChapter());
                } else {
                        try {
-                               BasicReader.openExternal(getLibrary(), meta.getLuid());
+                               openExternal(getLibrary(), meta.getLuid());
                        } catch (IOException e) {
                                messageBox("Error when trying to open the story",
                                                e.getMessage(), TMessageBox.Type.OK);
@@ -225,4 +227,9 @@ class TuiReaderApplication extends TApplication implements Reader {
                        return false;
                }
        }
+
+       @Override
+       public void openExternal(BasicLibrary lib, String luid) throws IOException {
+               reader.openExternal(lib, luid);
+       }
 }
similarity index 98%
rename from src/be/nikiroo/fanfix/reader/TuiReaderMainWindow.java
rename to src/be/nikiroo/fanfix/reader/tui/TuiReaderMainWindow.java
index 10c6466ca887dd39b32b956dad0e9fc0ace89ffb..0fccfafaaab717fc33726be4c49aaaba41bf3210 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.tui;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -15,6 +15,7 @@ import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.library.BasicLibrary;
 import be.nikiroo.fanfix.output.BasicOutput.OutputType;
+import be.nikiroo.fanfix.reader.Reader;
 
 /**
  * The library window, that will list all the (filtered) stories available in
similarity index 99%
rename from src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java
rename to src/be/nikiroo/fanfix/reader/tui/TuiReaderStoryWindow.java
index e8dafc3fa339b47f47f5c2cfb2df5e6d1fdace87..e4587e755917c0b2489fa1a32ce34dc1debb90db 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.tui;
 
 import java.util.ArrayList;
 import java.util.List;
similarity index 92%
rename from src/be/nikiroo/fanfix/reader/GuiReader.java
rename to src/be/nikiroo/fanfix/reader/ui/GuiReader.java
index b9d5954888333c57456d75f7027759ffcc55c2b8..576ac9cc80191c492e2e50572568ec0eaa79d9b7 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.ui;
 
 import java.awt.Desktop;
 import java.awt.EventQueue;
@@ -18,6 +18,7 @@ import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.library.BasicLibrary;
 import be.nikiroo.fanfix.library.CacheLibrary;
+import be.nikiroo.fanfix.reader.BasicReader;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.Version;
 import be.nikiroo.utils.ui.UIUtils;
@@ -147,6 +148,19 @@ class GuiReader extends BasicReader {
                });
        }
 
+       @Override
+       public void start(File target, String program) throws IOException {
+               if (program == null) {
+                       try {
+                               Desktop.getDesktop().browse(target.toURI());
+                       } catch (UnsupportedOperationException e) {
+                               super.start(target, program);
+                       }
+               } else {
+                       super.start(target, program);
+               }
+       }
+
        // delete from local reader library
        void clearLocalReaderCache(String luid) {
                try {
similarity index 96%
rename from src/be/nikiroo/fanfix/reader/GuiReaderBook.java
rename to src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java
index c70f30a8db69f11976c8b7345d322d8b21c8d074..4343ca522b207f335492210506bd1a4c13924d6c 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.ui;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -27,7 +27,9 @@ import javax.swing.JPanel;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.fanfix.reader.Reader;
+import be.nikiroo.utils.Image;
+import be.nikiroo.utils.ui.ImageUtilsAwt;
 import be.nikiroo.utils.ui.UIUtils;
 
 /**
@@ -380,7 +382,7 @@ class GuiReaderBook extends JPanel {
                InputStream in = Instance.getCache().getFromCache(id);
                if (in != null) {
                        try {
-                               resizedImage = ImageUtils.fromStream(in);
+                               resizedImage = ImageUtilsAwt.fromImage(new Image(in));
                                in.close();
                                in = null;
                        } catch (IOException e) {
@@ -390,7 +392,7 @@ class GuiReaderBook extends JPanel {
 
                if (resizedImage == null) {
                        try {
-                               BufferedImage cover = null;
+                               Image cover = null;
                                if (meta.getLuid() == null) {
                                        cover = reader.getLibrary()
                                                        .getSourceCover(meta.getSource());
@@ -398,6 +400,8 @@ class GuiReaderBook extends JPanel {
                                        cover = reader.getLibrary().getCover(meta.getLuid());
                                }
 
+                               BufferedImage coverb = ImageUtilsAwt.fromImage(cover);
+
                                resizedImage = new BufferedImage(SPINE_WIDTH + COVER_WIDTH,
                                                SPINE_HEIGHT + COVER_HEIGHT + HOFFSET,
                                                BufferedImage.TYPE_4BYTE_ABGR);
@@ -405,7 +409,7 @@ class GuiReaderBook extends JPanel {
                                g.setColor(Color.white);
                                g.fillRect(0, HOFFSET, COVER_WIDTH, COVER_HEIGHT);
                                if (cover != null) {
-                                       g.drawImage(cover, 0, HOFFSET, COVER_WIDTH, COVER_HEIGHT,
+                                       g.drawImage(coverb, 0, HOFFSET, COVER_WIDTH, COVER_HEIGHT,
                                                        null);
                                } else {
                                        g.setColor(Color.black);
@@ -430,7 +434,11 @@ class GuiReaderBook extends JPanel {
                        }
                }
 
-               return new ImageIcon(resizedImage);
+               if (resizedImage != null) {
+                       return new ImageIcon(resizedImage);
+               }
+
+               return null;
        }
 
        /**
similarity index 98%
rename from src/be/nikiroo/fanfix/reader/GuiReaderFrame.java
rename to src/be/nikiroo/fanfix/reader/ui/GuiReaderFrame.java
index 99091d376ed03de370002f75fceb4538c52a9f26..b98bed22cd8c42b0d290639015814f56b0d29dda 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.ui;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -45,7 +45,8 @@ import be.nikiroo.fanfix.library.BasicLibrary;
 import be.nikiroo.fanfix.library.BasicLibrary.Status;
 import be.nikiroo.fanfix.library.LocalLibrary;
 import be.nikiroo.fanfix.output.BasicOutput.OutputType;
-import be.nikiroo.fanfix.reader.GuiReaderBook.BookActionListener;
+import be.nikiroo.fanfix.reader.BasicReader;
+import be.nikiroo.fanfix.reader.ui.GuiReaderBook.BookActionListener;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.Version;
 import be.nikiroo.utils.ui.ConfigEditor;
@@ -107,8 +108,10 @@ class GuiReaderFrame extends JFrame {
                pane = new JPanel();
                pane.setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS));
 
-               color = Instance.getUiConfig().getColor(UiConfig.BACKGROUND_COLOR);
-               if (color != null) {
+               Integer icolor = Instance.getUiConfig().getColor(
+                               UiConfig.BACKGROUND_COLOR);
+               if (icolor != null) {
+                       color = new Color(icolor);
                        setBackground(color);
                        pane.setBackground(color);
                }
similarity index 97%
rename from src/be/nikiroo/fanfix/reader/GuiReaderGroup.java
rename to src/be/nikiroo/fanfix/reader/ui/GuiReaderGroup.java
index a087c4c12302851cbb4fe680de1e9a7aca42d0d0..c96b02df266e0ef307a023600a6085dd2caa83ad 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.fanfix.reader;
+package be.nikiroo.fanfix.reader.ui;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -12,7 +12,7 @@ import javax.swing.JLabel;
 import javax.swing.JPanel;
 
 import be.nikiroo.fanfix.data.MetaData;
-import be.nikiroo.fanfix.reader.GuiReaderBook.BookActionListener;
+import be.nikiroo.fanfix.reader.ui.GuiReaderBook.BookActionListener;
 import be.nikiroo.utils.ui.WrapLayout;
 
 /**
index 66ba64d621ac82e1498d009367da08cb044f0f19..f16cdc7b6453ac00753bb479850ab7eb2edcafc5 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -25,7 +24,7 @@ import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Paragraph;
 import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
 import be.nikiroo.fanfix.data.Story;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
 
@@ -750,7 +749,7 @@ public abstract class BasicSupport {
         * @return the {@link Paragraph}
         */
        private Paragraph makeParagraph(URL source, String line) {
-               BufferedImage image = null;
+               Image image = null;
                if (line.startsWith("[") && line.endsWith("]")) {
                        image = getImage(this, source, line.substring(1, line.length() - 1)
                                        .trim());
@@ -817,7 +816,7 @@ public abstract class BasicSupport {
         * 
         * @return the cover if any, or NULL
         */
-       static BufferedImage getDefaultCover(String subject) {
+       static Image getDefaultCover(String subject) {
                if (subject != null && !subject.isEmpty()
                                && Instance.getCoverDir() != null) {
                        try {
@@ -860,13 +859,18 @@ public abstract class BasicSupport {
         * @return the image if found, or NULL
         * 
         */
-       static BufferedImage getImage(BasicSupport support, URL source, String line) {
+       static Image getImage(BasicSupport support, URL source, String line) {
                URL url = getImageUrl(support, source, line);
                if (url != null) {
+                       if ("file".equals(url.getProtocol())) {
+                               if (new File(url.getPath()).isDirectory()) {
+                                       return null;
+                               }
+                       }
                        InputStream in = null;
                        try {
                                in = Instance.getCache().open(url, getSupport(url), true);
-                               return ImageUtils.fromStream(in);
+                               return new Image(in);
                        } catch (IOException e) {
                        } finally {
                                if (in != null) {
@@ -918,11 +922,14 @@ public abstract class BasicSupport {
                                        }
 
                                        for (String ext : getImageExt(true)) {
-                                               if (absPath != null && new File(absPath + ext).exists()) {
-                                                       url = new File(absPath + ext).toURI().toURL();
-                                               } else if (relPath != null
-                                                               && new File(relPath + ext).exists()) {
-                                                       url = new File(relPath + ext).toURI().toURL();
+                                               File absFile = new File(absPath + ext);
+                                               File relFile = new File(relPath + ext);
+                                               if (absPath != null && absFile.exists()
+                                                               && absFile.isFile()) {
+                                                       url = absFile.toURI().toURL();
+                                               } else if (relPath != null && relFile.exists()
+                                                               && relFile.isFile()) {
+                                                       url = relFile.toURI().toURL();
                                                }
                                        }
                                } catch (Exception e) {
index 77a4008068f4a6ec1b3ea876701dea70b0a830fb..b6524acac90fbb16d3ffd6e7621c84c4f518883a 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -16,7 +15,7 @@ import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.Chapter;
 import be.nikiroo.fanfix.data.Paragraph;
 import be.nikiroo.fanfix.data.Story;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 
 /**
@@ -76,7 +75,7 @@ class Cbz extends Epub {
 
                ZipInputStream zipIn = new ZipInputStream(getInput());
 
-               Map<String, BufferedImage> images = new HashMap<String, BufferedImage>();
+               Map<String, Image> images = new HashMap<String, Image>();
                for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn
                                .getNextEntry()) {
                        if (!entry.isDirectory()
@@ -92,7 +91,7 @@ class Cbz extends Epub {
                                if (imageEntry) {
                                        String uuid = meta.getUuid() + "_" + entry.getName();
                                        try {
-                                               images.put(uuid, ImageUtils.fromStream(zipIn));
+                                               images.put(uuid, new Image(zipIn));
                                        } catch (Exception e) {
                                                Instance.getTraceHandler().error(e);
                                        }
index 1baa6201cb217508074cd54608085d38ecadcd01..72c68b1a20e589f206275444390e1aaf0c72b247 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -13,6 +12,7 @@ import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.Chapter;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
 
@@ -87,7 +87,7 @@ class E621 extends BasicSupport {
                return true;
        }
 
-       private BufferedImage getCover(URL source) throws IOException {
+       private Image getCover(URL source) throws IOException {
                InputStream in = Instance.getCache().open(source, this, true);
                String images = getChapterContent(new URL(source.toString() + "?page="
                                + 1), in, 1, null);
index a25a99493ffb2fe18db1e0dfb12ffe1f1583a81e..c082b9144cae7bc7d76f781e7d57b97d64ea7186 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -14,6 +13,7 @@ import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.Chapter;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
 
@@ -78,8 +78,8 @@ class EHentai extends BasicSupport {
                return true;
        }
 
-       private BufferedImage getCover(URL source, InputStream in) {
-               BufferedImage author = null;
+       private Image getCover(URL source, InputStream in) {
+               Image author = null;
                String coverLine = getKeyLine(in, "<div id=\"gd1\"", " url(", ")");
                if (coverLine != null) {
                        coverLine = StringUtils.unhtml(coverLine).trim();
@@ -267,9 +267,10 @@ class EHentai extends BasicSupport {
                                try {
                                        pages.add(new URL(line));
                                } catch (MalformedURLException e) {
-                                       Instance.getTraceHandler().error(new IOException(
-                                                       "Parsing error, a link is not correctly parsed: "
-                                                                       + line, e));
+                                       Instance.getTraceHandler().error(
+                                                       new IOException(
+                                                                       "Parsing error, a link is not correctly parsed: "
+                                                                                       + line, e));
                                }
                        }
                }
index ad4d65f5a4c180b8d68db15e4d0d0a860e72cfdd..ba56cfb77540ac100e25a3ab4760544529ffea52 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -16,7 +15,7 @@ import java.util.zip.ZipInputStream;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.utils.IOUtils;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.MarkableFileInputStream;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
@@ -97,7 +96,7 @@ class Epub extends InfoText {
                tmp = File.createTempFile("fanfic-reader-parser_", ".tmp");
                File tmpInfo = new File(tmp + ".info");
                fakeSource = tmp.toURI().toURL();
-               BufferedImage cover = null;
+               Image cover = null;
 
                String url = source.toString();
                String title = null;
@@ -126,7 +125,7 @@ class Epub extends InfoText {
                                        // Cover
                                        if (getCover()) {
                                                try {
-                                                       cover = ImageUtils.fromStream(zipIn);
+                                                       cover = new Image(zipIn);
                                                } catch (Exception e) {
                                                        Instance.getTraceHandler().error(e);
                                                }
index 43f16c89b0c2526289721db103bac3308acb5c5b..b80156d471a818e02728ce92eff640ead174d210 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -15,6 +14,7 @@ import java.util.Scanner;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
 
@@ -161,8 +161,10 @@ class Fanfiction extends BasicSupport {
                                                return sdf
                                                                .format(new Date(1000 * Long.parseLong(line)));
                                        } catch (NumberFormatException e) {
-                                               Instance.getTraceHandler().error(new IOException(
-                                                               "Cannot convert publication date: " + line, e));
+                                               Instance.getTraceHandler().error(
+                                                               new IOException(
+                                                                               "Cannot convert publication date: "
+                                                                                               + line, e));
                                        }
                                }
                        }
@@ -176,7 +178,7 @@ class Fanfiction extends BasicSupport {
                return getLine(in, "title=\"Send Private Message\"", 1);
        }
 
-       private BufferedImage getCover(URL url, InputStream in) {
+       private Image getCover(URL url, InputStream in) {
                String key = "class='cimage";
                String line = getLine(in, key, 0);
                if (line != null) {
@@ -261,9 +263,11 @@ class Fanfiction extends BasicSupport {
                                                                }
                                                        });
                                                } catch (MalformedURLException e) {
-                                                       Instance.getTraceHandler().error(new IOException(
-                                                                       "Cannot parse chapter " + i + " url: "
-                                                                                       + (base + i + suffix), e));
+                                                       Instance.getTraceHandler()
+                                                                       .error(new IOException(
+                                                                                       "Cannot parse chapter " + i
+                                                                                                       + " url: "
+                                                                                                       + (base + i + suffix), e));
                                                }
                                        }
                                }
index 24aca5d4169353268d5d4ca1df0e1ae0d712f243..7d2eec442db68757617eedf8956fb7782bf2e7e9 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -14,6 +13,7 @@ import java.util.Scanner;
 
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
 
@@ -173,7 +173,7 @@ class Fimfiction extends BasicSupport {
                return getLine(in, "class=\"description-text bbcode\"", 1);
        }
 
-       private BufferedImage getCover(InputStream in) {
+       private Image getCover(InputStream in) {
                // Note: the 'og:image' is the SMALL cover, not the full version
                String cover = getLine(in, "class=\"story_container__story_image\"", 1);
                if (cover != null) {
index ccffd7c9d27205713cfe6e623b3a8c4c56532aac..b65256ca4b6a3a4db4e836113fe064587be35fbf 100644 (file)
@@ -56,8 +56,11 @@ public class InfoReader {
                meta.setType(getInfoTag(in, "TYPE"));
                meta.setImageDocument(getInfoTagBoolean(in, "IMAGES_DOCUMENT", false));
                if (withCover) {
-                       meta.setCover(BasicSupport.getImage(null, sourceInfoFile,
-                                       getInfoTag(in, "COVER")));
+                       String infoTag = getInfoTag(in, "COVER");
+                       if (infoTag != null && !infoTag.trim().isEmpty()) {
+                               meta.setCover(BasicSupport.getImage(null, sourceInfoFile,
+                                               infoTag));
+                       }
                        // Second chance: try to check for a cover next to the info file
                        if (meta.getCover() == null) {
                                String info = sourceInfoFile.getFile().toString();
index 502cb10188a30a0104bf1343e04021a2428ae496..8d31cb83adacf1a7fa7f80dda01a3ac380197086 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -13,7 +12,7 @@ import java.util.Scanner;
 
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
-import be.nikiroo.utils.ImageUtils;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
 
@@ -163,7 +162,7 @@ class MangaFox extends BasicSupport {
                return null;
        }
 
-       private BufferedImage getCover(InputStream in) {
+       private Image getCover(InputStream in) {
                String line = getLine(in, " property=\"og:image\"", 0);
                String cover = null;
                if (line != null) {
@@ -186,7 +185,7 @@ class MangaFox extends BasicSupport {
                        try {
                                coverIn = openEx(cover);
                                try {
-                                       return ImageUtils.fromStream(coverIn);
+                                       return new Image(coverIn);
                                } finally {
                                        coverIn.close();
                                }
@@ -361,9 +360,10 @@ class MangaFox extends BasicSupport {
                                        setCurrentReferer(url);
                                        pg.setProgress((i++) % pg.getMax());
                                } catch (IOException e) {
-                                       Instance.getTraceHandler().error(new IOException(
-                                                       "Cannot get the next manga page which is: "
-                                                                       + linkNext, e));
+                                       Instance.getTraceHandler().error(
+                                                       new IOException(
+                                                                       "Cannot get the next manga page which is: "
+                                                                                       + linkNext, e));
                                }
                        }
 
index ff9d264f8494b9d68ddf73fc557acc539b59044b..79ee85187abadde363ed1c4fc93c98508f1e2973 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -14,6 +13,7 @@ import java.util.Scanner;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 
 /**
@@ -151,7 +151,7 @@ class Text extends BasicSupport {
                return getChapterContent(source, in, 0, null);
        }
 
-       private BufferedImage getCover(URL source) {
+       private Image getCover(URL source) {
                String path;
                try {
                        path = new File(source.toURI()).getPath();
index 94c310dc6ff1f8a96743b27443983df02f4d0e5e..a612d4f24fcd2fc95a5fd0663d754b8dab4229ba 100644 (file)
@@ -1,6 +1,5 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -15,6 +14,7 @@ import java.util.Scanner;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
 
@@ -128,8 +128,7 @@ class YiffStar extends BasicSupport {
                return tags;
        }
 
-       private BufferedImage getCover(URL source, InputStream in)
-                       throws IOException {
+       private Image getCover(URL source, InputStream in) throws IOException {
 
                List<Entry<String, URL>> chaps = getChapters(source, in, null);
                if (!chaps.isEmpty()) {