mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 10:05:58 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3205969d3b | |||
| d24aedb0af | |||
| b86c7b98a5 | |||
|
|
69c192c08b |
@@ -12,13 +12,11 @@ A streamlined solution for managing MKV files, this program leverages MKVToolNix
|
|||||||
## Execution
|
## Execution
|
||||||
### Minimal usage
|
### Minimal usage
|
||||||
Portable: `java -jar mkvaudiosubtitlechanger-<version>.jar --library "X:/Files" --attribute-config eng:ger eng:OFF`
|
Portable: `java -jar mkvaudiosubtitlechanger-<version>.jar --library "X:/Files" --attribute-config eng:ger eng:OFF`
|
||||||
|
Windows & Linux (installed): `mkvaudiosubtitlechanger --library "X:/Files" --attribute-config eng:ger eng:OFF`
|
||||||
Windows (installed): `mkvaudiosubtitlechanger.jar --library "X:/Files" --attribute-config eng:ger eng:OFF`
|
|
||||||
|
|
||||||
### Safe usage (best for testing before applying to whole library)
|
### Safe usage (best for testing before applying to whole library)
|
||||||
Portable: `java -jar mkvaudiosubtitlechanger-<version>.jar --library "X:/Files" --attribute-config eng:ger eng:OFF --safe-mode`
|
Portable: `java -jar mkvaudiosubtitlechanger-<version>.jar --library "X:/Files" --attribute-config eng:ger eng:OFF --safe-mode`
|
||||||
|
Windows & Linux (installed): `mkvaudiosubtitlechanger --library "X:/Files" --attribute-config eng:ger eng:OFF --safe-mode`
|
||||||
Windows (installed): `mkvaudiosubtitlechanger.jar --library "X:/Files" --attribute-config eng:ger eng:OFF --safe-mode`
|
|
||||||
|
|
||||||
**Attribute-config must be entered in pairs: `audio:subtitle`; Example: `jpn:eng`. More about this topic
|
**Attribute-config must be entered in pairs: `audio:subtitle`; Example: `jpn:eng`. More about this topic
|
||||||
[here](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/Attribute-Config).**
|
[here](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/Attribute-Config).**
|
||||||
@@ -33,6 +31,7 @@ Windows (installed): `mkvaudiosubtitlechanger.jar --library "X:/Files" --attribu
|
|||||||
Keywords to identify commentary tracks (Defaults will be overwritten; Default: commentary, director)
|
Keywords to identify commentary tracks (Defaults will be overwritten; Default: commentary, director)
|
||||||
-d, --filter-date=<filterDate>
|
-d, --filter-date=<filterDate>
|
||||||
only consider files created newer than entered date (format: "dd.MM.yyyy-HH:mm:ss")
|
only consider files created newer than entered date (format: "dd.MM.yyyy-HH:mm:ss")
|
||||||
|
--debug Enable debug logging
|
||||||
-e, --excluded-directory=<excludedDirectories>...
|
-e, --excluded-directory=<excludedDirectories>...
|
||||||
Directories to be excluded, combines with config file
|
Directories to be excluded, combines with config file
|
||||||
--forced-keywords=<forcedKeywords>[, <forcedKeywords>...]...
|
--forced-keywords=<forcedKeywords>[, <forcedKeywords>...]...
|
||||||
|
|||||||
5
pom.xml
5
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>at.pcgamingfreaks</groupId>
|
<groupId>at.pcgamingfreaks</groupId>
|
||||||
<artifactId>MKVAudioSubtitleChanger</artifactId>
|
<artifactId>MKVAudioSubtitleChanger</artifactId>
|
||||||
<version>4.0.0</version>
|
<version>4.0.2</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<mainClass>at.pcgamingfreaks.mkvaudiosubtitlechanger.Main</mainClass>
|
<mainClass>at.pcgamingfreaks.mkvaudiosubtitlechanger.Main</mainClass>
|
||||||
@@ -27,8 +27,7 @@
|
|||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>log4j2.yml</include>
|
<include>log4j2.yaml</include>
|
||||||
<include>log4j2-debug.yml</include>
|
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import jakarta.validation.Validation;
|
|||||||
import jakarta.validation.Validator;
|
import jakarta.validation.Validator;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
|
import org.apache.logging.log4j.core.config.Configurator;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -39,6 +41,9 @@ public class Main implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (config.isDebug()) {
|
||||||
|
Configurator.setRootLevel(Level.DEBUG);
|
||||||
|
}
|
||||||
validate();
|
validate();
|
||||||
Config.setInstance(config);
|
Config.setInstance(config);
|
||||||
AttributeUpdaterKernel kernel = Config.getInstance().getCoherent() != null
|
AttributeUpdaterKernel kernel = Config.getInstance().getCoherent() != null
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ public class Config {
|
|||||||
description = "Keywords to prefer specific subtitle tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})")
|
description = "Keywords to prefer specific subtitle tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})")
|
||||||
private Set<String> preferredSubtitles;
|
private Set<String> preferredSubtitles;
|
||||||
|
|
||||||
|
@CommandLine.Option(names = {"--debug"}, description = "Enable debug logging")
|
||||||
|
private boolean debug;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-l", "--library"}, required = true, description = "path to library")
|
@CommandLine.Option(names = {"-l", "--library"}, required = true, description = "path to library")
|
||||||
public void setLibraryPath(File libraryPath) {
|
public void setLibraryPath(File libraryPath) {
|
||||||
if (!libraryPath.exists()) throw new CommandLine.ParameterException(spec.commandLine(), "Path does not exist: " + libraryPath.getAbsolutePath());
|
if (!libraryPath.exists()) throw new CommandLine.ParameterException(spec.commandLine(), "Path does not exist: " + libraryPath.getAbsolutePath());
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class DateValidator extends ConfigValidator<Date> {
|
|||||||
YAML yaml = new YAML(lastExecutionFile);
|
YAML yaml = new YAML(lastExecutionFile);
|
||||||
return parse(yaml.getString(Config.getInstance().getNormalizedLibraryPath(), DateUtils.convert(DEFAULT_DATE)));
|
return parse(yaml.getString(Config.getInstance().getNormalizedLibraryPath(), DateUtils.convert(DEFAULT_DATE)));
|
||||||
} catch (YamlInvalidContentException | IOException e) {
|
} catch (YamlInvalidContentException | IOException e) {
|
||||||
log.error("Couldn't open last-execution.properties");
|
log.error("Couldn't open last-execution.properties", e);
|
||||||
return INVALID_DATE;
|
return INVALID_DATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class FileFilter {
|
|||||||
BasicFileAttributes attributes = Files.readAttributes(pathName.toPath(), BasicFileAttributes.class);
|
BasicFileAttributes attributes = Files.readAttributes(pathName.toPath(), BasicFileAttributes.class);
|
||||||
return isNewer(DateUtils.convert(attributes.creationTime().toMillis()));
|
return isNewer(DateUtils.convert(attributes.creationTime().toMillis()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.warn("File attributes could not be read.", e);
|
log.warn("File attributes could not be read", e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
file.getAbsolutePath()
|
file.getAbsolutePath()
|
||||||
};
|
};
|
||||||
|
|
||||||
log.debug("{}", String.join(" ", command));
|
log.debug("Executing '{}': {}", file.getAbsolutePath(), String.join(" ", command));
|
||||||
InputStream inputStream = Runtime.getRuntime().exec(command)
|
InputStream inputStream = Runtime.getRuntime().exec(command)
|
||||||
.getInputStream();
|
.getInputStream();
|
||||||
jsonMap = mapper.readValue(inputStream, Map.class);
|
jsonMap = mapper.readValue(inputStream, Map.class);
|
||||||
@@ -69,7 +69,7 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug(fileAttributes.toString());
|
log.debug("File attributes of '{}': {}", file.getAbsolutePath(), fileAttributes.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("File could not be found or loaded: ", e);
|
log.error("File could not be found or loaded: ", e);
|
||||||
System.out.println("File could not be found or loaded: " + file.getAbsolutePath());
|
System.out.println("File could not be found or loaded: " + file.getAbsolutePath());
|
||||||
@@ -149,46 +149,50 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(File file, FileInfoDto fileInfo) throws IOException, MkvToolNixException {
|
public void update(File file, FileInfoDto fileInfo) throws IOException, MkvToolNixException {
|
||||||
StringBuilder sb = new StringBuilder();
|
List<String> command = new ArrayList<>();
|
||||||
sb.append(format("\"%s\" ", Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT)));
|
command.add(Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT));
|
||||||
sb.append(format("\"%s\" ", file.getAbsolutePath()));
|
command.add(String.format(file.getAbsolutePath()));
|
||||||
|
|
||||||
if (fileInfo.isAudioDifferent()) {
|
if (fileInfo.isAudioDifferent()) {
|
||||||
if (fileInfo.getExistingDefaultAudioLanes() != null && !fileInfo.getExistingDefaultAudioLanes().isEmpty()) {
|
if (fileInfo.getExistingDefaultAudioLanes() != null && !fileInfo.getExistingDefaultAudioLanes().isEmpty()) {
|
||||||
for (FileAttribute track : fileInfo.getExistingDefaultAudioLanes()) {
|
for (FileAttribute track : fileInfo.getExistingDefaultAudioLanes()) {
|
||||||
sb.append(format(DISABLE_DEFAULT_TRACK, track.getId()));
|
command.addAll(format(DISABLE_DEFAULT_TRACK, track.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append(format(ENABLE_DEFAULT_TRACK, fileInfo.getDesiredDefaultAudioLane().getId()));
|
command.addAll(format(ENABLE_DEFAULT_TRACK, fileInfo.getDesiredDefaultAudioLane().getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileInfo.getExistingForcedAudioLanes().isEmpty()) {
|
if (!fileInfo.getExistingForcedAudioLanes().isEmpty()) {
|
||||||
for (FileAttribute track : fileInfo.getExistingForcedAudioLanes()) {
|
for (FileAttribute track : fileInfo.getExistingForcedAudioLanes()) {
|
||||||
sb.append(format(DISABLE_FORCED_TRACK, track.getId()));
|
command.addAll(format(DISABLE_FORCED_TRACK, track.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileInfo.isSubtitleDifferent()) {
|
if (fileInfo.isSubtitleDifferent()) {
|
||||||
if (fileInfo.getExistingDefaultSubtitleLanes() != null && !fileInfo.getExistingDefaultSubtitleLanes().isEmpty()) {
|
if (fileInfo.getExistingDefaultSubtitleLanes() != null && !fileInfo.getExistingDefaultSubtitleLanes().isEmpty()) {
|
||||||
for (FileAttribute track : fileInfo.getExistingDefaultSubtitleLanes()) {
|
for (FileAttribute track : fileInfo.getExistingDefaultSubtitleLanes()) {
|
||||||
sb.append(format(DISABLE_DEFAULT_TRACK, track.getId()));
|
command.addAll(format(DISABLE_DEFAULT_TRACK, track.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fileInfo.getDesiredDefaultSubtitleLane() != null) {
|
if (fileInfo.getDesiredDefaultSubtitleLane() != null) {
|
||||||
sb.append(format(ENABLE_DEFAULT_TRACK, fileInfo.getDesiredDefaultSubtitleLane().getId()));
|
command.addAll(format(ENABLE_DEFAULT_TRACK, fileInfo.getDesiredDefaultSubtitleLane().getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileInfo.areForcedTracksDifferent()) {
|
if (fileInfo.areForcedTracksDifferent()) {
|
||||||
for (FileAttribute attribute : fileInfo.getDesiredForcedSubtitleLanes()) {
|
for (FileAttribute track : fileInfo.getDesiredForcedSubtitleLanes()) {
|
||||||
sb.append(format(ENABLE_FORCED_TRACK, attribute.getId()));
|
command.addAll(format(ENABLE_FORCED_TRACK, track.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug(sb.toString());
|
log.debug("Executing '{}'", String.join(" ", command));
|
||||||
InputStream inputstream = Runtime.getRuntime().exec(sb.toString()).getInputStream();
|
InputStream inputstream = Runtime.getRuntime().exec(command.toArray(new String[0])).getInputStream();
|
||||||
String output = IOUtils.toString(new InputStreamReader(inputstream));
|
String output = IOUtils.toString(new InputStreamReader(inputstream));
|
||||||
log.debug(output);
|
log.debug("Result: {}", output);
|
||||||
if (output.contains("Error")) throw new MkvToolNixException(output);
|
if (output.contains("Error")) throw new MkvToolNixException(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> format(String format, Object... args) {
|
||||||
|
return Arrays.asList(String.format(format, args).split(" "));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,10 +148,10 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
try {
|
try {
|
||||||
processor.update(fileInfo.getFile(), fileInfo);
|
processor.update(fileInfo.getFile(), fileInfo);
|
||||||
statistic.success();
|
statistic.success();
|
||||||
log.info("Updated {}", fileInfo.getFile().getAbsolutePath());
|
log.info("Commited {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getAbsolutePath());
|
||||||
} catch (IOException | MkvToolNixException e) {
|
} catch (IOException | MkvToolNixException e) {
|
||||||
statistic.failedChanging();
|
statistic.failedChanging();
|
||||||
log.warn("File couldn't be updated: '{}', Error: {}", fileInfo.getFile().getAbsoluteFile(), e.getMessage());
|
log.warn("Couldn't commit {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getAbsoluteFile(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
|||||||
|
|
||||||
if (fileInfos.stream().allMatch(elem -> ("OFF".equals(config.getSubtitleLanguage()) || elem.getDesiredDefaultSubtitleLane() != null)
|
if (fileInfos.stream().allMatch(elem -> ("OFF".equals(config.getSubtitleLanguage()) || elem.getDesiredDefaultSubtitleLane() != null)
|
||||||
&& elem.getDesiredDefaultAudioLane() != null)) {
|
&& elem.getDesiredDefaultAudioLane() != null)) {
|
||||||
log.info("Found {}/{} match for {}", config.getAudioLanguage(), config.getSubtitleLanguage(), file.getAbsolutePath());
|
log.info("Found {} match for {}", config.toStringShort(), file.getAbsolutePath());
|
||||||
fileInfos.forEach(this::updateFile);
|
fileInfos.forEach(this::updateFile);
|
||||||
return; // match found, end process here
|
return; // match found, end process here
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ public class AttributeConfig {
|
|||||||
return Objects.hash(audioLanguage, subtitleLanguage);
|
return Objects.hash(audioLanguage, subtitleLanguage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toStringShort() {
|
||||||
|
return audioLanguage + ":" + subtitleLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "AttributeConfig{"
|
return "AttributeConfig{"
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ Configuration:
|
|||||||
fileName: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/application.log
|
fileName: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/application.log
|
||||||
filePattern: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
filePattern: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||||
PatternLayout:
|
PatternLayout:
|
||||||
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
|
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
|
||||||
ThresholdFilter:
|
ThresholdFilter:
|
||||||
level: info
|
level: debug
|
||||||
Policies:
|
Policies:
|
||||||
OnStartupTriggeringPolicy:
|
OnStartupTriggeringPolicy:
|
||||||
minSize: 0
|
minSize: 0
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Configuration:
|
|||||||
Console:
|
Console:
|
||||||
name: Console_Out
|
name: Console_Out
|
||||||
PatternLayout:
|
PatternLayout:
|
||||||
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
|
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
|
||||||
ThresholdFilter:
|
ThresholdFilter:
|
||||||
level: debug
|
level: debug
|
||||||
RollingFile:
|
RollingFile:
|
||||||
@@ -12,7 +12,7 @@ Configuration:
|
|||||||
fileName: logs/application.log
|
fileName: logs/application.log
|
||||||
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||||
PatternLayout:
|
PatternLayout:
|
||||||
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
|
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
|
||||||
ThresholdFilter:
|
ThresholdFilter:
|
||||||
level: debug
|
level: debug
|
||||||
Policies:
|
Policies:
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ Configuration:
|
|||||||
fileName: ${sys:user.home}/AppData/Roaming/MKVAudioSubtitleChanger/logs/application.log
|
fileName: ${sys:user.home}/AppData/Roaming/MKVAudioSubtitleChanger/logs/application.log
|
||||||
filePattern: ${sys:user.home}/AppData/Roaming/MKVAudioSubtitleChanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
filePattern: ${sys:user.home}/AppData/Roaming/MKVAudioSubtitleChanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||||
PatternLayout:
|
PatternLayout:
|
||||||
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
|
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
|
||||||
ThresholdFilter:
|
ThresholdFilter:
|
||||||
level: info
|
level: debug
|
||||||
Policies:
|
Policies:
|
||||||
OnStartupTriggeringPolicy:
|
OnStartupTriggeringPolicy:
|
||||||
minSize: 0
|
minSize: 0
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ Configuration:
|
|||||||
fileName: logs/application.log
|
fileName: logs/application.log
|
||||||
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||||
PatternLayout:
|
PatternLayout:
|
||||||
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
|
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
|
||||||
ThresholdFilter:
|
ThresholdFilter:
|
||||||
level: info
|
level: debug
|
||||||
Policies:
|
Policies:
|
||||||
OnStartupTriggeringPolicy:
|
OnStartupTriggeringPolicy:
|
||||||
minSize: 0
|
minSize: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user