36 Commits

Author SHA1 Message Date
Michael
71e8e3d9ae Merge pull request #69 from RatzzFatzz/dev
Fix logging
2026-01-24 19:43:49 +01:00
RatzzFatzz
6a965e4084 Fix logging 2026-01-24 19:11:03 +01:00
Michael
28ec33d214 Merge pull request #68 from RatzzFatzz/dev
v5.1
2026-01-16 00:44:54 +01:00
RatzzFatzz
e80331beef Fix log4j2 file link on windows 2026-01-15 21:16:10 +01:00
RatzzFatzz
a5fce22b95 Fix lastExecutionHandler NPE 2026-01-15 21:14:54 +01:00
RatzzFatzz
a97ed89d08 Parameterize log4j2 configs 2026-01-15 13:32:35 +01:00
RatzzFatzz
cce84f5c15 Make path of lastFileExecution platform dependent 2026-01-15 12:40:09 +01:00
RatzzFatzz
ff38457af1 Revert lib updates of jackson & log4j2 2026-01-15 12:19:48 +01:00
RatzzFatzz
906ec944eb Fix filter-date format & add test for filter-date 2026-01-13 15:50:38 +01:00
RatzzFatzz
41e107ef85 Migrate from date to instant 2026-01-13 15:35:16 +01:00
RatzzFatzz
3c57eb44ef Migrate last execution handler to properties 2026-01-12 19:02:06 +01:00
RatzzFatzz
8dbfb22ed8 Fix log4j2 and jackson.databind dependency 2026-01-12 19:01:10 +01:00
RatzzFatzz
a5aae0acf4 Add handler for only new files parameter 2026-01-08 22:03:06 +01:00
RatzzFatzz
1165dd8380 Add support for multiple library paths 2025-12-29 00:12:28 +01:00
RatzzFatzz
be004e6146 Add support for multiple library paths 2025-12-28 23:59:33 +01:00
RatzzFatzz
31b155d8a3 Add tests for coherent file attribute updater 2025-12-27 20:55:41 +01:00
RatzzFatzz
94365651ff Add tests for single file attribute updater 2025-12-25 14:28:18 +01:00
RatzzFatzz
f18fdbdda6 Apply forced track if sub lang is OFF 2025-12-24 16:22:17 +01:00
RatzzFatzz
13283e3765 Update libs 2025-12-23 15:55:58 +01:00
Michael
949261fb17 Update log4j2
Bump org.apache.logging.log4j:log4j-core from 2.24.3 to 2.25.3
2025-12-23 01:05:03 +01:00
RatzzFatzz
6cf42e5915 Update example gif 2025-12-23 00:58:28 +01:00
RatzzFatzz
842b97dcb6 Fix NPE while sorting 2025-12-23 00:46:33 +01:00
RatzzFatzz
c2af135a57 Add information when safemode is active 2025-12-22 23:39:23 +01:00
RatzzFatzz
280771e545 Improve default value display on help 2025-12-22 23:37:45 +01:00
RatzzFatzz
7620771aed Update instructions in readme 2025-12-22 23:34:06 +01:00
RatzzFatzz
c7670e36c1 Add hearing impaired tracks as low prio default match 2025-12-21 00:44:49 +01:00
RatzzFatzz
1e31326ea2 Add logging about planned changes in safe mode 2025-12-20 20:05:45 +01:00
dependabot[bot]
7230134de6 Bump org.apache.logging.log4j:log4j-core from 2.24.3 to 2.25.3
Bumps org.apache.logging.log4j:log4j-core from 2.24.3 to 2.25.3.

---
updated-dependencies:
- dependency-name: org.apache.logging.log4j:log4j-core
  dependency-version: 2.25.3
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-19 23:52:26 +00:00
RatzzFatzz
fa84c483d9 Add comment to explain id collection 2025-12-19 22:59:57 +01:00
RatzzFatzz
62b637c241 Add changes list to info logging 2025-12-19 22:35:07 +01:00
RatzzFatzz
1bdd3874e7 Remove unused code 2025-12-18 21:27:12 +01:00
RatzzFatzz
3e74e23512 Remove attribute config as required option 2025-12-18 21:17:51 +01:00
RatzzFatzz
5f2248653b Improve status detection 2025-12-18 21:14:15 +01:00
RatzzFatzz
15128583df Improve result print 2025-12-17 14:27:27 +01:00
RatzzFatzz
76d25fca1b Fix finding hearing impaired flag changes 2025-12-17 13:32:23 +01:00
RatzzFatzz
957295127a Remove version from jar in Windows installer 2025-12-17 11:42:44 +01:00
40 changed files with 1087 additions and 554 deletions

View File

@@ -1,8 +1,7 @@
## Introduction ## 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.
![](example.gif)
![](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/blob/master/example.gif)
## Requirements ## Requirements
@@ -10,58 +9,54 @@ A streamlined solution for managing MKV files, this program leverages MKVToolNix
- mkvtoolnix installation - mkvtoolnix installation
## Execution ## Execution
Portable: ```shell
``` # Portable
java -jar mkvaudiosubtitlechanger-<version>.jar --library "X:/Files" --attribute-config eng:ger eng:OFF java -jar mkvaudiosubtitlechanger.jar --attribute-config eng:ger -s ./videos
``` # Installed
Windows & Linux (installed): mkvaudiosubtitlechanger.jar --attribute-config eng:ger -s ./videos
```
mkvaudiosubtitlechanger --library "X:/Files" --attribute-config eng:ger eng:OFF
``` ```
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 Using this parameter is not required, but it is the reason I originally started developing this tool.
[here](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/Attribute-Config).
### Available parameters ### Available parameters
``` ```
* -a, --attribute-config=<attributeConfig>... -a, --attribute-config=<attributeConfig>...
List of audio:subtitle pairs used to match in order List of audio:subtitle pairs for matching defaults in order (e.g. jpn:eng jpn:ger)
and update files accordingly (e.g. jpn:eng jpn:
ger)
* -l, --library=<libraryPath>
path to library
-m, --mkvtoolnix=<mkvToolNix> -m, --mkvtoolnix=<mkvToolNix>
path to mkvtoolnix installation path to mkvtoolnix installation
-s, --safemode test run (no files will be changes) -s, --safemode test run (no files will be changes)
-t, --threads=<threads> thread count (default: 2) -t, --threads=<threads> thread count
-c, --coherent=<coherent> try to match all files in dir of depth with the Default: 2
same attribute config -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 changes are only applied if it's a coherent match -cf, --force-coherent only applies changes if a coherent match was found for the specifically entered depth
-n, --only-new-file sets filter-date to last successful execution
(overwrites input of filter-date)
-d, --filter-date=<filterDate> -d, --filter-date=<filterDate>
only consider files created newer than entered date only consider files created newer than entered date (format: "dd.MM.yyyy-HH:mm:ss")
(format: "dd.MM.yyyy-HH:mm:ss")
-i, --include-pattern=<includePattern> -i, --include-pattern=<includePattern>
include files matching pattern (default: ".*") include files matching pattern
-e, --excluded=<excluded>... -e, --exclude=<excluded>...
Directories and files to be excluded (no wildcard) relative directories and files to be excluded (no wildcard)
-o, -overwrite-forced remove all forced flags -o, -overwrite-forced remove all forced flags
--forced-keywords=<forcedKeywords>[, <forcedKeywords>...]... --forced-keywords=<forcedKeywords>[, <forcedKeywords>...]...
Keywords to identify forced tracks (Defaults will Keywords to identify forced tracks (Defaults will be overwritten)
be overwritten; Default: forced, signs, songs) Default: forced, signs, songs
--commentary-keywords=<commentaryKeywords>[, <commentaryKeywords>...]... --commentary-keywords=<commentaryKeywords>[, <commentaryKeywords>...]...
Keywords to identify commentary tracks (Defaults Keywords to identify commentary tracks (Defaults will be overwritten)
will be overwritten; Default: comment, Default: comment, commentary, director
commentary, director)
--hearing-impaired=<hearingImpaired>[, <hearingImpaired>...]... --hearing-impaired=<hearingImpaired>[, <hearingImpaired>...]...
Keywords to identify hearing impaired tracks Keywords to identify hearing impaired tracks (Defaults will be overwritten
(Defaults will be overwritten; Default: SDH Default: SDH, CC
--preferred-subtitles=<preferredSubtitles>[, <preferredSubtitles>...]... --preferred-subtitles=<preferredSubtitles>[, <preferredSubtitles>...]...
Keywords to prefer specific subtitle tracks Keywords to prefer specific subtitle tracks (Defaults will be overwritten)
(Defaults will be overwritten; Default: unstyled) Default: unstyled
--debug Enable debug logging --debug Enable debug logging
-h, --help Show this help message and exit. -h, --help Show this help message and exit.
-V, --version Print version information and exit. -V, --version Print version information and exit.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 145 KiB

74
pom.xml
View File

@@ -29,7 +29,7 @@
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<includes> <includes>
<include>log4j2.yaml</include> <include>log4j2.yml</include>
</includes> </includes>
</resource> </resource>
</resources> </resources>
@@ -64,11 +64,19 @@
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<includes> <includes>
<include>log4j2-windows.yaml</include> <include>log4j2-windows.yml</include>
</includes> </includes>
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<finalName>${project.artifactId}</finalName>
</configuration>
</plugin>
<plugin> <plugin>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version> <version>3.3.1</version>
@@ -85,7 +93,7 @@
<resource> <resource>
<directory>${project.build.directory}</directory> <directory>${project.build.directory}</directory>
<includes> <includes>
<include>${project.artifactId}-${project.version}.jar</include> <include>${project.artifactId}.jar</include>
</includes> </includes>
</resource> </resource>
</resources> </resources>
@@ -122,7 +130,7 @@
<input>target/jpackage-input</input> <input>target/jpackage-input</input>
<mainClass>at.pcgamingfreaks.mkvaudiosubtitlechanger.Main</mainClass> <mainClass>at.pcgamingfreaks.mkvaudiosubtitlechanger.Main</mainClass>
<mainJar>${project.artifactId}-${project.version}.jar</mainJar> <mainJar>${project.artifactId}.jar</mainJar>
<resourceDir>${project.build.directory}/wix-resources/</resourceDir> <resourceDir>${project.build.directory}/wix-resources/</resourceDir>
<type>EXE</type> <type>EXE</type>
@@ -130,7 +138,7 @@
<winShortcut>false</winShortcut> <winShortcut>false</winShortcut>
<winMenu>false</winMenu> <winMenu>false</winMenu>
<javaOptions> <javaOptions>
<javaOption>-Dlog4j2.configurationFile=log4j2-windows.yaml</javaOption> <javaOption>-Dlog4j2.configurationFile=log4j2-windows.yml</javaOption>
</javaOptions> </javaOptions>
</configuration> </configuration>
<executions> <executions>
@@ -153,7 +161,7 @@
<resource> <resource>
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
<includes> <includes>
<include>log4j2-debian.yaml</include> <include>log4j2-debian.yml</include>
</includes> </includes>
</resource> </resource>
</resources> </resources>
@@ -326,12 +334,6 @@
</repositories> </repositories>
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/com.intellij/forms_rt -->
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>7.0.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
@@ -346,12 +348,19 @@
<version>4.7.7</version> <version>4.7.7</version>
</dependency> </dependency>
<!-- Jakarta Bean Validation -->
<!-- https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api -->
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>4.0.0-M1</version>
</dependency>
<!-- Hibernate Validator --> <!-- Hibernate Validator -->
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator --> <!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<dependency> <dependency>
<groupId>org.hibernate.validator</groupId> <groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId> <artifactId>hibernate-validator</artifactId>
<version>8.0.2.Final</version> <version>9.1.0.Final</version>
</dependency> </dependency>
<!-- Expression Language Implementation --> <!-- Expression Language Implementation -->
@@ -359,42 +368,32 @@
<dependency> <dependency>
<groupId>jakarta.el</groupId> <groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId> <artifactId>jakarta.el-api</artifactId>
<version>6.1.0-M1</version> <version>6.0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.glassfish</groupId> <groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId> <artifactId>jakarta.el</artifactId>
<version>5.0.0-M1</version> <version>5.0.0-M1</version>
</dependency> </dependency>
<!-- Jakarta Bean Validation -->
<!-- https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api -->
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.1.1</version>
</dependency>
<!-- region logging --> <!-- region logging -->
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api --> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId> <artifactId>log4j-api</artifactId>
<version>2.24.3</version> <version>2.25.3</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId> <artifactId>log4j-core</artifactId>
<version>2.24.3</version> <version>2.25.3</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j18-impl -->
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j2-impl --> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j2-impl -->
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId> <artifactId>log4j-slf4j2-impl</artifactId>
<version>2.24.3</version> <version>2.25.3</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml --> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml -->
@@ -414,13 +413,20 @@
<dependency> <dependency>
<groupId>commons-cli</groupId> <groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
<version>1.10.0</version> <version>1.11.0</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --> <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.19.0</version> <version>3.20.0</version>
</dependency>
<!-- Source: https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.21.0</version>
<scope>compile</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/me.tongfei/progressbar --> <!-- https://mvnrepository.com/artifact/me.tongfei/progressbar -->
<dependency> <dependency>
@@ -434,34 +440,34 @@
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>6.0.0</version> <version>6.0.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine --> <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<version>6.0.0</version> <version>6.0.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core --> <!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<version>5.20.0</version> <version>5.21.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<version>5.20.0</version> <version>5.21.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params --> <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId> <artifactId>junit-jupiter-params</artifactId>
<version>6.0.0</version> <version>6.0.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

View File

@@ -1 +1 @@
java -Dlog4j2.configurationFile=log4j2-debian.yaml -jar /usr/lib/${project.artifactId}/${project.artifactId}-${project.version}.jar "$@" java -Dlog4j2.configurationFile=log4j2-debian.yml -jar /usr/lib/${project.artifactId}/${project.artifactId}-${project.version}.jar "$@"

View File

@@ -1,16 +1,15 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl; package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.AttributeUpdater; import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.*;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.CoherentAttributeUpdater;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.SingleFileAttributeUpdater;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.CachedFileProcessor;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.FileProcessor;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.MkvFileProcessor;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil; import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
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.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.RollingFileAppender;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.Configurator; import org.apache.logging.log4j.core.config.Configurator;
import picocli.CommandLine; import picocli.CommandLine;
@@ -19,8 +18,8 @@ import picocli.CommandLine;
name = "mkvaudiosubtitlechanger", name = "mkvaudiosubtitlechanger",
usageHelpAutoWidth = true, usageHelpAutoWidth = true,
customSynopsis = { customSynopsis = {
"mkvaudiosubtitlechanger -a <attributeConfig> [...<attributeConfig>] -l <libraryPath> [-s]", "mkvaudiosubtitlechanger [-a <attributeConfig> [...<attributeConfig>]] [-s] <libraryPath>",
"Example: mkvaudiosubtitlechanger -a eng:eng eng:ger -l /mnt/media/ -s", "Example: mkvaudiosubtitlechanger -a eng:eng eng:ger -s /mnt/media/",
"" ""
}, },
requiredOptionMarker = '*', requiredOptionMarker = '*',
@@ -39,12 +38,36 @@ public class CommandRunner implements Runnable {
Configurator.setRootLevel(Level.DEBUG); Configurator.setRootLevel(Level.DEBUG);
} }
FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate()); if (config.isSafeMode()) {
log.info("Safemode active. No files will be changed!");
System.out.println("Safemode active. No files will be changed!");
}
LastExecutionHandler lastExecutionHandler = config.isOnlyNewFiles() ? new LastExecutionHandler(getApplicationHome()) : null;
FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate(), lastExecutionHandler);
FileProcessor fileProcessor = new CachedFileProcessor(new MkvFileProcessor(config.getMkvToolNix(), fileFilter)); 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());
AttributeUpdater kernel = config.getCoherent() != null AttributeUpdater kernel = config.getCoherent() != null
? new CoherentAttributeUpdater(config, fileProcessor) ? new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor, lastExecutionHandler)
: new SingleFileAttributeUpdater(config, fileProcessor); : new SingleFileAttributeUpdater(config, fileProcessor, attributeChangeProcessor, lastExecutionHandler);
kernel.execute(); kernel.execute();
} }
public String getApplicationHome() {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
for (org.apache.logging.log4j.core.Appender appender : config.getAppenders().values()) {
if (appender instanceof RollingFileAppender rollingFileAppender) {
String fileName = rollingFileAppender.getFileName();
return new java.io.File(fileName).getParentFile().getParent();
}
}
log.error("Could not load log4j2 path info");
System.out.println("Could not load log4j2 path info");
System.exit(1);
return null;
}
} }

