mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Finalize coherent feature
This commit is contained in:
@@ -4,6 +4,7 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileCollector;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileProcessor;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -84,7 +85,18 @@ public abstract class AttributeUpdaterKernel {
|
||||
*
|
||||
* @param file file or directory to update
|
||||
*/
|
||||
abstract void process(File file);
|
||||
void process(File file) {
|
||||
FileInfoDto fileInfo = new FileInfoDto(file);
|
||||
List<FileAttribute> attributes = processor.loadAttributes(file);
|
||||
|
||||
List<FileAttribute> nonForcedTracks = processor.retrieveNonForcedTracks(attributes);
|
||||
List<FileAttribute> nonCommentaryTracks = processor.retrieveNonCommentaryTracks(attributes);
|
||||
|
||||
processor.detectDefaultTracks(fileInfo, attributes, nonForcedTracks);
|
||||
processor.detectDesiredTracks(fileInfo, nonForcedTracks, nonCommentaryTracks);
|
||||
|
||||
updateFile(fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist file changes.
|
||||
@@ -92,7 +104,6 @@ public abstract class AttributeUpdaterKernel {
|
||||
* @param fileInfoDto contains information about file and desired configuration.
|
||||
*/
|
||||
protected void updateFile(FileInfoDto fileInfoDto) {
|
||||
statistic.total();
|
||||
switch (fileInfoDto.getStatus()) {
|
||||
case CHANGE_NECESSARY:
|
||||
statistic.shouldChange();
|
||||
@@ -117,6 +128,7 @@ public abstract class AttributeUpdaterKernel {
|
||||
}
|
||||
|
||||
try {
|
||||
statistic.total();
|
||||
processor.update(fileInfo.getFile(), fileInfo);
|
||||
statistic.success();
|
||||
log.info("Updated {}", fileInfo.getFile().getAbsolutePath());
|
||||
|
||||
@@ -61,6 +61,7 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
||||
}
|
||||
|
||||
for (AttributeConfig config : Config.getInstance().getAttributeConfig()) {
|
||||
|
||||
for (FileInfoDto fileInfo : fileInfos) {
|
||||
List<FileAttribute> attributes = fileAttributeCache.get(fileInfo);
|
||||
|
||||
@@ -72,8 +73,10 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
||||
}
|
||||
|
||||
if (fileInfos.stream().allMatch(elem -> elem.getDesiredSubtitleLane() != null && elem.getDesiredAudioLane() != null)) {
|
||||
log.debug("Found {}/{} match for {}", config.getAudioLanguage(), config.getSubtitleLanguage(), file.getAbsolutePath());
|
||||
break;
|
||||
log.info("Found {}/{} match for {}", config.getAudioLanguage(), config.getSubtitleLanguage(), file.getAbsolutePath());
|
||||
statistic.increaseTotalBy(fileInfos.size());
|
||||
fileInfos.forEach(this::updateFile);
|
||||
return; // match found, end process here
|
||||
}
|
||||
|
||||
fileInfos.forEach(f -> {
|
||||
@@ -82,8 +85,13 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
||||
});
|
||||
}
|
||||
|
||||
// apply config
|
||||
|
||||
// apply default process if nothing was found (if parameter is set)
|
||||
for(FileInfoDto fileInfo: fileInfos) {
|
||||
statistic.total();
|
||||
if (Config.getInstance().isForceCoherent()) {
|
||||
super.process(fileInfo.getFile());
|
||||
} else {
|
||||
statistic.excluded();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,9 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileCollector;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileProcessor;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -30,21 +26,4 @@ public class DefaultAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
||||
.filter(file -> !excludedFiles.contains(file))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
void process(File file) {
|
||||
FileInfoDto fileInfo = new FileInfoDto(file);
|
||||
List<FileAttribute> attributes = processor.loadAttributes(file);
|
||||
|
||||
List<FileAttribute> nonForcedTracks = processor.retrieveNonForcedTracks(attributes);
|
||||
List<FileAttribute> nonCommentaryTracks = processor.retrieveNonCommentaryTracks(attributes);
|
||||
|
||||
processor.detectDefaultTracks(fileInfo, attributes, nonForcedTracks);
|
||||
processor.detectDesiredTracks(fileInfo, nonForcedTracks, nonCommentaryTracks);
|
||||
|
||||
updateFile(fileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user