Skip to content

Commit

Permalink
Merge pull request #360
Browse files Browse the repository at this point in the history
optimisation fix
  • Loading branch information
yermak authored Dec 29, 2021
2 parents 3e04887 + db10c17 commit bac8f37
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;

@Deprecated
public class ArtWorkBean implements ArtWork {
private final String fileName;
private final long crc32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ public void run() {
javafx.application.Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("New Version Available!");
String path = FileManager.getPathToApplicationBundle();
// alert.setContentText("path:"+ path);
alert.setContentText("Would you like to download new version?");
Optional<ButtonType> result = alert.showAndWait();
if ((result.isPresent()) && (result.get() == ButtonType.OK)) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/uk/yermak/audiobookconverter/FFMediaLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import javafx.scene.image.Image;
import net.bramp.ffmpeg.FFprobe;
import net.bramp.ffmpeg.probe.FFmpegChapter;
import net.bramp.ffmpeg.probe.FFmpegFormat;
Expand All @@ -15,6 +16,8 @@
import uk.yermak.audiobookconverter.fx.ConversionContext;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -220,7 +223,7 @@ static Collection<File> findPictures(File dir) {
}
}

static void searchForPosters(List<MediaInfo> media) {
static void searchForPosters(List<MediaInfo> media) throws FileNotFoundException {
Set<File> searchDirs = new HashSet<>();
media.forEach(mi -> searchDirs.add(new File(mi.getFileName()).getParentFile()));

Expand All @@ -234,7 +237,8 @@ static void searchForPosters(List<MediaInfo> media) {
//adding artificial limit of image count to address issue #153.
if (!pictures.isEmpty()) {
for (int i = 0; i < 10 && i < pictures.size(); i++) {
context.addPosterIfMissingWithDelay(new ArtWorkBean(Utils.tempCopy(pictures.get(i).getPath())));
// context.addPosterIfMissingWithDelay(new ArtWorkBean(Utils.tempCopy(pictures.get(i).getPath())));
context.addPosterIfMissingWithDelay(new ArtWorkImage(new Image(new FileInputStream(pictures.get(i).getPath()))));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ String optimize() throws InterruptedException, IOException {
optimize = new String[]{
Platform.FFMPEG,
"-i", tempFile,
"-map", "0:v",
"-map", "0:v?",
"-map", "0:a",
"-c", "copy",
"-progress", progressParser.getUri().toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package uk.yermak.audiobookconverter;

import javafx.scene.image.Image;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -47,7 +50,7 @@ public ArtWork call() throws Exception {
FFMediaLoader.logger.debug("ArtWork Out: {}", out);
FFMediaLoader.logger.error("ArtWork Error: {}", err);

ArtWorkBean artWorkBean = new ArtWorkBean(poster);
ArtWork artWorkBean = new ArtWorkImage(new Image(new FileInputStream(poster)));
javafx.application.Platform.runLater(() -> {
if (!conversionGroup.isOver() && !conversionGroup.isStarted() && !conversionGroup.isDetached()) {
AudiobookConverter.getContext().addPosterIfMissingWithDelay(artWorkBean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import java.awt.datatransfer.Transferable;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.*;
import java.lang.invoke.MethodHandles;

/**
Expand All @@ -43,20 +41,25 @@ private void initialize() {

@FXML
private void addImage(ActionEvent actionEvent) {
FileChooser fileChooser = new FileChooser();
String sourceFolder = AppSetting.getProperty("source.folder");
fileChooser.setInitialDirectory(Platform.getInitialDirecotory(sourceFolder));
fileChooser.setTitle("Select JPG or PNG file");
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("jpg", "*.jpg", "*.jpeg", "*.jfif"),
new FileChooser.ExtensionFilter("png", "*.png"),
new FileChooser.ExtensionFilter("bmp", "*.bmp"));

File file = fileChooser.showOpenDialog(AudiobookConverter.getEnv().getWindow());
logger.debug("Opened dialog for art image in folder: {}", sourceFolder);
if (file != null) {
imageList.getItems().add(new ArtWorkBean(Utils.tempCopy(file.getAbsolutePath())));
logger.info("Added art work from file: {}", file);
try {
FileChooser fileChooser = new FileChooser();
String sourceFolder = AppSetting.getProperty("source.folder");
fileChooser.setInitialDirectory(Platform.getInitialDirecotory(sourceFolder));
fileChooser.setTitle("Select JPG or PNG file");
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("jpg", "*.jpg", "*.jpeg", "*.jfif"),
new FileChooser.ExtensionFilter("png", "*.png"),
new FileChooser.ExtensionFilter("bmp", "*.bmp"));

File file = fileChooser.showOpenDialog(AudiobookConverter.getEnv().getWindow());
logger.debug("Opened dialog for art image in folder: {}", sourceFolder);
if (file != null) {
imageList.getItems().add(new ArtWorkImage(new Image(new FileInputStream(file.getAbsolutePath()))));
// imageList.getItems().add(new ArtWorkBean(Utils.tempCopy(file.getAbsolutePath())));
logger.info("Added art work from file: {}", file);
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -110,7 +113,12 @@ public void pasteImage(ActionEvent actionEvent) {
java.util.List<String> artFiles = (java.util.List<String>) transferable.getTransferData(DataFlavor.javaFileListFlavor);

artFiles.stream().filter(s -> ArrayUtils.contains(ArtWork.IMAGE_EXTENSIONS, FilenameUtils.getExtension(s))).forEach(f -> {
AudiobookConverter.getContext().addPosterIfMissingWithDelay(new ArtWorkBean(Utils.tempCopy(f)));
// AudiobookConverter.getContext().addPosterIfMissingWithDelay(new ArtWorkBean(Utils.tempCopy(f)));
try {
AudiobookConverter.getContext().addPosterIfMissingWithDelay(new ArtWorkImage(new Image(new FileInputStream(f))));
} catch (FileNotFoundException e) {
logger.error("failed to paste image", e);
}
});
}
}
Expand Down

0 comments on commit bac8f37

Please sign in to comment.