Browse Source

feat: set book name

master
Dnomd343 2 years ago
parent
commit
6a690e6ea8
  1. 51
      src/main.java

51
src/main.java

@ -1,21 +1,36 @@
import mobimeta.*;
import java.io.File;
import java.util.Arrays;
import java.util.Iterator;
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;
private static MobiMeta readFile(File file) {
MobiMeta meta = null;
try {
meta = new MobiMeta(file);
} catch (MobiMetaException err) {
System.err.println("Error: " + err.getMessage());
return;
System.err.println("Error reading file: " + err.getMessage());
System.exit(1);
}
return meta;
}
private static void saveFile(MobiMeta meta, File file) {
try {
meta.saveToNewFile(file);
} catch (MobiMetaException err) {
System.err.println("Error saving file: " + err.getMessage());
}
}
private static void showMeta(File file) {
System.out.println(splitLine);
System.out.println("File name: " + file.getName());
MobiMeta meta = readFile(file);
String encoding = meta.getCharacterEncoding();
List<EXTHRecord> exthList = meta.getEXTHRecords();
System.out.println("Book name: " + meta.getFullName());
@ -48,13 +63,35 @@ class Main {
System.out.println(splitLine);
}
private static void setBookName(MobiMeta meta, String name) {
String encoding = meta.getCharacterEncoding();
List<EXTHRecord> exthList = meta.getEXTHRecords();
boolean flag = false;
for (EXTHRecord rec : exthList) {
if (rec.getRecordType() == 503) {
rec.setData(name, encoding);
flag = true;
}
}
if (!flag) { // without updated title
exthList.add(new EXTHRecord(503, name, encoding));
}
meta.setFullName(name);
meta.setEXTHRecords();
}
public static void main(String[] args) {
String testFile = "XXRS.azw3";
File target = new File(testFile);
showMeta(target);
// MobiMeta meta = readFile(target);
// setBookName(meta, "生若栩栩");
// showMeta(target);
// saveFile(meta, new File("XXRS_new.azw3"));
}
}

Loading…
Cancel
Save