mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 10:05:58 +01:00
Compare commits
16 Commits
v3.0-pre.3
...
v3.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a075dfb27c | ||
|
|
ed8e592963 | ||
|
|
0a7996f049 | ||
|
|
dd60ca93da | ||
|
|
ba770abb6a | ||
|
|
91f1e8f7bf | ||
| 0fda98426e | |||
| c74cdde442 | |||
| a8551fdbd5 | |||
|
|
b2e9762366 | ||
| cafb12f22a | |||
|
|
f6d65c2d53 | ||
| 1963d1cc5c | |||
| 686a9a0da1 | |||
| e19f780ff0 | |||
| f928cb035e |
35
README.md
35
README.md
@@ -19,23 +19,28 @@ Attribute-config must be entered in pairs: `audio:subtitle`; Example: `jpn:eng`.
|
|||||||
[here](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/Attribute-Config).
|
[here](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/Attribute-Config).
|
||||||
|
|
||||||
## Available parameters
|
## Available parameters
|
||||||
```shell
|
|
||||||
-l,--library <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)
|
|
||||||
-t,--threads <arg> Thread count (default: 2)
|
|
||||||
-i,--include-pattern <arg> Include files matching pattern (default: ".*")
|
|
||||||
-e,--exclude-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
|
|
||||||
-v,--version Display version
|
|
||||||
-h,--help "For help this is" - Yoda
|
|
||||||
```
|
```
|
||||||
|
-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
|
||||||
|
```
|
||||||
|
If you need more information about how each parameter works, check out [this wiki page](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/Parameters).
|
||||||
|
|
||||||
All parameters can also be defined in a config file.
|
All parameters can also be defined in a [config file](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/How-to-config-file).
|
||||||
Please read [this wiki page](https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/wiki/How-to-config-file) for more information.
|
|
||||||
|
|
||||||
## Build requirements
|
## Build requirements
|
||||||
- JDK 11 or higher
|
- JDK 11 or higher
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
mkvtoolnix: C:\Program Files\MKVToolNix
|
mkvtoolnix: C:\Program Files\MKVToolNix
|
||||||
library: X:/Files
|
library: X:/Files
|
||||||
|
|
||||||
config:
|
attribute-config:
|
||||||
1:
|
1:
|
||||||
audio: ger
|
audio: ger
|
||||||
subtitle: OFF
|
subtitle: OFF
|
||||||
@@ -14,6 +14,7 @@ config:
|
|||||||
|
|
||||||
#forced-keywords: ["forced", "signs"]
|
#forced-keywords: ["forced", "signs"]
|
||||||
#commentary-keywords: ["commentary", "director"]
|
#commentary-keywords: ["commentary", "director"]
|
||||||
|
#preferred-subtitles: ["unstyled"]
|
||||||
|
|
||||||
#exclude-directories:
|
#exclude-directories:
|
||||||
# - "D:/Path/To/File.mkv"
|
# - "D:/Path/To/File.mkv"
|
||||||
@@ -22,7 +23,12 @@ config:
|
|||||||
# If pattern is negated, can be used to exclude files
|
# If pattern is negated, can be used to exclude files
|
||||||
#include-pattern: "regex"
|
#include-pattern: "regex"
|
||||||
|
|
||||||
|
# Only files newer than
|
||||||
|
#filter-date: 20.03.2021-10:11:12
|
||||||
|
|
||||||
safe-mode:
|
safe-mode:
|
||||||
#coherent:
|
#coherent:
|
||||||
|
#force-coherent:
|
||||||
|
#only-new-files:
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
22
pom.xml
22
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>at.pcgamingfreaks</groupId>
|
<groupId>at.pcgamingfreaks</groupId>
|
||||||
<artifactId>MKVAudioSubtitleChanger</artifactId>
|
<artifactId>MKVAudioSubtitleChanger</artifactId>
|
||||||
<version>3.0</version>
|
<version>3.0.2</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean package</defaultGoal>
|
<defaultGoal>clean package</defaultGoal>
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.1.1</version>
|
<version>3.2.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifestEntries>
|
<manifestEntries>
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.2.1</version>
|
<version>3.4.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -62,6 +62,13 @@
|
|||||||
<include>*:*</include>
|
<include>*:*</include>
|
||||||
</includes>
|
</includes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<manifestEntries>
|
||||||
|
<Multi-Release>true</Multi-Release>
|
||||||
|
</manifestEntries>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
@@ -124,17 +131,18 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-api</artifactId>
|
<artifactId>log4j-api</artifactId>
|
||||||
<version>2.17.1</version>
|
<version>2.18.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-core</artifactId>
|
<artifactId>log4j-core</artifactId>
|
||||||
<version>2.17.1</version>
|
<version>2.18.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j18-impl -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-slf4j-impl</artifactId>
|
<artifactId>log4j-slf4j18-impl</artifactId>
|
||||||
<version>2.17.1</version>
|
<version>2.18.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
|||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ConfigLoader;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ConfigLoader;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.CachedMkvFileProcessor;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.AttributeUpdaterKernel;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.AttributeUpdaterKernel;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.CoherentAttributeUpdaterKernel;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.CoherentAttributeUpdaterKernel;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.DefaultAttributeUpdaterKernel;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.DefaultAttributeUpdaterKernel;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.MkvFileCollector;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.MkvFileCollector;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.MkvFileProcessor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -14,8 +14,8 @@ public class Main {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ConfigLoader.initConfig(args);
|
ConfigLoader.initConfig(args);
|
||||||
AttributeUpdaterKernel kernel = Config.getInstance().getCoherent() != null
|
AttributeUpdaterKernel kernel = Config.getInstance().getCoherent() != null
|
||||||
? new CoherentAttributeUpdaterKernel(new MkvFileCollector(), new MkvFileProcessor())
|
? new CoherentAttributeUpdaterKernel(new MkvFileCollector(), new CachedMkvFileProcessor())
|
||||||
: new DefaultAttributeUpdaterKernel(new MkvFileCollector(), new MkvFileProcessor());
|
: new DefaultAttributeUpdaterKernel(new MkvFileCollector(), new CachedMkvFileProcessor());
|
||||||
kernel.execute();
|
kernel.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class ConfigLoader {
|
|||||||
if (cmd == null) throw new NullPointerException();
|
if (cmd == null) throw new NullPointerException();
|
||||||
return cmd;
|
return cmd;
|
||||||
} catch (ParseException | NullPointerException e) {
|
} catch (ParseException | NullPointerException e) {
|
||||||
formatter.printHelp(106, "java -jar MKVAudioSubtitlesChanger.jar -l <path_to_library>",
|
formatter.printHelp(130, "java -jar MKVAudioSubtitlesChanger.jar -l <path_to_library>",
|
||||||
"\nParameters:", options,
|
"\nParameters:", options,
|
||||||
"\nFeature requests and bug reports: https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/issues");
|
"\nFeature requests and bug reports: https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/issues");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
@@ -93,8 +93,8 @@ public class ConfigLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void exitIfHelp(CommandLine cmd, Options options, HelpFormatter formatter) {
|
private static void exitIfHelp(CommandLine cmd, Options options, HelpFormatter formatter) {
|
||||||
if (cmd.hasOption("help")) {
|
if (cmd.hasOption(HELP.prop())) {
|
||||||
formatter.printHelp(106, "java -jar MKVAudioSubtitlesChanger.jar -l <path_to_library>",
|
formatter.printHelp(130, "java -jar MKVAudioSubtitlesChanger.jar -l <path_to_library>",
|
||||||
"\nParameters:", options,
|
"\nParameters:", options,
|
||||||
"\nFeature requests and bug reports: https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/issues");
|
"\nFeature requests and bug reports: https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/issues");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class Cache<Key, Value> {
|
||||||
|
private final Map<Key, Value> cache = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve {@link Value} from Cache or run creationFunction and return its value.
|
||||||
|
* @param key key of cache map
|
||||||
|
* @param creationFunction function to create missing values
|
||||||
|
* @return {@link Value} from Cache, or if missing result from creationFunction.
|
||||||
|
*/
|
||||||
|
public synchronized Value retrieve(Key key, Function<Key, Value> creationFunction) {
|
||||||
|
return cache.computeIfAbsent(key, creationFunction::apply);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CachedMkvFileProcessor extends MkvFileProcessor {
|
||||||
|
Cache<File, List<FileAttribute>> cache = new Cache<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FileAttribute> loadAttributes(File file) {
|
||||||
|
return cache.retrieve(file, super::loadAttributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ public class FileFilter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResultStatistic.getInstance().total();
|
||||||
ResultStatistic.getInstance().excluded();
|
ResultStatistic.getInstance().excluded();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,9 +30,8 @@ public interface FileProcessor {
|
|||||||
/**
|
/**
|
||||||
* Populate FileInfoDto with the desired tracks, based on AttributeConfig.
|
* Populate FileInfoDto with the desired tracks, based on AttributeConfig.
|
||||||
* @param info to be populated
|
* @param info to be populated
|
||||||
* @param nonForcedTracks List of all not forced tracks
|
* @param nonForcedTracks List of all non-forced tracks
|
||||||
* @param nonCommentaryTracks List of all not commentary tracks
|
* @param nonCommentaryTracks List of all non-commentary tracks
|
||||||
* @param configs
|
|
||||||
*/
|
*/
|
||||||
void detectDesiredTracks(FileInfoDto info, List<FileAttribute> nonForcedTracks, List<FileAttribute> nonCommentaryTracks,
|
void detectDesiredTracks(FileInfoDto info, List<FileAttribute> nonForcedTracks, List<FileAttribute> nonCommentaryTracks,
|
||||||
AttributeConfig... configs);
|
AttributeConfig... configs);
|
||||||
@@ -45,7 +44,7 @@ public interface FileProcessor {
|
|||||||
* Update the file.
|
* Update the file.
|
||||||
* @param file to be updated
|
* @param file to be updated
|
||||||
* @param fileInfo information to update file
|
* @param fileInfo information to update file
|
||||||
* @throws IOException
|
* @throws IOException when error occurs accessing file retrieving information
|
||||||
* @throws MkvToolNixException when error occurs while sending query to mkvpropedit
|
* @throws MkvToolNixException when error occurs while sending query to mkvpropedit
|
||||||
*/
|
*/
|
||||||
void update(File file, FileInfoDto fileInfo) throws IOException, MkvToolNixException;
|
void update(File file, FileInfoDto fileInfo) throws IOException, MkvToolNixException;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
|
|
||||||
private static final String DISABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=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 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 ENABLE_FORCED_TRACK = "--edit track:%s --set flag-forced=1 ";
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -69,8 +70,8 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
|
|
||||||
log.debug(fileAttributes.toString());
|
log.debug(fileAttributes.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.error("File could not be found or loaded: ", e);
|
||||||
log.error("File could not be found or loaded!");
|
System.out.println("File could not be found or loaded: " + file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
return fileAttributes;
|
return fileAttributes;
|
||||||
}
|
}
|
||||||
@@ -80,21 +81,17 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void detectDefaultTracks(FileInfoDto info, List<FileAttribute> attributes, List<FileAttribute> nonForcedTracks) {
|
public void detectDefaultTracks(FileInfoDto info, List<FileAttribute> attributes, List<FileAttribute> nonForcedTracks) {
|
||||||
Set<FileAttribute> detectedForcedSubtitleLanes = new HashSet<>();
|
|
||||||
for (FileAttribute attribute : attributes) {
|
for (FileAttribute attribute : attributes) {
|
||||||
if (attribute.isDefaultTrack() && AUDIO.equals(attribute.getType()))
|
if (AUDIO.equals(attribute.getType())) {
|
||||||
info.getDefaultAudioLanes().add(attribute);
|
if (attribute.isDefaultTrack()) info.getExistingDefaultAudioLanes().add(attribute);
|
||||||
if (attribute.isDefaultTrack() && SUBTITLES.equals(attribute.getType()))
|
if (attribute.isForcedTrack()) info.getExistingForcedAudioLanes().add(attribute);
|
||||||
info.getDefaultSubtitleLanes().add(attribute);
|
} else if (SUBTITLES.equals(attribute.getType())) {
|
||||||
if (attribute.isForcedTrack() && SUBTITLES.equals(attribute.getType()))
|
if (attribute.isDefaultTrack()) info.getExistingDefaultSubtitleLanes().add(attribute);
|
||||||
detectedForcedSubtitleLanes.add(attribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
info.setDesiredForcedSubtitleLanes(attributes.stream()
|
if (attribute.isForcedTrack()) info.getExistingForcedSubtitleLanes().add(attribute);
|
||||||
.filter(e -> !nonForcedTracks.contains(e))
|
else if (!nonForcedTracks.contains(attribute)) info.getDesiredForcedSubtitleLanes().add(attribute);
|
||||||
.filter(e -> !detectedForcedSubtitleLanes.contains(e))
|
}
|
||||||
.collect(Collectors.toSet())
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,9 +108,10 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
Optional<FileAttribute> desiredAudio = detectDesiredTrack(config.getAudioLanguage(), audioTracks).findFirst();
|
Optional<FileAttribute> desiredAudio = detectDesiredTrack(config.getAudioLanguage(), audioTracks).findFirst();
|
||||||
Optional<FileAttribute> desiredSubtitle = detectDesiredSubtitleTrack(config.getSubtitleLanguage(), subtitleTracks).findFirst();
|
Optional<FileAttribute> desiredSubtitle = detectDesiredSubtitleTrack(config.getSubtitleLanguage(), subtitleTracks).findFirst();
|
||||||
|
|
||||||
if (desiredAudio.isPresent() && desiredSubtitle.isPresent()) {
|
if (desiredAudio.isPresent() && ("OFF".equals(config.getSubtitleLanguage()) || desiredSubtitle.isPresent())) {
|
||||||
info.setDesiredAudioLane(desiredAudio.get());
|
info.setMatchedConfig(config);
|
||||||
info.setDesiredSubtitleLane(desiredSubtitle.get());
|
info.setDesiredDefaultAudioLane(desiredAudio.get());
|
||||||
|
info.setDesiredDefaultSubtitleLane(desiredSubtitle.orElse(null));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,21 +153,29 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
sb.append(format("\"%s\" ", file.getAbsolutePath()));
|
sb.append(format("\"%s\" ", file.getAbsolutePath()));
|
||||||
|
|
||||||
if (fileInfo.isAudioDifferent()) {
|
if (fileInfo.isAudioDifferent()) {
|
||||||
if (fileInfo.getDefaultAudioLanes() != null && !fileInfo.getDefaultSubtitleLanes().isEmpty()) {
|
if (fileInfo.getExistingDefaultAudioLanes() != null && !fileInfo.getExistingDefaultAudioLanes().isEmpty()) {
|
||||||
for (FileAttribute track: fileInfo.getDefaultAudioLanes()) {
|
for (FileAttribute track: fileInfo.getExistingDefaultAudioLanes()) {
|
||||||
sb.append(format(DISABLE_DEFAULT_TRACK, track.getId()));
|
sb.append(format(DISABLE_DEFAULT_TRACK, track.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append(format(ENABLE_DEFAULT_TRACK, fileInfo.getDesiredAudioLane().getId()));
|
sb.append(format(ENABLE_DEFAULT_TRACK, fileInfo.getDesiredDefaultAudioLane().getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fileInfo.getExistingForcedAudioLanes().isEmpty()) {
|
||||||
|
for (FileAttribute track: fileInfo.getExistingForcedAudioLanes()) {
|
||||||
|
sb.append(format(DISABLE_FORCED_TRACK, track.getId()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileInfo.isSubtitleDifferent()) {
|
if (fileInfo.isSubtitleDifferent()) {
|
||||||
if (fileInfo.getDefaultSubtitleLanes() != null && !fileInfo.getDefaultSubtitleLanes().isEmpty()) {
|
if (fileInfo.getExistingDefaultSubtitleLanes() != null && !fileInfo.getExistingDefaultSubtitleLanes().isEmpty()) {
|
||||||
for (FileAttribute track: fileInfo.getDefaultSubtitleLanes()) {
|
for (FileAttribute track: fileInfo.getExistingDefaultSubtitleLanes()) {
|
||||||
sb.append(format(DISABLE_DEFAULT_TRACK, track.getId()));
|
sb.append(format(DISABLE_DEFAULT_TRACK, track.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append(format(ENABLE_DEFAULT_TRACK, fileInfo.getDesiredSubtitleLane().getId()));
|
if (fileInfo.getDesiredDefaultSubtitleLane() != null) {
|
||||||
|
sb.append(format(ENABLE_DEFAULT_TRACK, fileInfo.getDesiredDefaultSubtitleLane().getId()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileInfo.areForcedTracksDifferent()) {
|
if (fileInfo.areForcedTracksDifferent()) {
|
||||||
@@ -178,6 +184,7 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info(sb.toString());
|
||||||
InputStream inputstream = Runtime.getRuntime().exec(sb.toString()).getInputStream();
|
InputStream inputstream = Runtime.getRuntime().exec(sb.toString()).getInputStream();
|
||||||
String output = IOUtils.toString(new InputStreamReader(inputstream));
|
String output = IOUtils.toString(new InputStreamReader(inputstream));
|
||||||
log.debug(output);
|
log.debug(output);
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
* @param fileInfoDto contains information about file and desired configuration.
|
* @param fileInfoDto contains information about file and desired configuration.
|
||||||
*/
|
*/
|
||||||
protected void updateFile(FileInfoDto fileInfoDto) {
|
protected void updateFile(FileInfoDto fileInfoDto) {
|
||||||
|
statistic.total();
|
||||||
switch (fileInfoDto.getStatus()) {
|
switch (fileInfoDto.getStatus()) {
|
||||||
case CHANGE_NECESSARY:
|
case CHANGE_NECESSARY:
|
||||||
statistic.shouldChange();
|
statistic.shouldChange();
|
||||||
@@ -139,7 +140,6 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
statistic.total();
|
|
||||||
processor.update(fileInfo.getFile(), fileInfo);
|
processor.update(fileInfo.getFile(), fileInfo);
|
||||||
statistic.success();
|
statistic.success();
|
||||||
log.info("Updated {}", fileInfo.getFile().getAbsolutePath());
|
log.info("Updated {}", fileInfo.getFile().getAbsolutePath());
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ import me.tongfei.progressbar.ProgressBarBuilder;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -34,8 +32,12 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
List<File> loadFiles(String path) {
|
List<File> loadFiles(String path) {
|
||||||
|
return loadFiles(path, Config.getInstance().getCoherent());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<File> loadFiles(String path, int depth) {
|
||||||
List<File> excludedFiles = loadExcludedFiles();
|
List<File> excludedFiles = loadExcludedFiles();
|
||||||
List<File> directories = collector.loadDirectories(path, Config.getInstance().getCoherent())
|
List<File> directories = collector.loadDirectories(path, depth)
|
||||||
.stream().filter(file -> !excludedFiles.contains(file))
|
.stream().filter(file -> !excludedFiles.contains(file))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
return directories.stream()
|
return directories.stream()
|
||||||
@@ -59,25 +61,20 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
void process(File file) {
|
void process(File file) {
|
||||||
|
process(file, Config.getInstance().getCoherent());
|
||||||
|
}
|
||||||
|
|
||||||
|
void process(File file, int depth) {
|
||||||
// TODO: Implement level crawl if coherence is not possible on user entered depth
|
// TODO: Implement level crawl if coherence is not possible on user entered depth
|
||||||
// IMPL idea: recursive method call, cache needs to be implemented
|
// IMPL idea: recursive method call, cache needs to be implemented
|
||||||
List<FileInfoDto> fileInfos = collector.loadFiles(file.getAbsolutePath())
|
List<FileInfoDto> fileInfos = collector.loadFiles(file.getAbsolutePath()).stream()
|
||||||
.stream().map(FileInfoDto::new)
|
.map(FileInfoDto::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
Map<FileInfoDto, List<FileAttribute>> fileAttributeCache = new HashMap<>();
|
|
||||||
for (FileInfoDto fileInfo : fileInfos) {
|
|
||||||
if (!Config.getInstance().getIncludePattern().matcher(fileInfo.getFile().getAbsolutePath()).matches()) {
|
|
||||||
statistic.excluded();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fileAttributeCache.put(fileInfo, processor.loadAttributes(fileInfo.getFile()));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (AttributeConfig config : Config.getInstance().getAttributeConfig()) {
|
for (AttributeConfig config : Config.getInstance().getAttributeConfig()) {
|
||||||
|
|
||||||
for (FileInfoDto fileInfo : fileInfos) {
|
for (FileInfoDto fileInfo : fileInfos) {
|
||||||
List<FileAttribute> attributes = fileAttributeCache.get(fileInfo);
|
List<FileAttribute> attributes = processor.loadAttributes(fileInfo.getFile());
|
||||||
|
|
||||||
List<FileAttribute> nonForcedTracks = processor.retrieveNonForcedTracks(attributes);
|
List<FileAttribute> nonForcedTracks = processor.retrieveNonForcedTracks(attributes);
|
||||||
List<FileAttribute> nonCommentaryTracks = processor.retrieveNonCommentaryTracks(attributes);
|
List<FileAttribute> nonCommentaryTracks = processor.retrieveNonCommentaryTracks(attributes);
|
||||||
@@ -86,22 +83,23 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
|||||||
processor.detectDesiredTracks(fileInfo, nonForcedTracks, nonCommentaryTracks, config);
|
processor.detectDesiredTracks(fileInfo, nonForcedTracks, nonCommentaryTracks, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileInfos.stream().allMatch(elem -> elem.getDesiredSubtitleLane() != null && elem.getDesiredAudioLane() != null)) {
|
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.getAudioLanguage(), config.getSubtitleLanguage(), file.getAbsolutePath());
|
||||||
statistic.increaseTotalBy(fileInfos.size());
|
|
||||||
fileInfos.forEach(this::updateFile);
|
fileInfos.forEach(this::updateFile);
|
||||||
return; // match found, end process here
|
return; // match found, end process here
|
||||||
}
|
}
|
||||||
|
|
||||||
fileInfos.forEach(f -> {
|
fileInfos.forEach(f -> {
|
||||||
f.setDesiredAudioLane(null);
|
f.setDesiredDefaultAudioLane(null);
|
||||||
f.setDesiredSubtitleLane(null);
|
f.setDesiredDefaultSubtitleLane(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("No coherent match found for {}", file.getAbsoluteFile());
|
||||||
|
|
||||||
for (FileInfoDto fileInfo : fileInfos) {
|
for (FileInfoDto fileInfo : fileInfos) {
|
||||||
statistic.total();
|
if (!Config.getInstance().isForceCoherent()) {
|
||||||
if (Config.getInstance().isForceCoherent()) {
|
|
||||||
super.process(fileInfo.getFile());
|
super.process(fileInfo.getFile());
|
||||||
} else {
|
} else {
|
||||||
statistic.excluded();
|
statistic.excluded();
|
||||||
|
|||||||
@@ -13,24 +13,39 @@ import java.util.Set;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class FileInfoDto {
|
public class FileInfoDto {
|
||||||
private final File file;
|
private final File file;
|
||||||
private Set<FileAttribute> defaultAudioLanes = new HashSet<>();
|
|
||||||
private Set<FileAttribute> defaultSubtitleLanes = new HashSet<>();
|
private Set<FileAttribute> existingDefaultAudioLanes = new HashSet<>();
|
||||||
private Set<FileAttribute> desiredForcedSubtitleLanes;
|
private Set<FileAttribute> existingForcedAudioLanes = new HashSet<>();
|
||||||
private FileAttribute desiredAudioLane;
|
|
||||||
private FileAttribute desiredSubtitleLane;
|
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() {
|
public boolean isAudioDifferent() {
|
||||||
return desiredAudioLane != null &&
|
return desiredDefaultAudioLane != null &&
|
||||||
(defaultAudioLanes == null || !defaultAudioLanes.contains(desiredAudioLane));
|
(existingDefaultAudioLanes == null || !existingDefaultAudioLanes.contains(desiredDefaultAudioLane) || existingDefaultAudioLanes.size() > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSubtitleDifferent() {
|
public boolean isSubtitleDifferent() {
|
||||||
return desiredSubtitleLane != null &&
|
return isSubtitleMatchDifferent() || isSubtitleOFF();
|
||||||
(defaultSubtitleLanes == null || !defaultSubtitleLanes.contains(desiredSubtitleLane));
|
}
|
||||||
|
|
||||||
|
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() {
|
public boolean areForcedTracksDifferent() {
|
||||||
return desiredForcedSubtitleLanes.size() > 0;
|
return !desiredForcedSubtitleLanes.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileStatus getStatus() {
|
public FileStatus getStatus() {
|
||||||
@@ -41,24 +56,24 @@ public class FileInfoDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isUnableToApplyConfig() {
|
private boolean isUnableToApplyConfig() {
|
||||||
return desiredAudioLane == null && desiredSubtitleLane == null;
|
return desiredDefaultAudioLane == null && desiredDefaultSubtitleLane == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAlreadySuitable() {
|
private boolean isAlreadySuitable() {
|
||||||
return defaultAudioLanes.contains(desiredAudioLane) && defaultSubtitleLanes.contains(desiredSubtitleLane);
|
return existingDefaultAudioLanes.contains(desiredDefaultAudioLane) && existingDefaultSubtitleLanes.contains(desiredDefaultSubtitleLane);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isChangeNecessary() {
|
private boolean isChangeNecessary() {
|
||||||
return isAudioDifferent() || isSubtitleDifferent() || areForcedTracksDifferent();
|
return isAudioDifferent() || isSubtitleDifferent() || areForcedTracksDifferent() || !existingForcedAudioLanes.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[" + "defaultAudioLanes=" + defaultAudioLanes +
|
return "[" + "defaultAudioLanes=" + existingDefaultAudioLanes +
|
||||||
", defaultSubtitleLanes=" + defaultSubtitleLanes +
|
", defaultSubtitleLanes=" + existingDefaultSubtitleLanes +
|
||||||
", desiredForcedSubtitleLanes=" + desiredForcedSubtitleLanes +
|
", desiredForcedSubtitleLanes=" + desiredForcedSubtitleLanes +
|
||||||
", desiredAudioLane=" + desiredAudioLane +
|
", desiredAudioLane=" + desiredDefaultAudioLane +
|
||||||
", desiredSubtitleLane=" + desiredSubtitleLane +
|
", desiredSubtitleLane=" + desiredDefaultSubtitleLane +
|
||||||
']';
|
']';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public class ResultStatistic {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String sb = "ResultStatistic[" + "filesTotal=" + filesTotal +
|
return "ResultStatistic: " + "filesTotal=" + filesTotal +
|
||||||
", excluded=" + excluded +
|
", excluded=" + excluded +
|
||||||
", shouldChange=" + shouldChange +
|
", shouldChange=" + shouldChange +
|
||||||
" (failedChanging=" + failedChanging +
|
" (failedChanging=" + failedChanging +
|
||||||
@@ -124,8 +124,6 @@ public class ResultStatistic {
|
|||||||
"), noSuitableConfigFound=" + noSuitableConfigFound +
|
"), noSuitableConfigFound=" + noSuitableConfigFound +
|
||||||
", alreadyFits=" + alreadyFits +
|
", alreadyFits=" + alreadyFits +
|
||||||
", failed=" + failed +
|
", failed=" + failed +
|
||||||
", runtime=" + formatTimer() +
|
", runtime=" + formatTimer();
|
||||||
']';
|
|
||||||
return sb;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_FILE;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class ConfigLoaderTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void initConfig() {
|
||||||
|
String[] sut = new String[]{"-a", "ger:ger", "-l", TEST_FILE,
|
||||||
|
"-s", "-cf", "-n",
|
||||||
|
"-c", "2",
|
||||||
|
"-t", "4",
|
||||||
|
"-i", ".*[abc].*",
|
||||||
|
"-fk", "testForced",
|
||||||
|
"-ck", "testCommentary",
|
||||||
|
"-ps", "testPreferred"
|
||||||
|
};
|
||||||
|
ConfigLoader.initConfig(sut);
|
||||||
|
|
||||||
|
assertTrue(Config.getInstance().getLibraryPath().exists());
|
||||||
|
assertEquals(List.of(new AttributeConfig("ger", "ger")), Config.getInstance().getAttributeConfig());
|
||||||
|
|
||||||
|
assertTrue(Config.getInstance().isSafeMode());
|
||||||
|
assertTrue(Config.getInstance().isForceCoherent());
|
||||||
|
assertTrue(Config.getInstance().isOnlyNewFiles());
|
||||||
|
assertNotNull(Config.getInstance().getFilterDate());
|
||||||
|
|
||||||
|
assertEquals(2, Config.getInstance().getCoherent());
|
||||||
|
assertEquals(4, Config.getInstance().getThreads());
|
||||||
|
assertEquals(".*[abc].*", Config.getInstance().getIncludePattern().pattern());
|
||||||
|
assertTrue(Config.getInstance().getForcedKeywords().contains("testForced"));
|
||||||
|
assertTrue(Config.getInstance().getCommentaryKeywords().contains("testCommentary"));
|
||||||
|
assertTrue(Config.getInstance().getPreferredSubtitles().contains("testPreferred"));
|
||||||
|
|
||||||
|
assertNull(Config.getInstance().getConfigPath());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,13 +20,12 @@ import static at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult.
|
|||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult.INVALID;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult.INVALID;
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.LIBRARY;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.LIBRARY;
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf;
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_DIR;
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_FILE;
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.argumentsOf;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.argumentsOf;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class PathValidatorTest {
|
class PathValidatorTest {
|
||||||
private static final String TEST_DIR = "src/test/resources/test-dir";
|
|
||||||
private static final String TEST_FILE = "src/test/resources/test-dir/test-file.mkv";
|
|
||||||
|
|
||||||
private static CommandLineParser parser;
|
private static CommandLineParser parser;
|
||||||
private static Options options;
|
private static Options options;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||||
|
|
||||||
|
public class PathUtils {
|
||||||
|
public static final String TEST_DIR = "src/test/resources/test-dir";
|
||||||
|
public static final String TEST_FILE = "src/test/resources/test-dir/test-file.mkv";
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class SetUtilsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void retainOf() {
|
||||||
|
List<Integer> list1 = List.of(1, 2, 3, 4, 5);
|
||||||
|
List<Integer> list2 = List.of(2, 4, 6, 8, 10);
|
||||||
|
Set<Integer> expected = Set.of(2, 4);
|
||||||
|
|
||||||
|
assertEquals(expected, SetUtils.retainOf(list1, list2));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.joining;
|
import static java.util.stream.Collectors.joining;
|
||||||
|
|
||||||
@@ -25,4 +29,18 @@ public class TestUtil {
|
|||||||
return Arguments.of(property, required, append, yaml, cmd, result, 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 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user