Skip to content

Commit

Permalink
Merge pull request #342 from yermak/clean-up
Browse files Browse the repository at this point in the history
clean up
  • Loading branch information
yermak authored Dec 20, 2021
2 parents 1b0ba8f + 7177de8 commit 344c18a
Show file tree
Hide file tree
Showing 24 changed files with 50 additions and 93 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
<version>2.11.0</version>
<scope>compile</scope>
</dependency>

Expand All @@ -83,7 +83,7 @@
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.0</version>
<version>11.1.1</version>
<exclusions>
<exclusion>
<groupId>org.openjfx</groupId>
Expand All @@ -95,13 +95,13 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<version>2.8.9</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1.1-jre</version>
<version>31.0.1-jre</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import org.controlsfx.control.Notifications;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.yermak.audiobookconverter.AppProperties;
import uk.yermak.audiobookconverter.Utils;
import uk.yermak.audiobookconverter.Version;
import uk.yermak.audiobookconverter.fx.ConversionContext;
import uk.yermak.audiobookconverter.fx.JfxEnv;
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/uk/yermak/audiobookconverter/Chapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ public long getDuration() {
return media.stream().mapToLong(MediaInfo::getDuration).sum();
}

/*
public String getDurationString() {
return Utils.formatTime(getDuration());
}
*/

