-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
389 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 0 additions & 65 deletions
65
src/main/java/fr/rakambda/mediaconverter/itemprocessor/AacConverter.java
This file was deleted.
Oops, something went wrong.
75 changes: 0 additions & 75 deletions
75
src/main/java/fr/rakambda/mediaconverter/itemprocessor/Av1Converter.java
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
src/main/java/fr/rakambda/mediaconverter/itemprocessor/AvifConverter.java
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
src/main/java/fr/rakambda/mediaconverter/itemprocessor/CommandConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package fr.rakambda.mediaconverter.itemprocessor; | ||
|
||
import fr.rakambda.mediaconverter.progress.ProgressBarHandle; | ||
import fr.rakambda.mediaconverter.progress.ProgressBarSupplier; | ||
import lombok.NonNull; | ||
import lombok.extern.log4j.Log4j2; | ||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
@Log4j2 | ||
public abstract class CommandConverter extends ConverterRunnable{ | ||
private final ProgressBarSupplier converterProgressBarSupplier; | ||
|
||
private ProgressBarHandle progressBar; | ||
private Process process; | ||
|
||
protected CommandConverter(@NonNull Path input, @NonNull Path output, @NonNull Path temporary, boolean deleteInput, ProgressBarSupplier converterProgressBarSupplier){ | ||
super(input, output, temporary, deleteInput); | ||
this.converterProgressBarSupplier = converterProgressBarSupplier; | ||
} | ||
|
||
@Override | ||
protected void convert(@NonNull ExecutorService executorService) throws Exception{ | ||
log.info("Converting {} to {}", getInput(), getOutput()); | ||
progressBar = converterProgressBarSupplier.get(); | ||
|
||
ProcessBuilder builder = new ProcessBuilder(getCommand()); | ||
executorService.execute(() -> { | ||
try{ | ||
progressBar.getProgressBar().stepTo(0); | ||
progressBar.getProgressBar().setExtraMessage(getOutput().getFileName().toString()); | ||
progressBar.getProgressBar().maxHint(1); | ||
|
||
process = builder.start(); | ||
process.onExit() | ||
.thenAccept(p -> progressBar.getProgressBar().stepTo(1)) | ||
.thenAccept(p -> close()); | ||
process.waitFor(); | ||
} | ||
catch(Exception e){ | ||
log.error("Failed to convert", e); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void cancel(){ | ||
if(Objects.nonNull(process)){ | ||
process.destroy(); | ||
} | ||
} | ||
|
||
@Override | ||
public void close(){ | ||
if(Objects.nonNull(progressBar)){ | ||
progressBar.close(); | ||
} | ||
} | ||
|
||
protected abstract String[] getCommand(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.