1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.awt
.image
.BufferedImage
;
4 import java
.io
.IOException
;
5 import java
.io
.InputStream
;
7 import java
.util
.ArrayList
;
8 import java
.util
.Collections
;
9 import java
.util
.HashMap
;
10 import java
.util
.List
;
12 import java
.util
.zip
.ZipEntry
;
13 import java
.util
.zip
.ZipInputStream
;
15 import be
.nikiroo
.fanfix
.Instance
;
16 import be
.nikiroo
.fanfix
.data
.Chapter
;
17 import be
.nikiroo
.fanfix
.data
.Paragraph
;
18 import be
.nikiroo
.fanfix
.data
.Story
;
19 import be
.nikiroo
.utils
.ImageUtils
;
20 import be
.nikiroo
.utils
.Progress
;
23 * Support class for CBZ files (works better with CBZ created with this program,
24 * as they have some metadata available).
28 class Cbz
extends Epub
{
30 protected boolean supports(URL url
) {
31 return url
.toString().toLowerCase().endsWith(".cbz");
35 public String
getSourceName() {
40 protected String
getDataPrefix() {
45 protected boolean requireInfo() {
50 protected boolean getCover() {
55 protected void preprocess(URL source
, InputStream in
) throws IOException
{
56 super.preprocess(source
, in
);
57 meta
.setImageDocument(true);
61 public Story
process(URL url
, Progress pg
) throws IOException
{
68 Progress pgMeta
= new Progress();
69 pg
.addProgress(pgMeta
, 10);
70 Story story
= processMeta(url
, false, true, pgMeta
);
73 story
.setChapters(new ArrayList
<Chapter
>());
74 Chapter chap
= new Chapter(1, null);
75 story
.getChapters().add(chap
);
77 ZipInputStream zipIn
= new ZipInputStream(getInput());
79 Map
<String
, BufferedImage
> images
= new HashMap
<String
, BufferedImage
>();
80 for (ZipEntry entry
= zipIn
.getNextEntry(); entry
!= null; entry
= zipIn
82 if (!entry
.isDirectory()
83 && entry
.getName().startsWith(getDataPrefix())) {
84 String entryLName
= entry
.getName().toLowerCase();
85 boolean imageEntry
= false;
86 for (String ext
: getImageExt(false)) {
87 if (entryLName
.endsWith(ext
)) {
93 String uuid
= meta
.getUuid() + "_" + entry
.getName();
95 images
.put(uuid
, ImageUtils
.fromStream(zipIn
));
96 } catch (Exception e
) {
97 Instance
.getTraceHandler().error(e
);
100 if (pg
.getProgress() < 85) {
109 // ZIP order is not correct for us
110 List
<String
> imagesList
= new ArrayList
<String
>(images
.keySet());
111 Collections
.sort(imagesList
);
115 for (String uuid
: imagesList
) {
117 chap
.getParagraphs().add(new Paragraph(images
.get(uuid
)));
118 } catch (Exception e
) {
119 Instance
.getTraceHandler().error(e
);
123 if (meta
.getCover() == null && !images
.isEmpty()) {
124 meta
.setCover(images
.get(imagesList
.get(0)));
125 meta
.setFakeCover(true);