mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
949261fb17 | ||
|
|
6cf42e5915 | ||
|
|
842b97dcb6 | ||
|
|
c2af135a57 | ||
|
|
280771e545 | ||
|
|
7620771aed | ||
|
|
c7670e36c1 | ||
|
|
1e31326ea2 | ||
|
|
7230134de6 | ||
|
|
fa84c483d9 | ||
|
|
62b637c241 |
73
README.md
73
README.md
@@ -1,8 +1,7 @@
|
||||
## Introduction
|
||||
|
||||
A streamlined solution for managing MKV files, this program leverages MKVToolNix to modify audio and subtitle track properties without the need for time-consuming file reencoding. Users can easily set their track preferences, and the application intelligently applies the best matching configuration. The tool focuses on metadata modification rather than full file rewriting, ensuring quick operations while maintaining the original file integrity. This makes it an ideal choice for managing multilingual media collections or batch processing multiple MKV files.
|
||||
|
||||

|
||||
This CLI tool uses MKVToolNix to quickly modify track properties in MKV files without reencoding. Use profiles to set default audio/subtitle tracks and add commentary, hearing impaired, and forced flags in bulk.
|
||||

|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -10,58 +9,54 @@ A streamlined solution for managing MKV files, this program leverages MKVToolNix
|
||||
- mkvtoolnix installation
|
||||
|
||||
## Execution
|
||||
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
|
||||
```shell
|
||||
# Portable
|
||||
java -jar mkvaudiosubtitlechanger.jar --attribute-config eng:ger -s ./videos
|
||||
# Installed
|
||||
mkvaudiosubtitlechanger.jar --attribute-config eng:ger -s ./videos
|
||||
```
|
||||
Remove `--safemode` or `-s` to actually apply the changes. Using safemode for the first execution is recommended.
|
||||
|
||||
Add `--safe-mode` oder `-s` to not change any files. This is recommended for the first executions.
|
||||
### Update defaults
|
||||
To update the default flag for tracks use `--attribute-config` or `-a`.
|
||||
This parameter takes in a list of pairs `audio:subtitle` (E.g. `eng:ger`).
|
||||
The order of these configs matters, because they are processed in order.
|
||||
The matching stops when the first match was found or when no match was found.
|
||||
For example `-a ger:OFF eng:ger` first tries to find a match for german audio, if that is not possible it tries the same for english with german subs.
|
||||
This can be extended indefinitely.
|
||||
|
||||
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).
|
||||
Using this parameter is not required, but it is the reason I originally started developing this tool.
|
||||
|
||||
### Available parameters
|
||||
```
|
||||
* -a, --attribute-config=<attributeConfig>...
|
||||
List of audio:subtitle pairs used to match in order
|
||||
and update files accordingly (e.g. jpn:eng jpn:
|
||||
ger)
|
||||
* -l, --library=<libraryPath>
|
||||
path to library
|
||||
-a, --attribute-config=<attributeConfig>...
|
||||
List of audio:subtitle pairs for matching defaults in order (e.g. jpn:eng jpn:ger)
|
||||
-m, --mkvtoolnix=<mkvToolNix>
|
||||
path to mkvtoolnix installation
|
||||
-s, --safemode test run (no files will be changes)
|
||||
-t, --threads=<threads> thread count (default: 2)
|
||||
-c, --coherent=<coherent> try to match all files in dir of depth with the
|
||||
same attribute config
|
||||
-cf, --force-coherent changes are only applied if it's a coherent match
|
||||
-n, --only-new-file sets filter-date to last successful execution
|
||||
(overwrites input of filter-date)
|
||||
-t, --threads=<threads> thread count
|
||||
Default: 2
|
||||
-c, --coherent=<coherent> try to match all files in dir of depth with the same attribute config. Attempting increasing deeper levels until match is found (worst case applying config on single file basis)
|
||||
-cf, --force-coherent only applies changes if a coherent match was found for the specifically entered depth
|
||||
-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")
|
||||
-i, --include-pattern=<includePattern>
|
||||
include files matching pattern (default: ".*")
|
||||
-e, --excluded=<excluded>...
|
||||
Directories and files to be excluded (no wildcard)
|
||||
include files matching pattern
|
||||
-e, --exclude=<excluded>...
|
||||
relative directories and files to be excluded (no wildcard)
|
||||
-o, -overwrite-forced remove all forced flags
|
||||
--forced-keywords=<forcedKeywords>[, <forcedKeywords>...]...
|
||||
Keywords to identify forced tracks (Defaults will
|
||||
be overwritten; Default: forced, signs, songs)
|
||||
Keywords to identify forced tracks (Defaults will be overwritten)
|
||||
Default: forced, signs, songs
|
||||
--commentary-keywords=<commentaryKeywords>[, <commentaryKeywords>...]...
|
||||
Keywords to identify commentary tracks (Defaults
|
||||
will be overwritten; Default: comment,
|
||||
commentary, director)
|
||||
Keywords to identify commentary tracks (Defaults will be overwritten)
|
||||
Default: comment, commentary, director
|
||||
--hearing-impaired=<hearingImpaired>[, <hearingImpaired>...]...
|
||||
Keywords to identify hearing impaired tracks
|
||||
(Defaults will be overwritten; Default: SDH
|
||||
Keywords to identify hearing impaired tracks (Defaults will be overwritten
|
||||
Default: SDH, CC
|
||||
--preferred-subtitles=<preferredSubtitles>[, <preferredSubtitles>...]...
|
||||
Keywords to prefer specific subtitle tracks
|
||||
(Defaults will be overwritten; Default: unstyled)
|
||||
Keywords to prefer specific subtitle tracks (Defaults will be overwritten)
|
||||
Default: unstyled
|
||||
--debug Enable debug logging
|
||||
-h, --help Show this help message and exit.
|
||||
-V, --version Print version information and exit.
|
||||
|
||||
BIN
example.gif
BIN
example.gif
Binary file not shown.
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 145 KiB |
2
pom.xml
2
pom.xml
@@ -395,7 +395,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.24.3</version>
|
||||
<version>2.25.3</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j18-impl -->
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j2-impl -->
|
||||
|
||||
@@ -34,6 +34,11 @@ public class CommandRunner implements Runnable {
|
||||
Configurator.setRootLevel(Level.DEBUG);
|
||||
}
|
||||
|
||||
if (config.isSafeMode()) {
|
||||
log.info("Safemode active. No files will be changed!");
|
||||
System.out.println("Safemode active. No files will be changed!");
|
||||
}
|
||||
|
||||
FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate());
|
||||
FileProcessor fileProcessor = new CachedFileProcessor(new MkvFileProcessor(config.getMkvToolNix(), fileFilter));
|
||||
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired());
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
||||
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SubtitleTrackComparator implements Comparator<TrackAttributes> {
|
||||
private final String[] preferredSubtitles;
|
||||
private final Set<String> preferredSubtitles;
|
||||
private final Set<String> hearingImpairedKeywords;
|
||||
|
||||
public SubtitleTrackComparator(Collection<String> preferredSubtitles, Collection<String> hearingImpairedKeywords) {
|
||||
this.preferredSubtitles = new HashSet<>(preferredSubtitles.stream().map(String::toLowerCase).toList());
|
||||
this.hearingImpairedKeywords = new HashSet<>(hearingImpairedKeywords.stream().map(String::toLowerCase).toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -17,12 +24,22 @@ public class SubtitleTrackComparator implements Comparator<TrackAttributes> {
|
||||
public int compare(TrackAttributes track1, TrackAttributes track2) {
|
||||
int result = 0;
|
||||
|
||||
if (StringUtils.containsAnyIgnoreCase(track1.trackName(), preferredSubtitles)) {
|
||||
result++;
|
||||
}
|
||||
if (StringUtils.containsAnyIgnoreCase(track2.trackName(), preferredSubtitles)) {
|
||||
result--;
|
||||
}
|
||||
String track1Name = Strings.isNotBlank(track1.trackName()) ? track1.trackName().toLowerCase() : "";
|
||||
String track2Name = Strings.isNotBlank(track2.trackName()) ? track2.trackName().toLowerCase() : "";
|
||||
|
||||
if (preferredSubtitles.contains(track1Name)) result++;
|
||||
else for (String keyword: preferredSubtitles) if (track1Name.contains(keyword)) result++;
|
||||
|
||||
if (preferredSubtitles.contains(track2Name)) result--;
|
||||
else for (String keyword: preferredSubtitles) if (track2Name.contains(keyword)) result--;
|
||||
|
||||
|
||||
if (track1.hearingImpaired()) result--;
|
||||
else if (hearingImpairedKeywords.contains(track1Name)) result--;
|
||||
else for (String keyword: hearingImpairedKeywords) if (track1Name.contains(keyword)) result--;
|
||||
if (track2.hearingImpaired()) result++;
|
||||
else if (hearingImpairedKeywords.contains(track2Name)) result++;
|
||||
else for (String keyword: hearingImpairedKeywords) if (track2Name.contains(keyword)) result++;
|
||||
|
||||
if (result == 0) {
|
||||
if (track1.defaultt()) result++;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class AttributeChangeProcessor {
|
||||
private final Set<String> forcedKeywords;
|
||||
|
||||
public AttributeChangeProcessor(String[] preferredSubtitles, Set<String> forcedKeywords, Set<String> commentaryKeywords, Set<String> hearingImpairedKeywords) {
|
||||
this.subtitleTrackComparator = new SubtitleTrackComparator(preferredSubtitles);
|
||||
this.subtitleTrackComparator = new SubtitleTrackComparator(Arrays.stream(preferredSubtitles).toList(), hearingImpairedKeywords);
|
||||
this.commentaryKeywords = commentaryKeywords;
|
||||
this.hearingImpairedKeywords = hearingImpairedKeywords;
|
||||
this.forcedKeywords = forcedKeywords;
|
||||
@@ -24,26 +24,12 @@ public class AttributeChangeProcessor {
|
||||
private List<TrackAttributes> filterForPossibleDefaults(List<TrackAttributes> tracks) {
|
||||
Stream<TrackAttributes> attributes = tracks.stream();
|
||||
|
||||
if (true) { // TODO: config for including commentary
|
||||
attributes = attributes
|
||||
return attributes
|
||||
.filter(attr -> !attr.commentary())
|
||||
.filter(attr -> {
|
||||
if (attr.trackName() == null) return true;
|
||||
return commentaryKeywords.stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (true) { // TODO: config for including hearing impaired
|
||||
attributes = attributes
|
||||
.filter(attr -> !attr.hearingImpaired())
|
||||
.filter(attr -> {
|
||||
if (attr.trackName() == null) return true;
|
||||
return hearingImpairedKeywords.stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
|
||||
});;
|
||||
}
|
||||
|
||||
return attributes
|
||||
})
|
||||
.filter(attr -> !attr.forced())
|
||||
.filter(attr -> {
|
||||
if (attr.trackName() == null) return true;
|
||||
|
||||
@@ -12,10 +12,12 @@ import me.tongfei.progressbar.ProgressBarStyle;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AttributeUpdater {
|
||||
@@ -85,15 +87,18 @@ public abstract class AttributeUpdater {
|
||||
if (!fileInfo.getChanges().isEmpty()) {
|
||||
statistic.changePlanned();
|
||||
|
||||
if (config.isSafeMode()) return;
|
||||
if (config.isSafeMode()) {
|
||||
log.info("Planned changes [{}] for {}", changeLog(fileInfo), fileInfo.getFile().getPath());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
log.info("Committing changes [{}] to {}", changeLog(fileInfo), fileInfo.getFile().getPath());
|
||||
fileProcessor.update(fileInfo);
|
||||
statistic.changeSuccessful();
|
||||
log.info("Commited {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getPath());
|
||||
} catch (IOException | MkvToolNixException e) {
|
||||
statistic.changeFailed();
|
||||
log.warn("Couldn't commit {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getPath(), e);
|
||||
log.warn("Couldn't commit changes [{}] to {}", changeLog(fileInfo), fileInfo.getFile().getPath(), e);
|
||||
}
|
||||
} else if (fileInfo.getChanges().isEmpty()) {
|
||||
statistic.unchanged();
|
||||
@@ -102,6 +107,15 @@ public abstract class AttributeUpdater {
|
||||
}
|
||||
}
|
||||
|
||||
private String changeLog(FileInfo fileInfo) {
|
||||
List<String> changes = new ArrayList<>();
|
||||
if (fileInfo.getMatchedConfig() != null) changes.add("defaults " + fileInfo.getMatchedConfig().toStringShort());
|
||||
if (!fileInfo.getChanges().getForcedTrack().isEmpty()) changes.add("forced tags");
|
||||
if (!fileInfo.getChanges().getCommentaryTrack().isEmpty()) changes.add("commentary tags");
|
||||
if (!fileInfo.getChanges().getHearingImpairedTrack().isEmpty()) changes.add("hearing impaired tags");
|
||||
return String.join(", ", changes);
|
||||
}
|
||||
|
||||
// should this be here?
|
||||
// protected void writeLastExecutionDate() {
|
||||
// if (config.isSafeMode()) {
|
||||
|
||||
@@ -47,6 +47,7 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
|
||||
matchedFiles.size(), files.size(), rootDir.getPath());
|
||||
}
|
||||
|
||||
log.info("Found coherent match {} for {}", matchedConfig.toStringShort(), rootDir.getPath());
|
||||
matchedFiles.forEach(fileInfo -> {
|
||||
attributeChangeProcessor.findForcedTracksAndApplyChanges(fileInfo, this.config.isOverwriteForced());
|
||||
attributeChangeProcessor.findCommentaryTracksAndApplyChanges(fileInfo);
|
||||
@@ -64,12 +65,12 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
|
||||
});
|
||||
|
||||
if (config.isForceCoherent()) {
|
||||
log.info("No coherent match found, aborting: {}", rootDir.getPath());
|
||||
log.info("No coherent match found, skipping {}", rootDir.getPath());
|
||||
statistic.increaseUnchangedBy(files.size());
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("No coherent match found, trying to find coherent match in child directories: {}", rootDir.getPath());
|
||||
log.info("No coherent match found, attempting to find coherent match in child directories of {}", rootDir.getPath());
|
||||
for (File dir: fileProcessor.loadDirectory(rootDir.getPath(), 1)) this.process(dir);
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
|
||||
fileInfo.setMatchedConfig(null);
|
||||
|
||||
if (fileInfo.getTracks().isEmpty()) {
|
||||
log.warn("No attributes found for file {}", file);
|
||||
log.warn("No attributes found for {}", file);
|
||||
statistic.unknownFailed();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ public class MkvFileProcessor implements FileProcessor {
|
||||
for (Map<String, Object> attribute : tracks) {
|
||||
if (!"video".equals(attribute.get("type"))) {
|
||||
Map<String, Object> properties = (Map<String, Object>) attribute.get("properties");
|
||||
// mkvpropedit takes in the n-th track, based on the order of mkvmerge --idenfity
|
||||
fileInfo.addTrack(new TrackAttributes(
|
||||
(int) properties.get("number"),
|
||||
(String) properties.get("language"),
|
||||
|
||||
@@ -31,7 +31,7 @@ public class SingleFileAttributeUpdater extends AttributeUpdater {
|
||||
FileInfo fileInfo = fileProcessor.readAttributes(file);
|
||||
|
||||
if (fileInfo.getTracks().isEmpty()) {
|
||||
log.warn("No attributes found for file {}", file);
|
||||
log.warn("No attributes found for {}", file);
|
||||
statistic.unknownFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class InputConfig implements CommandLine.IVersionProvider {
|
||||
private File libraryPath;
|
||||
|
||||
@Option(names = {"-a", "--attribute-config"}, arity = "1..*", converter = AttributeConfigConverter.class,
|
||||
description = "List of audio:subtitle pairs used to match in order and update files accordingly (e.g. jpn:eng jpn:ger)")
|
||||
description = "List of audio:subtitle pairs for matching defaults in order (e.g. jpn:eng jpn:ger)")
|
||||
private AttributeConfig[] attributeConfig = new AttributeConfig[0];
|
||||
@ValidMkvToolNix(message = "does not exist")
|
||||
@Option(names = {"-m", "--mkvtoolnix"}, defaultValue = "${DEFAULT_MKV_TOOL_NIX}", description = "path to mkvtoolnix installation")
|
||||
@@ -43,7 +43,7 @@ public class InputConfig implements CommandLine.IVersionProvider {
|
||||
private boolean safeMode;
|
||||
|
||||
@Min(1)
|
||||
@Option(names = {"-t", "--threads"}, defaultValue = "2", description = "thread count (default: ${DEFAULT-VALUE})")
|
||||
@Option(names = {"-t", "--threads"}, defaultValue = "2", showDefaultValue = CommandLine.Help.Visibility.ALWAYS, description = "thread count")
|
||||
private int threads;
|
||||
|
||||
@Min(0)
|
||||
@@ -57,7 +57,7 @@ public class InputConfig implements CommandLine.IVersionProvider {
|
||||
// private boolean onlyNewFiles;
|
||||
@Option(names = {"-d", "--filter-date"}, defaultValue = Option.NULL_VALUE, description = "only consider files created newer than entered date (format: \"dd.MM.yyyy-HH:mm:ss\")")
|
||||
private Date filterDate;
|
||||
@Option(names = {"-i", "--include-pattern"}, defaultValue = ".*", description = "include files matching pattern (default: \".*\")")
|
||||
@Option(names = {"-i", "--include-pattern"}, defaultValue = ".*", description = "include files matching pattern")
|
||||
private Pattern includePattern;
|
||||
@Option(names = {"-e", "--exclude"}, arity = "1..*",
|
||||
description = "relative directories and files to be excluded (no wildcard)")
|
||||
@@ -66,17 +66,17 @@ public class InputConfig implements CommandLine.IVersionProvider {
|
||||
|
||||
@Option(names = {"-o", "-overwrite-forced"}, description = "remove all forced flags")
|
||||
private boolean overwriteForced;
|
||||
@Option(names = {"--forced-keywords"}, arity = "1..*", defaultValue = "forced, signs, songs", split = ", ",
|
||||
description = "Keywords to identify forced tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})")
|
||||
@Option(names = {"--forced-keywords"}, arity = "1..*", defaultValue = "forced, signs, songs", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
|
||||
split = ", ", description = "Keywords to identify forced tracks (Defaults will be overwritten)")
|
||||
private Set<String> forcedKeywords;
|
||||
@Option(names = {"--commentary-keywords"}, arity = "1..*", defaultValue = "comment, commentary, director", split = ", ",
|
||||
description = "Keywords to identify commentary tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})")
|
||||
@Option(names = {"--commentary-keywords"}, arity = "1..*", defaultValue = "comment, commentary, director", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
|
||||
split = ", ", description = "Keywords to identify commentary tracks (Defaults will be overwritten)")
|
||||
private Set<String> commentaryKeywords;
|
||||
@Option(names = {"--hearing-impaired"}, arity = "1..*", defaultValue = "SDH, CC", split = ", ",
|
||||
description = "Keywords to identify hearing impaired tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE}")
|
||||
@Option(names = {"--hearing-impaired"}, arity = "1..*", defaultValue = "SDH, CC", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
|
||||
split = ", ", description = "Keywords to identify hearing impaired tracks (Defaults will be overwritten")
|
||||
private Set<String> hearingImpaired;
|
||||
@Option(names = {"--preferred-subtitles"}, arity = "1..*", defaultValue = "unstyled", split = ", ",
|
||||
description = "Keywords to prefer specific subtitle tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})")
|
||||
@Option(names = {"--preferred-subtitles"}, arity = "1..*", defaultValue = "unstyled", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
|
||||
split = ", ", description = "Keywords to prefer specific subtitle tracks (Defaults will be overwritten)")
|
||||
private Set<String> preferredSubtitles;
|
||||
@Option(names = {"--debug"}, description = "Enable debug logging")
|
||||
private boolean debug;
|
||||
|
||||
@@ -6,7 +6,7 @@ Configuration:
|
||||
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 | %C{1} | %msg %n %throwable"
|
||||
Pattern: "%d{DEFAULT} | %-5level | %msg %n %throwable"
|
||||
ThresholdFilter:
|
||||
level: debug
|
||||
Policies:
|
||||
|
||||
@@ -6,7 +6,7 @@ Configuration:
|
||||
fileName: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs/application.log
|
||||
filePattern: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||
PatternLayout:
|
||||
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
|
||||
Pattern: "%d{DEFAULT} | %-5level | %msg %n %throwable"
|
||||
ThresholdFilter:
|
||||
level: debug
|
||||
Policies:
|
||||
|
||||
@@ -6,7 +6,7 @@ Configuration:
|
||||
fileName: logs/application.log
|
||||
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||
PatternLayout:
|
||||
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
|
||||
Pattern: "%d{DEFAULT} | %-5level | %msg %n %throwable"
|
||||
ThresholdFilter:
|
||||
level: debug
|
||||
Policies:
|
||||
|
||||
@@ -12,32 +12,48 @@ import java.util.stream.Stream;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SubtitleTrackComparatorTest {
|
||||
private static final SubtitleTrackComparator comparator = new SubtitleTrackComparator(new String[]{"unstyled"});
|
||||
|
||||
private static Stream<Arguments> compareArguments() {
|
||||
return Stream.of(
|
||||
Arguments.of(List.of(attr("unstyled sub", false), attr("styled sub", false)),
|
||||
List.of(attr("unstyled sub", false), attr("styled sub", false))),
|
||||
Arguments.of(List.of(attr("styled sub", false), attr("unstyled sub", false)),
|
||||
List.of(attr("unstyled sub", false), attr("styled sub", false))),
|
||||
Arguments.of(attr(""), attr(""), 0),
|
||||
Arguments.of(attr("pref"), attr(""), 1),
|
||||
Arguments.of(attr(""), attr("pref"), -1),
|
||||
Arguments.of(attr("pref"), attr("pref"), 0),
|
||||
|
||||
Arguments.of(List.of(attr("unstyled sub", true), attr("styled sub", false)),
|
||||
List.of(attr("unstyled sub", true), attr("styled sub", false))),
|
||||
Arguments.of(List.of(attr("styled sub", true), attr("unstyled sub", false)),
|
||||
List.of(attr("unstyled sub", false), attr("styled sub", true))),
|
||||
Arguments.of(attr("", true), attr("", true), 0),
|
||||
Arguments.of(attr("", true), attr(""), -1),
|
||||
Arguments.of(attr("CC", true), attr(""), -1),
|
||||
Arguments.of(attr("CC"), attr(""), -1),
|
||||
Arguments.of(attr(""), attr("", true), 1),
|
||||
Arguments.of(attr(""), attr("CC", true), 1),
|
||||
Arguments.of(attr(""), attr("CC"), 1),
|
||||
|
||||
Arguments.of(List.of(attr("unstyled sub", true), attr("unstyled sub", false)),
|
||||
List.of(attr("unstyled sub", true), attr("unstyled sub", false)))
|
||||
Arguments.of(attr("pref", true), attr("pref"), -1),
|
||||
Arguments.of(attr("pref", true), attr("pref", true), 0),
|
||||
Arguments.of(attr("pref"), attr("pref", true), 1),
|
||||
Arguments.of(attr("", true), attr("pref"), -2),
|
||||
Arguments.of(attr("pref"), attr("", true), 2),
|
||||
|
||||
Arguments.of(attr(null), attr(null), 0),
|
||||
Arguments.of(attr(null), attr(""), 0),
|
||||
Arguments.of(attr(null), attr("pref"), -1),
|
||||
Arguments.of(attr(""), attr(null), 0),
|
||||
Arguments.of(attr("pref"), attr(null), 1)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("compareArguments")
|
||||
void compare(List<TrackAttributes> input, List<TrackAttributes> expected) {
|
||||
assertIterableEquals(expected, input.stream().sorted(comparator.reversed()).toList());
|
||||
void compare(TrackAttributes track1, TrackAttributes track2, int expected) {
|
||||
SubtitleTrackComparator comparator = new SubtitleTrackComparator(List.of("pref"), List.of("CC", "SDH"));
|
||||
int actual = comparator.compare(track1, track2);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
private static TrackAttributes attr(String trackName, boolean defaultTrack) {
|
||||
return new TrackAttributes(0, "", trackName, defaultTrack, false, false, false, TrackType.SUBTITLES);
|
||||
private static TrackAttributes attr(String trackname) {
|
||||
return attr(trackname, false);
|
||||
}
|
||||
|
||||
private static TrackAttributes attr(String trackName, boolean hearingImpaired) {
|
||||
return new TrackAttributes(0, "", trackName, false, false, false, hearingImpaired, TrackType.SUBTITLES);
|
||||
}
|
||||
}
|
||||
@@ -71,19 +71,29 @@ class AttributeChangeProcessorTest {
|
||||
Map.ofEntries()
|
||||
),
|
||||
Arguments.of(
|
||||
List.of(AUDIO_ENG_DEFAULT, AUDIO_GER_HEARING, SUB_GER),
|
||||
arr(a("ger:ger")), null,
|
||||
Map.ofEntries()
|
||||
),
|
||||
Arguments.of(
|
||||
List.of(AUDIO_ENG_DEFAULT, withName(AUDIO_GER, "SDH"), SUB_GER),
|
||||
arr(a("ger:ger")), null,
|
||||
Map.ofEntries()
|
||||
),
|
||||
Arguments.of(
|
||||
List.of(AUDIO_ENG_DEFAULT, AUDIO_GER_COMMENTARY, AUDIO_GER_HEARING, AUDIO_GER, SUB_GER_FORCED, SUB_GER),
|
||||
List.of(AUDIO_GER, withName(SUB_GER, "SDH")),
|
||||
arr(a("ger:ger")), "ger:ger",
|
||||
Map.ofEntries(off(AUDIO_ENG_DEFAULT), on(AUDIO_GER), on(SUB_GER))
|
||||
Map.ofEntries(on(AUDIO_GER), on(withName(SUB_GER, "SDH")))
|
||||
),
|
||||
Arguments.of(
|
||||
List.of(AUDIO_GER, withName(SUB_GER, "SDH"), SUB_GER),
|
||||
arr(a("ger:ger")), "ger:ger",
|
||||
Map.ofEntries(on(AUDIO_GER), on(SUB_GER))
|
||||
),
|
||||
Arguments.of(
|
||||
List.of(AUDIO_GER, SUB_GER_HEARING),
|
||||
arr(a("ger:ger")), "ger:ger",
|
||||
Map.ofEntries(on(AUDIO_GER), on(SUB_GER_HEARING))
|
||||
),
|
||||
Arguments.of(
|
||||
List.of(AUDIO_GER, SUB_GER_HEARING, SUB_GER),
|
||||
arr(a("ger:ger")), "ger:ger",
|
||||
Map.ofEntries(on(AUDIO_GER), on(SUB_GER))
|
||||
),
|
||||
Arguments.of(
|
||||
List.of(AUDIO_GER, SUB_ENG_HEARING, SUB_GER),
|
||||
arr(a("ger:eng")), "ger:eng",
|
||||
Map.ofEntries(on(AUDIO_GER), on(SUB_ENG_HEARING))
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -128,9 +138,9 @@ class AttributeChangeProcessorTest {
|
||||
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, withName(AUDIO_GER, "Forced"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
|
||||
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, withName(AUDIO_GER, "commentary"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
|
||||
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, withName(AUDIO_GER, "Commentary"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
|
||||
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, withName(AUDIO_GER, "SDH"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
|
||||
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, withName(AUDIO_GER, "sdh"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
|
||||
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, SUB_GER, SUB_GER_FORCED, AUDIO_GER_COMMENTARY, AUDIO_GER_HEARING), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER))
|
||||
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, withName(AUDIO_GER, "SDH"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER, withName(AUDIO_GER, "SDH"))),
|
||||
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, withName(AUDIO_GER, "sdh"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER, withName(AUDIO_GER, "sdh"))),
|
||||
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, SUB_GER, SUB_GER_FORCED, AUDIO_GER_COMMENTARY, AUDIO_GER_HEARING), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER, AUDIO_GER_HEARING))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.AUDIO_GER;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_FILE;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class AttributeUpdaterTest {
|
||||
@@ -56,7 +57,7 @@ class AttributeUpdaterTest {
|
||||
}
|
||||
|
||||
private static FileInfo info(AttributeConfig config, TrackAttributes attr) {
|
||||
FileInfo fileInfo = new FileInfo(null);
|
||||
FileInfo fileInfo = new FileInfo(new File(TEST_FILE));
|
||||
fileInfo.setMatchedConfig(config);
|
||||
if(attr != null) fileInfo.getChanges().getDefaultTrack().put(attr, true);
|
||||
return fileInfo;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class FileInfoTestUtil {
|
||||
public static final TrackAttributes AUDIO_GER_COMMENTARY = new TrackAttributes(0, "ger", "", false, false, true, false, TrackType.AUDIO);
|
||||
public static final TrackAttributes AUDIO_ENG_COMMENTARY = new TrackAttributes(1, "eng", "", false, false, true, false, TrackType.AUDIO);
|
||||
public static final TrackAttributes AUDIO_GER_HEARING = new TrackAttributes(0, "ger", "", false, false, false, true, TrackType.AUDIO);
|
||||
public static final TrackAttributes AUDIO_ENG_HEARING = new TrackAttributes(1, "ger", "", false, false, false, true, TrackType.AUDIO);
|
||||
public static final TrackAttributes AUDIO_ENG_HEARING = new TrackAttributes(1, "eng", "", false, false, false, true, TrackType.AUDIO);
|
||||
|
||||
public static final TrackAttributes SUB_GER = new TrackAttributes(0, "ger", "", false, false, false, false, TrackType.SUBTITLES);
|
||||
public static final TrackAttributes SUB_ENG = new TrackAttributes(1, "eng", "", false, false, false, false, TrackType.SUBTITLES);
|
||||
@@ -21,6 +21,8 @@ public class FileInfoTestUtil {
|
||||
public static final TrackAttributes SUB_ENG_DEFAULT = new TrackAttributes(1, "eng", "", true, false, false, false, TrackType.SUBTITLES);
|
||||
public static final TrackAttributes SUB_GER_FORCED = new TrackAttributes(0, "ger", "", false, true, false, false, TrackType.SUBTITLES);
|
||||
public static final TrackAttributes SUB_ENG_FORCED = new TrackAttributes(1, "eng", "", false, true, false, false, TrackType.SUBTITLES);
|
||||
public static final TrackAttributes SUB_GER_HEARING = new TrackAttributes(0, "ger", "", false, false, false, true, TrackType.SUBTITLES);
|
||||
public static final TrackAttributes SUB_ENG_HEARING = new TrackAttributes(1, "eng", "", false, false, false, true, TrackType.SUBTITLES);
|
||||
|
||||
public static TrackAttributes withName(TrackAttributes track, String trackName) {
|
||||
return new TrackAttributes(track.id(), track.language(), trackName, track.defaultt(), track.forced(), track.commentary(), track.hearingImpaired(), track.type());
|
||||
|
||||
Reference in New Issue
Block a user