Skip to content
Snippets Groups Projects
Unverified Commit 4a509860 authored by Yarick Yermak's avatar Yarick Yermak Committed by GitHub
Browse files

Merge pull request #226 from yermak/development

Bug fixes
parents fe9869d2 9f429a0d
No related branches found
No related tags found
No related merge requests found
...@@ -15,11 +15,13 @@ public class AppProperties { ...@@ -15,11 +15,13 @@ public class AppProperties {
final static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); final static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final File APP_DIR = new File(System.getProperty("APP_HOME")); public static final File APP_DIR = new File(System.getProperty("APP_HOME"));
public static final File PROP_FILE = new File(APP_DIR, Version.getVersionString() + ".properties"); public static final File PROP_FILE = new File(APP_DIR, Version.getVersionString() + ".properties");
private static final Properties applicationProps = new Properties();
private static Properties getAppProperties() { static {
//TODO:add default props here loadAppProperties();
Properties defaultProperties = new Properties(); }
Properties applicationProps = new Properties(defaultProperties);
private static synchronized Properties loadAppProperties() {
if (PROP_FILE.exists()) { if (PROP_FILE.exists()) {
try (FileInputStream in = new FileInputStream(PROP_FILE)) { try (FileInputStream in = new FileInputStream(PROP_FILE)) {
applicationProps.load(in); applicationProps.load(in);
...@@ -31,13 +33,11 @@ public class AppProperties { ...@@ -31,13 +33,11 @@ public class AppProperties {
} }
public static String getProperty(String key) { public static String getProperty(String key) {
Properties applicationProps = getAppProperties();
return applicationProps.getProperty(key); return applicationProps.getProperty(key);
} }
public static Properties getProperties(String group) { public static Properties getProperties(String group) {
Properties properties = new Properties(); Properties properties = new Properties();
Properties applicationProps = getAppProperties();
Enumeration<Object> keys = applicationProps.keys(); Enumeration<Object> keys = applicationProps.keys();
while (keys.hasMoreElements()) { while (keys.hasMoreElements()) {
String propName = (String) keys.nextElement(); String propName = (String) keys.nextElement();
...@@ -49,8 +49,7 @@ public class AppProperties { ...@@ -49,8 +49,7 @@ public class AppProperties {
return properties; return properties;
} }
public static void setProperty(String key, String value) { public static synchronized void setProperty(String key, String value) {
Properties applicationProps = getAppProperties();
applicationProps.put(key, value); applicationProps.put(key, value);
File appDir = APP_DIR; File appDir = APP_DIR;
if (appDir.exists() || appDir.mkdir()) { if (appDir.exists() || appDir.mkdir()) {
......
...@@ -44,22 +44,6 @@ public class Utils { ...@@ -44,22 +44,6 @@ public class Utils {
} }
} }
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) { public static String renderChapter(Chapter chapter, Map<String, Function<Chapter, Object>> context) {
String chapterFormat = AppProperties.getProperty("chapter_format"); String chapterFormat = AppProperties.getProperty("chapter_format");
if (chapterFormat == null) { if (chapterFormat == null) {
...@@ -91,11 +75,15 @@ public class Utils { ...@@ -91,11 +75,15 @@ public class Utils {
public static String getOuputFilenameSuggestion(AudioBookInfo bookInfo) { public static String getOuputFilenameSuggestion(AudioBookInfo bookInfo) {
String filenameFormat = AppProperties.getProperty("filename_format"); String filenameFormat = AppProperties.getProperty("filename_format");
if (filenameFormat == null) { 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); 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("WRITER", bookInfo.writer().trimToNull());
filenameTemplate.add("TITLE", bookInfo.title().trimToNull()); filenameTemplate.add("TITLE", bookInfo.title().trimToNull());
filenameTemplate.add("SERIES", bookInfo.series().trimToNull()); filenameTemplate.add("SERIES", bookInfo.series().trimToNull());
...@@ -146,12 +134,6 @@ public class Utils { ...@@ -146,12 +134,6 @@ public class Utils {
TimeUnit.MILLISECONDS.toSeconds(millis) % TimeUnit.MINUTES.toSeconds(1)); 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) { public static String formatSize(long bytes) {
if (bytes == -1L) { if (bytes == -1L) {
return "---"; return "---";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment