Skip to content

Commit

Permalink
fix #101
Browse files Browse the repository at this point in the history
  • Loading branch information
yermak committed Jan 29, 2021
1 parent cdb60c6 commit a421bce
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions src/main/java/uk/yermak/audiobookconverter/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ public static void closeSilently(Process process) {
}
}

public static String formatChapter(int partNumber, Chapter chapter) {
String chapterFormat = AppProperties.getProperty("chapter_format");
if (chapterFormat == null) {
chapterFormat = "<if(BOOK_NUMBER)> Book <BOOK_NUMBER>. <endif>Chapter <CHAPTER_NUMBER><if(CHAPTER_TITLE)>- <CHAPTER_TITLE><endif> - <DURATION>";
AppProperties.setProperty("chapter_format", chapterFormat);
}

ST chapterTemplate = new ST(chapterFormat);
chapterTemplate.add("BOOK_NUMBER", partNumber == 0 ? null : partNumber);
chapterTemplate.add("CHAPTER_NUMBER", chapter.getNumber() == 0 ? null : chapter.getNumber());
chapterTemplate.add("CHAPTER_TITLE", StringUtils.isEmpty(chapter.getDetails()) ? chapter.getTitle() : chapter.getDetails());
chapterTemplate.add("DURATION", Utils.formatTime(chapter.getDuration()));
return chapterTemplate.render();

}

public static String renderChapter(Chapter chapter, Map<String, Function<Chapter, Object>> context) {
String chapterFormat = AppProperties.getProperty("chapter_format");
if (chapterFormat == null) {
Expand Down Expand Up @@ -91,11 +75,15 @@ public static String renderChapter(Chapter chapter, Map<String, Function<Chapter
public static String getOuputFilenameSuggestion(AudioBookInfo bookInfo) {
String filenameFormat = AppProperties.getProperty("filename_format");
if (filenameFormat == null) {
filenameFormat = "<WRITER> <if(SERIES)>- [<SERIES><if(BOOK_NUMBER)> -<BOOK_NUMBER><endif>] <endif>- <TITLE><if(NARRATOR)> (<NARRATOR>)<endif>";
filenameFormat = "<WRITER> <if(SERIES)> - [<SERIES><if(BOOK_NUMBER)> - <BOOK_NUMBER; format=\"%,02d\"><endif>] <endif> - <TITLE><if(NARRATOR)> (<NARRATOR>)<endif>";
AppProperties.setProperty("filename_format", filenameFormat);
}

ST filenameTemplate = new ST(filenameFormat);
STGroup g = new STGroupString("");
g.registerRenderer(Number.class, new NumberRenderer());
g.registerRenderer(Duration.class, new DurationRender());

ST filenameTemplate = new ST(g, filenameFormat);
filenameTemplate.add("WRITER", bookInfo.writer().trimToNull());
filenameTemplate.add("TITLE", bookInfo.title().trimToNull());
filenameTemplate.add("SERIES", bookInfo.series().trimToNull());
Expand Down Expand Up @@ -146,12 +134,6 @@ public static String formatTime(long millis) {
TimeUnit.MILLISECONDS.toSeconds(millis) % TimeUnit.MINUTES.toSeconds(1));
}

public static String formatTimeForFilename(long millis) {
return String.format("%02d-%02d-%02d", TimeUnit.MILLISECONDS.toHours(millis),
TimeUnit.MILLISECONDS.toMinutes(millis) % TimeUnit.HOURS.toMinutes(1),
TimeUnit.MILLISECONDS.toSeconds(millis) % TimeUnit.MINUTES.toSeconds(1));
}

public static String formatSize(long bytes) {
if (bytes == -1L) {
return "---";
Expand Down

0 comments on commit a421bce

Please sign in to comment.