1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.io
.IOException
;
5 import java
.util
.ArrayList
;
6 import java
.util
.Collections
;
7 import java
.util
.HashMap
;
10 import java
.util
.zip
.ZipEntry
;
11 import java
.util
.zip
.ZipInputStream
;
13 import be
.nikiroo
.fanfix
.Instance
;
14 import be
.nikiroo
.fanfix
.data
.Chapter
;
15 import be
.nikiroo
.fanfix
.data
.Paragraph
;
16 import be
.nikiroo
.fanfix
.data
.Story
;
17 import be
.nikiroo
.utils
.Image
;
18 import be
.nikiroo
.utils
.Progress
;
21 * Support class for CBZ files (works better with CBZ created with this program,
22 * as they have some metadata available).
26 class Cbz
extends Epub
{
28 protected boolean supports(URL url
) {
29 return url
.toString().toLowerCase().endsWith(".cbz");
33 public String
getSourceName() {
38 protected String
getDataPrefix() {
43 protected boolean requireInfo() {
48 protected boolean isImagesDocumentByDefault() {
53 protected boolean getCover() {
58 public Story
process(URL url
, Progress pg
) throws IOException
{
65 Progress pgMeta
= new Progress();
66 pg
.addProgress(pgMeta
, 10);
67 Story story
= processMeta(url
, false, true, pgMeta
);
70 story
.setChapters(new ArrayList
<Chapter
>());
71 Chapter chap
= new Chapter(1, null);
72 story
.getChapters().add(chap
);
74 ZipInputStream zipIn
= new ZipInputStream(getInput());
76 Map
<String
, Image
> images
= new HashMap
<String
, Image
>();
77 for (ZipEntry entry
= zipIn
.getNextEntry(); entry
!= null; entry
= zipIn
79 if (!entry
.isDirectory()
80 && entry
.getName().startsWith(getDataPrefix())) {
81 String entryLName
= entry
.getName().toLowerCase();
82 boolean imageEntry
= false;
83 for (String ext
: getImageExt(false)) {
84 if (entryLName
.endsWith(ext
)) {
90 String uuid
= meta
.getUuid() + "_" + entry
.getName();
92 images
.put(uuid
, new Image(zipIn
));
93 } catch (Exception e
) {
94 Instance
.getTraceHandler().error(e
);
97 if (pg
.getProgress() < 85) {
106 // ZIP order is not correct for us
107 List
<String
> imagesList
= new ArrayList
<String
>(images
.keySet());
108 Collections
.sort(imagesList
);
112 for (String uuid
: imagesList
) {
114 chap
.getParagraphs().add(new Paragraph(images
.get(uuid
)));
115 } catch (Exception e
) {
116 Instance
.getTraceHandler().error(e
);
120 if (meta
.getCover() == null && !images
.isEmpty()) {
121 meta
.setCover(images
.get(imagesList
.get(0)));
122 meta
.setFakeCover(true);