From 5118c33c1359b8ed46c53443c13c0de3b60e10eb Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 18 Mar 2023 18:00:37 +0800 Subject: [PATCH] feat: show metadata info --- src/main.java | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main.java diff --git a/src/main.java b/src/main.java new file mode 100644 index 0000000..78d8817 --- /dev/null +++ b/src/main.java @@ -0,0 +1,60 @@ +import mobimeta.*; + +import java.io.File; +import java.util.List; + +class Main { + static String splitLine = "================================================================"; + + public static void showMeta(File file) { + System.out.println(splitLine); + System.out.println("File name: " + file.getName()); + MobiMeta meta; + try { + meta = new MobiMeta(file); + } catch (MobiMetaException err) { + System.err.println("Error: " + err.getMessage()); + return; + } + String encoding = meta.getCharacterEncoding(); + List exthList = meta.getEXTHRecords(); + System.out.println("Book name: " + meta.getFullName()); + System.out.println("Encoding: " + encoding); + System.out.println("Locale: " + meta.getLocale()); + System.out.println(splitLine); + System.out.print(meta.getMetaInfo()); + + System.out.print(splitLine); + for (EXTHRecord rec : exthList) { + if (!rec.isKnownType()) { + continue; // skip unknown EXTH record + } + System.out.println(); + int type = rec.getRecordType(); + String desc = rec.getTypeDescription(); + String content = StreamUtils.byteArrayToString(rec.getData(), encoding); + System.out.println("[" + type + "](" + desc + "): " + content); + } + + System.out.println(splitLine); + for (EXTHRecord rec : exthList) { + if (rec.isKnownType()) { + continue; // only show unknown type + } + int type = rec.getRecordType(); + String content = StreamUtils.byteArrayToString(rec.getData(), encoding); + System.out.println("[" + type + "]: " + content); + } + System.out.println(splitLine); + } + + public static void main(String[] args) { + + String testFile = "XXRS.azw3"; + + File target = new File(testFile); + + showMeta(target); + + } +}