cbz: fix cover not copied from some file conversion
authorNiki Roo <niki@nikiroo.be>
Wed, 18 Sep 2019 20:34:31 +0000 (22:34 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 18 Sep 2019 20:34:31 +0000 (22:34 +0200)
src/be/nikiroo/fanfix/supported/Cbz.java

index c7475fa775640e39f57aa8b1d218ab3cd51841b8..22e436a22188b6e0442ba5f21c977ca0ddaed90c 100644 (file)
@@ -13,6 +13,7 @@ import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
 import be.nikiroo.fanfix.Instance;
+import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.data.Chapter;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Paragraph;
@@ -90,7 +91,7 @@ class Cbz extends Epub {
                                                        imageEntry = true;
                                                }
                                        }
-
+                                       
                                        if (imageEntry) {
                                                String uuid = meta.getUuid() + "_" + entry.getName();
                                                try {
@@ -111,6 +112,14 @@ class Cbz extends Epub {
                                        }
                                }
                        }
+                       
+                       String ext = "."
+                                       + Instance.getConfig()
+                                                       .getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER)
+                                                       .toLowerCase();
+                       String coverName = meta.getUuid() + "_" + basename + ext;
+                       Image cover = images.get(coverName);
+                       images.remove(coverName);
 
                        pg.setProgress(85);
 
@@ -120,7 +129,7 @@ class Cbz extends Epub {
 
                        pg.setProgress(90);
 
-                       // only the description is kept
+                       // only the description/cover is kept
                        Story origStory = getStoryFromTxt(tmpDir, basename);
                        if (origStory != null) {
                                if (origStory.getMeta().getCover() == null) {
@@ -128,6 +137,9 @@ class Cbz extends Epub {
                                }
                                story.setMeta(origStory.getMeta());
                        }
+                       if (story.getMeta().getCover() == null) {
+                               story.getMeta().setCover(cover);
+                       }
                        story.setChapters(new ArrayList<Chapter>());
 
                        // Check if we can find non-images chapters, for hybrid-cbz support