12 Commits

Author SHA1 Message Date
3205969d3b Update readme 2025-05-02 03:33:14 +02:00
d24aedb0af Fix mkvpropedit call & improve logging 2025-05-02 03:27:24 +02:00
b86c7b98a5 Fix logging for portable 2025-05-01 22:55:11 +02:00
Michael
69c192c08b Update README.md 2025-02-22 20:37:04 +01:00
Michael
7dd01234b6 Merge pull request #57 from RatzzFatzz/dev
Fix execution on linux
2025-02-18 19:23:08 +01:00
RatzzFatzz
8f38abcf3a Fix execution on linux 2025-02-18 19:15:02 +01:00
Michael
fc4e80ead0 Merge pull request #55 from RatzzFatzz/dev
Release v4.0
2025-02-06 22:27:06 +01:00
RatzzFatzz
e81b06f6fa Improve logging 2025-02-06 00:18:49 +01:00
RatzzFatzz
dc770c9325 Fix file count if no info was found 2025-02-06 00:00:28 +01:00
RatzzFatzz
471255a09b Fix windows installer build 2025-02-05 23:32:01 +01:00
RatzzFatzz
9c8315aec7 Remove config-template 2025-02-05 23:13:54 +01:00
Michael
a075dfb27c Remove forced audio tracks & minor refactoring 2024-05-27 22:31:34 +02:00
19 changed files with 77 additions and 94 deletions

View File

@@ -92,11 +92,11 @@ jobs:
with:
timezoneWindows: "Berlin Standard Time"
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4.7.0
with:
distribution: temurin
java-version: 17
java-version: 21
- name: Setup workspace
run: mkdir artifacts

View File

