24 Commits

Author SHA1 Message Date
RatzzFatzz
b0f927dfa8 Implement OFF for audio tracks 2025-10-16 17:10:33 +02:00
RatzzFatzz
37c65df60c Update dependencies && Fix status reporting if no subs are available for file 2025-10-16 00:30:54 +02:00
0e9d008c7e Fix formatting in README.md 2025-05-12 16:00:19 +02:00
3205969d3b Update readme 2025-05-02 03:33:14 +02:00
d24aedb0af Fix mkvpropedit call & improve logging 2025-05-02 03:27:24 +02:00
b86c7b98a5 Fix logging for portable 2025-05-01 22:55:11 +02:00
Michael
69c192c08b Update README.md 2025-02-22 20:37:04 +01:00
Michael
7dd01234b6 Merge pull request #57 from RatzzFatzz/dev
Fix execution on linux
2025-02-18 19:23:08 +01:00
RatzzFatzz
8f38abcf3a Fix execution on linux 2025-02-18 19:15:02 +01:00
Michael
fc4e80ead0 Merge pull request #55 from RatzzFatzz/dev
Release v4.0
2025-02-06 22:27:06 +01:00
RatzzFatzz
e81b06f6fa Improve logging 2025-02-06 00:18:49 +01:00
RatzzFatzz
dc770c9325 Fix file count if no info was found 2025-02-06 00:00:28 +01:00
RatzzFatzz
471255a09b Fix windows installer build 2025-02-05 23:32:01 +01:00
RatzzFatzz
9c8315aec7 Remove config-template 2025-02-05 23:13:54 +01:00
RatzzFatzz
c33777b038 Add debian build to github action 2025-02-05 23:02:40 +01:00
RatzzFatzz
6c08ce69ea Fix logging for debian build 2025-02-05 22:59:38 +01:00
RatzzFatzz
7f8c14e3a9 Use maven properties for wix installer vars 2025-02-05 16:00:01 +01:00
RatzzFatzz
553c672e4d Implement debian package build 2025-02-05 15:49:46 +01:00
RatzzFatzz
d98c4cd49e Handle empty input 2025-02-04 17:57:34 +01:00
RatzzFatzz
21f244ff3f Update logging config 2025-02-04 17:48:45 +01:00
RatzzFatzz
ffac36ac27 Update example gif 2025-02-04 14:45:57 +01:00
RatzzFatzz
0813744148 Update README.md 2025-02-04 13:56:29 +01:00
RatzzFatzz
44d2601d3e Update config parameters and descriptions 2025-02-04 13:49:19 +01:00
Michael
a075dfb27c Remove forced audio tracks & minor refactoring 2024-05-27 22:31:34 +02:00
37 changed files with 716 additions and 462 deletions

View File

@@ -20,11 +20,11 @@ jobs:
with:
timezoneLinux: "Europe/Berlin"
- name: Set up JDK 21
- name: Set up JDK 17
uses: actions/setup-java@v4.7.0
with:
distribution: temurin
java-version: 21
java-version: 17
- name: Setup workspace
run: mkdir artifacts
@@ -41,6 +41,41 @@ jobs:
with:
args: 'artifacts/M*'
debian-build:
runs-on: ubuntu-latest
steps:
- name: Install mkvtoolnix
run: sudo apt-get install -y mkvtoolnix
- name: Checkout
uses: actions/checkout@v4
- name: Set timezone
uses: szenius/set-timezone@v2.0
with:
timezoneLinux: "Europe/Berlin"
- name: Set up JDK 17
uses: actions/setup-java@v4.7.0
with:
distribution: temurin
java-version: 17
- name: Setup workspace
run: mkdir artifacts
- name: Build with Maven
run: |
mvn clean package --file pom.xml -P linux
cp target/M*.deb artifacts/
- name: Upload artifacts
uses: skx/github-action-publish-binaries@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: 'artifacts/M*'
windows-installer-build:
runs-on: windows-latest
steps:

View File

