Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AudioBookConverter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Gummi
AudioBookConverter
Commits
4a509860
Unverified
Commit
4a509860
authored
Jan 29, 2021
by
Yarick Yermak
Committed by
GitHub
Jan 29, 2021
Browse files
Options
Downloads
Plain Diff
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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/uk/yermak/audiobookconverter/AppProperties.java
+7
-8
7 additions, 8 deletions
...main/java/uk/yermak/audiobookconverter/AppProperties.java
src/main/java/uk/yermak/audiobookconverter/Utils.java
+6
-24
6 additions, 24 deletions
src/main/java/uk/yermak/audiobookconverter/Utils.java
with
13 additions
and
32 deletions
src/main/java/uk/yermak/audiobookconverter/AppProperties.java
+
7
−
8
View file @
4a509860
...
@@ -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
())
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/uk/yermak/audiobookconverter/Utils.java
+
6
−
24
View file @
4a509860
...
@@ -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
"---"
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment