1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import java
.util
.ArrayList
;
7 import java
.util
.Collections
;
8 import java
.util
.HashMap
;
11 import java
.util
.zip
.ZipEntry
;
12 import java
.util
.zip
.ZipInputStream
;
14 import be
.nikiroo
.fanfix
.Instance
;
15 import be
.nikiroo
.fanfix
.data
.Chapter
;
16 import be
.nikiroo
.fanfix
.data
.Paragraph
;
17 import be
.nikiroo
.fanfix
.data
.Story
;
18 import be
.nikiroo
.utils
.Image
;
19 import be
.nikiroo
.utils
.Progress
;
22 * Support class for CBZ files (works better with CBZ created with this program,
23 * as they have some metadata available).
27 class Cbz
extends Epub
{
29 protected boolean supports(URL url
) {
30 return url
.toString().toLowerCase().endsWith(".cbz");
34 public String
getSourceName() {
39 protected String
getDataPrefix() {
44 protected boolean requireInfo() {
49 protected boolean getCover() {
54 protected void preprocess(URL source
, InputStream in
) throws IOException
{
55 super.preprocess(source
, in
);
56 meta
.setImageDocument(true);
60 public Story
process(URL url
, Progress pg
) throws IOException
{
67 Progress pgMeta
= new Progress();
68 pg
.addProgress(pgMeta
, 10);
69 Story story
= processMeta(url
, false, true, pgMeta
);
72 story
.setChapters(new ArrayList
<Chapter
>());
73 Chapter chap
= new Chapter(1, null);
74 story
.getChapters().add(chap
);
76 ZipInputStream zipIn
= new ZipInputStream(getInput());
78 Map
<String
, Image
> images
= new HashMap
<String
, Image
>();
79 for (ZipEntry entry
= zipIn
.getNextEntry(); entry
!= null; entry
= zipIn
81 if (!entry
.isDirectory()
82 && entry
.getName().startsWith(getDataPrefix())) {
83 String entryLName
= entry
.getName().toLowerCase();
84 boolean imageEntry
= false;
85 for (String ext
: getImageExt(false)) {
86 if (entryLName
.endsWith(ext
)) {
92 String uuid
= meta
.getUuid() + "_" + entry
.getName();
94 images
.put(uuid
, new Image(zipIn
));
95 } catch (Exception e
) {
96 Instance
.getTraceHandler().error(e
);
99 if (pg
.getProgress() < 85) {
108 // ZIP order is not correct for us
109 List
<String
> imagesList
= new ArrayList
<String
>(images
.keySet());
110 Collections
.sort(imagesList
);
114 for (String uuid
: imagesList
) {
116 chap
.getParagraphs().add(new Paragraph(images
.get(uuid
)));
117 } catch (Exception e
) {
118 Instance
.getTraceHandler().error(e
);
122 if (meta
.getCover() == null && !images
.isEmpty()) {
123 meta
.setCover(images
.get(imagesList
.get(0)));
124 meta
.setFakeCover(true);