@@ -1,49 +1,64 @@
## Introduction
This program helps to change audio and subtitle tracks of mkv files without rewriting the file. Only track properties will be updated.
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.
![](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/blob/master/example.gif)
## Requirements
- Java 11 or higher
- Java 21 or newer
- mkvtoolnix installation
## Execution
**Minimal usage:**
`java -jar mkvaudiosubtitlechanger.jar --library "X:/Files" --attribute-config eng:ger eng:OFF`
Portable:
```
java -jar mkvaudiosubtitlechanger-<version>.jar --library "X:/Files" --attribute-config eng:ger eng:OFF
```
Windows & Linux (installed):
```
mkvaudiosubtitlechanger --library "X:/Files" --attribute-config eng:ger eng:OFF
```
**Safe usage (best for testing before applying to whole library):**
`java -jar mkvaudiosubtitlechanger.jar --library "X:/Files" --attribute-config eng:ger eng:OFF --safe-mode`
Add `--safe-mode` oder `-s` to not change any files. This is recommended for the first executions.
Attribute-config must be entered in pairs: `audio:subtitle`; Example: `jpn:eng`. More about this topic
[here](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/Attribute-Config).
## Available parameters
### Available parameters
```
-l,--library-path <arg> Path to library
-a,--attribute-config <arg> Attribute config to decide which tracks to choose when
-p,--config-path <arg> Path to config file
-m,--mkvtoolnix <arg> Path to mkv tool nix installation
-s,--safe-mode Test run (no files will be changes)
-c,--coherent <arg> Try to match all files in dir of depth with the same config
-cf,--force-coherent Force coherent and don't update anything if config fits not whole config (default: false)
-n,--only-new-files Sets filter-date to last successful execution (Overwrites input of filter-date)
-d,--filter-date <arg> Only consider files created newer than entered date (format: "dd.MM.yyyy-HH:mm:ss")
-t,--threads <arg> Thread count (default: 2)
-i,--include-pattern <arg> Include files matching pattern (default: ".*")
-e,--excluded-directories <arg> Directories to be excluded, combines with config file
-fk,--forced-keywords <arg> Additional keywords to identify forced tracks
-ck,--commentary-keywords <arg> Additional keywords to identify commentary tracks
-ps,--preferred-subtitles <arg> Additional keywords to prefer specific subtitle tracks
-v,--version Display version
-h,--help "For help this is" - Yoda
-a, --attribute-config=<attributeConfig>...
List of audio:subtitle pairs used to match in order and update files accordingly (e.g. jpn:eng jpn:ger)
-c, --coherent=<coherent> try to match all files in dir of depth with the same attribute config
-cf, --force-coherent changes are only applied if it's a coherent match
--commentary-keywords=<commentaryKeywords>[, <commentaryKeywords>...]...
Keywords to identify commentary tracks (Defaults will be overwritten; Default: commentary, director)
-d, --filter-date=<filterDate>
only consider files created newer than entered date (format: "dd.MM.yyyy-HH:mm:ss")
--debug Enable debug logging
-e, --excluded-directory=<excludedDirectories>...
Directories to be excluded, combines with config file
--forced-keywords=<forcedKeywords>[, <forcedKeywords>...]...
Keywords to identify forced tracks (Defaults will be overwritten; Default: forced, signs, songs)
-h, --help Show this help message and exit.
-i, --include-pattern=<includePattern>
include files matching pattern (default: ".*")
-l, --library=<libraryPath>
path to library
-m, --mkvtoolnix=<mkvToolNix>
path to mkvtoolnix installation
-n, --only-new-file sets filter-date to last successful execution (overwrites input of filter-date)
--preferred-subtitles=<preferredSubtitles>[, <preferredSubtitles>...]...
Keywords to prefer specific subtitle tracks (Defaults will be overwritten; Default: unstyled)
-s, --safemode test run (no files will be changes)
-t, --threads=<threads> thread count (default: 2)
-V, --version Print version information and exit.
```
If you need more information about how each parameter works, check out [this wiki page](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/Parameters).
If you need more information how each parameter works, check out [this wiki page](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/Parameters-v4).
All parameters can also be defined in a [config file](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/How-to-config-file).
All parameters can also be defined in a [config file](https://picocli.info/#_argument_files_for_long_command_lines).
## Build requirements
- JDK 11 or higher
- JDK 21 or newer
- Maven 3
- Git
@@ -51,5 +66,5 @@ All parameters can also be defined in a [config file](https://github.com/RatzzFa
```shell
git clone https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
cd MKVAudioSubtitleChanger
mvn package
mvn clean package -Pportable
```

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

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

226
pom.xml
View File

@@ -6,12 +6,18 @@
<groupId>at.pcgamingfreaks</groupId>
<artifactId>MKVAudioSubtitleChanger</artifactId>
<version>4.0.0</version>
<version>4.0.4</version>
<properties>
<mainClass>at.pcgamingfreaks.mkvaudiosubtitlechanger.Main</mainClass>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lombok-version>1.18.36</lombok-version>
<project.maintainer>RatzzFatzz</project.maintainer>
<project.maintainer.mail>github.contact@ratzloeffel.de</project.maintainer.mail>
<project.description>Command-line utility for batch-managing default audio and subtitle tracks in MKV files.</project.description>
<java-version>17</java-version>
<lombok-version>1.18.42</lombok-version>
</properties>
<profiles>
@@ -22,8 +28,7 @@
<resource>
<directory>src/main/resources</directory>
<includes>
<include>log4j2.yml</include>
<include>log4j2-debug.yml</include>
<include>log4j2.yaml</include>
</includes>
</resource>
</resources>
@@ -66,24 +71,70 @@
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-jpackage-input</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/jpackage-input</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>filter-windows-installer-info</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/wix-resources</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/wix/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.panteleyev</groupId>
<artifactId>jpackage-maven-plugin</artifactId>
<version>1.6.5</version>
<version>1.7.1</version>
<configuration>
<name>${project.artifactId}</name>
<vendor>RatzzFatzz</vendor>
<appVersion>${project.version}</appVersion>
<destination>target/installer</destination>
<input>target/jpackage-input</input>
<mainClass>at.pcgamingfreaks.mkvaudiosubtitlechanger.Main</mainClass>
<mainJar>${project.artifactId}-${project.version}.jar</mainJar>
<resourceDir>${project.build.directory}/wix-resources/</resourceDir>
<type>EXE</type>
<winConsole>true</winConsole>
<winShortcut>false</winShortcut>
<winMenu>false</winMenu>
<javaOptions>
<javaOption>-Dlog4j.configurationFile=log4j2-windows.yaml</javaOption>
</javaOptions>
</configuration>
<executions>
<execution>
<id>windows</id>
<configuration>
<resourceDir>${project.basedir}/src/main/resources/</resourceDir>
<type>EXE</type>
<winConsole>true</winConsole>
<winShortcut>false</winShortcut>
<winMenu>false</winMenu>
<javaOptions>
<javaOption>-Dlog4j.configurationFile=log4j2-installed.yaml</javaOption>
</javaOptions>
</configuration>
<phase>package</phase>
<goals>
<goal>jpackage</goal>
@@ -97,25 +148,71 @@
<profile>
<id>linux</id>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>log4j2-debian.yaml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.panteleyev</groupId>
<artifactId>jpackage-maven-plugin</artifactId>
<version>1.4.0</version>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>linux-deb</id>
<configuration>
<type>DEB</type>
<installDir>/usr/local/bin</installDir>
<linuxShortcut>false</linuxShortcut>
<linuxPackageName>mkvasc</linuxPackageName>
<linuxDebMaintainer>your@email.com</linuxDebMaintainer>
</configuration>
<id>filter-linux-package-info</id>
<phase>package</phase>
<goals>
<goal>jpackage</goal>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/debian-package-info</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/deb</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>jdeb</artifactId>
<groupId>org.vafer</groupId>
<version>1.13</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jdeb</goal>
</goals>
<configuration>
<dataSet>
<!-- JAR file -->
<data>
<src>${project.build.directory}/${project.build.finalName}.jar</src>
<type>file</type>
<mapper>
<type>perm</type>
<prefix>/usr/lib/${project.artifactId}</prefix>
</mapper>
</data>
<!-- Launcher script -->
<data>
<src>${project.build.directory}/debian-package-info/bin/mkvaudiosubtitlechanger</src>
<type>file</type>
<mapper>
<type>perm</type>
<prefix>/usr/bin</prefix>
<filemode>755</filemode>
</mapper>
</data>
</dataSet>
<controlDir>${project.build.directory}/debian-package-info/control</controlDir>
</configuration>
</execution>
</executions>
</plugin>
@@ -197,8 +294,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>21</source>
<target>21</target>
<source>${java-version}</source>
<target>${java-version}</target>
<compilerArgs>
<arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
</compilerArgs>
@@ -211,58 +308,13 @@
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.7.6</version>
<version>4.7.7</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-jpackage-input</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/jpackage-input</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.panteleyev</groupId>
<artifactId>jpackage-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<name>${project.artifactId}</name>
<vendor>RatzzFatzz</vendor>
<appVersion>${project.version}</appVersion>
<destination>target/installer</destination>
<input>target/jpackage-input</input>
<mainClass>at.pcgamingfreaks.mkvaudiosubtitlechanger.Main</mainClass>
<mainJar>${project.artifactId}-${project.version}.jar</mainJar>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<repositories>
@@ -290,7 +342,7 @@
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.7.6</version>
<version>4.7.7</version>
</dependency>
<!-- Hibernate Validator -->
@@ -306,7 +358,7 @@
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<version>6.0.1</version>
<version>6.1.0-M1</version>
</dependency>
<dependency>
@@ -320,7 +372,7 @@
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
<version>3.1.1</version>
</dependency>
<!-- region logging -->
@@ -348,26 +400,26 @@
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.18.2</version>
<version>2.20.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.18.2</version>
<version>2.20.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.9.0</version>
<version>1.10.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.17.0</version>
<version>3.19.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/me.tongfei/progressbar -->
<dependency>
@@ -381,28 +433,28 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.4</version>
<version>6.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.4</version>
<version>6.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.15.2</version>
<version>5.20.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.11.4</version>
<version>6.0.0</version>
<scope>test</scope>
</dependency>
@@ -416,7 +468,7 @@
<dependency>
<groupId>net.harawata</groupId>
<artifactId>appdirs</artifactId>
<version>1.3.0</version>
<version>1.5.0</version>
</dependency>
</dependencies>

View File

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

8
src/deb/control/control Normal file
View File

@@ -0,0 +1,8 @@
Package: ${project.artifactId}
Version: ${project.version}
Section: misc
Priority: optional
Architecture: all
Depends: java-runtime (>=${java-version}), mkvtoolnix
Maintainer: ${project.maintainer} <${project.maintainer.mail}>
Description: ${project.description}

View File

@@ -12,17 +12,20 @@ import jakarta.validation.Validation;
import jakarta.validation.Validator;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import picocli.CommandLine;
import java.util.Set;
@Slf4j
@CommandLine.Command(
name = "mkvasc",
name = "mkvaudiosubtitlechanger",
usageHelpWidth = 120,
customSynopsis = {
"mkvasc -a <attributeConfig>... -l <libraryPath> [-s]",
"Example: mkvasc -a eng:eng eng:ger -l /mnt/media/ -s"
"mkvaudiosubtitlechanger -a <attributeConfig>... -l <libraryPath> [-s]",
"Example: mkvaudiosubtitlechanger -a eng:eng eng:ger -l /mnt/media/ -s",
""
},
mixinStandardHelpOptions = true,
versionProvider = ProjectUtil.class
@@ -38,6 +41,9 @@ public class Main implements Runnable {
@Override
public void run() {
if (config.isDebug()) {
Configurator.setRootLevel(Level.DEBUG);
}
validate();
Config.setInstance(config);
AttributeUpdaterKernel kernel = Config.getInstance().getCoherent() != null
@@ -60,6 +66,9 @@ public class Main implements Runnable {
}
public static void main(String[] args) {
if (args.length == 0) {
args = new String[] { "--help" };
}
new CommandLine(Main.class).execute(args);
}
}

View File

@@ -5,7 +5,6 @@ import picocli.CommandLine;
import java.util.regex.Pattern;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LanguageValidatorUtil.isAudioLanguageValid;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LanguageValidatorUtil.isLanguageValid;
public class AttributeConfigConverter implements CommandLine.ITypeConverter<AttributeConfig> {
@@ -50,7 +49,7 @@ public class AttributeConfigConverter implements CommandLine.ITypeConverter<Attr
* @throws CommandLine.TypeConversionException if either language code is invalid
*/
private static void validateResult(AttributeConfig attr) {
if (!isAudioLanguageValid(attr.getAudioLanguage()))
if (!isLanguageValid(attr.getAudioLanguage()))
throw new CommandLine.TypeConversionException("Audio language invalid: " + attr.getAudioLanguage());
if (!isLanguageValid(attr.getSubtitleLanguage()))
throw new CommandLine.TypeConversionException("Subtitle language invalid: " + attr.getSubtitleLanguage());

View File

@@ -20,7 +20,7 @@ import java.util.regex.Pattern;
@Getter
@Setter
@NoArgsConstructor
public class Config {
public class Config implements CommandLine.IVersionProvider {
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private static Config config = null;
@@ -30,7 +30,8 @@ public class Config {
@CommandLine.Spec
CommandLine.Model.CommandSpec spec;
@CommandLine.Option(names = {"-a", "--attribute-config"}, required = true, arity = "1..*", converter = AttributeConfigConverter.class)
@CommandLine.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 List<AttributeConfig> attributeConfig;
@Setter(AccessLevel.NONE)
@@ -51,7 +52,7 @@ public class Config {
@CommandLine.Option(names = {"-cf", "--force-coherent"}, description = "changes are only applied if it's a coherent match")
private boolean forceCoherent;
@CommandLine.Option(names = {"-n"}, description = "sets filter-date to last successful execution (overwrites input of filter-date)")
@CommandLine.Option(names = {"-n", "--only-new-file"}, description = "sets filter-date to last successful execution (overwrites input of filter-date)")
private boolean onlyNewFiles;
@CommandLine.Option(names = {"-d", "--filter-date"}, defaultValue = CommandLine.Option.NULL_VALUE, description = "only consider files created newer than entered date (format: \"dd.MM.yyyy-HH:mm:ss\")")
private Date filterDate;
@@ -61,15 +62,18 @@ public class Config {
description = "Directories to be excluded, combines with config file")
private Set<String> excludedDirectories = new HashSet<>();
@CommandLine.Option(names = {"-fk", "--force-keywords"}, arity = "1..*",
description = "Additional keywords to identify forced tracks (Defaults are will be overwritten; Default: ${DEFAULT-VALUE}")
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs", "songs"));
@CommandLine.Option(names = {"-ck", "--commentary-keywords"}, arity = "1..*",
description = "Additional keywords to identify commentary tracks (Defaults are will be overwritten; Default: ${DEFAULT-VALUE}")
private Set<String> commentaryKeywords = new HashSet<>(Arrays.asList("commentary", "director"));
@CommandLine.Option(names = {"-ps", "--preferred-subtiltes"}, arity = "1..*",
description = "Additional keywords to prefer specific subtitle tracks (Defaults are will be overwritten; Default: ${DEFAULT-VALUE}")
private Set<String> preferredSubtitles = new HashSet<>(Arrays.asList("unstyled"));
@CommandLine.Option(names = {"--forced-keywords"}, arity = "1..*", defaultValue = "forced, signs, songs", split = ", ",
description = "Keywords to identify forced tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})")
private Set<String> forcedKeywords;
@CommandLine.Option(names = {"--commentary-keywords"}, arity = "1..*", defaultValue = "commentary, director", split = ", ",
description = "Keywords to identify commentary tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})")
private Set<String> commentaryKeywords;
@CommandLine.Option(names = {"--preferred-subtitles"}, arity = "1..*", defaultValue = "unstyled", split = ", ",
description = "Keywords to prefer specific subtitle tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})")
private Set<String> preferredSubtitles;
@CommandLine.Option(names = {"--debug"}, description = "Enable debug logging")
private boolean debug;
@CommandLine.Option(names = {"-l", "--library"}, required = true, description = "path to library")
public void setLibraryPath(File libraryPath) {
@@ -147,5 +151,10 @@ public class Config {
.add("attributeConfig=" + attributeConfig)
.toString();
}
@Override
public String[] getVersion() throws Exception {
return new String[0];
}
}

View File

@@ -10,7 +10,6 @@ import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LanguageValidatorUtil.isAudioLanguageValid;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LanguageValidatorUtil.isLanguageValid;
@Deprecated
@@ -80,7 +79,7 @@ public class AttributeConfigValidator extends ConfigValidator<List<AttributeConf
}
boolean isValid;
for (AttributeConfig attributeConfig : result) {
isValid = isAudioLanguageValid(attributeConfig.getAudioLanguage())
isValid = isLanguageValid(attributeConfig.getAudioLanguage())
&& isLanguageValid(attributeConfig.getSubtitleLanguage());
if (!isValid) return false;
}

View File

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

View File

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

View File

@@ -3,7 +3,7 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
import java.io.File;
import java.io.IOException;
@@ -25,7 +25,7 @@ public interface FileProcessor {
* @param attributes Track information of FileInfoDto
* @param nonForcedTracks List of all not forced tracks
*/
void detectDefaultTracks(FileInfoDto info, List<FileAttribute> attributes, List<FileAttribute> nonForcedTracks);
void detectDefaultTracks(FileInfo info, List<FileAttribute> attributes, List<FileAttribute> nonForcedTracks);
/**
* Populate FileInfoDto with the desired tracks, based on AttributeConfig.
@@ -33,7 +33,7 @@ public interface FileProcessor {
* @param nonForcedTracks List of all non-forced tracks
* @param nonCommentaryTracks List of all non-commentary tracks
*/
void detectDesiredTracks(FileInfoDto info, List<FileAttribute> nonForcedTracks, List<FileAttribute> nonCommentaryTracks,
void detectDesiredTracks(FileInfo info, List<FileAttribute> nonForcedTracks, List<FileAttribute> nonCommentaryTracks,
AttributeConfig... configs);
List<FileAttribute> retrieveNonForcedTracks(List<FileAttribute> attributes);
@@ -43,9 +43,9 @@ public interface FileProcessor {
/**
* Update the file.
* @param file to be updated
* @param fileInfo information to update file
* @param fileInfo information used to update file
* @throws IOException when error occurs accessing file retrieving information
* @throws MkvToolNixException when error occurs while sending query to mkvpropedit
*/
void update(File file, FileInfoDto fileInfo) throws IOException, MkvToolNixException;
void update(File file, FileInfo fileInfo) throws IOException, MkvToolNixException;
}

View File

@@ -28,10 +28,10 @@ public class MkvFileProcessor implements FileProcessor {
private static final SubtitleTrackComparator subtitleTrackComparator =
new SubtitleTrackComparator(Config.getInstance().getPreferredSubtitles().toArray(new String[0]));
private static final String DISABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=0 ";
private static final String ENABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=1 ";
private static final String DISABLE_FORCED_TRACK = "--edit track:%s --set flag-forced=0 ";
private static final String ENABLE_FORCED_TRACK = "--edit track:%s --set flag-forced=1 ";
private static final String DISABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=0";
private static final String ENABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=1";
private static final String DISABLE_FORCED_TRACK = "--edit track:%s --set flag-forced=0";
private static final String ENABLE_FORCED_TRACK = "--edit track:%s --set flag-forced=1";
@SuppressWarnings("unchecked")
@Override
@@ -39,16 +39,17 @@ public class MkvFileProcessor implements FileProcessor {
Map<String, Object> jsonMap;
List<FileAttribute> fileAttributes = new ArrayList<>();
try {
String command = format("\"%s\"", Config.getInstance().getPathFor(MkvToolNix.MKV_MERGE));
String[] arguments = new String[]{
command,
String[] command = new String[]{
Config.getInstance().getPathFor(MkvToolNix.MKV_MERGE),
"--identify",
"--identification-format",
"json",
file.getAbsoluteFile().toString()
file.getAbsolutePath()
};
InputStream inputStream = Runtime.getRuntime().exec(arguments).getInputStream();
log.debug("Executing '{}': {}", file.getAbsolutePath(), String.join(" ", command));
InputStream inputStream = Runtime.getRuntime().exec(command)
.getInputStream();
jsonMap = mapper.readValue(inputStream, Map.class);
List<Map<String, Object>> tracks = (List<Map<String, Object>>) jsonMap.get("tracks");
if (tracks == null) {
@@ -68,7 +69,7 @@ public class MkvFileProcessor implements FileProcessor {
}
}
log.debug(fileAttributes.toString());
log.debug("File attributes of '{}': {}", file.getAbsolutePath(), fileAttributes.toString());
} catch (IOException e) {
log.error("File could not be found or loaded: ", e);
System.out.println("File could not be found or loaded: " + file.getAbsolutePath());
@@ -80,15 +81,15 @@ public class MkvFileProcessor implements FileProcessor {
* {@inheritDoc}
*/
@Override
public void detectDefaultTracks(FileInfoDto info, List<FileAttribute> attributes, List<FileAttribute> nonForcedTracks) {
public void detectDefaultTracks(FileInfo info, List<FileAttribute> attributes, List<FileAttribute> nonForcedTracks) {
for (FileAttribute attribute : attributes) {
if (AUDIO.equals(attribute.getType())) {
if (attribute.isDefaultTrack()) info.getExistingDefaultAudioLanes().add(attribute);
if (attribute.isForcedTrack()) info.getExistingForcedAudioLanes().add(attribute);
} else if (SUBTITLES.equals(attribute.getType())) {
if (attribute.isDefaultTrack()) info.getExistingDefaultSubtitleLanes().add(attribute);
if (AUDIO.equals(attribute.type())) {
if (attribute.defaultTrack()) info.getExistingDefaultAudioLanes().add(attribute);
if (attribute.forcedTrack()) info.getExistingForcedAudioLanes().add(attribute);
} else if (SUBTITLES.equals(attribute.type())) {
if (attribute.defaultTrack()) info.getExistingDefaultSubtitleLanes().add(attribute);
if (attribute.isForcedTrack()) info.getExistingForcedSubtitleLanes().add(attribute);
if (attribute.forcedTrack()) info.getExistingForcedSubtitleLanes().add(attribute);
else if (!nonForcedTracks.contains(attribute)) info.getDesiredForcedSubtitleLanes().add(attribute);
}
}
@@ -98,19 +99,20 @@ public class MkvFileProcessor implements FileProcessor {
* {@inheritDoc}
*/
@Override
public void detectDesiredTracks(FileInfoDto info, List<FileAttribute> nonForcedTracks, List<FileAttribute> nonCommentaryTracks,
public void detectDesiredTracks(FileInfo info, List<FileAttribute> nonForcedTracks, List<FileAttribute> nonCommentaryTracks,
AttributeConfig... configs) {
Set<FileAttribute> tracks = SetUtils.retainOf(nonForcedTracks, nonCommentaryTracks);
Set<FileAttribute> audioTracks = tracks.stream().filter(a -> AUDIO.equals(a.getType())).collect(Collectors.toSet());
Set<FileAttribute> subtitleTracks = tracks.stream().filter(a -> SUBTITLES.equals(a.getType())).collect(Collectors.toSet());
Set<FileAttribute> audioTracks = tracks.stream().filter(a -> AUDIO.equals(a.type())).collect(Collectors.toSet());
Set<FileAttribute> subtitleTracks = tracks.stream().filter(a -> SUBTITLES.equals(a.type())).collect(Collectors.toSet());
for (AttributeConfig config : configs) {
Optional<FileAttribute> desiredAudio = detectDesiredTrack(config.getAudioLanguage(), audioTracks).findFirst();
Optional<FileAttribute> desiredSubtitle = detectDesiredSubtitleTrack(config.getSubtitleLanguage(), subtitleTracks).findFirst();
if (desiredAudio.isPresent() && ("OFF".equals(config.getSubtitleLanguage()) || desiredSubtitle.isPresent())) {
if (("OFF".equals(config.getAudioLanguage()) || desiredAudio.isPresent())
&& ("OFF".equals(config.getSubtitleLanguage()) || desiredSubtitle.isPresent())) {
info.setMatchedConfig(config);
info.setDesiredDefaultAudioLane(desiredAudio.get());
info.setDesiredDefaultAudioLane(desiredAudio.orElse(null));
info.setDesiredDefaultSubtitleLane(desiredSubtitle.orElse(null));
break;
}
@@ -118,7 +120,7 @@ public class MkvFileProcessor implements FileProcessor {
}
private Stream<FileAttribute> detectDesiredTrack(String language, Set<FileAttribute> tracks) {
return tracks.stream().filter(track -> language.equals(track.getLanguage()));
return tracks.stream().filter(track -> language.equals(track.language()));
}
private Stream<FileAttribute> detectDesiredSubtitleTrack(String language, Set<FileAttribute> tracks) {
@@ -129,16 +131,16 @@ public class MkvFileProcessor implements FileProcessor {
@Override
public List<FileAttribute> retrieveNonForcedTracks(List<FileAttribute> attributes) {
return attributes.stream()
.filter(elem -> !StringUtils.containsAnyIgnoreCase(elem.getTrackName(),
.filter(elem -> !StringUtils.containsAnyIgnoreCase(elem.trackName(),
Config.getInstance().getForcedKeywords().toArray(new CharSequence[0])))
.filter(elem -> !elem.isForcedTrack())
.filter(elem -> !elem.forcedTrack())
.collect(Collectors.toList());
}
@Override
public List<FileAttribute> retrieveNonCommentaryTracks(List<FileAttribute> attributes) {
return attributes.stream()
.filter(elem -> !StringUtils.containsAnyIgnoreCase(elem.getTrackName(),
.filter(elem -> !StringUtils.containsAnyIgnoreCase(elem.trackName(),
Config.getInstance().getCommentaryKeywords().toArray(new CharSequence[0])))
.collect(Collectors.toList());
}
@@ -147,47 +149,50 @@ public class MkvFileProcessor implements FileProcessor {
* {@inheritDoc}
*/
@Override
public void update(File file, FileInfoDto fileInfo) throws IOException, MkvToolNixException {
StringBuilder sb = new StringBuilder();
sb.append(format("\"%s\" ", Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT)));
sb.append(format("\"%s\" ", file.getAbsolutePath()));
public void update(File file, FileInfo fileInfo) throws IOException, MkvToolNixException {
List<String> command = new ArrayList<>();
command.add(Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT));
command.add(String.format(file.getAbsolutePath()));
if (fileInfo.isAudioDifferent()) {
if (fileInfo.getExistingDefaultAudioLanes() != null && !fileInfo.getExistingDefaultAudioLanes().isEmpty()) {
for (FileAttribute track: fileInfo.getExistingDefaultAudioLanes()) {
sb.append(format(DISABLE_DEFAULT_TRACK, track.getId()));
}
}
sb.append(format(ENABLE_DEFAULT_TRACK, fileInfo.getDesiredDefaultAudioLane().getId()));
removeExistingAndAddDesiredLanes(fileInfo.getExistingDefaultAudioLanes(), fileInfo.getDesiredDefaultAudioLane(), command);
}
if (!fileInfo.getExistingForcedAudioLanes().isEmpty()) {
for (FileAttribute track: fileInfo.getExistingForcedAudioLanes()) {
sb.append(format(DISABLE_FORCED_TRACK, track.getId()));
for (FileAttribute track : fileInfo.getExistingForcedAudioLanes()) {
command.addAll(format(DISABLE_FORCED_TRACK, track.id()));
}
}
if (fileInfo.isSubtitleDifferent()) {
if (fileInfo.getExistingDefaultSubtitleLanes() != null && !fileInfo.getExistingDefaultSubtitleLanes().isEmpty()) {
for (FileAttribute track: fileInfo.getExistingDefaultSubtitleLanes()) {
sb.append(format(DISABLE_DEFAULT_TRACK, track.getId()));
}
}
if (fileInfo.getDesiredDefaultSubtitleLane() != null) {
sb.append(format(ENABLE_DEFAULT_TRACK, fileInfo.getDesiredDefaultSubtitleLane().getId()));
}
removeExistingAndAddDesiredLanes(fileInfo.getExistingDefaultSubtitleLanes(), fileInfo.getDesiredDefaultSubtitleLane(), command);
}
if (fileInfo.areForcedTracksDifferent()) {
for (FileAttribute attribute : fileInfo.getDesiredForcedSubtitleLanes()) {
sb.append(format(ENABLE_FORCED_TRACK, attribute.getId()));
for (FileAttribute track : fileInfo.getDesiredForcedSubtitleLanes()) {
command.addAll(format(ENABLE_FORCED_TRACK, track.id()));
}
}
log.info(sb.toString());
InputStream inputstream = Runtime.getRuntime().exec(sb.toString()).getInputStream();
log.debug("Executing '{}'", String.join(" ", command));
InputStream inputstream = Runtime.getRuntime().exec(command.toArray(new String[0])).getInputStream();
String output = IOUtils.toString(new InputStreamReader(inputstream));
log.debug(output);
log.debug("Result: {}", output);
if (output.contains("Error")) throw new MkvToolNixException(output);
}
private void removeExistingAndAddDesiredLanes(Set<FileAttribute> existingDefaultLanes, FileAttribute desiredDefaultLanes, List<String> command) {
if (existingDefaultLanes != null && !existingDefaultLanes.isEmpty()) {
for (FileAttribute track : existingDefaultLanes) {
command.addAll(format(DISABLE_DEFAULT_TRACK, track.id()));
}
}
if (desiredDefaultLanes != null) {
command.addAll(format(ENABLE_DEFAULT_TRACK, desiredDefaultLanes.id()));
}
}
private List<String> format(String format, Object... args) {
return Arrays.asList(String.format(format, args).split(" "));
}
}

View File

@@ -17,16 +17,16 @@ public class SubtitleTrackComparator implements Comparator<FileAttribute> {
public int compare(FileAttribute track1, FileAttribute track2) {
int result = 0;
if (StringUtils.containsAnyIgnoreCase(track1.getTrackName(), preferredSubtitles)) {
if (StringUtils.containsAnyIgnoreCase(track1.trackName(), preferredSubtitles)) {
result++;
}
if (StringUtils.containsAnyIgnoreCase(track2.getTrackName(), preferredSubtitles)) {
if (StringUtils.containsAnyIgnoreCase(track2.trackName(), preferredSubtitles)) {
result--;
}
if (result == 0) {
if (track1.isDefaultTrack()) result++;
if (track2.isDefaultTrack()) result--;
if (track1.defaultTrack()) result++;
if (track2.defaultTrack()) result--;
}
return result;

View File

@@ -6,7 +6,7 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileCollector;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileProcessor;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
@@ -19,7 +19,6 @@ import me.tongfei.progressbar.ProgressBar;
import me.tongfei.progressbar.ProgressBarBuilder;
import me.tongfei.progressbar.ProgressBarStyle;
import net.harawata.appdirs.AppDirsFactory;
import picocli.CommandLine;
import java.io.File;
import java.io.IOException;
@@ -97,9 +96,16 @@ public abstract class AttributeUpdaterKernel {
* @param file file or directory to update
*/
void process(File file) {
FileInfoDto fileInfo = new FileInfoDto(file);
FileInfo fileInfo = new FileInfo(file);
List<FileAttribute> attributes = processor.loadAttributes(file);
if (attributes == null || attributes.isEmpty()) {
log.warn("No attributes found for file {}", file);
statistic.total();
statistic.failure();
return;
}
List<FileAttribute> nonForcedTracks = processor.retrieveNonForcedTracks(attributes);
List<FileAttribute> nonCommentaryTracks = processor.retrieveNonCommentaryTracks(attributes);
@@ -113,16 +119,16 @@ public abstract class AttributeUpdaterKernel {
/**
* Persist file changes.
*
* @param fileInfoDto contains information about file and desired configuration.
* @param fileInfo contains information about file and desired configuration.
*/
protected void updateFile(FileInfoDto fileInfoDto) {
protected void updateFile(FileInfo fileInfo) {
statistic.total();
switch (fileInfoDto.getStatus()) {
switch (fileInfo.getStatus()) {
case CHANGE_NECESSARY:
statistic.shouldChange();
commitChange(fileInfoDto);
commitChange(fileInfo);
break;
case UNABLE_TO_APPLY:
case NO_SUITABLE_CONFIG:
statistic.noSuitableConfigFound();
break;
case ALREADY_SUITED:
@@ -135,7 +141,7 @@ public abstract class AttributeUpdaterKernel {
}
}
private void commitChange(FileInfoDto fileInfo) {
private void commitChange(FileInfo fileInfo) {
if (Config.getInstance().isSafeMode()) {
return;
}
@@ -143,10 +149,10 @@ public abstract class AttributeUpdaterKernel {
try {
processor.update(fileInfo.getFile(), fileInfo);
statistic.success();
log.info("Updated {}", fileInfo.getFile().getAbsolutePath());
log.info("Commited {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getAbsolutePath());
} catch (IOException | MkvToolNixException e) {
statistic.failedChanging();
log.warn("File couldn't be updated: '{}', Error: {}", fileInfo.getFile().getAbsoluteFile(), e.getMessage());
log.warn("Couldn't commit {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getAbsoluteFile(), e);
}
}

View File

@@ -5,7 +5,7 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileCollector;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileProcessor;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
import lombok.extern.slf4j.Slf4j;
import me.tongfei.progressbar.ProgressBarBuilder;
import org.apache.commons.lang3.StringUtils;
@@ -67,13 +67,13 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
void process(File file, int depth) {
// TODO: Implement level crawl if coherence is not possible on user entered depth
// IMPL idea: recursive method call, cache needs to be implemented
List<FileInfoDto> fileInfos = collector.loadFiles(file.getAbsolutePath()).stream()
.map(FileInfoDto::new)
List<FileInfo> fileInfos = collector.loadFiles(file.getAbsolutePath()).stream()
.map(FileInfo::new)
.collect(Collectors.toList());
for (AttributeConfig config : Config.getInstance().getAttributeConfig()) {
for (FileInfoDto fileInfo : fileInfos) {
for (FileInfo fileInfo : fileInfos) {
List<FileAttribute> attributes = processor.loadAttributes(fileInfo.getFile());
List<FileAttribute> nonForcedTracks = processor.retrieveNonForcedTracks(attributes);
@@ -85,7 +85,7 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
if (fileInfos.stream().allMatch(elem -> ("OFF".equals(config.getSubtitleLanguage()) || elem.getDesiredDefaultSubtitleLane() != null)
&& elem.getDesiredDefaultAudioLane() != null)) {
log.info("Found {}/{} match for {}", config.getAudioLanguage(), config.getSubtitleLanguage(), file.getAbsolutePath());
log.info("Found {} match for {}", config.toStringShort(), file.getAbsolutePath());
fileInfos.forEach(this::updateFile);
return; // match found, end process here
}
@@ -98,7 +98,7 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
log.info("No coherent match found for {}", file.getAbsoluteFile());
for (FileInfoDto fileInfo : fileInfos) {
for (FileInfo fileInfo : fileInfos) {
if (!Config.getInstance().isForceCoherent()) {
super.process(fileInfo.getFile());
} else {

View File

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

View File

@@ -1,22 +1,12 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.util.Objects;
@Slf4j
@Getter
@AllArgsConstructor
public class FileAttribute {
private final int id;
private final String language;
private final String trackName;
private final boolean defaultTrack;
private final boolean forcedTrack;
private final LaneType type;
public record FileAttribute(int id, String language, String trackName, boolean defaultTrack, boolean forcedTrack,
LaneType type) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -30,11 +20,6 @@ public class FileAttribute {
&& type == attribute.type;
}
@Override
public int hashCode() {
return Objects.hash(id, language, trackName, defaultTrack, forcedTrack, type);
}
@Override
public String toString() {
return "[" + "id=" + id +

View File

@@ -0,0 +1,84 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
@Getter
@Setter
@RequiredArgsConstructor
public class FileInfo {
private final File file;
private Set<FileAttribute> existingDefaultAudioLanes = new HashSet<>();
private Set<FileAttribute> existingForcedAudioLanes = new HashSet<>();
private Set<FileAttribute> existingDefaultSubtitleLanes = new HashSet<>();
private Set<FileAttribute> existingForcedSubtitleLanes = new HashSet<>();
private Set<FileAttribute> desiredForcedSubtitleLanes = new HashSet<>();
private FileAttribute desiredDefaultAudioLane;
private FileAttribute desiredDefaultSubtitleLane;
private AttributeConfig matchedConfig;
public boolean isAudioDifferent() {
return isMatchDifferent(existingDefaultAudioLanes, desiredDefaultAudioLane)
|| isLaneOff(existingDefaultAudioLanes, desiredDefaultAudioLane, AttributeConfig::getAudioLanguage);
}
public boolean isSubtitleDifferent() {
return isMatchDifferent(existingDefaultSubtitleLanes, desiredDefaultSubtitleLane)
|| isLaneOff(existingDefaultSubtitleLanes, desiredDefaultSubtitleLane, AttributeConfig::getSubtitleLanguage);
}
private boolean isMatchDifferent(Set<FileAttribute> existingDefault, FileAttribute desiredDefault) {
return desiredDefault != null &&
(existingDefault == null || !existingDefault.contains(desiredDefault) || existingDefault.size() > 1);
}
private boolean isLaneOff(Set<FileAttribute> existingDefault, FileAttribute desiredDefault, Function<AttributeConfig, String> inputLane) {
return desiredDefault == null
&& (matchedConfig != null && "OFF".equals(inputLane.apply(matchedConfig)))
&& (existingDefault != null && !existingDefault.isEmpty());
}
public boolean areForcedTracksDifferent() {
return !desiredForcedSubtitleLanes.isEmpty() && !existingForcedSubtitleLanes.containsAll(desiredForcedSubtitleLanes);
}
public FileStatus getStatus() {
if (isChangeNecessary()) return FileStatus.CHANGE_NECESSARY;
if (isUnableToApplyConfig()) return FileStatus.NO_SUITABLE_CONFIG;
if (isAlreadySuited()) return FileStatus.ALREADY_SUITED;
return FileStatus.UNKNOWN;
}
private boolean isUnableToApplyConfig() {
return desiredDefaultAudioLane == null && !"OFF".equals(matchedConfig.getAudioLanguage())
&& desiredDefaultSubtitleLane == null && !"OFF".equals(matchedConfig.getSubtitleLanguage());
}
private boolean isAlreadySuited() {
return (desiredDefaultAudioLane == null || existingDefaultAudioLanes.contains(desiredDefaultAudioLane))
&& (desiredDefaultSubtitleLane == null || existingDefaultSubtitleLanes.contains(desiredDefaultSubtitleLane));
}
private boolean isChangeNecessary() {
return isAudioDifferent() || isSubtitleDifferent() || areForcedTracksDifferent() || !existingForcedAudioLanes.isEmpty();
}
@Override
public String toString() {
return "[" + "defaultAudioLanes=" + existingDefaultAudioLanes +
", defaultSubtitleLanes=" + existingDefaultSubtitleLanes +
", desiredForcedSubtitleLanes=" + desiredForcedSubtitleLanes +
", desiredAudioLane=" + desiredDefaultAudioLane +
", desiredSubtitleLane=" + desiredDefaultSubtitleLane +
']';
}
}

View File

@@ -1,79 +0,0 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
@Getter
@Setter
@RequiredArgsConstructor
public class FileInfoDto {
private final File file;
private Set<FileAttribute> existingDefaultAudioLanes = new HashSet<>();
private Set<FileAttribute> existingForcedAudioLanes = new HashSet<>();
private Set<FileAttribute> existingDefaultSubtitleLanes = new HashSet<>();
private Set<FileAttribute> existingForcedSubtitleLanes = new HashSet<>();
private Set<FileAttribute> desiredForcedSubtitleLanes = new HashSet<>();
private FileAttribute desiredDefaultAudioLane;
private FileAttribute desiredDefaultSubtitleLane;
private AttributeConfig matchedConfig;
public boolean isAudioDifferent() {
return desiredDefaultAudioLane != null &&
(existingDefaultAudioLanes == null || !existingDefaultAudioLanes.contains(desiredDefaultAudioLane) || existingDefaultAudioLanes.size() > 1);
}
public boolean isSubtitleDifferent() {
return isSubtitleMatchDifferent() || isSubtitleOFF();
}
private boolean isSubtitleMatchDifferent() {
return desiredDefaultSubtitleLane != null
&& (existingDefaultSubtitleLanes == null || !existingDefaultSubtitleLanes.contains(desiredDefaultSubtitleLane) || existingDefaultSubtitleLanes.size() > 1);
}
private boolean isSubtitleOFF() {
return desiredDefaultSubtitleLane == null && "OFF".equals(matchedConfig.getSubtitleLanguage()) &&
(existingDefaultSubtitleLanes != null && !existingDefaultSubtitleLanes.isEmpty());
}
public boolean areForcedTracksDifferent() {
return !desiredForcedSubtitleLanes.isEmpty();
}
public FileStatus getStatus() {
if (isChangeNecessary()) return FileStatus.CHANGE_NECESSARY;
if (isUnableToApplyConfig()) return FileStatus.UNABLE_TO_APPLY;
if (isAlreadySuitable()) return FileStatus.ALREADY_SUITED;
return FileStatus.UNKNOWN;
}
private boolean isUnableToApplyConfig() {
return desiredDefaultAudioLane == null && desiredDefaultSubtitleLane == null;
}
private boolean isAlreadySuitable() {
return existingDefaultAudioLanes.contains(desiredDefaultAudioLane) && existingDefaultSubtitleLanes.contains(desiredDefaultSubtitleLane);
}
private boolean isChangeNecessary() {
return isAudioDifferent() || isSubtitleDifferent() || areForcedTracksDifferent() || !existingForcedAudioLanes.isEmpty();
}
@Override
public String toString() {
return "[" + "defaultAudioLanes=" + existingDefaultAudioLanes +
", defaultSubtitleLanes=" + existingDefaultSubtitleLanes +
", desiredForcedSubtitleLanes=" + desiredForcedSubtitleLanes +
", desiredAudioLane=" + desiredDefaultAudioLane +
", desiredSubtitleLane=" + desiredDefaultSubtitleLane +
']';
}
}

View File

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

View File

@@ -23,10 +23,6 @@ public class LanguageValidatorUtil {
}
}
public static boolean isAudioLanguageValid(String language) {
return !language.equals("OFF") && isLanguageValid(language);
}
public static boolean isLanguageValid(String language) {
return ISO3_LANGUAGES.contains(language);
}

View File

@@ -0,0 +1,34 @@
Configuration:
name: DefaultLogger
Appenders:
RollingFile:
name: FileAppender
fileName: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/application.log
filePattern: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
ThresholdFilter:
level: debug
Policies:
OnStartupTriggeringPolicy:
minSize: 0
DefaultRolloverStrategy:
max: 30
Delete:
basePath: archive
maxDepth: 1
IfLastModified:
age: 30d
IfAccumulatedFileSize:
exceeds: 1GB
Loggers:
Root:
level: info
AppenderRef:
- ref: FileAppender
Logger:
name: "com.zaxxer.hikari.HikariConfig"
level: info
AppenderRef:
- ref: FileAppender

View File

@@ -4,20 +4,30 @@ Configuration:
Console:
name: Console_Out
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
ThresholdFilter:
level: debug
RollingFile:
name: FileAppender
fileName: logs/application.log
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
ThresholdFilter:
level: debug
Policies:
OnStartupTriggeringPolicy:
minSize: 0
DefaultRolloverStrategy:
max: 30
Delete:
basePath: logs/archive
maxDepth: 1
IfLastModified:
age: 30d
IfAccumulatedFileSize:
exceeds: 1GB
Loggers:
Root:
level: debug

View File

@@ -1,24 +1,27 @@
Configuration:
name: DefaultLogger
Appenders:
File:
name: FileAppender
fileName: ${sys:user.home}/AppData/Roaming/MyApplication/MyApplication.log
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
ThresholdFilter:
level: info
RollingFile:
name: FileAppender
fileName: ${sys:user.home}/AppData/Roaming/MKVAudioSubtitleChanger/logs/application.log
filePattern: ${sys:user.home}/AppData/Roaming/MKVAudioSubtitleChanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log
filePattern: ${sys:user.home}/AppData/Roaming/MKVAudioSubtitleChanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
ThresholdFilter:
level: info
level: debug
Policies:
OnStartupTriggeringPolicy:
minSize: 0
DefaultRolloverStrategy:
max: 30
Delete:
basePath: logs/archive
maxDepth: 1
IfLastModified:
age: 30d
IfAccumulatedFileSize:
exceeds: 1GB
Loggers:
Root:
level: info

View File

@@ -4,14 +4,24 @@ Configuration:
RollingFile:
name: FileAppender
fileName: logs/application.log
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
ThresholdFilter:
level: info
level: debug
Policies:
OnStartupTriggeringPolicy:
minSize: 0
DefaultRolloverStrategy:
max: 30
Delete:
basePath: logs/archive
maxDepth: 1
IfLastModified:
age: 30d
IfAccumulatedFileSize:
exceeds: 1GB
Loggers:
Root:
level: info

View File

@@ -18,11 +18,11 @@ class ConfigTest {
"-c", "2",
"-t", "4",
"-i", ".*[abc].*",
"-fk", "testForced",
"-ck", "testCommentary",
"-ps", "testPreferred"
"--forced-keywords", "testForced",
"--commentary-keywords", "testCommentary",
"--preferred-subtitles", "testPreferred"
};
CommandLine.populateCommand(Config.getInstance(), sut);
CommandLine.populateCommand(Config.getInstance(true), sut);
assertTrue(Config.getInstance().getLibraryPath().exists());
assertEquals(List.of(new AttributeConfig("ger", "ger"), new AttributeConfig("eng", "eng")),
@@ -41,6 +41,5 @@ class ConfigTest {
assertTrue(Config.getInstance().getPreferredSubtitles().contains("testPreferred"));
assertNull(Config.getInstance().getConfigPath());
}
}

View File

@@ -19,14 +19,14 @@ class SetConfigParameterTest {
private static Stream<Arguments> provideTestCases() {
return Stream.of(
Arguments.of(args("-ck", "test"), 1, (Function<Config, Set<String>>) Config::getCommentaryKeywords),
Arguments.of(args("-ck", "test", "test1", "test2", "test3", "test4"), 5, (Function<Config, Set<String>>) Config::getCommentaryKeywords),
Arguments.of(args("--commentary-keywords", "test"), 1, (Function<Config, Set<String>>) Config::getCommentaryKeywords),
Arguments.of(args("--commentary-keywords", "test", "test1", "test2", "test3", "test4"), 5, (Function<Config, Set<String>>) Config::getCommentaryKeywords),
Arguments.of(args(), 2, (Function<Config, Set<String>>) Config::getCommentaryKeywords),
Arguments.of(args("-fk", "test"), 1, (Function<Config, Set<String>>) Config::getForcedKeywords),
Arguments.of(args("-fk", "test", "test1", "test2", "test3", "test4"), 5, (Function<Config, Set<String>>) Config::getForcedKeywords),
Arguments.of(args("--forced-keywords", "test"), 1, (Function<Config, Set<String>>) Config::getForcedKeywords),
Arguments.of(args("--forced-keywords", "test", "test1", "test2", "test3", "test4"), 5, (Function<Config, Set<String>>) Config::getForcedKeywords),
Arguments.of(args(), 3, (Function<Config, Set<String>>) Config::getForcedKeywords),
Arguments.of(args("-ps", "test"), 1, (Function<Config, Set<String>>) Config::getPreferredSubtitles),
Arguments.of(args("-ps", "test", "test1", "test2", "test3", "test4"), 5, (Function<Config, Set<String>>) Config::getPreferredSubtitles),
Arguments.of(args("--preferred-subtitles", "test"), 1, (Function<Config, Set<String>>) Config::getPreferredSubtitles),
Arguments.of(args("--preferred-subtitles", "test", "test1", "test2", "test3", "test4"), 5, (Function<Config, Set<String>>) Config::getPreferredSubtitles),
Arguments.of(args(), 1, (Function<Config, Set<String>>) Config::getPreferredSubtitles)
);
}
@@ -42,9 +42,9 @@ class SetConfigParameterTest {
@Test
void validate() {
Main sut = new Main();
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-ck")));
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-fk")));
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("--commentary-keywords")));
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("--forced-keywords")));
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-e")));
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-ps")));
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("--preferred-subtitles")));
}
}

View File

@@ -0,0 +1,42 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.createFileInfo;
import static org.junit.jupiter.api.Assertions.*;
class MkvFileProcessorTest {
private static Stream<Arguments> detectDesiredTracks() {
return Stream.of(
Arguments.of(new AttributeConfig("ger", "OFF"), List.of(AUDIO_GER, AUDIO_ENG), new AttributeConfig[] {new AttributeConfig("ger", "OFF"), new AttributeConfig("eng", "OFF")}),
Arguments.of(new AttributeConfig("eng", "OFF"), List.of(AUDIO_ENG), new AttributeConfig[] {new AttributeConfig("ger", "OFF"), new AttributeConfig("eng", "OFF")}),
Arguments.of(new AttributeConfig("eng", "ger"), List.of(AUDIO_GER, AUDIO_ENG, SUB_GER, SUB_ENG), new AttributeConfig[] {new AttributeConfig("eng", "ger"), new AttributeConfig("ger", "eng")}),
Arguments.of(new AttributeConfig("ger", "eng"), List.of(AUDIO_GER, SUB_GER, SUB_ENG), new AttributeConfig[] {new AttributeConfig("eng", "ger"), new AttributeConfig("ger", "eng")}),
Arguments.of(new AttributeConfig("OFF", "ger"), List.of(AUDIO_GER, SUB_GER, SUB_ENG), new AttributeConfig[] {new AttributeConfig("OFF", "ger"), new AttributeConfig("ger", "eng")})
);
}
@ParameterizedTest
@MethodSource
void detectDesiredTracks(AttributeConfig expectedMatch, List<FileAttribute> tracks, AttributeConfig... configs) {
Config.getInstance().setPreferredSubtitles(Set.of());
FileInfo info = new FileInfo(null);
MkvFileProcessor processor = new MkvFileProcessor();
processor.detectDesiredTracks(info, tracks, tracks, configs);
assertEquals(expectedMatch.getAudioLanguage(), info.getMatchedConfig().getAudioLanguage());
assertEquals(expectedMatch.getSubtitleLanguage(), info.getMatchedConfig().getSubtitleLanguage());
}
}

View File

@@ -1,59 +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.util.Set;
import java.util.stream.Stream;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.createFileInfo;
import static org.junit.jupiter.api.Assertions.*;
class FileInfoDtoTest {
private static final FileAttribute AUDIO_GER_DEFAULT = new FileAttribute(0, "ger", "", true, false, LaneType.AUDIO);
private static final FileAttribute AUDIO_GER = new FileAttribute(0, "ger", "", false, false, LaneType.AUDIO);
private static final FileAttribute AUDIO_ENG_DEFAULT = new FileAttribute(1, "eng", "", true, false, LaneType.AUDIO);
private static final FileAttribute AUDIO_ENG = new FileAttribute(1, "eng", "", false, false, LaneType.AUDIO);
private static final FileAttribute SUB_GER_DEFAULT = new FileAttribute(0, "ger", "", true, false, LaneType.SUBTITLES);
private static final FileAttribute SUB_GER = new FileAttribute(0, "ger", "", false, false, LaneType.SUBTITLES);
private static final FileAttribute SUB_ENG_DEFAULT = new FileAttribute(1, "eng", "", true, false, LaneType.SUBTITLES);
private static final FileAttribute SUB_ENG = new FileAttribute(1, "eng", "", false, false, LaneType.SUBTITLES);
private static Stream<Arguments> isAudioDifferent() {
return Stream.of(
Arguments.of(createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_GER_DEFAULT), false),
Arguments.of(createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_ENG), true),
Arguments.of(createFileInfo(Set.of(AUDIO_GER_DEFAULT, AUDIO_ENG_DEFAULT), AUDIO_GER_DEFAULT), true),
Arguments.of(createFileInfo(Set.of(), AUDIO_GER), true),
Arguments.of(createFileInfo(null, AUDIO_GER), true)
);
}
@ParameterizedTest
@MethodSource
void isAudioDifferent(FileInfoDto underTest, boolean expected) {
assertEquals(expected, underTest.isAudioDifferent());
}
private static Stream<Arguments> isSubtitleDifferent() {
return Stream.of(
Arguments.of(createFileInfo(Set.of(SUB_GER_DEFAULT), SUB_GER_DEFAULT, new AttributeConfig("", "ger")), false),
Arguments.of(createFileInfo(Set.of(SUB_GER_DEFAULT), SUB_ENG, new AttributeConfig("", "eng")), true),
Arguments.of(createFileInfo(Set.of(SUB_GER_DEFAULT, SUB_ENG_DEFAULT), SUB_ENG, new AttributeConfig("", "eng")), true),
Arguments.of(createFileInfo(Set.of(), SUB_ENG, new AttributeConfig("", "ger")), true),
Arguments.of(createFileInfo(null, SUB_GER, new AttributeConfig("", "ger")), true),
Arguments.of(createFileInfo(null, null, new AttributeConfig("", "OFF")), false),
Arguments.of(createFileInfo(Set.of(), null, new AttributeConfig("", "OFF")), false),
Arguments.of(createFileInfo(Set.of(SUB_GER_DEFAULT), null, new AttributeConfig("", "OFF")), true)
);
}
@ParameterizedTest
@MethodSource
void isSubtitleDifferent(FileInfoDto underTest, boolean expected) {
assertEquals(expected, underTest.isSubtitleDifferent());
}
}

View File

@@ -0,0 +1,87 @@
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.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> isAudioDifferent() {
return Stream.of(
Arguments.of(createFileInfoAudio(Set.of(AUDIO_GER_DEFAULT), AUDIO_GER_DEFAULT, new AttributeConfig("ger", "")), false),
Arguments.of(createFileInfoAudio(Set.of(AUDIO_GER_DEFAULT), AUDIO_ENG, new AttributeConfig("eng", "")), true),
Arguments.of(createFileInfoAudio(Set.of(AUDIO_GER_DEFAULT, AUDIO_ENG_DEFAULT), AUDIO_GER_DEFAULT, new AttributeConfig("ger", "")), true),
Arguments.of(createFileInfoAudio(Set.of(), AUDIO_GER, new AttributeConfig("ger", "")), true),
Arguments.of(createFileInfoAudio(null, AUDIO_GER, new AttributeConfig("ger", "")), true),
Arguments.of(createFileInfoAudio(Set.of(AUDIO_GER_DEFAULT), null, new AttributeConfig("OFF", "")), true),
Arguments.of(createFileInfoAudio(Set.of(), null, new AttributeConfig("OFF", "")), false),
Arguments.of(createFileInfoAudio(null, null, new AttributeConfig("OFF", "")), false)
);
}
@ParameterizedTest
@MethodSource
void isAudioDifferent(FileInfo underTest, boolean expected) {
assertEquals(expected, underTest.isAudioDifferent());
}
private static Stream<Arguments> isSubtitleDifferent() {
return Stream.of(
Arguments.of(createFileInfoSubs(Set.of(SUB_GER_DEFAULT), SUB_GER_DEFAULT, new AttributeConfig("", "ger")), false),
Arguments.of(createFileInfoSubs(Set.of(SUB_GER_DEFAULT), SUB_ENG, new AttributeConfig("", "eng")), true),
Arguments.of(createFileInfoSubs(Set.of(SUB_GER_DEFAULT, SUB_ENG_DEFAULT), SUB_ENG, new AttributeConfig("", "eng")), true),
Arguments.of(createFileInfoSubs(Set.of(), SUB_ENG, new AttributeConfig("", "ger")), true),
Arguments.of(createFileInfoSubs(null, SUB_GER, new AttributeConfig("", "ger")), true),
Arguments.of(createFileInfoSubs(null, null, new AttributeConfig("", "OFF")), false),
Arguments.of(createFileInfoSubs(Set.of(), null, new AttributeConfig("", "OFF")), false),
Arguments.of(createFileInfoSubs(Set.of(SUB_GER_DEFAULT), null, new AttributeConfig("", "OFF")), true)
);
}
@ParameterizedTest
@MethodSource
void isSubtitleDifferent(FileInfo underTest, boolean expected) {
assertEquals(expected, underTest.isSubtitleDifferent());
}
private static Stream<Arguments> getStatus() {
return Stream.of(
Arguments.of(CHANGE_NECESSARY, createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_ENG, Set.of(), null, Set.of(), Set.of(), Set.of(), new AttributeConfig("eng", "OFF"))),
Arguments.of(CHANGE_NECESSARY, createFileInfo(Set.of(), null, Set.of(SUB_GER_DEFAULT), SUB_ENG, Set.of(), Set.of(), Set.of(), new AttributeConfig("OFF", "eng"))),
Arguments.of(CHANGE_NECESSARY, createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_ENG, Set.of(SUB_GER_DEFAULT), SUB_ENG, Set.of(), Set.of(), Set.of(), new AttributeConfig("OFF", "eng"))),
Arguments.of(CHANGE_NECESSARY, createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_GER_DEFAULT, Set.of(SUB_GER_DEFAULT), SUB_GER_DEFAULT, Set.of(AUDIO_ENG_FORCED), Set.of(), Set.of(), new AttributeConfig("ger", "ger"))),
Arguments.of(CHANGE_NECESSARY, createFileInfo(Set.of(), null, Set.of(), null, Set.of(AUDIO_ENG_FORCED), Set.of(), Set.of(), new AttributeConfig("OFF", "OFF"))),
Arguments.of(CHANGE_NECESSARY, createFileInfo(Set.of(), null, Set.of(), null, Set.of(), Set.of(), Set.of(SUB_GER_FORCED), new AttributeConfig("OFF", "OFF"))),
Arguments.of(CHANGE_NECESSARY, createFileInfo(Set.of(), null, Set.of(), null, Set.of(), Set.of(SUB_ENG_FORCED), Set.of(SUB_GER_FORCED), new AttributeConfig("OFF", "OFF"))),
Arguments.of(CHANGE_NECESSARY, createFileInfo(Set.of(), null, Set.of(), null, Set.of(AUDIO_ENG_FORCED), Set.of(SUB_ENG_FORCED), Set.of(SUB_GER_FORCED), new AttributeConfig("OFF", "OFF"))),
Arguments.of(CHANGE_NECESSARY, createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_ENG, Set.of(SUB_GER_DEFAULT), SUB_ENG, Set.of(AUDIO_ENG_FORCED), Set.of(SUB_ENG_FORCED), Set.of(SUB_GER_FORCED), new AttributeConfig("eng", "eng"))),
Arguments.of(CHANGE_NECESSARY, createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_GER_DEFAULT, Set.of(SUB_GER_DEFAULT), SUB_GER_DEFAULT, Set.of(), Set.of(SUB_ENG_FORCED), Set.of(SUB_ENG_FORCED, SUB_GER), new AttributeConfig("ger", "ger"))),
Arguments.of(NO_SUITABLE_CONFIG, createFileInfo(Set.of(AUDIO_ENG_DEFAULT), null, Set.of(SUB_GER_DEFAULT), null, Set.of(), Set.of(), Set.of(), new AttributeConfig("eng", "ger"))),
Arguments.of(NO_SUITABLE_CONFIG, createFileInfo(Set.of(AUDIO_ENG_DEFAULT), null, Set.of(), null, Set.of(), Set.of(), Set.of(), new AttributeConfig("eng", "ger"))),
Arguments.of(NO_SUITABLE_CONFIG, createFileInfo(Set.of(), null, Set.of(), null, Set.of(), Set.of(), Set.of(), new AttributeConfig("eng", "ger"))),
Arguments.of(ALREADY_SUITED, createFileInfo(Set.of(), null, Set.of(), null, Set.of(), Set.of(), Set.of(), new AttributeConfig("OFF", "OFF"))),
Arguments.of(ALREADY_SUITED, createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_GER_DEFAULT, Set.of(), null, Set.of(), Set.of(), Set.of(), new AttributeConfig("ger", "OFF"))),
Arguments.of(ALREADY_SUITED, createFileInfo(Set.of(), null, Set.of(SUB_ENG_DEFAULT), SUB_ENG_DEFAULT, Set.of(), Set.of(), Set.of(), new AttributeConfig("OFF", "ger"))),
Arguments.of(ALREADY_SUITED, createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_GER_DEFAULT, Set.of(SUB_ENG_DEFAULT), SUB_ENG_DEFAULT, Set.of(), Set.of(), Set.of(), new AttributeConfig("ger", "eng"))),
Arguments.of(ALREADY_SUITED, createFileInfo(Set.of(AUDIO_GER_DEFAULT), AUDIO_GER_DEFAULT, Set.of(SUB_ENG_DEFAULT), SUB_ENG_DEFAULT, Set.of(), Set.of(SUB_GER_FORCED), Set.of(SUB_GER_FORCED), new AttributeConfig("ger", "eng")))
);
}
@ParameterizedTest
@MethodSource
void getStatus(FileStatus expected, FileInfo underTest) {
FileStatus actual = underTest.getStatus();
assertEquals(expected, actual);
}
}

View File

@@ -0,0 +1,20 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.LaneType;
public class FileInfoTestUtil {
public static final FileAttribute AUDIO_GER_DEFAULT = new FileAttribute(0, "ger", "", true, false, LaneType.AUDIO);
public static final FileAttribute AUDIO_ENG_DEFAULT = new FileAttribute(1, "eng", "", true, false, LaneType.AUDIO);
public static final FileAttribute AUDIO_GER = new FileAttribute(0, "ger", "", false, false, LaneType.AUDIO);
public static final FileAttribute AUDIO_ENG = new FileAttribute(1, "eng", "", false, false, LaneType.AUDIO);
public static final FileAttribute AUDIO_GER_FORCED = new FileAttribute(0, "ger", "", false, true, LaneType.AUDIO);
public static final FileAttribute AUDIO_ENG_FORCED = new FileAttribute(1, "eng", "", false, true, LaneType.AUDIO);
public static final FileAttribute SUB_GER_DEFAULT = new FileAttribute(0, "ger", "", true, false, LaneType.SUBTITLES);
public static final FileAttribute SUB_ENG_DEFAULT = new FileAttribute(1, "eng", "", true, false, LaneType.SUBTITLES);
public static final FileAttribute SUB_GER = new FileAttribute(0, "ger", "", false, false, LaneType.SUBTITLES);
public static final FileAttribute SUB_ENG = new FileAttribute(1, "eng", "", false, false, LaneType.SUBTITLES);
public static final FileAttribute SUB_GER_FORCED = new FileAttribute(0, "ger", "", false, true, LaneType.SUBTITLES);
public static final FileAttribute SUB_ENG_FORCED = new FileAttribute(1, "eng", "", false, true, LaneType.SUBTITLES);
}

View File

@@ -4,7 +4,7 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
import org.junit.jupiter.params.provider.Arguments;
import java.util.Arrays;
@@ -20,28 +20,46 @@ public class TestUtil {
}
public static <T> Arguments argumentsOf(ConfigProperty property, boolean required, T defaultValue, String yaml, String[] cmd,
ValidationResult result) {
ValidationResult result) {
return Arguments.of(property, required, defaultValue, yaml, cmd, result);
}
public static Arguments argumentsOf(ConfigProperty property, boolean required, boolean append, String yaml, String[] cmd,
ValidationResult result, int expectedSize) {
ValidationResult result, int expectedSize) {
return Arguments.of(property, required, append, yaml, cmd, result, expectedSize);
}
public static FileInfoDto createFileInfo(Set<FileAttribute> defaultAudio, FileAttribute desiredAudio) {
FileInfoDto fileInfoDto = new FileInfoDto(null);
fileInfoDto.setExistingDefaultAudioLanes(defaultAudio);
fileInfoDto.setDesiredDefaultAudioLane(desiredAudio);
return fileInfoDto;
public static FileInfo createFileInfoAudio(Set<FileAttribute> defaultAudio, FileAttribute desiredAudio, AttributeConfig config) {
FileInfo fileInfo = new FileInfo(null);
fileInfo.setExistingDefaultAudioLanes(defaultAudio);
fileInfo.setDesiredDefaultAudioLane(desiredAudio);
fileInfo.setMatchedConfig(config);
return fileInfo;
}
public static FileInfoDto createFileInfo(Set<FileAttribute> defaultSubtitle, FileAttribute desiredSubtitle, AttributeConfig config) {
FileInfoDto fileInfoDto = new FileInfoDto(null);
fileInfoDto.setExistingDefaultSubtitleLanes(defaultSubtitle);
fileInfoDto.setDesiredDefaultSubtitleLane(desiredSubtitle);
fileInfoDto.setMatchedConfig(config);
return fileInfoDto;
public static FileInfo createFileInfoSubs(Set<FileAttribute> defaultSubtitle, FileAttribute desiredSubtitle, AttributeConfig config) {
FileInfo fileInfo = new FileInfo(null);
fileInfo.setExistingDefaultSubtitleLanes(defaultSubtitle);
fileInfo.setDesiredDefaultSubtitleLane(desiredSubtitle);
fileInfo.setMatchedConfig(config);
return fileInfo;
}
public static FileInfo createFileInfo(Set<FileAttribute> defaultAudio, FileAttribute desiredAudio,
Set<FileAttribute> defaultSubtitle, FileAttribute desiredSubtitle,
Set<FileAttribute> existingForcedAudioLanes,
Set<FileAttribute> existingForcedSubs, Set<FileAttribute> desiredForcedSubs,
AttributeConfig matchedConfig) {
FileInfo fileInfo = new FileInfo(null);
fileInfo.setExistingDefaultAudioLanes(defaultAudio);
fileInfo.setDesiredDefaultAudioLane(desiredAudio);
fileInfo.setExistingDefaultSubtitleLanes(defaultSubtitle);
fileInfo.setDesiredDefaultSubtitleLane(desiredSubtitle);
fileInfo.setExistingForcedAudioLanes(existingForcedAudioLanes);
fileInfo.setExistingForcedSubtitleLanes(existingForcedSubs);
fileInfo.setDesiredForcedSubtitleLanes(desiredForcedSubs);
fileInfo.setMatchedConfig(matchedConfig);
return fileInfo;
}
public static String[] args(String... args) {

View File

@@ -24,12 +24,12 @@
<?endif?>
<?define JpProductCode="*"?>
<?define JpAppName="MKVAudioSubtitleChanger"?>
<?define JpAppVersion="4.0.0"?>
<?define JpAppVendor="RatzzFatzz"?>
<?define JpAppName="${project.artifactId}"?>
<?define JpAppVersion="${project.version}"?>
<?define JpAppVendor="${project.maintainer}"?>
<?define JpProductUpgradeCode="a9527300-d364-4cc3-a392-94035065d8c9"?>
<?define JpAppDescription="Change audio and subtitle tracks for .mkv files"?>
<?define JpHelpURL="github.com/RatzzFatzz"?>
<?define JpAppDescription="${project.description}"?>
<?define JpHelpURL="github.com/${project.maintainer}/${project.artifactId}"?>
<Product
Id="$(var.JpProductCode)"