1 package be
.nikiroo
.fanfix
.supported
;
4 import java
.io
.IOException
;
5 import java
.io
.InputStream
;
7 import java
.util
.ArrayList
;
8 import java
.util
.Collections
;
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
;
19 * Support class for CBZ files (works better with CBZ created with this program,
20 * as they have some metadata available).
24 class Cbz
extends Epub
{
26 protected boolean supports(URL url
) {
27 return url
.toString().toLowerCase().endsWith(".cbz");
31 public String
getSourceName() {
36 protected String
getDataPrefix() {
41 protected boolean requireInfo() {
46 protected boolean getCover() {
51 protected void preprocess(URL source
, InputStream in
) throws IOException
{
52 super.preprocess(source
, in
);
53 meta
.setImageDocument(true);
57 public Story
process(URL url
) throws IOException
{
58 Story story
= processMeta(url
, false, true);
59 story
.setChapters(new ArrayList
<Chapter
>());
60 Chapter chap
= new Chapter(1, null);
61 story
.getChapters().add(chap
);
63 ZipInputStream zipIn
= new ZipInputStream(getInput());
65 List
<String
> images
= new ArrayList
<String
>();
66 for (ZipEntry entry
= zipIn
.getNextEntry(); entry
!= null; entry
= zipIn
68 if (!entry
.isDirectory()
69 && entry
.getName().startsWith(getDataPrefix())) {
70 String entryLName
= entry
.getName().toLowerCase();
71 boolean imageEntry
= false;
72 for (String ext
: getImageExt(false)) {
73 if (entryLName
.endsWith(ext
)) {
79 String uuid
= meta
.getUuid() + "_" + entry
.getName();
82 Instance
.getCache().addToCache(zipIn
, uuid
);
83 } catch (Exception e
) {
90 // ZIP order is not sure
91 Collections
.sort(images
);
93 for (String uuid
: images
) {
95 chap
.getParagraphs().add(
96 new Paragraph(new File(uuid
).toURI().toURL()));
97 } catch (Exception e
) {