1 package be
.nikiroo
.fanfix
.output
;
3 import java
.io
.BufferedWriter
;
5 import java
.io
.FileOutputStream
;
6 import java
.io
.IOException
;
7 import java
.io
.OutputStreamWriter
;
9 import be
.nikiroo
.fanfix
.Instance
;
10 import be
.nikiroo
.fanfix
.bundles
.Config
;
11 import be
.nikiroo
.fanfix
.data
.MetaData
;
13 public class InfoCover
{
14 public static void writeInfo(File targetDir
, String targetName
,
15 MetaData meta
) throws IOException
{
16 File info
= new File(targetDir
, targetName
+ ".info");
18 BufferedWriter infoWriter
= null;
20 infoWriter
= new BufferedWriter(new OutputStreamWriter(
21 new FileOutputStream(info
), "UTF-8"));
25 if (meta
.getTags() != null) {
26 for (String tag
: meta
.getTags()) {
27 if (!tags
.isEmpty()) {
34 writeMeta(infoWriter
, "TITLE", meta
.getTitle());
35 writeMeta(infoWriter
, "AUTHOR", meta
.getAuthor());
36 writeMeta(infoWriter
, "DATE", meta
.getDate());
37 writeMeta(infoWriter
, "SUBJECT", meta
.getSubject());
38 writeMeta(infoWriter
, "SOURCE", meta
.getSource());
39 writeMeta(infoWriter
, "URL", meta
.getUrl());
40 writeMeta(infoWriter
, "TAGS", tags
);
41 writeMeta(infoWriter
, "UUID", meta
.getUuid());
42 writeMeta(infoWriter
, "LUID", meta
.getLuid());
43 writeMeta(infoWriter
, "LANG", meta
.getLang() == null ?
""
44 : meta
.getLang().toLowerCase());
45 writeMeta(infoWriter
, "IMAGES_DOCUMENT",
46 meta
.isImageDocument() ?
"true" : "false");
47 writeMeta(infoWriter
, "TYPE", meta
.getType());
48 if (meta
.getCover() != null) {
49 String format
= Instance
.getInstance().getConfig()
50 .getString(Config
.FILE_FORMAT_IMAGE_FORMAT_COVER
).toLowerCase();
51 writeMeta(infoWriter
, "COVER", targetName
+ "." + format
);
53 writeMeta(infoWriter
, "COVER", "");
55 writeMeta(infoWriter
, "EPUBCREATOR", BasicOutput
.EPUB_CREATOR
);
56 writeMeta(infoWriter
, "PUBLISHER", meta
.getPublisher());
57 writeMeta(infoWriter
, "WORDCOUNT",
58 Long
.toString(meta
.getWords()));
59 writeMeta(infoWriter
, "CREATION_DATE", meta
.getCreationDate());
60 writeMeta(infoWriter
, "FAKE_COVER",
61 Boolean
.toString(meta
.isFakeCover()));
64 if (infoWriter
!= null) {
70 public static void writeCover(File targetDir
, String targetName
,
72 if (meta
!= null && meta
.getCover() != null) {
74 Instance
.getInstance().getCache().saveAsImage(meta
.getCover(), new File(targetDir
, targetName
), true);
75 } catch (IOException e
) {
76 // Allow to continue without cover
77 Instance
.getInstance().getTraceHandler().error(new IOException("Failed to save the cover image", e
));
82 private static void writeMeta(BufferedWriter writer
, String key
,
83 String value
) throws IOException
{
88 writer
.write(String
.format("%s=\"%s\"\n", key
, value
.replace("\"", "'")));