View File

@@ -1,7 +1,6 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl; package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -9,9 +8,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.Date; import java.time.Instant;
import java.util.HashSet; import java.util.*;
import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -20,7 +18,8 @@ import java.util.regex.Pattern;
public class FileFilter { public class FileFilter {
private final Set<String> excluded; private final Set<String> excluded;
private final Pattern includePattern; private final Pattern includePattern;
private final Date filterDate; private final Instant filterDate;
private final LastExecutionHandler lastExecutionHandler;
private final String EXTENSION_GROUP = "extension"; private final String EXTENSION_GROUP = "extension";
private final Pattern extensionPattern = Pattern.compile(String.format(".*(?<%s>\\..*)", EXTENSION_GROUP)); private final Pattern extensionPattern = Pattern.compile(String.format(".*(?<%s>\\..*)", EXTENSION_GROUP));
@@ -33,8 +32,9 @@ public class FileFilter {
} }
if (!hasMatchingPattern(pathName) if (!hasMatchingPattern(pathName)
|| !isNewer(pathName) || isExcluded(pathName, new HashSet<>(excluded))
|| isExcluded(pathName, new HashSet<>(excluded))) { || lastExecutionHandler != null && !isNewer(pathName, lastExecutionHandler.get(pathName.getAbsolutePath()))
|| !isNewer(pathName, filterDate)) {
log.debug("Excluded {}", pathName); log.debug("Excluded {}", pathName);
ResultStatistic.getInstance().excluded(); ResultStatistic.getInstance().excluded();
return false; return false;
@@ -52,21 +52,18 @@ public class FileFilter {
return includePattern.matcher(pathName.getName()).matches(); return includePattern.matcher(pathName.getName()).matches();
} }
private boolean isNewer(File pathName) { private boolean isNewer(File pathName, Instant date) {
if (filterDate == null) return true; if (date == null) return true;
try { try {
BasicFileAttributes attributes = Files.readAttributes(pathName.toPath(), BasicFileAttributes.class); BasicFileAttributes attributes = Files.readAttributes(pathName.toPath(), BasicFileAttributes.class);
return isNewer(DateUtils.convert(attributes.creationTime().toMillis())); return attributes.creationTime().toInstant().isAfter(date)
|| attributes.lastModifiedTime().toInstant().isAfter(date);
} 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;
} }
private boolean isNewer(Date creationDate) {
return creationDate.toInstant().isAfter(filterDate.toInstant());
}
private boolean isExcluded(File pathName, Set<String> excludedDirs) { private boolean isExcluded(File pathName, Set<String> excludedDirs) {
if (excludedDirs.contains(pathName.getPath())) return true; if (excludedDirs.contains(pathName.getPath())) return true;

View File

@@ -0,0 +1,56 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.Instant;
import java.util.Properties;
@Slf4j
public class LastExecutionHandler {
private static final String FILE_NAME = "last-execution.properties";
private final File file;
private final Properties lastFileExecution;
public LastExecutionHandler(String path) {
file = new File(path + "/" + FILE_NAME);
lastFileExecution = loadLastFileExecution(file);
}
public Properties loadLastFileExecution(File file) {
Properties properties = new Properties();
try (FileInputStream in = new FileInputStream(file)) {
properties.load(in);
} catch (IOException e) {
log.info("Couldn't find or read {}", file.getPath(), e);
}
return properties;
}
public Instant get(String path) {
if (!lastFileExecution.containsKey(path)) return null;
return Instant.parse(lastFileExecution.getProperty(path));
}
public void update(String path) {
update(path, Instant.now());
}
public void update(String path, Instant execution) {
if (lastFileExecution == null) return;
lastFileExecution.put(path, execution.toString());
}
public void persist() {
try (FileOutputStream out = new FileOutputStream(file)) {
lastFileExecution.store(out, "MKVAudioSubtitleChanger - Last file execution");
} catch (IOException e) {
log.warn("Persisting last file execution dates failed", e);
}
}
}

View File

@@ -1,14 +1,21 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl; package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
import lombok.RequiredArgsConstructor; import org.apache.logging.log4j.util.Strings;
import org.apache.commons.lang3.StringUtils;
import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
@RequiredArgsConstructor
public class SubtitleTrackComparator implements Comparator<TrackAttributes> { 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} * {@inheritDoc}
@@ -17,12 +24,22 @@ public class SubtitleTrackComparator implements Comparator<TrackAttributes> {
public int compare(TrackAttributes track1, TrackAttributes track2) { public int compare(TrackAttributes track1, TrackAttributes track2) {
int result = 0; int result = 0;
if (StringUtils.containsAnyIgnoreCase(track1.trackName(), preferredSubtitles)) { String track1Name = Strings.isNotBlank(track1.trackName()) ? track1.trackName().toLowerCase() : "";
result++; String track2Name = Strings.isNotBlank(track2.trackName()) ? track2.trackName().toLowerCase() : "";
}
if (StringUtils.containsAnyIgnoreCase(track2.trackName(), preferredSubtitles)) { if (preferredSubtitles.contains(track1Name)) result++;
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 (result == 0) {
if (track1.defaultt()) result++; if (track1.defaultt()) result++;

View File

@@ -37,10 +37,10 @@ public class AttributeConfigConverter implements CommandLine.ITypeConverter<Attr
* @return valid {@link AttributeConfig} * @return valid {@link AttributeConfig}
*/ */
private static AttributeConfig validateResult(AttributeConfig attr) { private static AttributeConfig validateResult(AttributeConfig attr) {
if (!isLanguageValid(attr.getAudioLanguage())) if (!isLanguageValid(attr.getAudioLang()))
throw new CommandLine.TypeConversionException("Audio language invalid: " + attr.getAudioLanguage()); throw new CommandLine.TypeConversionException("Audio language invalid: " + attr.getAudioLang());
if (!isLanguageValid(attr.getSubtitleLanguage())) if (!isLanguageValid(attr.getSubLang()))
throw new CommandLine.TypeConversionException("Subtitle language invalid: " + attr.getSubtitleLanguage()); throw new CommandLine.TypeConversionException("Subtitle language invalid: " + attr.getSubLang());
return attr; return attr;
} }

View File

@@ -4,8 +4,6 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.SubtitleTrackComparator;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
public class AttributeChangeProcessor { public class AttributeChangeProcessor {
@@ -15,47 +13,19 @@ public class AttributeChangeProcessor {
private final Set<String> forcedKeywords; private final Set<String> forcedKeywords;
public AttributeChangeProcessor(String[] preferredSubtitles, Set<String> forcedKeywords, Set<String> commentaryKeywords, Set<String> hearingImpairedKeywords) { 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.commentaryKeywords = commentaryKeywords;
this.hearingImpairedKeywords = hearingImpairedKeywords; this.hearingImpairedKeywords = hearingImpairedKeywords;
this.forcedKeywords = forcedKeywords; this.forcedKeywords = forcedKeywords;
} }
private List<TrackAttributes> filterForPossibleDefaults(List<TrackAttributes> tracks) { /**
Stream<TrackAttributes> attributes = tracks.stream(); * Looks for default matches and applies them if found.
*/
if (true) { // TODO: config for including commentary public void findAndApplyDefaultMatch(FileInfo fileInfo, AttributeConfig... configs) {
attributes = 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;
return forcedKeywords.stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
})
.toList();
}
public void findDefaultMatchAndApplyChanges(FileInfo fileInfo, AttributeConfig... configs) {
Map<String, List<TrackAttributes>> audiosByLanguage = new HashMap<>(fileInfo.getTracks().size()); Map<String, List<TrackAttributes>> audiosByLanguage = new HashMap<>(fileInfo.getTracks().size());
Map<String, List<TrackAttributes>> subsByLanguage = new HashMap<>(fileInfo.getTracks().size()); Map<String, List<TrackAttributes>> subsByLanguage = new HashMap<>(fileInfo.getTracks().size());
filterForPossibleDefaults(fileInfo.getTracks()).forEach(track -> { getPossibleDefaults(fileInfo.getTracks()).forEach(track -> {
if (TrackType.AUDIO.equals(track.type())) if (TrackType.AUDIO.equals(track.type()))
audiosByLanguage.computeIfAbsent(track.language(), (k) -> new ArrayList<>()).add(track); audiosByLanguage.computeIfAbsent(track.language(), (k) -> new ArrayList<>()).add(track);
else if (TrackType.SUBTITLES.equals(track.type())) else if (TrackType.SUBTITLES.equals(track.type()))
@@ -63,40 +33,69 @@ public class AttributeChangeProcessor {
}); });
for (AttributeConfig config : configs) { for (AttributeConfig config : configs) {
if (("OFF".equals(config.getAudioLanguage()) || audiosByLanguage.containsKey(config.getAudioLanguage())) if (("OFF".equals(config.getAudioLang()) || audiosByLanguage.containsKey(config.getAudioLang()))
&& ("OFF".equals(config.getSubtitleLanguage()) || subsByLanguage.containsKey(config.getSubtitleLanguage()))) { && ("OFF".equals(config.getSubLang()) || subsByLanguage.containsKey(config.getSubLang()))) {
fileInfo.setMatchedConfig(config); fileInfo.setMatchedConfig(config);
break; break;
} }
// TODO: forced if OFF
} }
if (fileInfo.getMatchedConfig() == null) return; if (fileInfo.getMatchedConfig() == null) return;
applyDefaultChanges(fileInfo, FileInfo::getAudioTracks, fileInfo.getMatchedConfig().getAudioLanguage(), AttributeConfig match = fileInfo.getMatchedConfig();
() -> audiosByLanguage.get(fileInfo.getMatchedConfig().getAudioLanguage()).get(0)); removeExistingDefaults(fileInfo);
applyDefaultChanges(fileInfo, FileInfo::getSubtitleTracks, fileInfo.getMatchedConfig().getSubtitleLanguage(), if (!"OFF".equals(match.getAudioLang())) applyNewDefault(fileInfo, audiosByLanguage.get(fileInfo.getMatchedConfig().getAudioLang()).get(0));
() -> subsByLanguage.get(fileInfo.getMatchedConfig().getSubtitleLanguage()).stream().max(subtitleTrackComparator).get()); if (!"OFF".equals(match.getSubLang())) applyNewDefault(fileInfo, subsByLanguage.get(fileInfo.getMatchedConfig().getSubLang()).stream().max(subtitleTrackComparator).get());
} }
private void applyDefaultChanges(FileInfo fileInfo, Function<FileInfo, List<TrackAttributes>> tracks, String language, Supplier<TrackAttributes> targetDefaultSupplier) { /**
tracks.apply(fileInfo).stream() * If match with xxx:OFF was found forced track in audio language is applied as default.
* Forced track detection takes changes of {@link AttributeChangeProcessor#findAndApplyForcedTracks} into consideration.
*/
public void applyForcedAsDefault(FileInfo fileInfo) {
AttributeConfig c = fileInfo.getMatchedConfig();
if (c == null) return;
if (!"OFF".equals(c.getAudioLang()) && "OFF".equals(c.getSubLang())) {
getForcedTracks(fileInfo)
.filter(track -> c.getAudioLang().equals(track.language()))
.findFirst()
.ifPresent(track -> applyNewDefault(fileInfo, track));
}
}
private Stream<TrackAttributes> getPossibleDefaults(List<TrackAttributes> tracks) {
Stream<TrackAttributes> attributes = tracks.stream();
return attributes
.filter(attr -> !attr.commentary())
.filter(attr -> {
if (attr.trackName() == null) return true;
return commentaryKeywords.stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
})
.filter(attr -> !attr.forced())
.filter(attr -> {
if (attr.trackName() == null) return true;
return forcedKeywords.stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
});
}
private void removeExistingDefaults(FileInfo fileInfo) {
fileInfo.getTracks().stream()
.filter(TrackAttributes::defaultt) .filter(TrackAttributes::defaultt)
.forEach(attr -> fileInfo.getChanges().getDefaultTrack().put(attr, false)); .forEach(attr -> fileInfo.getChanges().getDefaultTrack().put(attr, false));
if (!"OFF".equals(language)) {
TrackAttributes targetDefault = targetDefaultSupplier.get();
if (fileInfo.getChanges().getDefaultTrack().containsKey(targetDefault)) {
fileInfo.getChanges().getDefaultTrack().remove(targetDefault);
} else {
fileInfo.getChanges().getDefaultTrack().put(targetDefault, true);
} }
private void applyNewDefault(FileInfo fileInfo, TrackAttributes targetDefault) {
Map<TrackAttributes, Boolean> changes = fileInfo.getChanges().getDefaultTrack();
if (changes.containsKey(targetDefault)) {
changes.remove(targetDefault);
} else {
changes.put(targetDefault, true);
} }
} }
public void findForcedTracksAndApplyChanges(FileInfo fileInfo, boolean overwrite) { public void findAndApplyForcedTracks(FileInfo fileInfo, boolean overwrite) {
Stream<TrackAttributes> forcedTracks = fileInfo.getTracks().stream() Stream<TrackAttributes> forcedTracks = getForcedTracks(fileInfo);
.filter(track -> track.trackName() != null)
.filter(track -> forcedKeywords.stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT))));
if (overwrite) { if (overwrite) {
fileInfo.getTracks().stream().filter(TrackAttributes::forced).forEach(attr -> { fileInfo.getTracks().stream().filter(TrackAttributes::forced).forEach(attr -> {
@@ -111,7 +110,19 @@ public class AttributeChangeProcessor {
}); });
} }
public void findCommentaryTracksAndApplyChanges(FileInfo fileInfo) { private Stream<TrackAttributes> getForcedTracks(FileInfo fileInfo) {
return fileInfo.getTracks().stream()
.filter(track -> {
if (fileInfo.getChanges().getForcedTrack().containsKey(track)) return fileInfo.getChanges().getForcedTrack().get(track);
return matchesForcedKeywords(track) || track.forced();
});
}
private boolean matchesForcedKeywords(TrackAttributes track) {
return track.trackName() != null && forcedKeywords.stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT)));
}
public void findAndApplyCommentaryTracks(FileInfo fileInfo) {
fileInfo.getTracks().stream() fileInfo.getTracks().stream()
.filter(track -> !track.commentary()) .filter(track -> !track.commentary())
.filter(track -> track.trackName() != null) .filter(track -> track.trackName() != null)
@@ -121,9 +132,9 @@ public class AttributeChangeProcessor {
}); });
} }
public void findHearingImpairedTracksAndApplyChanges(FileInfo fileInfo) { public void findAndApplyHearingImpairedTracks(FileInfo fileInfo) {
fileInfo.getTracks().stream() fileInfo.getTracks().stream()
.filter(track -> !track.commentary()) .filter(track -> !track.hearingImpaired())
.filter(track -> track.trackName() != null) .filter(track -> track.trackName() != null)
.filter(track -> hearingImpairedKeywords.stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT)))) .filter(track -> hearingImpairedKeywords.stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT))))
.forEach(attr -> { .forEach(attr -> {

View File

@@ -1,6 +1,7 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors; package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException; import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.LastExecutionHandler;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
@@ -12,10 +13,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.ArrayList;
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;
@Slf4j @Slf4j
public abstract class AttributeUpdater { public abstract class AttributeUpdater {
@@ -23,14 +26,16 @@ public abstract class AttributeUpdater {
protected final InputConfig config; protected final InputConfig config;
protected final FileProcessor fileProcessor; protected final FileProcessor fileProcessor;
protected final AttributeChangeProcessor attributeChangeProcessor; protected final AttributeChangeProcessor attributeChangeProcessor;
protected final LastExecutionHandler lastExecutionHandler;
protected final ResultStatistic statistic = ResultStatistic.getInstance(); protected final ResultStatistic statistic = ResultStatistic.getInstance();
private final ExecutorService executor; private final ExecutorService executor;
public AttributeUpdater(InputConfig config, FileProcessor fileProcessor) { public AttributeUpdater(InputConfig config, FileProcessor fileProcessor, AttributeChangeProcessor attributeChangeProcessor, LastExecutionHandler lastExecutionHandler) {
this.config = config; this.config = config;
this.fileProcessor = fileProcessor; this.fileProcessor = fileProcessor;
this.attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired()); this.attributeChangeProcessor = attributeChangeProcessor;
this.lastExecutionHandler = lastExecutionHandler;
this.executor = Executors.newFixedThreadPool(config.getThreads()); this.executor = Executors.newFixedThreadPool(config.getThreads());
} }
@@ -60,10 +65,10 @@ public abstract class AttributeUpdater {
executor.awaitTermination(1, TimeUnit.DAYS); executor.awaitTermination(1, TimeUnit.DAYS);
} }
// writeLastExecutionDate(); if (lastExecutionHandler != null) lastExecutionHandler.persist();
statistic.stopTimer(); statistic.stopTimer();
statistic.printResult(); statistic.print();
} }
protected abstract List<File> getFiles(); protected abstract List<File> getFiles();
@@ -82,35 +87,37 @@ public abstract class AttributeUpdater {
* @param fileInfo contains information about file and desired configuration. * @param fileInfo contains information about file and desired configuration.
*/ */
protected void checkStatusAndUpdate(FileInfo fileInfo) { protected void checkStatusAndUpdate(FileInfo fileInfo) {
switch (fileInfo.getStatus()) { if (lastExecutionHandler != null) lastExecutionHandler.update(fileInfo.getFile().getAbsolutePath());
case CHANGE_NECESSARY: if (!fileInfo.getChanges().isEmpty()) {
statistic.shouldChange(); statistic.changePlanned();
commitChange(fileInfo);
break;
case NO_SUITABLE_CONFIG:
statistic.noSuitableConfigFound();
break;
case ALREADY_SUITED:
statistic.alreadyFits();
break;
case UNKNOWN:
default:
statistic.failure();
break;
}
}
private void commitChange(FileInfo fileInfo) { if (config.isSafeMode()) {
if (config.isSafeMode()) return; log.info("Planned changes [{}] for {}", changeLog(fileInfo), fileInfo.getFile().getPath());
return;
}
try { try {
log.info("Committing changes [{}] to {}", changeLog(fileInfo), fileInfo.getFile().getPath());
fileProcessor.update(fileInfo); fileProcessor.update(fileInfo);
statistic.success(); statistic.changeSuccessful();
log.info("Commited {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getPath());
} catch (IOException | MkvToolNixException e) { } catch (IOException | MkvToolNixException e) {
statistic.failedChanging(); 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();
} else {
statistic.unknownFailed();
}
}
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? // should this be here?

View File

@@ -1,5 +1,6 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors; package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.LastExecutionHandler;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
@@ -7,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import me.tongfei.progressbar.ProgressBarBuilder; import me.tongfei.progressbar.ProgressBarBuilder;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -14,8 +16,8 @@ import java.util.Set;
@Slf4j @Slf4j
public class CoherentAttributeUpdater extends SingleFileAttributeUpdater { public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
public CoherentAttributeUpdater(InputConfig config, FileProcessor processor) { public CoherentAttributeUpdater(InputConfig config, FileProcessor processor, AttributeChangeProcessor attributeChangeProcessor, LastExecutionHandler lastExecutionHandler) {
super(config, processor); super(config, processor, attributeChangeProcessor, lastExecutionHandler);
} }
@Override @Override
@@ -25,7 +27,9 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
} }
protected List<File> getFiles() { protected List<File> getFiles() {
return fileProcessor.loadDirectory(config.getLibraryPath().getPath(), config.getCoherent()); return Arrays.stream(config.getLibraryPath())
.flatMap(path -> fileProcessor.loadDirectory(path.getPath(), config.getCoherent()).stream())
.toList();
} }
@Override @Override
@@ -47,29 +51,31 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
matchedFiles.size(), files.size(), rootDir.getPath()); matchedFiles.size(), files.size(), rootDir.getPath());
} }
log.info("Found coherent match {} for {}", matchedConfig.toStringShort(), rootDir.getPath());
matchedFiles.forEach(fileInfo -> { matchedFiles.forEach(fileInfo -> {
attributeChangeProcessor.findForcedTracksAndApplyChanges(fileInfo, this.config.isOverwriteForced()); attributeChangeProcessor.findAndApplyForcedTracks(fileInfo, this.config.isOverwriteForced());
attributeChangeProcessor.findCommentaryTracksAndApplyChanges(fileInfo); attributeChangeProcessor.applyForcedAsDefault(fileInfo);
attributeChangeProcessor.findHearingImpairedTracksAndApplyChanges(fileInfo); attributeChangeProcessor.findAndApplyCommentaryTracks(fileInfo);
attributeChangeProcessor.findAndApplyHearingImpairedTracks(fileInfo);
checkStatusAndUpdate(fileInfo); checkStatusAndUpdate(fileInfo);
}); });
return; // match was found and process must be stopped return; // match was found and process must be stopped
} }
// Couldn't match any config at current level. Resetting changes and trying to one level deeper // Couldn't match any config at current level. Resetting changes and trying one level deeper
matchedFiles.forEach(fileInfo -> { matchedFiles.forEach(fileInfo -> {
fileInfo.resetChanges(); fileInfo.resetChanges();
fileInfo.setMatchedConfig(null); fileInfo.setMatchedConfig(null);
}); });
if (config.isForceCoherent()) { if (config.isForceCoherent()) {
log.info("No coherent match found, aborting: {}", rootDir.getPath()); log.info("No coherent match found, skipping {}", rootDir.getPath());
statistic.increaseNoSuitableConfigFoundBy(files.size()); statistic.increaseUnchangedBy(files.size());
return; 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); for (File dir: fileProcessor.loadDirectory(rootDir.getPath(), 1)) this.process(dir);
} }
@@ -83,12 +89,12 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
fileInfo.setMatchedConfig(null); fileInfo.setMatchedConfig(null);
if (fileInfo.getTracks().isEmpty()) { if (fileInfo.getTracks().isEmpty()) {
log.warn("No attributes found for file {}", file); log.warn("No attributes found for {}", file);
statistic.failure(); statistic.unknownFailed();
break; break;
} }
attributeChangeProcessor.findDefaultMatchAndApplyChanges(fileInfo, config); attributeChangeProcessor.findAndApplyDefaultMatch(fileInfo, config);
if (matchedConfig == null) matchedConfig = fileInfo.getMatchedConfig(); if (matchedConfig == null) matchedConfig = fileInfo.getMatchedConfig();
if (matchedConfig == null || matchedConfig != fileInfo.getMatchedConfig()) { if (matchedConfig == null || matchedConfig != fileInfo.getMatchedConfig()) {

View File

@@ -6,7 +6,7 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.core.util.IOUtils; import org.apache.commons.io.IOUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -120,6 +120,7 @@ public class MkvFileProcessor implements FileProcessor {
for (Map<String, Object> attribute : tracks) { for (Map<String, Object> attribute : tracks) {
if (!"video".equals(attribute.get("type"))) { if (!"video".equals(attribute.get("type"))) {
Map<String, Object> properties = (Map<String, Object>) attribute.get("properties"); 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( fileInfo.addTrack(new TrackAttributes(
(int) properties.get("number"), (int) properties.get("number"),
(String) properties.get("language"), (String) properties.get("language"),
@@ -127,7 +128,7 @@ public class MkvFileProcessor implements FileProcessor {
(Boolean) properties.getOrDefault("default_track", false), (Boolean) properties.getOrDefault("default_track", false),
(Boolean) properties.getOrDefault("forced_track", false), (Boolean) properties.getOrDefault("forced_track", false),
(Boolean) properties.getOrDefault("commentary_track", false), (Boolean) properties.getOrDefault("commentary_track", false),
(Boolean) properties.getOrDefault("hearing_impaired_track", false), (Boolean) properties.getOrDefault("flag_hearing_impaired", false),
TrackType.valueOf(((String) attribute.get("type")).toUpperCase(Locale.ENGLISH)))); TrackType.valueOf(((String) attribute.get("type")).toUpperCase(Locale.ENGLISH))));
} }
} }

View File

@@ -1,18 +1,20 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors; package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.LastExecutionHandler;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.tongfei.progressbar.ProgressBarBuilder; import me.tongfei.progressbar.ProgressBarBuilder;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.List; import java.util.List;
@Slf4j @Slf4j
public class SingleFileAttributeUpdater extends AttributeUpdater { public class SingleFileAttributeUpdater extends AttributeUpdater {
public SingleFileAttributeUpdater(InputConfig config, FileProcessor processor) { public SingleFileAttributeUpdater(InputConfig config, FileProcessor processor, AttributeChangeProcessor attributeChangeProcessor, LastExecutionHandler lastExecutionHandler) {
super(config, processor); super(config, processor, attributeChangeProcessor, lastExecutionHandler);
} }
@Override @Override
@@ -23,7 +25,9 @@ public class SingleFileAttributeUpdater extends AttributeUpdater {
@Override @Override
protected List<File> getFiles() { protected List<File> getFiles() {
return fileProcessor.loadFiles(config.getLibraryPath().getPath()); return Arrays.stream(config.getLibraryPath())
.flatMap(path -> fileProcessor.loadFiles(path.getPath()).stream())
.toList();
} }
@Override @Override
@@ -31,15 +35,16 @@ public class SingleFileAttributeUpdater extends AttributeUpdater {
FileInfo fileInfo = fileProcessor.readAttributes(file); FileInfo fileInfo = fileProcessor.readAttributes(file);
if (fileInfo.getTracks().isEmpty()) { if (fileInfo.getTracks().isEmpty()) {
log.warn("No attributes found for file {}", file); log.warn("No attributes found for {}", file);
statistic.failure(); statistic.unknownFailed();
return; return;
} }
attributeChangeProcessor.findDefaultMatchAndApplyChanges(fileInfo, config.getAttributeConfig()); attributeChangeProcessor.findAndApplyDefaultMatch(fileInfo, config.getAttributeConfig());
attributeChangeProcessor.findForcedTracksAndApplyChanges(fileInfo, config.isOverwriteForced()); attributeChangeProcessor.findAndApplyForcedTracks(fileInfo, config.isOverwriteForced());
attributeChangeProcessor.findCommentaryTracksAndApplyChanges(fileInfo); attributeChangeProcessor.applyForcedAsDefault(fileInfo);
attributeChangeProcessor.findHearingImpairedTracksAndApplyChanges(fileInfo); attributeChangeProcessor.findAndApplyCommentaryTracks(fileInfo);
attributeChangeProcessor.findAndApplyHearingImpairedTracks(fileInfo);
checkStatusAndUpdate(fileInfo); checkStatusAndUpdate(fileInfo);
} }

View File

@@ -2,16 +2,26 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation;
import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext; import jakarta.validation.ConstraintValidatorContext;
import lombok.extern.slf4j.Slf4j;
import java.io.File; import java.io.File;
import java.util.Arrays;
public class ValidFileValidator implements ConstraintValidator<ValidFile, File> { @Slf4j
public class ValidFileValidator implements ConstraintValidator<ValidFile, File[]> {
@Override @Override
public void initialize(ValidFile constraintAnnotation) { public void initialize(ValidFile constraintAnnotation) {
} }
@Override @Override
public boolean isValid(File file, ConstraintValidatorContext context) { public boolean isValid(File[] files, ConstraintValidatorContext context) {
return file != null && file.exists(); if (files == null || files.length == 0) return false;
for (File file: files) {
if (!file.exists()) {
log.error("{} does not exist", file.getPath());
return false;
}
}
return true;
} }
} }

View File

@@ -10,8 +10,8 @@ import java.util.Objects;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class AttributeConfig { public class AttributeConfig {
private final String audioLanguage; private final String audioLang;
private final String subtitleLanguage; private final String subLang;
public static AttributeConfig of(String audioLanguage, String subtitleLanguage) { public static AttributeConfig of(String audioLanguage, String subtitleLanguage) {
return new AttributeConfig(audioLanguage, subtitleLanguage); return new AttributeConfig(audioLanguage, subtitleLanguage);
@@ -22,23 +22,23 @@ public class AttributeConfig {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
AttributeConfig that = (AttributeConfig) o; AttributeConfig that = (AttributeConfig) o;
return Objects.equals(audioLanguage, that.audioLanguage) && Objects.equals(subtitleLanguage, that.subtitleLanguage); return Objects.equals(audioLang, that.audioLang) && Objects.equals(subLang, that.subLang);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(audioLanguage, subtitleLanguage); return Objects.hash(audioLang, subLang);
} }
public String toStringShort() { public String toStringShort() {
return audioLanguage + ":" + subtitleLanguage; return audioLang + ":" + subLang;
} }
@Override @Override
public String toString() { public String toString() {
return "AttributeConfig{" return "AttributeConfig{"
+ "audioLanguage='" + audioLanguage + '\'' + "audioLanguage='" + audioLang + '\''
+ ", subtitleLanguage='" + subtitleLanguage + '\'' + + ", subtitleLanguage='" + subLang + '\'' +
'}'; '}';
} }
} }

View File

@@ -53,11 +53,4 @@ public class FileInfo {
public void resetChanges() { public void resetChanges() {
changes = new PlannedChange(); changes = new PlannedChange();
} }
public FileStatus getStatus() {
if (!changes.isEmpty()) return FileStatus.CHANGE_NECESSARY;
if (matchedConfig == null) return FileStatus.NO_SUITABLE_CONFIG;
if (changes.isEmpty()) return FileStatus.ALREADY_SUITED;
return FileStatus.UNKNOWN;
}
} }

View File

@@ -1,8 +0,0 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
public enum FileStatus {
CHANGE_NECESSARY,
NO_SUITABLE_CONFIG,
ALREADY_SUITED,
UNKNOWN;
}

View File

@@ -12,6 +12,7 @@ import org.apache.commons.lang3.SystemUtils;
import picocli.CommandLine; import picocli.CommandLine;
import java.io.File; import java.io.File;
import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import picocli.CommandLine.Option; import picocli.CommandLine.Option;
@@ -28,12 +29,13 @@ public class InputConfig implements CommandLine.IVersionProvider {
@CommandLine.Spec @CommandLine.Spec
CommandLine.Model.CommandSpec spec; CommandLine.Model.CommandSpec spec;
@Option(names = {"-a", "--attribute-config"}, required = true, 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)")
private AttributeConfig[] attributeConfig;
@ValidFile(message = "does not exist") @ValidFile(message = "does not exist")
@Option(names = {"-l", "--library"}, required = true, description = "path to library") @CommandLine.Parameters(description = "paths to library", arity = "1..*")
private File libraryPath; private File[] libraryPath;
@Option(names = {"-a", "--attribute-config"}, arity = "1..*", converter = AttributeConfigConverter.class,
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") @ValidMkvToolNix(message = "does not exist")
@Option(names = {"-m", "--mkvtoolnix"}, defaultValue = "${DEFAULT_MKV_TOOL_NIX}", description = "path to mkvtoolnix installation") @Option(names = {"-m", "--mkvtoolnix"}, defaultValue = "${DEFAULT_MKV_TOOL_NIX}", description = "path to mkvtoolnix installation")
private File mkvToolNix; private File mkvToolNix;
@@ -42,7 +44,7 @@ public class InputConfig implements CommandLine.IVersionProvider {
private boolean safeMode; private boolean safeMode;
@Min(1) @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; private int threads;
@Min(0) @Min(0)
@@ -52,11 +54,11 @@ public class InputConfig implements CommandLine.IVersionProvider {
private boolean forceCoherent; private boolean forceCoherent;
// TODO: implement usage // TODO: implement usage
// @Option(names = {"-n", "--only-new-file"}, description = "sets filter-date to last successful execution (overwrites input of filter-date)") @Option(names = {"-n", "--only-new-files"}, description = "ignores all files unchanged and previously processed")
// private boolean onlyNewFiles; 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\")") @Option(names = {"-d", "--filter-date"}, defaultValue = Option.NULL_VALUE, description = "only consider files created newer than entered date (following ISO-8601 yyyy-MM-ddTHH:mm:ss.sssZ)")
private Date filterDate; private Instant 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; private Pattern includePattern;
@Option(names = {"-e", "--exclude"}, arity = "1..*", @Option(names = {"-e", "--exclude"}, arity = "1..*",
description = "relative directories and files to be excluded (no wildcard)") description = "relative directories and files to be excluded (no wildcard)")
@@ -65,17 +67,17 @@ public class InputConfig implements CommandLine.IVersionProvider {
@Option(names = {"-o", "-overwrite-forced"}, description = "remove all forced flags") @Option(names = {"-o", "-overwrite-forced"}, description = "remove all forced flags")
private boolean overwriteForced; private boolean overwriteForced;
@Option(names = {"--forced-keywords"}, arity = "1..*", defaultValue = "forced, signs, songs", split = ", ", @Option(names = {"--forced-keywords"}, arity = "1..*", defaultValue = "forced, signs, songs", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
description = "Keywords to identify forced tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})") split = ", ", description = "Keywords to identify forced tracks (Defaults will be overwritten)")
private Set<String> forcedKeywords; private Set<String> forcedKeywords;
@Option(names = {"--commentary-keywords"}, arity = "1..*", defaultValue = "comment, commentary, director", split = ", ", @Option(names = {"--commentary-keywords"}, arity = "1..*", defaultValue = "comment, commentary, director", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
description = "Keywords to identify commentary tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})") split = ", ", description = "Keywords to identify commentary tracks (Defaults will be overwritten)")
private Set<String> commentaryKeywords; private Set<String> commentaryKeywords;
@Option(names = {"--hearing-impaired"}, arity = "1..*", defaultValue = "SDH, CC", split = ", ", @Option(names = {"--hearing-impaired"}, arity = "1..*", defaultValue = "SDH, CC", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
description = "Keywords to identify hearing impaired tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE}") split = ", ", description = "Keywords to identify hearing impaired tracks (Defaults will be overwritten")
private Set<String> hearingImpaired; private Set<String> hearingImpaired;
@Option(names = {"--preferred-subtitles"}, arity = "1..*", defaultValue = "unstyled", split = ", ", @Option(names = {"--preferred-subtitles"}, arity = "1..*", defaultValue = "unstyled", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
description = "Keywords to prefer specific subtitle tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})") split = ", ", description = "Keywords to prefer specific subtitle tracks (Defaults will be overwritten)")
private Set<String> preferredSubtitles; private Set<String> preferredSubtitles;
@Option(names = {"--debug"}, description = "Enable debug logging") @Option(names = {"--debug"}, description = "Enable debug logging")
private boolean debug; private boolean debug;
@@ -90,8 +92,8 @@ public class InputConfig implements CommandLine.IVersionProvider {
return new StringJoiner(", ", InputConfig.class.getSimpleName() + "[", "]") return new StringJoiner(", ", InputConfig.class.getSimpleName() + "[", "]")
.add("configPath=" + configPath) .add("configPath=" + configPath)
.add("spec=" + spec) .add("spec=" + spec)
.add("attributeConfig=" + Arrays.toString(attributeConfig))
.add("libraryPath=" + libraryPath) .add("libraryPath=" + libraryPath)
.add("attributeConfig=" + Arrays.toString(attributeConfig))
.add("mkvToolNix=" + mkvToolNix) .add("mkvToolNix=" + mkvToolNix)
.add("safeMode=" + safeMode) .add("safeMode=" + safeMode)
.add("threads=" + threads) .add("threads=" + threads)

View File

@@ -1,33 +1,21 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model; package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Getter @Getter
@Slf4j @Slf4j
public class ResultStatistic { public class ResultStatistic {
private static final String result = "Total files: %s%n" + private static final String PRINT_TEMPLATE = "Total: %s, Changing: %s (Successful: %s, Failed %s), Unchanged: %s, Excluded: %s, Unknown/Failed: %s\nRuntime: %s";
"├─ Excluded: %s%n" +
"├─ Should change: %s%n" +
"│ ├─ Failed changing: %s%n" +
"│ └─ Successfully changed: %s%n" +
"├─ No suitable config found: %s%n" +
"├─ Already fit config: %s%n" +
"└─ Failed: %s%n" +
"Runtime: %s";
private static ResultStatistic instance; private static ResultStatistic instance;
private int changePlanned = 0;
private int changeFailed = 0;
private int changeSuccessful = 0;
private int unchanged = 0;
private int excluded = 0; private int excluded = 0;
private int unknownFailed = 0;
private int shouldChange = 0;
private int failedChanging = 0;
private int successfullyChanged = 0;
private int noSuitableConfigFound = 0;
private int alreadyFits = 0;
private int failed = 0;
@Getter(AccessLevel.NONE)
private long startTime = 0; private long startTime = 0;
private long runtime = 0; private long runtime = 0;
@@ -43,43 +31,35 @@ public class ResultStatistic {
} }
public int total() { public int total() {
return shouldChange + noSuitableConfigFound + alreadyFits + failed; return changePlanned + unchanged + excluded + unknownFailed;
} }
public void increaseExcludedBy(int amount) { public synchronized void changePlanned() {
excluded += amount; changePlanned++;
}
public synchronized void changeSuccessful() {
changeSuccessful++;
}
public synchronized void changeFailed() {
changeFailed++;
}
public synchronized void unchanged() {
unchanged++;
}
public synchronized void increaseUnchangedBy(int amount) {
unchanged += amount;
} }
public synchronized void excluded() { public synchronized void excluded() {
excluded++; excluded++;
} }
public synchronized void shouldChange() { public synchronized void unknownFailed() {
shouldChange++; unknownFailed++;
}
public synchronized void success() {
successfullyChanged++;
}
public synchronized void failedChanging() {
failedChanging++;
}
public synchronized void noSuitableConfigFound() {
noSuitableConfigFound++;
}
public synchronized void increaseNoSuitableConfigFoundBy(int amount) {
noSuitableConfigFound += amount;
}
public synchronized void alreadyFits() {
alreadyFits++;
}
public synchronized void failure() {
failed++;
} }
public void startTimer() { public void startTimer() {
@@ -90,11 +70,6 @@ public class ResultStatistic {
runtime = System.currentTimeMillis() - startTime; runtime = System.currentTimeMillis() - startTime;
} }
public void printResult() {
System.out.println(prettyPrint());
log.info(this.toString());
}
private String formatTimer() { private String formatTimer() {
int seconds = (int) (runtime / 1000); int seconds = (int) (runtime / 1000);
int minutes = seconds / 60; int minutes = seconds / 60;
@@ -112,22 +87,14 @@ public class ResultStatistic {
} }
} }
public String prettyPrint() { public void print() {
return String.format(result, total(), excluded, shouldChange, failedChanging, successfullyChanged, String result = this.toString();
noSuitableConfigFound, alreadyFits, failed, formatTimer()); System.out.println(result);
log.info(result);
} }
@Override @Override
public String toString() { public String toString() {
return "ResultStatistic: " + "total=" + total() + return String.format(PRINT_TEMPLATE, total(), changePlanned, changeSuccessful, changeFailed, unchanged, excluded, unknownFailed, formatTimer());
", excluded=" + excluded +
", shouldChange=" + shouldChange +
" (failedChanging=" + failedChanging +
", successfullyChanged=" + successfullyChanged +
"), noSuitableConfigFound=" + noSuitableConfigFound +
", alreadyFits=" + alreadyFits +
", failed=" + failed +
", runtime=" + formatTimer();
} }
} }

View File

@@ -16,6 +16,8 @@ public record TrackAttributes(int id, String language, String trackName,
return id == attribute.id return id == attribute.id
&& defaultt == attribute.defaultt && defaultt == attribute.defaultt
&& forced == attribute.forced && forced == attribute.forced
&& commentary == attribute.commentary
&& hearingImpaired == attribute.hearingImpaired
&& Objects.equals(language, attribute.language) && Objects.equals(language, attribute.language)
&& Objects.equals(trackName, attribute.trackName) && Objects.equals(trackName, attribute.trackName)
&& type == attribute.type; && type == attribute.type;
@@ -28,6 +30,8 @@ public record TrackAttributes(int id, String language, String trackName,
", trackName='" + trackName + '\'' + ", trackName='" + trackName + '\'' +
", defaultt=" + defaultt + ", defaultt=" + defaultt +
", forced=" + forced + ", forced=" + forced +
", commentary=" + commentary +
", hearingImpaired=" + hearingImpaired +
", type=" + type + ", type=" + type +
']'; ']';
} }

View File

@@ -1,29 +0,0 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtils {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
public static Date convert(long millis) {
return new Date(millis);
}
/**
* Convert String to date.
* @return parsed date, defaultDate if exception occurs
*/
public static Date convert(String date, Date defaultDate) {
try {
return dateFormat.parse(date);
} catch (ParseException e) {
return defaultDate;
}
}
public static String convert(Date date) {
return dateFormat.format(date);
}
}

View File

@@ -1,12 +1,20 @@
Configuration: Configuration:
name: DefaultLogger name: MainConfig
Properties:
Property:
- name: logDir
value: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs
- name: logPattern
value: "%d{DEFAULT} | %-5level | %msg %n %throwable"
Appenders: Appenders:
RollingFile: RollingFile:
name: FileAppender name: FileAppender
fileName: logs/application.log fileName: ${logDir}/application.log
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout: PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable" Pattern: ${logPattern}
ThresholdFilter: ThresholdFilter:
level: debug level: debug
Policies: Policies:

View File

@@ -1,18 +1,25 @@
Configuration: Configuration:
name: DefaultLogger
Properties:
Property:
- name: logDir
value: "./logs"
- name: log_pattern
value: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
Appenders: Appenders:
Console: Console:
name: Console_Out name: Console_Out
PatternLayout: PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable" Pattern: ${log_pattern}
ThresholdFilter: ThresholdFilter:
level: debug level: debug
RollingFile: RollingFile:
name: FileAppender name: FileAppender
fileName: logs/application.log fileName: ${logDir}/application.log
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout: PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable" Pattern: ${logPattern}
ThresholdFilter: ThresholdFilter:
level: debug level: debug
Policies: Policies:

View File

@@ -1,12 +1,20 @@
Configuration: Configuration:
name: DefaultLogger name: WindowsConfig
Properties:
Property:
- name: logDir
value: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs
- name: logPattern
value: "%d{DEFAULT} | %-5level | %msg %n %throwable"
Appenders: Appenders:
RollingFile: RollingFile:
name: FileAppender name: FileAppender
fileName: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/application.log fileName: ${logDir}/application.log
filePattern: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout: PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable" Pattern: ${logPattern}
ThresholdFilter: ThresholdFilter:
level: debug level: debug
Policies: Policies:
@@ -15,7 +23,7 @@ Configuration:
DefaultRolloverStrategy: DefaultRolloverStrategy:
max: 30 max: 30
Delete: Delete:
basePath: archive basePath: logs/archive
maxDepth: 1 maxDepth: 1
IfLastModified: IfLastModified:
age: 30d age: 30d

View File

@@ -1,12 +1,20 @@
Configuration: Configuration:
name: DefaultLogger name: MainConfig
Properties:
Property:
- name: logDir
value: ./logs
- name: logPattern
value: "%d{DEFAULT} | %-5level | %msg %n %throwable"
Appenders: Appenders:
RollingFile: RollingFile:
name: FileAppender name: FileAppender
fileName: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs/application.log fileName: ${logDir}/application.log
filePattern: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout: PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable" Pattern: ${logPattern}
ThresholdFilter: ThresholdFilter:
level: debug level: debug
Policies: Policies:

View File

@@ -0,0 +1,23 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.CommandRunner;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidationExecutionStrategy;
import org.junit.jupiter.api.Test;
import picocli.CommandLine;
import java.time.Instant;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_FILE;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class PicoCliTest {
@Test
void loadFilterDate() {
CommandRunner underTest = new CommandRunner();
new CommandLine(underTest)
.setExecutionStrategy(new ValidationExecutionStrategy())
.parseArgs("-d", "2012-12-12T12:12:12.00Z", TEST_FILE);
assertEquals(Instant.parse("2012-12-12T12:12:12.00Z"), underTest.getConfig().getFilterDate());
}
}

View File

@@ -1,8 +1,6 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl; package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
@@ -14,11 +12,13 @@ import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import java.io.File; import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.Date; import java.nio.file.attribute.FileTime;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -71,12 +71,14 @@ class FileFilterTest {
when(file.toPath()).thenReturn(Path.of(TEST_FILE)); when(file.toPath()).thenReturn(Path.of(TEST_FILE));
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
FileFilter fileFilter = new FileFilter(excludedDirs, Pattern.compile(pattern), new Date(currentTime + filterDateOffset)); when(attributes.creationTime()).thenReturn(FileTime.fromMillis(currentTime));
when(attributes.lastModifiedTime()).thenReturn(FileTime.fromMillis(currentTime));
FileFilter fileFilter = new FileFilter(excludedDirs, Pattern.compile(pattern), Instant.ofEpochMilli(currentTime).plus(filterDateOffset, ChronoUnit.SECONDS), null);
try (MockedStatic<DateUtils> mockedFiles = Mockito.mockStatic(DateUtils.class)) { try (MockedStatic<Files> mockedFiles = Mockito.mockStatic(Files.class)) {
mockedFiles mockedFiles
.when(() -> DateUtils.convert(anyLong())) .when(() -> Files.readAttributes(any(), eq(BasicFileAttributes.class)))
.thenReturn(new Date(currentTime)); .thenReturn(attributes);
assertEquals(acceptanceExpected, fileFilter.accept(file, new HashSet<>(extensions)), "File is accepted"); assertEquals(acceptanceExpected, fileFilter.accept(file, new HashSet<>(extensions)), "File is accepted");
assertEquals(excluded, ResultStatistic.getInstance().getExcluded() > 0, "Is counted in excluded statistic"); assertEquals(excluded, ResultStatistic.getInstance().getExcluded() > 0, "Is counted in excluded statistic");

View File

@@ -0,0 +1,74 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.Instant;
import static org.junit.jupiter.api.Assertions.*;
class LastExecutionHandlerTest {
private static final String LAST_EXECUTION_PATH = ".";
private static final String LAST_EXECUTION_FILE = "./last-execution.properties";
private static final String TEST_MKV_FILE = "/arst/file.mkv";
@AfterEach
void destruct() {
File file = new File(LAST_EXECUTION_FILE);
if (file.exists()) file.delete();
}
@Test
void missingFile() throws IOException {
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_PATH);
assertNull(underTest.get(TEST_MKV_FILE));
underTest.update(TEST_MKV_FILE);
assertNotNull(underTest.get(TEST_MKV_FILE));
underTest.persist();
File file = new File(LAST_EXECUTION_FILE);
assertTrue(file.exists());
assertTrue(Files.readString(file.toPath()).contains(TEST_MKV_FILE + "="));
}
@Test
void emptyFile() throws IOException {
File file = new File(LAST_EXECUTION_FILE);
file.createNewFile();
missingFile(); // does the checks needed for empty file case
}
@Test
void existingFileNoChanges() throws IOException {
File file = new File(LAST_EXECUTION_FILE);
file.createNewFile();
Files.writeString(file.toPath(), TEST_MKV_FILE + "=" + Instant.now());
String expected = Files.readString(file.toPath()).replace(":", "\\:");
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_PATH);
assertNotNull(underTest.get(TEST_MKV_FILE));
underTest.persist();
File file1 = new File(LAST_EXECUTION_FILE);
assertTrue(file1.exists());
assertTrue(Files.readString(file.toPath()).contains(expected), "File contains expected value");
}
@Test
void existingFileWithChanges() throws IOException {
File file = new File(LAST_EXECUTION_FILE);
file.createNewFile();
Files.writeString(file.toPath(), TEST_MKV_FILE + "=" + Instant.now());
String expected = Files.readString(file.toPath());
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_PATH);
assertNotNull(underTest.get(TEST_MKV_FILE));
underTest.update(TEST_MKV_FILE);
assertNotNull(underTest.get(TEST_MKV_FILE));
underTest.persist();
File file1 = new File(LAST_EXECUTION_FILE);
assertTrue(file1.exists());
assertNotEquals(expected, Files.readString(file.toPath()));
}
}

View File

@@ -12,32 +12,48 @@ import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class SubtitleTrackComparatorTest { class SubtitleTrackComparatorTest {
private static final SubtitleTrackComparator comparator = new SubtitleTrackComparator(new String[]{"unstyled"});
private static Stream<Arguments> compareArguments() { private static Stream<Arguments> compareArguments() {
return Stream.of( return Stream.of(
Arguments.of(List.of(attr("unstyled sub", false), attr("styled sub", false)), Arguments.of(attr(""), attr(""), 0),
List.of(attr("unstyled sub", false), attr("styled sub", false))), Arguments.of(attr("pref"), attr(""), 1),
Arguments.of(List.of(attr("styled sub", false), attr("unstyled sub", false)), Arguments.of(attr(""), attr("pref"), -1),
List.of(attr("unstyled sub", false), attr("styled sub", false))), Arguments.of(attr("pref"), attr("pref"), 0),
Arguments.of(List.of(attr("unstyled sub", true), attr("styled sub", false)), Arguments.of(attr("", true), attr("", true), 0),
List.of(attr("unstyled sub", true), attr("styled sub", false))), Arguments.of(attr("", true), attr(""), -1),
Arguments.of(List.of(attr("styled sub", true), attr("unstyled sub", false)), Arguments.of(attr("CC", true), attr(""), -1),
List.of(attr("unstyled sub", false), attr("styled sub", true))), 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)), Arguments.of(attr("pref", true), attr("pref"), -1),
List.of(attr("unstyled sub", true), attr("unstyled sub", false))) 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 @ParameterizedTest
@MethodSource("compareArguments") @MethodSource("compareArguments")
void compare(List<TrackAttributes> input, List<TrackAttributes> expected) { void compare(TrackAttributes track1, TrackAttributes track2, int expected) {
assertIterableEquals(expected, input.stream().sorted(comparator.reversed()).toList()); 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) { private static TrackAttributes attr(String trackname) {
return new TrackAttributes(0, "", trackName, defaultTrack, false, false, false, TrackType.SUBTITLES); return attr(trackname, false);
}
private static TrackAttributes attr(String trackName, boolean hearingImpaired) {
return new TrackAttributes(0, "", trackName, false, false, false, hearingImpaired, TrackType.SUBTITLES);
} }
} }

View File

@@ -12,13 +12,13 @@ import java.lang.reflect.Method;
import java.util.*; import java.util.*;
import java.util.stream.Stream; import java.util.stream.Stream;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*; import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TrackAttributeUtil.*;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
class AttributeChangeProcessorTest { class AttributeChangeProcessorTest {
private static Stream<Arguments> attributeConfigMatching() { private static Stream<Arguments> findAndApplyDefaultMatch() {
return Stream.of( return Stream.of(
Arguments.of( Arguments.of(
List.of(withName(AUDIO_ENG, null), SUB_ENG), List.of(withName(AUDIO_ENG, null), SUB_ENG),
@@ -71,31 +71,42 @@ class AttributeChangeProcessorTest {
Map.ofEntries() Map.ofEntries()
), ),
Arguments.of( Arguments.of(
List.of(AUDIO_ENG_DEFAULT, AUDIO_GER_HEARING, SUB_GER), List.of(AUDIO_GER, withName(SUB_GER, "SDH")),
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),
arr(a("ger:ger")), "ger:ger", 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))
) )
); );
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("attributeConfigMatching") @MethodSource("findAndApplyDefaultMatch")
void findDefaultMatchAndApplyChanges(List<TrackAttributes> tracks, AttributeConfig[] config, String expectedConfig, Map<TrackAttributes, Boolean> changes) { void findAndApplyDefaultMatch(List<TrackAttributes> tracks, AttributeConfig[] config, String expectedConfig, Map<TrackAttributes, Boolean> changes) {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of("commentary"), Set.of("SDH")); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of("commentary"), Set.of("SDH"));
FileInfo fileInfo = new FileInfo(null); FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks); fileInfo.addTracks(tracks);
attributeChangeProcessor.findDefaultMatchAndApplyChanges(fileInfo, config);
attributeChangeProcessor.findAndApplyDefaultMatch(fileInfo, config);
assertEquals(expectedConfig, fileInfo.getMatchedConfig() != null ? fileInfo.getMatchedConfig().toStringShort() : fileInfo.getMatchedConfig()); assertEquals(expectedConfig, fileInfo.getMatchedConfig() != null ? fileInfo.getMatchedConfig().toStringShort() : fileInfo.getMatchedConfig());
assertEquals(changes.size(), fileInfo.getChanges().getDefaultTrack().size()); assertEquals(changes.size(), fileInfo.getChanges().getDefaultTrack().size());
changes.forEach((key, value) -> { changes.forEach((key, value) -> {
@@ -104,55 +115,116 @@ class AttributeChangeProcessorTest {
}); });
} }
private static AttributeConfig[] arr(AttributeConfig... configs) { private static Stream<Arguments> applyForcedAsDefault() {
return configs; return Stream.of(
Arguments.of(
List.of(AUDIO_GER, SUB_GER_FORCED),
a("ger:OFF"),
Map.ofEntries(on(SUB_GER_FORCED))
),
Arguments.of(
List.of(AUDIO_GER, SUB_GER_FORCED, SUB_GER),
a("ger:OFF"),
Map.ofEntries(on(SUB_GER_FORCED))
),
Arguments.of(
List.of(AUDIO_GER, withName(SUB_GER, "forced")),
a("ger:OFF"),
Map.ofEntries(on(withName(SUB_GER, "forced")))
),
Arguments.of(
List.of(AUDIO_GER, SUB_GER_FORCED, SUB_ENG),
a("ger:eng"),
Map.ofEntries()
),
Arguments.of(
List.of(AUDIO_GER, SUB_GER_FORCED, SUB_ENG),
null,
Map.ofEntries()
)
);
} }
private static AttributeConfig a(String config) { @ParameterizedTest
String[] split = config.split(":"); @MethodSource("applyForcedAsDefault")
return new AttributeConfig(split[0], split[1]); void applyForcedAsDefault(List<TrackAttributes> tracks, AttributeConfig config, Map<TrackAttributes, Boolean> changes) {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of(""), Set.of(""));
FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks);
fileInfo.setMatchedConfig(config);
attributeChangeProcessor.applyForcedAsDefault(fileInfo);
assertEquals(changes.size(), fileInfo.getChanges().getDefaultTrack().size());
changes.forEach((key, value) -> {
assertTrue(fileInfo.getChanges().getDefaultTrack().containsKey(key));
assertEquals(value, fileInfo.getChanges().getDefaultTrack().get(key));
});
} }
private static Map.Entry<TrackAttributes, Boolean> on(TrackAttributes track) { private static Stream<Arguments> getPossibleDefaults() {
return Map.entry(track, true);
}
private static Map.Entry<TrackAttributes, Boolean> off(TrackAttributes track) {
return Map.entry(track, false);
}
private static Stream<Arguments> filterForPossibleDefaults() {
return Stream.of( return Stream.of(
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)), Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
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, "forced"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
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, "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, "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, 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)), 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)) 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))
); );
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("filterForPossibleDefaults") @MethodSource("getPossibleDefaults")
void filterForPossibleDefaults(List<TrackAttributes> tracks, Set<TrackAttributes> expected) throws InvocationTargetException, IllegalAccessException { void getPossibleDefaults(List<TrackAttributes> tracks, Set<TrackAttributes> expected) throws InvocationTargetException, IllegalAccessException {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of("commentary"), Set.of("SDH")); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of("commentary"), Set.of("SDH"));
Optional<Method> method = Arrays.stream(AttributeChangeProcessor.class.getDeclaredMethods()) Optional<Method> method = Arrays.stream(AttributeChangeProcessor.class.getDeclaredMethods())
.filter(m -> m.getName().equals("filterForPossibleDefaults")) .filter(m -> m.getName().equals("getPossibleDefaults"))
.findFirst(); .findFirst();
assertTrue(method.isPresent()); assertTrue(method.isPresent());
Method underTest = method.get(); Method underTest = method.get();
underTest.setAccessible(true); underTest.setAccessible(true);
List<TrackAttributes> result = (List<TrackAttributes>) underTest.invoke(attributeChangeProcessor, tracks); List<TrackAttributes> result = ((Stream<TrackAttributes>) underTest.invoke(attributeChangeProcessor, tracks)).toList();
assertEquals(expected.size(), result.size()); assertEquals(expected.size(), result.size());
for (TrackAttributes track : result) { for (TrackAttributes track : result) {
assertTrue(expected.contains(track)); assertTrue(expected.contains(track));
} }
} }
private static Stream<Arguments> findForcedTracksAndApplyChanges() { private static Stream<Arguments> getForcedTracks() {
return Stream.of(
Arguments.of(List.of(withName(SUB_GER, "forced")), Map.of(), Set.of(withName(SUB_GER, "forced"))),
Arguments.of(List.of(SUB_GER_FORCED), Map.of(), Set.of(SUB_GER_FORCED)),
Arguments.of(List.of(SUB_GER_FORCED, withName(SUB_GER, "forced")), Map.of(), Set.of(SUB_GER_FORCED, withName(SUB_GER, "forced"))),
Arguments.of(List.of(SUB_GER_FORCED, withName(SUB_GER, "forced")), Map.of(SUB_GER_FORCED, false), Set.of(withName(SUB_GER, "forced"))),
Arguments.of(List.of(SUB_GER, withName(SUB_GER, "forced")), Map.of(SUB_GER, true), Set.of(SUB_GER, withName(SUB_GER, "forced")))
);
}
@ParameterizedTest
@MethodSource("getForcedTracks")
void getForcedTracks(List<TrackAttributes> tracks, Map<TrackAttributes, Boolean> changes, Set<TrackAttributes> expected) throws InvocationTargetException, IllegalAccessException {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of(), Set.of());
FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks);
changes.forEach((key, val) -> fileInfo.getChanges().getForcedTrack().put(key, val));
Optional<Method> method = Arrays.stream(AttributeChangeProcessor.class.getDeclaredMethods())
.filter(m -> m.getName().equals("getForcedTracks"))
.findFirst();
assertTrue(method.isPresent());
Method underTest = method.get();
underTest.setAccessible(true);
List<TrackAttributes> result = ((Stream<TrackAttributes>) underTest.invoke(attributeChangeProcessor, fileInfo)).toList();
assertEquals(expected.size(), result.size());
for (TrackAttributes track : result) {
assertTrue(expected.contains(track));
}
}
private static Stream<Arguments> findAndApplyForcedTracks() {
return Stream.of( return Stream.of(
Arguments.of(List.of(), Arguments.of(List.of(),
Set.of("song & signs"), false, Set.of("song & signs"), false,
@@ -186,13 +258,13 @@ class AttributeChangeProcessorTest {
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("findForcedTracksAndApplyChanges") @MethodSource("findAndApplyForcedTracks")
void findForcedTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, boolean overwrite, Map<TrackAttributes, Boolean> changes) { void findAndApplyForcedTracks(List<TrackAttributes> tracks, Set<String> keywords, boolean overwrite, Map<TrackAttributes, Boolean> changes) {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, keywords, Set.of(), Set.of()); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, keywords, Set.of(), Set.of());
FileInfo fileInfo = new FileInfo(null); FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks); fileInfo.addTracks(tracks);
attributeChangeProcessor.findForcedTracksAndApplyChanges(fileInfo, overwrite); attributeChangeProcessor.findAndApplyForcedTracks(fileInfo, overwrite);
assertEquals(changes.size(), fileInfo.getChanges().getForcedTrack().size()); assertEquals(changes.size(), fileInfo.getChanges().getForcedTrack().size());
changes.forEach((key, value) -> { changes.forEach((key, value) -> {
@@ -201,7 +273,7 @@ class AttributeChangeProcessorTest {
}); });
} }
private static Stream<Arguments> findCommentaryTracksAndApplyChanges() { private static Stream<Arguments> findAndApplyCommentaryTracks() {
return Stream.of( return Stream.of(
Arguments.of(List.of(withName(SUB_GER, "commentary"), withName(SUB_GER, null)), Arguments.of(List.of(withName(SUB_GER, "commentary"), withName(SUB_GER, null)),
Set.of("commentary"), Set.of("commentary"),
@@ -223,13 +295,13 @@ class AttributeChangeProcessorTest {
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("findCommentaryTracksAndApplyChanges") @MethodSource("findAndApplyCommentaryTracks")
void findCommentaryTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) { void findAndApplyCommentaryTracks(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of(), keywords, Set.of()); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of(), keywords, Set.of());
FileInfo fileInfo = new FileInfo(null); FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks); fileInfo.addTracks(tracks);
attributeChangeProcessor.findCommentaryTracksAndApplyChanges(fileInfo); attributeChangeProcessor.findAndApplyCommentaryTracks(fileInfo);
assertEquals(changes.size(), fileInfo.getChanges().getCommentaryTrack().size()); assertEquals(changes.size(), fileInfo.getChanges().getCommentaryTrack().size());
changes.forEach((key, value) -> { changes.forEach((key, value) -> {
@@ -238,7 +310,7 @@ class AttributeChangeProcessorTest {
}); });
} }
private static Stream<Arguments> findHearingImpairedTracksAndApplyChanges() { private static Stream<Arguments> findAndApplyHearingImpairedTracks() {
return Stream.of( return Stream.of(
Arguments.of(List.of(withName(SUB_GER, "SDH"), withName(SUB_GER, null)), Arguments.of(List.of(withName(SUB_GER, "SDH"), withName(SUB_GER, null)),
Set.of("SDH"), Set.of("SDH"),
@@ -248,7 +320,7 @@ class AttributeChangeProcessorTest {
Set.of("SDH"), Set.of("SDH"),
Map.ofEntries(on(withName(SUB_GER, "SDH"))) Map.ofEntries(on(withName(SUB_GER, "SDH")))
), ),
Arguments.of(List.of(withName(AUDIO_GER_COMMENTARY, "SDH")), Arguments.of(List.of(withName(AUDIO_GER_HEARING, "SDH")),
Set.of("SDH"), Set.of("SDH"),
Map.ofEntries() Map.ofEntries()
), ),
@@ -260,13 +332,13 @@ class AttributeChangeProcessorTest {
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("findCommentaryTracksAndApplyChanges") @MethodSource("findAndApplyHearingImpairedTracks")
void findHearingImpairedTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) { void findAndApplyHearingImpairedTracks(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of(), Set.of(), keywords); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of(), Set.of(), keywords);
FileInfo fileInfo = new FileInfo(null); FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks); fileInfo.addTracks(tracks);
attributeChangeProcessor.findHearingImpairedTracksAndApplyChanges(fileInfo); attributeChangeProcessor.findAndApplyHearingImpairedTracks(fileInfo);
assertEquals(changes.size(), fileInfo.getChanges().getHearingImpairedTrack().size()); assertEquals(changes.size(), fileInfo.getChanges().getHearingImpairedTrack().size());
changes.forEach((key, value) -> { changes.forEach((key, value) -> {

View File

@@ -0,0 +1,66 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.LastExecutionHandler;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.File;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Stream;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TrackAttributeUtil.AUDIO_GER;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_FILE;
import static org.junit.jupiter.api.Assertions.*;
class AttributeUpdaterTest {
@BeforeEach
void setup() {
ResultStatistic.getInstance(true);
}
private static Stream<Arguments> checkStatusAndUpdate() {
return Stream.of(
Arguments.of(info(new AttributeConfig("ger", "ger"), AUDIO_GER), supplier(() -> ResultStatistic.getInstance().getChangePlanned())),
Arguments.of(info(new AttributeConfig("ger", "ger"), null), supplier(() -> ResultStatistic.getInstance().getUnchanged())),
Arguments.of(info(null, null), supplier(() -> ResultStatistic.getInstance().getUnchanged()))
);
}
@ParameterizedTest
@MethodSource("checkStatusAndUpdate")
void checkStatusAndUpdate(FileInfo fileInfo, Supplier<Integer> getActual) {
InputConfig config = new InputConfig();
config.setThreads(1);
config.setSafeMode(true);
AttributeUpdater underTest = new AttributeUpdater(config, null, null, new LastExecutionHandler("")) {
@Override
protected List<File> getFiles() {
return List.of();
}
@Override
protected void process(File file) {
}
};
underTest.checkStatusAndUpdate(fileInfo);
assertEquals(1, getActual.get());
}
private static Supplier<Integer> supplier(Supplier<Integer> supplier) {
return supplier;
}
private static FileInfo info(AttributeConfig config, TrackAttributes attr) {
FileInfo fileInfo = new FileInfo(new File(TEST_FILE));
fileInfo.setMatchedConfig(config);
if(attr != null) fileInfo.getChanges().getDefaultTrack().put(attr, true);
return fileInfo;
}
}

View File

@@ -1,12 +1,12 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors; package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.CommandRunner; import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.CommandRunner;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.LastExecutionHandler;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
@@ -21,19 +21,17 @@ import java.lang.reflect.Method;
import java.util.*; import java.util.*;
import java.util.stream.Stream; import java.util.stream.Stream;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*; import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_DIR;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TrackAttributeUtil.*;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class CoherentAttributeUpdaterTest { class CoherentAttributeUpdaterTest {
@Mock(lenient = true) @Mock(lenient = true)
FileProcessor fileProcessor; FileProcessor fileProcessor;
@Test
void process() {
}
private static Stream<Arguments> findMatch() { private static Stream<Arguments> findMatch() {
return Stream.of( return Stream.of(
Arguments.of(AttributeConfig.of("ger", "ger"), Arguments.of(AttributeConfig.of("ger", "ger"),
@@ -65,9 +63,11 @@ class CoherentAttributeUpdaterTest {
@MethodSource("findMatch") @MethodSource("findMatch")
void findMatch(AttributeConfig attributeConfig, List<Pair<File, FileInfo>> fileInfoMock, boolean expectedMatch, int expectedMatchCount) throws InvocationTargetException, IllegalAccessException { void findMatch(AttributeConfig attributeConfig, List<Pair<File, FileInfo>> fileInfoMock, boolean expectedMatch, int expectedMatchCount) throws InvocationTargetException, IllegalAccessException {
CommandRunner commandRunner = new CommandRunner(); CommandRunner commandRunner = new CommandRunner();
new CommandLine(commandRunner).parseArgs("-l", "/arst", "-a", "ger:ger"); new CommandLine(commandRunner).parseArgs("-a", "ger:ger", "/arst");
InputConfig config = commandRunner.getConfig(); InputConfig config = commandRunner.getConfig();
CoherentAttributeUpdater updater = new CoherentAttributeUpdater(config, fileProcessor); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired());
LastExecutionHandler lastExecutionHandler = new LastExecutionHandler("");
CoherentAttributeUpdater updater = new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor, lastExecutionHandler);
Set<FileInfo> matchedFiles = new HashSet<>(fileInfoMock.size() * 2); Set<FileInfo> matchedFiles = new HashSet<>(fileInfoMock.size() * 2);
List<File> files = new ArrayList<>(); List<File> files = new ArrayList<>();
@@ -90,4 +90,130 @@ class CoherentAttributeUpdaterTest {
fileInfo.addTracks(List.of(tracks)); fileInfo.addTracks(List.of(tracks));
return Pair.of(file, fileInfo); return Pair.of(file, fileInfo);
} }
private static Stream<Arguments> process() {
return Stream.of(
Arguments.of(
arr(a("ger:ger")), a("ger:ger"),
List.of(
List.of(AUDIO_GER, SUB_GER),
List.of(AUDIO_GER, SUB_GER)
),
List.of(
Map.ofEntries(on(AUDIO_GER), on(SUB_GER)),
Map.ofEntries(on(AUDIO_GER), on(SUB_GER))
),
List.of(
Map.ofEntries(),
Map.ofEntries()
),
List.of(
Map.ofEntries(),
Map.ofEntries()
),
List.of(
Map.ofEntries(),
Map.ofEntries()
)
),
Arguments.of(
arr(a("eng:eng"), a("ger:ger")), a("ger:ger"),
List.of(
List.of(SUB_ENG, AUDIO_GER, SUB_GER),
List.of(AUDIO_ENG, SUB_ENG, AUDIO_GER, SUB_GER)
),
List.of(
Map.ofEntries(on(AUDIO_GER), on(SUB_GER)),
Map.ofEntries(on(AUDIO_GER), on(SUB_GER))
),
List.of(
Map.ofEntries(),
Map.ofEntries()
),
List.of(
Map.ofEntries(),
Map.ofEntries()
),
List.of(
Map.ofEntries(),
Map.ofEntries()
)
),
Arguments.of(
arr(a("eng:eng"), a("ger:ger")), a("eng:eng"),
List.of(
List.of(AUDIO_ENG, withName(SUB_ENG, "SDH"), AUDIO_GER, SUB_GER),
List.of(AUDIO_ENG, SUB_ENG, AUDIO_GER, SUB_GER)
),
List.of(
Map.ofEntries(on(AUDIO_ENG), on(withName(SUB_ENG, "SDH"))),
Map.ofEntries(on(AUDIO_ENG), on(SUB_ENG))
),
List.of(
Map.ofEntries(),
Map.ofEntries()
),
List.of(
Map.ofEntries(),
Map.ofEntries()
),
List.of(
Map.ofEntries(on(withName(SUB_ENG, "SDH"))),
Map.ofEntries()
)
)
);
}
@ParameterizedTest
@MethodSource("process")
void process(AttributeConfig[] attributeConfigs, AttributeConfig expectedMatch,
List<List<TrackAttributes>> tracks,
List<Map<TrackAttributes, Boolean>> defaultExp,
List<Map<TrackAttributes, Boolean>> forcedExp,
List<Map<TrackAttributes, Boolean>> commentaryExp,
List<Map<TrackAttributes, Boolean>> hearingImpairedExp) {
InputConfig config = new InputConfig();
config.setThreads(1);
config.setSafeMode(true);
config.setAttributeConfig(attributeConfigs);
FileProcessor fileProcessor = spy(FileProcessor.class);
List<File> testMkvFiles = new ArrayList<>();
List<FileInfo> testFileInfo = new ArrayList<>();
for (int i = 0; i < tracks.size(); i++) {
List<TrackAttributes> tracks1 = tracks.get(i);
File file = new File(TEST_DIR + i);
FileInfo fileInfo = new FileInfo(file);
fileInfo.addTracks(tracks1);
doReturn(fileInfo).when(fileProcessor).readAttributes(file);
testMkvFiles.add(file);
testFileInfo.add(fileInfo);
}
doReturn(testMkvFiles).when(fileProcessor).loadFiles(any());
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{"pref"}, Set.of("forced"), Set.of("commentary"), Set.of("SDH"));
LastExecutionHandler lastExecutionHandler = new LastExecutionHandler("");
CoherentAttributeUpdater underTest = new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor, lastExecutionHandler);
underTest.process(new File(""));
for (int i = 0; i < testFileInfo.size(); i++) {
FileInfo fileInfo = testFileInfo.get(i);
assertEquals(expectedMatch, fileInfo.getMatchedConfig());
assertEquals(fileInfo.getChanges().getDefaultTrack().size(), defaultExp.get(i).size());
defaultExp.get(i).forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getDefaultTrack().get(key), "Default track flag"));
assertEquals(fileInfo.getChanges().getForcedTrack().size(), forcedExp.get(i).size());
forcedExp.get(i).forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getForcedTrack().get(key), "Forced track flag"));
assertEquals(fileInfo.getChanges().getCommentaryTrack().size(), commentaryExp.get(i).size());
commentaryExp.get(i).forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getCommentaryTrack().get(key), "Commentary track flag"));
assertEquals(fileInfo.getChanges().getHearingImpairedTrack().size(), hearingImpairedExp.get(i).size());
hearingImpairedExp.get(i).forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getHearingImpairedTrack().get(key), "Hearing Impaired track flag"));
}
}
} }

View File

@@ -57,6 +57,8 @@ class MkvFileProcessorTest {
"default_track": true, "default_track": true,
"enabled_track": true, "enabled_track": true,
"forced_track": false, "forced_track": false,
"commentary_track": true,
"flag_hearing_impaired": true,
"language": "eng", "language": "eng",
"number": 3 "number": 3
}, },
@@ -88,8 +90,8 @@ class MkvFileProcessorTest {
assertEquals("eng", sub.language()); assertEquals("eng", sub.language());
assertTrue(sub.defaultt()); assertTrue(sub.defaultt());
assertFalse(sub.forced()); assertFalse(sub.forced());
assertFalse(sub.hearingImpaired()); assertTrue(sub.hearingImpaired());
assertFalse(sub.commentary()); assertTrue(sub.commentary());
assertEquals(TrackType.SUBTITLES, sub.type()); assertEquals(TrackType.SUBTITLES, sub.type());
} }

View File

@@ -0,0 +1,98 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.LastExecutionHandler;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_DIR;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TrackAttributeUtil.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
class SingleFileAttributeUpdaterTest {
private static Stream<Arguments> process() {
return Stream.of(
Arguments.of(
arr(a("ger:OFF")), a("ger:OFF"),
List.of(AUDIO_GER, SUB_GER_FORCED),
Map.ofEntries(on(AUDIO_GER), on(SUB_GER_FORCED)),
Map.ofEntries(),
Map.ofEntries(),
Map.ofEntries()
),
Arguments.of(
arr(a("ger:ger")), a("ger:ger"),
List.of(AUDIO_GER, SUB_GER, withName(AUDIO_GER, "SDH"), withName(AUDIO_GER, "commentary"), withName(SUB_GER, "Forced")),
Map.ofEntries(on(AUDIO_GER), on(SUB_GER)),
Map.ofEntries(on(withName(SUB_GER, "Forced"))),
Map.ofEntries(on(withName(AUDIO_GER, "commentary"))),
Map.ofEntries(on(withName(AUDIO_GER, "SDH")))
),
Arguments.of(
arr(a("ger:OFF")), a("ger:OFF"),
List.of(AUDIO_GER, SUB_GER, withName(AUDIO_GER, "SDH"), withName(AUDIO_GER, "commentary"), withName(SUB_GER, "Forced")),
Map.ofEntries(on(AUDIO_GER), on(withName(SUB_GER, "Forced"))),
Map.ofEntries(on(withName(SUB_GER, "Forced"))),
Map.ofEntries(on(withName(AUDIO_GER, "commentary"))),
Map.ofEntries(on(withName(AUDIO_GER, "SDH")))
),
Arguments.of(
arr(a("ger:eng")), null,
List.of(AUDIO_GER, SUB_GER, withName(AUDIO_GER, "SDH"), withName(AUDIO_GER, "commentary"), withName(SUB_GER, "Forced")),
Map.ofEntries(),
Map.ofEntries(on(withName(SUB_GER, "Forced"))),
Map.ofEntries(on(withName(AUDIO_GER, "commentary"))),
Map.ofEntries(on(withName(AUDIO_GER, "SDH")))
)
);
}
@ParameterizedTest
@MethodSource("process")
void process(AttributeConfig[] attributeConfigs, AttributeConfig expectedMatch,
List<TrackAttributes> tracks,
Map<TrackAttributes, Boolean> defaultExp,
Map<TrackAttributes, Boolean> forcedExp,
Map<TrackAttributes, Boolean> commentaryExp,
Map<TrackAttributes, Boolean> hearingImpairedExp) {
InputConfig config = new InputConfig();
config.setThreads(1);
config.setSafeMode(true);
config.setAttributeConfig(attributeConfigs);
FileInfo fileInfo = new FileInfo(new File(TEST_DIR));
fileInfo.addTracks(tracks);
FileProcessor fileProcessor = spy(FileProcessor.class);
doReturn(fileInfo).when(fileProcessor).readAttributes(any());
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{"pref"}, Set.of("forced"), Set.of("commentary"), Set.of("SDH"));
LastExecutionHandler lastExecutionHandler = new LastExecutionHandler("");
SingleFileAttributeUpdater underTest = new SingleFileAttributeUpdater(config, fileProcessor, attributeChangeProcessor, lastExecutionHandler);
underTest.process(fileInfo.getFile());
assertEquals(expectedMatch, fileInfo.getMatchedConfig());
assertEquals(fileInfo.getChanges().getDefaultTrack().size(), defaultExp.size());
defaultExp.forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getDefaultTrack().get(key), "Default track flag"));
assertEquals(fileInfo.getChanges().getForcedTrack().size(), forcedExp.size());
forcedExp.forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getForcedTrack().get(key), "Forced track flag"));
assertEquals(fileInfo.getChanges().getCommentaryTrack().size(), commentaryExp.size());
commentaryExp.forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getCommentaryTrack().get(key), "Commentary track flag"));
assertEquals(fileInfo.getChanges().getHearingImpairedTrack().size(), hearingImpairedExp.size());
hearingImpairedExp.forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getHearingImpairedTrack().get(key), "Hearing Impaired track flag"));
}
}

View File

@@ -12,7 +12,6 @@ import java.io.StringWriter;
import java.util.stream.Stream; import java.util.stream.Stream;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.*; import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.*;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class ValidationExecutionStrategyTest { class ValidationExecutionStrategyTest {
@@ -22,25 +21,25 @@ class ValidationExecutionStrategyTest {
CommandRunner underTest = new CommandRunner(); CommandRunner underTest = new CommandRunner();
new CommandLine(underTest) new CommandLine(underTest)
.setExecutionStrategy(new ValidationExecutionStrategy()) .setExecutionStrategy(new ValidationExecutionStrategy())
.parseArgs("-a", "ger:ger", "-l", TEST_FILE, "-m", TEST_MKVTOOLNIX_DIR); .parseArgs("-a", "ger:ger", "-m", TEST_MKVTOOLNIX_DIR, TEST_FILE);
assertEquals(TEST_FILE, underTest.getConfig().getLibraryPath().getPath().replace("\\", "/")); assertEquals(TEST_FILE, underTest.getConfig().getLibraryPath()[0].getPath().replace("\\", "/"));
assertEquals(TEST_MKVTOOLNIX_DIR, underTest.getConfig().getMkvToolNix().getPath().replace("\\", "/")); assertEquals(TEST_MKVTOOLNIX_DIR, underTest.getConfig().getMkvToolNix().getPath().replace("\\", "/"));
} }
private static Stream<Arguments> validateFailure() { private static Stream<Arguments> validateFailure() {
return Stream.of( return Stream.of(
Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): --library=<libraryPath>"), Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): <libraryPath>"),
Arguments.of(new String[]{"-a", "jpn:ger", "-l"}, "Missing required parameter for option '--library' (<libraryPath>)"), Arguments.of(new String[]{"/arstarstarst"}, "libraryPath does not exist"),
Arguments.of(new String[]{"-l", "/arstarstarst"}, "Error: Missing required argument(s): --attribute-config=<attributeConfig>"), Arguments.of(new String[]{TEST_DIR, "/arstarstarst"}, "libraryPath does not exist"),
Arguments.of(new String[]{"-l", "/arstarstarst", "-a",}, "Missing required parameter for option '--attribute-config' at index 0 (<attributeConfig>)"), Arguments.of(new String[]{"/arstarstarst", "-a",}, "Missing required parameter for option '--attribute-config' at index 0 (<attributeConfig>)"),
Arguments.of(new String[]{"-l", "/arstarstarst", "-a", "jpn:ger"}, "libraryPath does not exist"), Arguments.of(new String[]{"/arstarstarst", "-a", "jpn:ger"}, "libraryPath does not exist"),
Arguments.of(args("-m"), "Missing required parameter for option '--mkvtoolnix' (<mkvToolNix>)"), Arguments.of(new String[]{"/arstarstarst", "-m"}, "Missing required parameter for option '--mkvtoolnix' (<mkvToolNix>)"),
Arguments.of(args("-m", TEST_INVALID_DIR), "mkvToolNix does not exist"), Arguments.of(new String[]{"./", "-m", TEST_INVALID_DIR}, "mkvToolNix does not exist"),
Arguments.of(args("-t"), "Missing required parameter for option '--threads' (<threads>)"), Arguments.of(new String[]{"./", "-t"}, "Missing required parameter for option '--threads' (<threads>)"),
Arguments.of(args("-t", "0"), "threads must be greater than or equal to 1"), Arguments.of(new String[]{"./", "-t", "0"}, "threads must be greater than or equal to 1"),
Arguments.of(args("-t", "-1"), "threads must be greater than or equal to 1"), Arguments.of(new String[]{"./", "-t", "-1"}, "threads must be greater than or equal to 1"),
Arguments.of(args("-c", "-1"), "coherent must be greater than or equal to 0") Arguments.of(new String[]{"./", "-c", "-1"}, "coherent must be greater than or equal to 0")
); );
} }

View File

@@ -1,39 +0,0 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.nio.file.attribute.FileAttribute;
import java.util.Set;
import java.util.stream.Stream;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileStatus.*;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.*;
import static org.junit.jupiter.api.Assertions.*;
class FileInfoTest {
private static Stream<Arguments> getStatus() {
return Stream.of(
Arguments.of(CHANGE_NECESSARY, info(new AttributeConfig("ger", "ger"), AUDIO_GER)),
Arguments.of(ALREADY_SUITED, info(new AttributeConfig("ger", "ger"), null)),
Arguments.of(NO_SUITABLE_CONFIG, info(null, null))
);
}
@ParameterizedTest
@MethodSource
void getStatus(FileStatus expected, FileInfo underTest) {
FileStatus actual = underTest.getStatus();
assertEquals(expected, actual);
}
private static FileInfo info(AttributeConfig config, TrackAttributes attr) {
FileInfo fileInfo = new FileInfo(null);
fileInfo.setMatchedConfig(config);
if(attr != null) fileInfo.getChanges().getDefaultTrack().put(attr, true);
return fileInfo;
}
}

View File

@@ -1,23 +0,0 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.*;
@Disabled
class DateUtilsTest {
@Test
void convert() {
Date expectedDate = new Date(0);
String expectedString = "01.01.1970-01:00:00";
assertEquals(expectedDate, DateUtils.convert(0));
assertEquals(expectedDate, DateUtils.convert(expectedString, expectedDate));
assertEquals(expectedDate, DateUtils.convert("1234;15", expectedDate));
assertEquals(expectedString, DateUtils.convert(expectedDate));
}
}

View File

@@ -3,10 +3,10 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
public class TestUtil { public class TestUtil {
public static String[] args(String... args) { public static String[] args(String... args) {
String[] staticArray = new String[]{"-l", "/", "-a", "jpn:ger"}; String[] staticArray = new String[]{"-a", "jpn:ger", "/"};
String[] result = new String[staticArray.length + args.length]; String[] result = new String[staticArray.length + args.length];
System.arraycopy(staticArray, 0, result, 0, staticArray.length); System.arraycopy(args, 0, result, 0, args.length);
System.arraycopy(args, 0, result, staticArray.length, args.length); System.arraycopy(staticArray, 0, result, args.length, staticArray.length);
return result; return result;
} }
} }

View File

@@ -1,9 +1,12 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util; package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackType; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackType;
public class FileInfoTestUtil { import java.util.Map;
public class TrackAttributeUtil {
public static final TrackAttributes AUDIO_GER = new TrackAttributes(0, "ger", "", false, false, false, false, TrackType.AUDIO); public static final TrackAttributes AUDIO_GER = new TrackAttributes(0, "ger", "", false, false, false, false, TrackType.AUDIO);
public static final TrackAttributes AUDIO_ENG = new TrackAttributes(1, "eng", "", false, false, false, false, TrackType.AUDIO); public static final TrackAttributes AUDIO_ENG = new TrackAttributes(1, "eng", "", false, false, false, false, TrackType.AUDIO);
public static final TrackAttributes AUDIO_GER_DEFAULT = new TrackAttributes(0, "ger", "", true, false, false, false, TrackType.AUDIO); public static final TrackAttributes AUDIO_GER_DEFAULT = new TrackAttributes(0, "ger", "", true, false, false, false, TrackType.AUDIO);
@@ -13,7 +16,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_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_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_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_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); public static final TrackAttributes SUB_ENG = new TrackAttributes(1, "eng", "", false, false, false, false, TrackType.SUBTITLES);
@@ -21,8 +24,28 @@ 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_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_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_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) { 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()); return new TrackAttributes(track.id(), track.language(), trackName, track.defaultt(), track.forced(), track.commentary(), track.hearingImpaired(), track.type());
} }
public static AttributeConfig[] arr(AttributeConfig... configs) {
return configs;
}
public static AttributeConfig a(String config) {
String[] split = config.split(":");
return new AttributeConfig(split[0], split[1]);
}
public static Map.Entry<TrackAttributes, Boolean> on(TrackAttributes track) {
return Map.entry(track, true);
}
public static Map.Entry<TrackAttributes, Boolean> off(TrackAttributes track) {
return Map.entry(track, false);
}
} }