1 package be
.nikiroo
.fanfix
.supported
;
3 import java
.awt
.image
.BufferedImage
;
5 import java
.io
.IOException
;
6 import java
.io
.InputStream
;
8 import java
.util
.ArrayList
;
9 import java
.util
.Collections
;
10 import java
.util
.List
;
11 import java
.util
.zip
.ZipEntry
;
12 import java
.util
.zip
.ZipInputStream
;
14 import javax
.imageio
.ImageIO
;
16 import be
.nikiroo
.fanfix
.Instance
;
17 import be
.nikiroo
.fanfix
.data
.Chapter
;
18 import be
.nikiroo
.fanfix
.data
.Paragraph
;
19 import be
.nikiroo
.fanfix
.data
.Story
;
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
);
71 if (!pgMeta
.isDone()) {
72 pgMeta
.setProgress(pgMeta
.getMax()); // 10%
75 story
.setChapters(new ArrayList
<Chapter
>());
76 Chapter chap
= new Chapter(1, null);
77 story
.getChapters().add(chap
);
79 ZipInputStream zipIn
= new ZipInputStream(getInput());
81 List
<String
> images
= new ArrayList
<String
>();
82 for (ZipEntry entry
= zipIn
.getNextEntry(); entry
!= null; entry
= zipIn
84 if (!entry
.isDirectory()
85 && entry
.getName().startsWith(getDataPrefix())) {
86 String entryLName
= entry
.getName().toLowerCase();
87 boolean imageEntry
= false;
88 for (String ext
: getImageExt(false)) {
89 if (entryLName
.endsWith(ext
)) {
95 String uuid
= meta
.getUuid() + "_" + entry
.getName();
97 File tmp
= Instance
.getCache().addToCache(zipIn
, uuid
);
98 images
.add(tmp
.toURI().toURL().toString());
99 } catch (Exception e
) {
108 // ZIP order is not correct for us
109 Collections
.sort(images
);
112 for (String uuid
: images
) {
114 chap
.getParagraphs().add(new Paragraph(new URL(uuid
)));
115 } catch (Exception e
) {
120 if (meta
.getCover() == null && !images
.isEmpty()) {
121 InputStream in
= Instance
.getCache().open(new URL(images
.get(0)),
124 BufferedImage fcover
= ImageIO
.read(in
);
125 meta
.setCover(fcover
);
126 meta
.setFakeCover(true);