@@ -12,13 +12,11 @@ A streamlined solution for managing MKV files, this program leverages MKVToolNix
## Execution
### Minimal usage
Portable: `java -jar mkvaudiosubtitlechanger-<version>.jar --library "X:/Files" --attribute-config eng:ger eng:OFF`
Windows (installed): `mkvaudiosubtitlechanger.jar --library "X:/Files" --attribute-config eng:ger eng:OFF`
Windows & Linux (installed): `mkvaudiosubtitlechanger --library "X:/Files" --attribute-config eng:ger eng:OFF`
### 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`
Windows (installed): `mkvaudiosubtitlechanger.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`
**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).**
@@ -33,6 +31,7 @@ Windows (installed): `mkvaudiosubtitlechanger.jar --library "X:/Files" --attribu
Keywords to identify commentary tracks (Defaults will be overwritten; Default: commentary, director)
-d, --filter-date=<filterDate>
only consider files created newer than entered date (format: "dd.MM.yyyy-HH:mm:ss")
--debug Enable debug logging
-e, --excluded-directory=<excludedDirectories>...
Directories to be excluded, combines with config file
--forced-keywords=<forcedKeywords>[, <forcedKeywords>...]...

View File

@@ -1,34 +0,0 @@
mkvtoolnix: C:\Program Files\MKVToolNix
library: X:/Files
attribute-config:
1:
audio: ger
subtitle: OFF
2:
audio: eng
subtitle: ger
# Recommendations for data stored on HDDs, increase when using SSDs
#threads: 2
#forced-keywords: ["forced", "signs"]
#commentary-keywords: ["commentary", "director"]
#preferred-subtitles: ["unstyled"]
#exclude-directories:
# - "D:/Path/To/File.mkv"
# - "D:/Path/To/Directory"
# If pattern is negated, can be used to exclude files
#include-pattern: "regex"
# Only files newer than
#filter-date: 20.03.2021-10:11:12
safe-mode:
#coherent:
#force-coherent:
#only-new-files:

View File

@@ -14,10 +14,6 @@
<destName>${project.artifactId}.jar</destName>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>${project.basedir}/config-template.yaml</source>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source></source>
</file>

View File

@@ -6,7 +6,7 @@
<groupId>at.pcgamingfreaks</groupId>
<artifactId>MKVAudioSubtitleChanger</artifactId>
<version>4.0.0</version>
<version>4.0.2</version>
<properties>
<mainClass>at.pcgamingfreaks.mkvaudiosubtitlechanger.Main</mainClass>
@@ -27,8 +27,7 @@
<resource>
<directory>src/main/resources</directory>
<includes>
<include>log4j2.yml</include>
<include>log4j2-debug.yml</include>
<include>log4j2.yaml</include>
</includes>
</resource>
</resources>

View File

@@ -12,6 +12,8 @@ import jakarta.validation.Validation;
import jakarta.validation.Validator;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import picocli.CommandLine;
import java.util.Set;
@@ -39,6 +41,9 @@ public class Main implements Runnable {
@Override
public void run() {
if (config.isDebug()) {
Configurator.setRootLevel(Level.DEBUG);
}
validate();
Config.setInstance(config);
AttributeUpdaterKernel kernel = Config.getInstance().getCoherent() != null

View File

@@ -72,6 +72,9 @@ public class Config {
description = "Keywords to prefer specific subtitle tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})")
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")
public void setLibraryPath(File libraryPath) {
if (!libraryPath.exists()) throw new CommandLine.ParameterException(spec.commandLine(), "Path does not exist: " + libraryPath.getAbsolutePath());

View File

@@ -40,7 +40,7 @@ public class DateValidator extends ConfigValidator<Date> {
YAML yaml = new YAML(lastExecutionFile);
return parse(yaml.getString(Config.getInstance().getNormalizedLibraryPath(), DateUtils.convert(DEFAULT_DATE)));
} catch (YamlInvalidContentException | IOException e) {
log.error("Couldn't open last-execution.properties");
log.error("Couldn't open last-execution.properties", e);
return INVALID_DATE;
}
}

View File

@@ -41,7 +41,7 @@ public class FileFilter {
BasicFileAttributes attributes = Files.readAttributes(pathName.toPath(), BasicFileAttributes.class);
return isNewer(DateUtils.convert(attributes.creationTime().toMillis()));
} catch (IOException e) {
log.warn("File attributes could not be read.", e);
log.warn("File attributes could not be read", e);
}
return true;
}

View File

@@ -28,10 +28,10 @@ public class MkvFileProcessor implements FileProcessor {
private static final SubtitleTrackComparator subtitleTrackComparator =
new SubtitleTrackComparator(Config.getInstance().getPreferredSubtitles().toArray(new String[0]));
private static final String DISABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=0 ";
private static final String ENABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=1 ";
private static final String DISABLE_FORCED_TRACK = "--edit track:%s --set flag-forced=0 ";
private static final String ENABLE_FORCED_TRACK = "--edit track:%s --set flag-forced=1 ";
private static final String DISABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=0";
private static final String ENABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=1";
private static final String DISABLE_FORCED_TRACK = "--edit track:%s --set flag-forced=0";
private static final String ENABLE_FORCED_TRACK = "--edit track:%s --set flag-forced=1";
@SuppressWarnings("unchecked")
@Override
@@ -39,16 +39,17 @@ public class MkvFileProcessor implements FileProcessor {
Map<String, Object> jsonMap;
List<FileAttribute> fileAttributes = new ArrayList<>();
try {
String command = format("\"%s\"", Config.getInstance().getPathFor(MkvToolNix.MKV_MERGE));
String[] arguments = new String[]{
command,
String[] command = new String[]{
Config.getInstance().getPathFor(MkvToolNix.MKV_MERGE),
"--identify",
"--identification-format",
"json",
file.getAbsoluteFile().toString()
file.getAbsolutePath()
};
InputStream inputStream = Runtime.getRuntime().exec(arguments).getInputStream();
log.debug("Executing '{}': {}", file.getAbsolutePath(), String.join(" ", command));
InputStream inputStream = Runtime.getRuntime().exec(command)
.getInputStream();
jsonMap = mapper.readValue(inputStream, Map.class);
List<Map<String, Object>> tracks = (List<Map<String, Object>>) jsonMap.get("tracks");
if (tracks == null) {
@@ -68,7 +69,7 @@ public class MkvFileProcessor implements FileProcessor {
}
}
log.debug(fileAttributes.toString());
log.debug("File attributes of '{}': {}", file.getAbsolutePath(), fileAttributes.toString());
} catch (IOException e) {
log.error("File could not be found or loaded: ", e);
System.out.println("File could not be found or loaded: " + file.getAbsolutePath());
@@ -148,46 +149,50 @@ public class MkvFileProcessor implements FileProcessor {
*/
@Override
public void update(File file, FileInfoDto fileInfo) throws IOException, MkvToolNixException {
StringBuilder sb = new StringBuilder();
sb.append(format("\"%s\" ", Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT)));
sb.append(format("\"%s\" ", file.getAbsolutePath()));
List<String> command = new ArrayList<>();
command.add(Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT));
command.add(String.format(file.getAbsolutePath()));
if (fileInfo.isAudioDifferent()) {
if (fileInfo.getExistingDefaultAudioLanes() != null && !fileInfo.getExistingDefaultAudioLanes().isEmpty()) {
for (FileAttribute track: fileInfo.getExistingDefaultAudioLanes()) {
sb.append(format(DISABLE_DEFAULT_TRACK, track.getId()));
for (FileAttribute track : fileInfo.getExistingDefaultAudioLanes()) {
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()) {
for (FileAttribute track: fileInfo.getExistingForcedAudioLanes()) {
sb.append(format(DISABLE_FORCED_TRACK, track.getId()));
for (FileAttribute track : fileInfo.getExistingForcedAudioLanes()) {
command.addAll(format(DISABLE_FORCED_TRACK, track.getId()));
}
}
if (fileInfo.isSubtitleDifferent()) {
if (fileInfo.getExistingDefaultSubtitleLanes() != null && !fileInfo.getExistingDefaultSubtitleLanes().isEmpty()) {
for (FileAttribute track: fileInfo.getExistingDefaultSubtitleLanes()) {
sb.append(format(DISABLE_DEFAULT_TRACK, track.getId()));
for (FileAttribute track : fileInfo.getExistingDefaultSubtitleLanes()) {
command.addAll(format(DISABLE_DEFAULT_TRACK, track.getId()));
}
}
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()) {
for (FileAttribute attribute : fileInfo.getDesiredForcedSubtitleLanes()) {
sb.append(format(ENABLE_FORCED_TRACK, attribute.getId()));
for (FileAttribute track : fileInfo.getDesiredForcedSubtitleLanes()) {
command.addAll(format(ENABLE_FORCED_TRACK, track.getId()));
}
}
log.info(sb.toString());
InputStream inputstream = Runtime.getRuntime().exec(sb.toString()).getInputStream();
log.debug("Executing '{}'", String.join(" ", command));
InputStream inputstream = Runtime.getRuntime().exec(command.toArray(new String[0])).getInputStream();
String output = IOUtils.toString(new InputStreamReader(inputstream));
log.debug(output);
log.debug("Result: {}", 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(" "));
}
}

View File

@@ -19,7 +19,6 @@ import me.tongfei.progressbar.ProgressBar;
import me.tongfei.progressbar.ProgressBarBuilder;
import me.tongfei.progressbar.ProgressBarStyle;
import net.harawata.appdirs.AppDirsFactory;
import picocli.CommandLine;
import java.io.File;
import java.io.IOException;
@@ -100,6 +99,12 @@ public abstract class AttributeUpdaterKernel {
FileInfoDto fileInfo = new FileInfoDto(file);
List<FileAttribute> attributes = processor.loadAttributes(file);
if (attributes == null || attributes.isEmpty()) {
statistic.total();
statistic.failure();
return;
}
List<FileAttribute> nonForcedTracks = processor.retrieveNonForcedTracks(attributes);
List<FileAttribute> nonCommentaryTracks = processor.retrieveNonCommentaryTracks(attributes);
@@ -122,7 +127,7 @@ public abstract class AttributeUpdaterKernel {
statistic.shouldChange();
commitChange(fileInfoDto);
break;
case UNABLE_TO_APPLY:
case NO_SUITABLE_CONFIG:
statistic.noSuitableConfigFound();
break;
case ALREADY_SUITED:
@@ -143,10 +148,10 @@ public abstract class AttributeUpdaterKernel {
try {
processor.update(fileInfo.getFile(), fileInfo);
statistic.success();
log.info("Updated {}", fileInfo.getFile().getAbsolutePath());
log.info("Commited {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getAbsolutePath());
} catch (IOException | MkvToolNixException e) {
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);
}
}

View File

@@ -85,7 +85,7 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
if (fileInfos.stream().allMatch(elem -> ("OFF".equals(config.getSubtitleLanguage()) || elem.getDesiredDefaultSubtitleLane() != 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);
return; // match found, end process here
}

View File

@@ -26,6 +26,10 @@ public class AttributeConfig {
return Objects.hash(audioLanguage, subtitleLanguage);
}
public String toStringShort() {
return audioLanguage + ":" + subtitleLanguage;
}
@Override
public String toString() {
return "AttributeConfig{"

View File

@@ -40,8 +40,9 @@ public class FileInfoDto {
}
private boolean isSubtitleOFF() {
return desiredDefaultSubtitleLane == null && "OFF".equals(matchedConfig.getSubtitleLanguage()) &&
(existingDefaultSubtitleLanes != null && !existingDefaultSubtitleLanes.isEmpty());
return desiredDefaultSubtitleLane == null
&& (matchedConfig != null && "OFF".equals(matchedConfig.getSubtitleLanguage()))
&& (existingDefaultSubtitleLanes != null && !existingDefaultSubtitleLanes.isEmpty());
}
public boolean areForcedTracksDifferent() {
@@ -50,7 +51,7 @@ public class FileInfoDto {
public FileStatus getStatus() {
if (isChangeNecessary()) return FileStatus.CHANGE_NECESSARY;
if (isUnableToApplyConfig()) return FileStatus.UNABLE_TO_APPLY;
if (isUnableToApplyConfig()) return FileStatus.NO_SUITABLE_CONFIG;
if (isAlreadySuitable()) return FileStatus.ALREADY_SUITED;
return FileStatus.UNKNOWN;
}

View File

@@ -2,7 +2,7 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
public enum FileStatus {
CHANGE_NECESSARY,
UNABLE_TO_APPLY,
NO_SUITABLE_CONFIG,
ALREADY_SUITED,
UNKNOWN;
}

View File

@@ -3,12 +3,12 @@ Configuration:
Appenders:
RollingFile:
name: FileAppender
fileName: /var/log/MKVAudioSubtitleChanger/application.log
filePattern: /var/log/MKVAudioSubtitleChanger/archive/application-%d{yyyy-MM-dd}-%i.log.gz
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
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
ThresholdFilter:
level: info
level: debug
Policies:
OnStartupTriggeringPolicy:
minSize: 0

View File

@@ -4,7 +4,7 @@ Configuration:
Console:
name: Console_Out
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
ThresholdFilter:
level: debug
RollingFile:
@@ -12,7 +12,7 @@ Configuration:
fileName: logs/application.log
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
ThresholdFilter:
level: debug
Policies:

View File

@@ -6,9 +6,9 @@ Configuration:
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
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
ThresholdFilter:
level: info
level: debug
Policies:
OnStartupTriggeringPolicy:
minSize: 0

View File

@@ -6,9 +6,9 @@ Configuration:
fileName: logs/application.log
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
ThresholdFilter:
level: info
level: debug
Policies:
OnStartupTriggeringPolicy:
minSize: 0