mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Add property for file exclusion
This commit is contained in:
13
README.md
13
README.md
@@ -21,12 +21,13 @@ Opening terminal / cmd in the directory of the jar and the config file and execu
|
|||||||
|
|
||||||
### Additional arameters
|
### Additional arameters
|
||||||
```properties
|
```properties
|
||||||
-c,--config path to config
|
-c,--config path to config
|
||||||
-h,--help "for help this is" - Yoda
|
-e,--exclude-directories <arg> Directories to exclude
|
||||||
-k,--forcedKeywords <arg> Additional keywords to identify forced tracks
|
-h,--help "for help this is" - Yoda
|
||||||
-l,--library <arg> path to library (Required)
|
-k,--forcedKeywords <arg> Additional keywords to identify forcedtracks"
|
||||||
-s,--safe-mode Test run (no files will be changes)
|
-l,--library <arg> path to library
|
||||||
-t,--threads <arg> thread count
|
-s,--safe-mode Test run (no files will be changes)
|
||||||
|
-t,--threads <arg> thread count
|
||||||
```
|
```
|
||||||
|
|
||||||
### config.yml example
|
### config.yml example
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ mkvtoolnixPath: C:\Program Files\MKVToolNix
|
|||||||
# Recommendations for data stored on HDDs, increase when using SSDs
|
# Recommendations for data stored on HDDs, increase when using SSDs
|
||||||
threads: 2
|
threads: 2
|
||||||
#forcedKeywords: ["forced", "signs"]
|
#forcedKeywords: ["forced", "signs"]
|
||||||
|
#exclude-directories:
|
||||||
|
# - "D:/Path/To/File.mkv"
|
||||||
|
# - "D:/Path/To/Directory"
|
||||||
config:
|
config:
|
||||||
1:
|
1:
|
||||||
audio: ger
|
audio: ger
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ import me.tongfei.progressbar.ProgressBarStyle;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class AttributeUpdaterKernel {
|
public class AttributeUpdaterKernel {
|
||||||
@@ -37,7 +39,13 @@ public class AttributeUpdaterKernel {
|
|||||||
statistic.startTimer();
|
statistic.startTimer();
|
||||||
|
|
||||||
try (ProgressBar progressBar = pbBuilder().build()) {
|
try (ProgressBar progressBar = pbBuilder().build()) {
|
||||||
List<File> files = collector.loadFiles(Config.getInstance().getLibraryPath());
|
List<File> excludedFiles = Config.getInstance().getExcludedDirectories().stream()
|
||||||
|
.map(collector::loadFiles)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
List<File> files = collector.loadFiles(Config.getInstance().getLibraryPath()).stream()
|
||||||
|
.filter(file -> !excludedFiles.contains(file))
|
||||||
|
.collect(Collectors.toList());
|
||||||
progressBar.maxHint(files.size());
|
progressBar.maxHint(files.size());
|
||||||
files.forEach(file -> executor.submit(() -> process(file, progressBar)));
|
files.forEach(file -> executor.submit(() -> process(file, progressBar)));
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
|
|
||||||
@Log4j2
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class MKVToolProperties {
|
|
||||||
private String mkvmergePath;
|
|
||||||
private String mkvpropeditPath;
|
|
||||||
|
|
||||||
private static MKVToolProperties instance = null;
|
|
||||||
|
|
||||||
private MKVToolProperties() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MKVToolProperties getInstance() {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = new MKVToolProperties();
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,6 +9,7 @@ import org.apache.commons.cli.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.*;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.*;
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf;
|
||||||
import static java.lang.Integer.parseInt;
|
import static java.lang.Integer.parseInt;
|
||||||
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@@ -20,14 +21,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void initConfig(String[] args) {
|
private static void initConfig(String[] args) {
|
||||||
Options options = new Options();
|
Options options = initOptions();
|
||||||
options.addOption("h", HELP.toString(), false, "\"for help this is\" - Yoda");
|
|
||||||
options.addRequiredOption("l", LIBRARY.toString(), true, "path to library");
|
|
||||||
options.addOption("c", CONFIG.toString(), false, "path to config");
|
|
||||||
options.addOption("t", THREADS.toString(), true, "thread count");
|
|
||||||
options.addOption("s", SAFE_MODE.toString(), false, "Test run (no files will be changes)");
|
|
||||||
options.addOption(create("k", FORCED_KEYWORDS.toString(), Option.UNLIMITED_VALUES, "Additional keywords to identify forced tracks"));
|
|
||||||
|
|
||||||
CommandLineParser parser = new DefaultParser();
|
CommandLineParser parser = new DefaultParser();
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
HelpFormatter formatter = new HelpFormatter();
|
||||||
try {
|
try {
|
||||||
@@ -39,12 +33,14 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Config config = Config.getInstance();
|
Config config = Config.getInstance();
|
||||||
config.loadConfig(cmd.getOptionValue(CONFIG.toString(), "config.yaml")); // use cmd input
|
config.loadConfig(cmd.getOptionValue(CONFIG_PATH.prop(), "config.yaml")); // use cmd input
|
||||||
config.setLibraryPath(cmd.getOptionValue("library"));
|
config.setLibraryPath(cmd.getOptionValue("library"));
|
||||||
config.setSafeMode(cmd.hasOption("safe-mode"));
|
config.setSafeMode(cmd.hasOption("safe-mode"));
|
||||||
if (cmd.hasOption("threads")) config.setThreadCount(parseInt(cmd.getOptionValue("threads")));
|
if (cmd.hasOption("threads")) config.setThreadCount(parseInt(cmd.getOptionValue("threads")));
|
||||||
if (cmd.hasOption(FORCED_KEYWORDS.toString()))
|
if (cmd.hasOption(FORCED_KEYWORDS.prop()))
|
||||||
config.getForcedKeywords().addAll(List.of(cmd.getOptionValues(FORCED_KEYWORDS.toString())));
|
config.getForcedKeywords().addAll(List.of(cmd.getOptionValues(FORCED_KEYWORDS.prop())));
|
||||||
|
if (cmd.hasOption(EXCLUDE_DIRECTORY.prop()))
|
||||||
|
config.getExcludedDirectories().addAll(List.of(cmd.getOptionValues(EXCLUDE_DIRECTORY.prop())));
|
||||||
config.isValid();
|
config.isValid();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
@@ -53,10 +49,15 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Option create(String opt, String longOpt, int args, String desc) {
|
private static Options initOptions() {
|
||||||
Option option = new Option(opt, desc);
|
Options options = new Options();
|
||||||
option.setLongOpt(longOpt);
|
options.addOption(optionOf(HELP, "h", false));
|
||||||
option.setArgs(args);
|
options.addOption(optionOf(LIBRARY, "l", true, true));
|
||||||
return option;
|
options.addOption(optionOf(CONFIG_PATH, "c", false));
|
||||||
|
options.addOption(optionOf(THREADS, "t", true));
|
||||||
|
options.addOption(optionOf(SAFE_MODE, "s", false));
|
||||||
|
options.addOption(optionOf(FORCED_KEYWORDS, "k", Option.UNLIMITED_VALUES, false));
|
||||||
|
options.addOption(optionOf(EXCLUDE_DIRECTORY, "e", Option.UNLIMITED_VALUES, false));
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class Config {
|
|||||||
private List<AttributeConfig> attributeConfig;
|
private List<AttributeConfig> attributeConfig;
|
||||||
private int threadCount;
|
private int threadCount;
|
||||||
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs"));
|
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs"));
|
||||||
|
private Set<String> excludedDirectories = new HashSet<>();
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private String mkvtoolnixPath;
|
private String mkvtoolnixPath;
|
||||||
private String libraryPath;
|
private String libraryPath;
|
||||||
@@ -73,6 +74,7 @@ public class Config {
|
|||||||
setMkvtoolnixPath(loadMkvToolNixPath(config));
|
setMkvtoolnixPath(loadMkvToolNixPath(config));
|
||||||
setWindows(System.getProperty("os.name").toLowerCase().contains("windows"));
|
setWindows(System.getProperty("os.name").toLowerCase().contains("windows"));
|
||||||
getForcedKeywords().addAll(loadForcedKeywords(config));
|
getForcedKeywords().addAll(loadForcedKeywords(config));
|
||||||
|
getExcludedDirectories().addAll(loadExcludeDirectories(config));
|
||||||
} catch (YamlInvalidContentException | YamlKeyNotFoundException | IOException e) {
|
} catch (YamlInvalidContentException | YamlKeyNotFoundException | IOException e) {
|
||||||
log.fatal("Config could not be loaded: {}", e.getMessage());
|
log.fatal("Config could not be loaded: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -90,18 +92,22 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int loadThreadCount(YAML config) throws YamlKeyNotFoundException {
|
private int loadThreadCount(YAML config) throws YamlKeyNotFoundException {
|
||||||
return config.isSet(ConfigProperty.THREADS.toString())
|
return config.isSet(ConfigProperty.THREADS.prop())
|
||||||
? Integer.parseInt(config.getString(ConfigProperty.THREADS.toString()))
|
? Integer.parseInt(config.getString(ConfigProperty.THREADS.prop()))
|
||||||
: 1;
|
: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> loadForcedKeywords(YAML config) {
|
private List<String> loadForcedKeywords(YAML config) {
|
||||||
return config.getStringList(ConfigProperty.FORCED_KEYWORDS.toString(), new ArrayList<>());
|
return config.getStringList(ConfigProperty.FORCED_KEYWORDS.prop(), new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> loadExcludeDirectories(YAML config) {
|
||||||
|
return config.getStringList(ConfigProperty.EXCLUDE_DIRECTORY.prop(), new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String loadMkvToolNixPath(YAML config) throws YamlKeyNotFoundException {
|
private String loadMkvToolNixPath(YAML config) throws YamlKeyNotFoundException {
|
||||||
return config.isSet(MKV_TOOL_NIX.toString())
|
return config.isSet(MKV_TOOL_NIX.prop())
|
||||||
? config.getString(MKV_TOOL_NIX.toString())
|
? config.getString(MKV_TOOL_NIX.prop())
|
||||||
: defaultMkvToolNixPath();
|
: defaultMkvToolNixPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class MkvFileCollector implements FileCollector {
|
|||||||
public List<File> loadFiles(String path) {
|
public List<File> loadFiles(String path) {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (file.isFile() && file.getAbsolutePath().endsWith(".mkv")) {
|
if (file.isFile() && file.getAbsolutePath().endsWith(".mkv")) {
|
||||||
return new ArrayList<File>() {{
|
return new ArrayList<>() {{
|
||||||
add(file);
|
add(file);
|
||||||
}};
|
}};
|
||||||
} else if (file.isDirectory()) {
|
} else if (file.isDirectory()) {
|
||||||
|
|||||||
@@ -1,22 +1,28 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
|
||||||
|
|
||||||
public enum ConfigProperty {
|
public enum ConfigProperty {
|
||||||
MKV_TOOL_NIX("mkvtoolnixPath"),
|
MKV_TOOL_NIX("mkvtoolnixPath", "Path to mkv tool nix installation"),
|
||||||
THREADS("threads"),
|
THREADS("threads", "thread count"),
|
||||||
FORCED_KEYWORDS("forcedKeywords"),
|
FORCED_KEYWORDS("forcedKeywords", "Additional keywords to identify forced tracks\""),
|
||||||
CONFIG("config"),
|
CONFIG_PATH("config", "path to config"),
|
||||||
LIBRARY("library"),
|
LIBRARY("library", "path to library"),
|
||||||
SAFE_MODE("safe-mode"),
|
SAFE_MODE("safe-mode", "Test run (no files will be changes)"),
|
||||||
HELP("help");
|
HELP("help", "\"for help this is\" - Yoda"),
|
||||||
|
EXCLUDE_DIRECTORY("exclude-directories", "Directories to exclude");
|
||||||
|
|
||||||
private final String property;
|
private final String property;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
ConfigProperty(String property) {
|
ConfigProperty(String property, String description) {
|
||||||
this.property = property;
|
this.property = property;
|
||||||
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public String desc() {
|
||||||
public String toString() {
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String prop() {
|
||||||
return property;
|
return property;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
||||||
|
import org.apache.commons.cli.Option;
|
||||||
|
|
||||||
|
public class CommandLineOptionsUtil {
|
||||||
|
public static Option optionOf(ConfigProperty property, String opt, boolean hasArg) {
|
||||||
|
return optionOf(property, opt, hasArg ? 1 : 0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Option optionOf(ConfigProperty property, String opt, boolean hasArg, boolean required) {
|
||||||
|
return optionOf(property, opt, hasArg ? 1 : 0, required);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Option optionOf(ConfigProperty property, String opt, int args, boolean required) {
|
||||||
|
Option option = new Option(opt, property.desc());
|
||||||
|
option.setArgs(args);
|
||||||
|
option.setLongOpt(property.prop());
|
||||||
|
option.setRequired(required);
|
||||||
|
return option;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user