Adds option for overwriting original files
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
This commit is contained in:
parent
972691db76
commit
87f5743a24
@ -62,6 +62,11 @@ public class ConfigKey<T> {
|
||||
*/
|
||||
public static final ConfigKey<Boolean> COPY_ATTACHED_IMAGES = createKey("copy-attached-images", Boolean.class, false);
|
||||
|
||||
/**
|
||||
* The configuration key for whether to overwrite the original file when converting
|
||||
*/
|
||||
public static final ConfigKey<Boolean> OVERWRITE_FILES = createKey("overwrite-files", Boolean.class, false);
|
||||
|
||||
private final String configKey;
|
||||
private final T defaultValue;
|
||||
private final Class<T> type;
|
||||
|
@ -23,6 +23,7 @@ public class Configuration {
|
||||
private MinimalSubtitlePreference minimalSubtitlePreference;
|
||||
private boolean deInterlaceVideo;
|
||||
private boolean copyAttachedImages;
|
||||
private boolean overwriteFiles;
|
||||
|
||||
/**
|
||||
* Instantiates and loads a new configuration
|
||||
@ -57,6 +58,7 @@ public class Configuration {
|
||||
animeSubtitleLanguages = ConfigHelper.asStringList(configHandler.getValue(ConfigKey.SUBTITLE_LANGUAGES_ANIME));
|
||||
deInterlaceVideo = ConfigHelper.asBoolean(configHandler.getValue(ConfigKey.DE_INTERLACE_VIDEO));
|
||||
copyAttachedImages = ConfigHelper.asBoolean(configHandler.getValue(ConfigKey.COPY_ATTACHED_IMAGES));
|
||||
overwriteFiles = ConfigHelper.asBoolean(configHandler.getValue(ConfigKey.OVERWRITE_FILES));
|
||||
try {
|
||||
minimalSubtitlePreference = MinimalSubtitlePreference.valueOf(String.valueOf(configHandler.getValue(
|
||||
ConfigKey.MINIMAL_SUBTITLE_PREFERENCE)));
|
||||
@ -171,4 +173,13 @@ public class Configuration {
|
||||
return this.copyAttachedImages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the original files should be overwritten after conversion has been finished
|
||||
*
|
||||
* @return <p>True if the original file should be overwritten</p>
|
||||
*/
|
||||
public boolean overwriteFiles() {
|
||||
return this.overwriteFiles;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -85,6 +85,16 @@ public abstract class AbstractConverter implements Converter {
|
||||
int exitCode = FFMpegHelper.runProcess(processBuilder, file.getParentFile(), "\n", true).exitCode();
|
||||
if (exitCode != 0) {
|
||||
handleError(ffMpegCommand, file, newPath);
|
||||
} else if (FFMpegConvert.getConfiguration().overwriteFiles() &&
|
||||
FileUtil.getExtension(newPath).equalsIgnoreCase(FileUtil.getExtension(file.getPath()))) {
|
||||
File outputFile = new File(newPath);
|
||||
if (!file.delete()) {
|
||||
OutputUtil.println("Unable to remove original file.");
|
||||
System.exit(1);
|
||||
} else if (!outputFile.renameTo(file)) {
|
||||
OutputUtil.println("Failed to re-name file after conversion!");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,13 @@ public enum StreamType {
|
||||
*/
|
||||
COVER_IMAGE,
|
||||
|
||||
/**
|
||||
* Binary data
|
||||
*
|
||||
* <p>Binary data streams only cause problems, as they cannot, for example, be included in an MKV file.</p>
|
||||
*/
|
||||
DATA,
|
||||
|
||||
/**
|
||||
* None of the above
|
||||
*/
|
||||
|
@ -314,6 +314,8 @@ public final class FFMpegHelper {
|
||||
parsedStreams.add(new OtherStream(streamInfo, 0, true));
|
||||
}
|
||||
}
|
||||
case DATA -> OutputUtil.print("A binary stream was found. Those are ignored they will generally " +
|
||||
"cause the conversion to fail.");
|
||||
}
|
||||
}
|
||||
return parsedStreams;
|
||||
@ -342,6 +344,8 @@ public final class FFMpegHelper {
|
||||
return StreamType.AUDIO;
|
||||
case "subtitle":
|
||||
return StreamType.SUBTITLE;
|
||||
case "data":
|
||||
return StreamType.DATA;
|
||||
default:
|
||||
return StreamType.OTHER;
|
||||
}
|
||||
|
@ -20,3 +20,5 @@ minimal-subtitle-preference=AVOID
|
||||
de-interlace-video=false
|
||||
# Whether to copy attached cover images. FFMpeg sometimes throws errors when including attached images.
|
||||
copy-attached-images=false
|
||||
# Whether to overwrite original files after conversion. Note that if enabled, the original files are lost, which is troublesome if the conversion arguments are incorrect.
|
||||
overwrite-files=false
|
Loading…
Reference in New Issue
Block a user