@Override
public boolean split() {
if (part.getChapters().size() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

public class ConversionException extends RuntimeException {

public ConversionException(String message) {
super(message);
}

public ConversionException(String message, Throwable cause) {
super(message, cause);
}
Expand All @@ -14,7 +10,4 @@ public ConversionException(Throwable cause) {
super(cause);
}

public ConversionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
12 changes: 4 additions & 8 deletions src/main/java/uk/yermak/audiobookconverter/ConversionGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,13 @@ public void launch(ListView<ProgressComponent> progressQueue, ProgressComponent
Chapter chapter = chapters.get(i);
String finalDesination = outputDestination;
if (chapters.size() > 1) {
finalDesination = finalDesination.replace("." + format.toString(), ", Chapter " + (i + 1) + "." + format.toString());
finalDesination = finalDesination.replace("." + format.toString(), ", Chapter " + (i + 1) + "." + format);
}
String finalName = new File(finalDesination).getName();
logger.debug("Adding conversion for chapter {}", finalName);

ConversionProgress conversionProgress = this.start(chapter, finalDesination);
Platform.runLater(() -> {
progressQueue.getItems().add(0, new ProgressComponent(conversionProgress));
});
Platform.runLater(() -> progressQueue.getItems().add(0, new ProgressComponent(conversionProgress)));

}
} else {
Expand All @@ -156,15 +154,13 @@ public void launch(ListView<ProgressComponent> progressQueue, ProgressComponent
Part part = parts.get(i);
String finalDesination = outputDestination;
if (parts.size() > 1) {
finalDesination = finalDesination.replace("." + format.toString(), ", Part " + (i + 1) + "." + format.toString());
finalDesination = finalDesination.replace("." + format.toString(), ", Part " + (i + 1) + "." + format);
}
String finalName = new File(finalDesination).getName();
logger.debug("Adding conversion for part {}", finalName);

ConversionProgress conversionProgress = this.start(part, finalDesination);
Platform.runLater(() -> {
progressQueue.getItems().add(0, new ProgressComponent(conversionProgress));
});
Platform.runLater(() -> progressQueue.getItems().add(0, new ProgressComponent(conversionProgress)));
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/uk/yermak/audiobookconverter/ConversionJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void run() {

String tempFile = Utils.getTmp(jobId, outputDestination.hashCode(), conversionGroup.getWorkfileExtension());

File metaFile = null;
try {
// conversion.getOutputParameters().updateAuto(conversion.getMedia());

Expand Down Expand Up @@ -94,8 +93,6 @@ public void run() {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
error(e.getMessage() + "; " + sw.getBuffer().toString());
} finally {
FileUtils.deleteQuietly(metaFile);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/uk/yermak/audiobookconverter/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ protected String getAppPath() {
}

@Override
protected File getConfigFilePath(File file) {
protected File getConfigFilePath() {
return new File(getAppPath(), "Contents/app/path.properties");
}
},

LINUX {
@Override
protected File getConfigFilePath(File file) {
protected File getConfigFilePath() {
return new File("../lib/app/path.properties");

}
Expand Down Expand Up @@ -83,14 +83,13 @@ protected String getAppPath() {
return "";
}

protected File getConfigFilePath(File file) {
protected File getConfigFilePath() {
return new File("app/path.properties");
}

synchronized Properties loadAppProperties() {
if (properties.isEmpty()) {
File file = null;
file = getConfigFilePath(file);
File file = getConfigFilePath();

if (file.exists()) {
try (FileInputStream in = new FileInputStream(file)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ static void parseCue(MediaInfoBean mediaInfo, String cue) {
private static long parseCueTime(String substring) {
String cleanText = cleanText(substring);
String[] split = cleanText.split(":");
long time = 1000 * (Integer.parseInt(split[0]) * 60 + Integer.parseInt(split[1])) + Integer.parseInt(split[2]) * 1000 / 75;
return time;
return 1000 * (Integer.parseInt(split[0]) * 60 + Integer.parseInt(split[1])) + Integer.parseInt(split[2]) * 1000 / 75;
}

private static String cleanText(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class FFMpegConcatenator {
private final ProgressCallback callback;
private ProgressParser progressParser;
private List<String> tmpFiles = new ArrayList<>();
private String fileListFileName;

public FFMpegConcatenator(ConversionJob conversionJob, String outputFileName, MetadataBuilder metadataBuilder, List<MediaInfo> media, ProgressCallback callback) {
this.conversionJob = conversionJob;
Expand All @@ -49,14 +48,12 @@ protected static File prepareFiles(long jobId, List<MediaInfo> media, String wor

public void concat() throws IOException, InterruptedException {
if (conversionJob.getStatus().isOver()) return;
fileListFileName = prepareFiles(conversionJob.jobId, media, conversionJob.getConversionGroup().getWorkfileExtension()).getAbsolutePath();
String fileListFileName = prepareFiles(conversionJob.jobId, media, conversionJob.getConversionGroup().getWorkfileExtension()).getAbsolutePath();

while (ProgressStatus.PAUSED.equals(conversionJob.getStatus())) Thread.sleep(1000);
callback.reset();
try {
progressParser = new TcpProgressParser(progress -> {
callback.converted(progress.out_time_ns / 1000000, progress.total_size);
});
progressParser = new TcpProgressParser(progress -> callback.converted(progress.out_time_ns / 1000000, progress.total_size));
progressParser.start();
} catch (URISyntaxException e) {
}
Expand All @@ -83,15 +80,15 @@ public void concat() throws IOException, InterruptedException {
while (!conversionJob.getStatus().isOver() && !finished) {
finished = process.waitFor(500, TimeUnit.MILLISECONDS);
}
logger.debug("Concat Out: {}", out.toString());
logger.error("Concat Error: {}", err.toString());
logger.debug("Concat Out: {}", out);
logger.error("Concat Error: {}", err);

if (process.exitValue() != 0) {
throw new ConversionException("Concatenation exit code " + process.exitValue() + "!=0", new Error(err.toString()));
}

if (!new File(outputFileName).exists()) {
throw new ConversionException("Concatenation failed, no output file:" + out.toString(), new Error(err.toString()));
throw new ConversionException("Concatenation failed, no output file:" + out, new Error(err.toString()));
}
} catch (Exception e) {
logger.error("Error during concatination of files:", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public String call() throws Exception {
while (!conversionJob.getStatus().isOver() && !finished) {
finished = process.waitFor(500, TimeUnit.MILLISECONDS);
}
logger.debug("ffmpeg out: {}", out.toString());
logger.warn("ffmpeg err: {}", err.toString());
logger.debug("ffmpeg out: {}", out);
logger.warn("ffmpeg err: {}", err);

DurationVerifier.ffMpegUpdateDuration(mediaInfo, outputFileName);
return outputFileName;
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/uk/yermak/audiobookconverter/FFMpegOptimizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ public class FFMpegOptimizer {
private String tempFile;
private final String outputFileName;

private final ProgressCallback callback;
private ProgressParser progressParser;


public FFMpegOptimizer(ConversionJob conversionJob, String tempFile, String outputFileName, ProgressCallback callback) {
this.conversionJob = conversionJob;
this.tempFile = tempFile;
this.outputFileName = outputFileName;
this.callback = callback;
}


Expand All @@ -45,7 +43,7 @@ public void moveResultingFile() {
}
}

private void optimize() throws IOException, InterruptedException {
private void optimize() throws InterruptedException {
if (conversionJob.getStatus().isOver()) return;
while (ProgressStatus.PAUSED.equals(conversionJob.getStatus())) Thread.sleep(1000);
// callback.reset();
Expand Down Expand Up @@ -88,15 +86,15 @@ private void optimize() throws IOException, InterruptedException {
while (!conversionJob.getStatus().isOver() && !finished) {
finished = process.waitFor(500, TimeUnit.MILLISECONDS);
}
logger.debug("Optimize Out: {}", out.toString());
logger.error("Optimize Error: {}", err.toString());
logger.debug("Optimize Out: {}", out);
logger.error("Optimize Error: {}", err);

if (process.exitValue() != 0) {
throw new ConversionException("Optimisation exit code " + process.exitValue() + "!=0", new Error(err.toString()));
}

if (!new File(Utils.getTmp(conversionJob.jobId, outputFileName.hashCode()+1, conversionJob.getConversionGroup().getWorkfileExtension())).exists()) {
throw new ConversionException("Optimisation failed, no output file:" + out.toString(), new Error(err.toString()));
throw new ConversionException("Optimisation failed, no output file:" + out, new Error(err.toString()));
}
} catch (Exception e) {
logger.error("Error during optimisation of resulting file:", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public ArtWork call() throws Exception {
if (conversionGroup.isOver() || conversionGroup.isStarted() || conversionGroup.isDetached())
throw new InterruptedException("ArtWork loading was interrupted");
String poster = Utils.getTmp(mediaInfo.hashCode(), stream, format);
//TODO consider replacing with m4art extract for m4b files
ProcessBuilder pictureProcessBuilder = new ProcessBuilder(Environment.FFMPEG,
"-i", mediaInfo.getFileName(),
"-map", "0:" + stream,
Expand All @@ -47,8 +46,8 @@ public ArtWork call() throws Exception {
while (!conversionGroup.isOver() && !finished) {
finished = process.waitFor(500, TimeUnit.MILLISECONDS);
}
FFMediaLoader.logger.debug("ArtWork Out: {}", out.toString());
FFMediaLoader.logger.error("ArtWork Error: {}", err.toString());
FFMediaLoader.logger.debug("ArtWork Out: {}", out);
FFMediaLoader.logger.error("ArtWork Error: {}", err);

ArtWorkBean artWorkBean = new ArtWorkBean(poster);
Platform.runLater(() -> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/uk/yermak/audiobookconverter/MediaInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public interface MediaInfo extends Organisable {

void setChapter(Chapter chapter);

public Chapter getChapter();
Chapter getChapter();

public int getUID();
int getUID();
}


Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.yermak.audiobookconverter;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.Future;

public class MediaInfoProxy implements MediaInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void coverArt(String outputFileName) throws IOException, InterruptedExcep
}
}

public void updateSinglePoster(ArtWork poster, int index, String outputFileName) throws IOException, InterruptedException {
public void updateSinglePoster(ArtWork poster, int index, String outputFileName) {
Process process = null;
try {
ProcessBuilder artProcessBuilder = new ProcessBuilder(Environment.MP4ART,
Expand All @@ -53,15 +53,15 @@ public void updateSinglePoster(ArtWork poster, int index, String outputFileName)
while (!conversionJob.getStatus().isOver() && !finished) {
finished = process.waitFor(500, TimeUnit.MILLISECONDS);
}
logger.debug("mp4art out: {}", out.toString());
logger.warn("mp4art err: {}", err.toString());
logger.debug("mp4art out: {}", out);
logger.warn("mp4art err: {}", err);

if (process.exitValue() != 0) {
throw new ConversionException("ArtWork failed with code " + process.exitValue() + "!=0", new Error(err.toString()));
}

if (!new File(outputFileName).exists()) {
throw new ConversionException("ArtWork failed, no output file:" + out.toString(), new Error(err.toString()));
throw new ConversionException("ArtWork failed, no output file:" + out, new Error(err.toString()));
}
} catch (Exception e) {
logger.error("Failed to apply art work", e);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/uk/yermak/audiobookconverter/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ public static String renderPart(Part part, Map<String, Function<Part, Object>> c
ST partTemplate = new ST(g, partFormat);


context.forEach((key, value) -> {
partTemplate.add(key, value.apply(part));
});
context.forEach((key, value) -> partTemplate.add(key, value.apply(part)));

String result = partTemplate.render();
char[] toRemove = new char[]{':', '\\', '/', '>', '<', '|', '?', '*', '"'};
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/uk/yermak/audiobookconverter/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class Version {

public static String getVersionString() {
return "AudioBookConverter-5.6.3";
return "AudiobookConverter-#{APP_VERSION}#";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void initialize() {
year.textProperty().addListener(o -> AudiobookConverter.getContext().getBookInfo().year().set(year.getText()));
comment.textProperty().addListener(o -> AudiobookConverter.getContext().getBookInfo().comment().set(comment.getText()));

AudiobookConverter.getContext().addContextDetachListener(observable -> Platform.runLater(() -> clearTags()));
AudiobookConverter.getContext().addContextDetachListener(observable -> Platform.runLater(this::clearTags));
}

private void updateTags(ObservableList<MediaInfo> media, boolean clear) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ public void movePosterUp(final Integer selected) {
}

public void addPosterIfMissingWithDelay(ArtWork artWork) {
Platform.runLater(() -> {
addPosterIfMissing(artWork);
});
Platform.runLater(() -> addPosterIfMissing(artWork));
}

public void addPosterIfMissing(ArtWork artWork) {
Expand Down
Loading

0 comments on commit 344c18a

Please sign in to comment.