Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force re-encoding, artwork fixes #340

Merged
merged 9 commits into from
Dec 20, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void run() {
List<MediaInfo> prioritizedMedia = prioritiseMedia();

for (MediaInfo mediaInfo : prioritizedMedia) {
String tempOutput = Utils.getTmp(jobId, mediaInfo.getFileName().hashCode(), conversionGroup.getWorkfileExtension());
String tempOutput = Utils.getTmp(jobId, mediaInfo.getUID(), conversionGroup.getWorkfileExtension());
ProgressCallback callback = progressCallbacks.get(mediaInfo.getFileName() + "-" + mediaInfo.getDuration());
Future<String> converterFuture = executorService.submit(new FFMpegNativeConverter(this, mediaInfo, tempOutput, callback));
futures.add(converterFuture);
Expand Down Expand Up @@ -96,11 +96,6 @@ public void run() {
e.printStackTrace(new PrintWriter(sw));
error(e.getMessage() + "; " + sw.getBuffer().toString());
} finally {
/*
for (MediaInfo mediaInfo : convertable.getMedia()) {
FileUtils.deleteQuietly(new File(Utils.getTmp(jobId, mediaInfo.hashCode() + mediaInfo.getDuration(), conversionGroup.getWorkfileExtension())));
}
*/
FileUtils.deleteQuietly(metaFile);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ 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(), mediaInfo.hashCode(), format);
//TODO consider replacing with m4art extract for m4b files
ProcessBuilder pictureProcessBuilder = new ProcessBuilder(Utils.FFMPEG,
"-i", mediaInfo.getFileName(),
"-y",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public FFMpegConcatenator(ConversionJob conversionJob, String outputFileName, Me

protected static File prepareFiles(long jobId, List<MediaInfo> media, String workfileExtension) throws IOException {
File fileListFile = new File(System.getProperty("java.io.tmpdir"), "filelist." + jobId + ".txt");
List<String> outFiles = media.stream().map(mediaInfo -> "file '" + Utils.getTmp(jobId, mediaInfo.getFileName().hashCode(), workfileExtension) + "'").collect(Collectors.toList());
List<String> outFiles = media.stream().map(mediaInfo -> "file '" + Utils.getTmp(jobId, mediaInfo.getUID(), workfileExtension) + "'").collect(Collectors.toList());
FileUtils.writeLines(fileListFile, "UTF-8", outFiles);
return fileListFile;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public void concat() throws IOException, InterruptedException {
} finally {
Utils.closeSilently(process);
Utils.closeSilently(progressParser);
media.forEach(mediaInfo -> FileUtils.deleteQuietly(new File(Utils.getTmp(conversionJob.jobId, mediaInfo.getFileName().hashCode(), conversionJob.getConversionGroup().getWorkfileExtension()))));
media.forEach(mediaInfo -> FileUtils.deleteQuietly(new File(Utils.getTmp(conversionJob.jobId, mediaInfo.getUID(), conversionJob.getConversionGroup().getWorkfileExtension()))));
FileUtils.deleteQuietly(new File(fileListFileName));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/uk/yermak/audiobookconverter/MediaInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface MediaInfo extends Organisable {

public Chapter getChapter();

public int getUID();
}


21 changes: 5 additions & 16 deletions src/main/java/uk/yermak/audiobookconverter/MediaInfoBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public void setDuration(final long duration) {
this.duration = duration;
}

@Override
public int getUID() {
return Objects.hash(fileName);
}

public int getChannels() {
return this.channels;
}
Expand Down Expand Up @@ -89,13 +94,11 @@ public void setCodec(final String codec) {
this.codec = codec;
}


@Override
public long getOffset() {
return -1;
}


public MediaInfoBean(final String fileName) {
this.fileName = fileName;
this.channels = 2;
Expand All @@ -104,19 +107,5 @@ public MediaInfoBean(final String fileName) {
this.duration = 0L;
this.codec = "";
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MediaInfo)) return false;
MediaInfo that = (MediaInfo) o;
return getFileName().equals(that.getFileName());
}

@Override
public int hashCode() {
return Objects.hash(getFileName(), getDuration());
}

}

18 changes: 5 additions & 13 deletions src/main/java/uk/yermak/audiobookconverter/MediaInfoProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public Chapter getChapter() {
return this.getMediaInfo().getChapter();
}

@Override
public int getUID() {
return this.getMediaInfo().getUID();
}

@Override
public long getOffset() {
return this.getMediaInfo().getOffset();
Expand All @@ -114,19 +119,6 @@ public void setDuration(long duration) {
this.futureLoad = futureLoad;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MediaInfo)) return false;
MediaInfo that = (MediaInfo) o;
return getFileName().equals(that.getFileName());
}

@Override
public int hashCode() {
return Objects.hash(getFileName(), getDuration());
}

@Override
public int getNumber() {
return this.getMediaInfo().getNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public void setChapter(Chapter chapter) {
}

@Override
public long getOffset() {
return track.getStart();
public int getUID() {
return Objects.hash(mediaInfo.getFileName(), track.getTrackNo());
}

@Override
public int hashCode() {
return Objects.hash(getFileName(), track.getTrackNo(), getDuration());
public long getOffset() {
return track.getStart();
}

@Override
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/uk/yermak/audiobookconverter/OutputParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class OutputParameters {
protected boolean cbr = format.defaultCBR();
protected Integer cutoff = format.defaultCutoff();
protected transient SimpleObjectProperty<Double> speed = new SimpleObjectProperty(1.0);
protected boolean force = false;

private boolean splitChapters = false;

Expand All @@ -31,6 +32,7 @@ public OutputParameters(OutputParameters parameters) {
this.format = parameters.getFormat();
this.splitChapters = parameters.isSplitChapters();
this.speed = new SimpleObjectProperty<>(parameters.getSpeed());
this.force = parameters.force;
}

OutputParameters() {
Expand All @@ -48,7 +50,7 @@ public OutputParameters(OutputParameters parameters) {


public boolean needReencode(String codec) {
return format.needsReencode(codec);
return format.needsReencode(codec) || force;
}

public void setupFormat(Format format) {
Expand Down Expand Up @@ -142,5 +144,13 @@ public ObservableValue<Double> getSpeedObservable() {
protected void initSpeed() {
speed = new SimpleObjectProperty<>(1.0);
}

public void setForce(boolean force) {
this.force = force;
}

public boolean isForce() {
return force;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Slider;
Expand All @@ -23,11 +26,13 @@
public class OutputController {
final static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final String DISABLED = "Disabled";
public static final String FORCE = "Always";

@FXML
public ComboBox<Format> outputFormatBox;
@FXML
public ComboBox<String> presetBox;
public ComboBox<String> force;

@FXML
private ComboBox<String> splitFileBox;
Expand Down Expand Up @@ -83,6 +88,14 @@ private void initialize() {
if (newValue == null) return;
ConverterApplication.getContext().setSpeed(Double.valueOf(newValue));
});
force.getSelectionModel().select(0);
force.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
if (newValue == null) return;
ConverterApplication.getContext().getOutputParameters().setForce(FORCE.equals(newValue));
}
});

outputFormatBox.getItems().addAll(Format.values());
outputFormatBox.getSelectionModel().select(0);
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/uk/yermak/audiobookconverter/fx/output.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@
GridPane.halignment="LEFT"/>
<ComboBox fx:id="cutoff" GridPane.columnIndex="4" GridPane.rowIndex="2" GridPane.halignment="RIGHT"/>

<Label text="Force re-encoding" GridPane.columnIndex="3" GridPane.rowIndex="3"
GridPane.halignment="LEFT"/>
<ComboBox fx:id="force" GridPane.columnIndex="4" GridPane.rowIndex="3" GridPane.halignment="RIGHT">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="Auto"/>
<String fx:value="Always"/>
</FXCollections>
</items>
</ComboBox>

<Pane prefWidth="50" GridPane.columnIndex="5" GridPane.rowIndex="0" GridPane.rowSpan="3"/>


Expand Down