CBZ: fix meta for non-images documents
[fanfix.git] / src / be / nikiroo / fanfix / supported / Epub.java
index ad4d65f5a4c180b8d68db15e4d0d0a860e72cfdd..8ae4c6c37052c5569674804b3be5d4fa3244f343 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);
                                                }
@@ -197,11 +196,12 @@ class Epub extends InfoText {
                        meta.setUrl(url);
                        meta.setTitle(title);
                        meta.setAuthor(author);
+                       meta.setImageDocument(isImagesDocumentByDefault());
                }
        }
 
        @Override
-       protected void close() throws IOException {
+       protected void close() {
                if (tmp != null && tmp.exists()) {
                        if (!tmp.delete()) {
                                tmp.deleteOnExit();
@@ -211,7 +211,11 @@ class Epub extends InfoText {
                tmp = null;
 
                if (fakeIn != null) {
-                       fakeIn.close();
+                       try {
+                               fakeIn.close();
+                       } catch (Exception e) {
+                               Instance.getTraceHandler().error(e);
+                       }
                }
 
                super.close();
@@ -228,4 +232,8 @@ class Epub extends InfoText {
        protected boolean getCover() {
                return true;
        }
+
+       protected boolean isImagesDocumentByDefault() {
+               return false;
+       }
 }