Fix excluded file count

This commit is contained in:
2023-03-11 19:21:55 +01:00
parent 6372cc560c
commit cf64833d3e
6 changed files with 60 additions and 12 deletions

View File

@@ -159,7 +159,7 @@
<dependency> <dependency>
<groupId>me.tongfei</groupId> <groupId>me.tongfei</groupId>
<artifactId>progressbar</artifactId> <artifactId>progressbar</artifactId>
<version>0.9.3</version> <version>0.9.5</version>
</dependency> </dependency>
<!-- endregion --> <!-- endregion -->
<!-- region unit-tests --> <!-- region unit-tests -->

View File

@@ -1,13 +1,19 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl; package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config; import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.io.File; import java.io.File;
public class FileFilter { public class FileFilter {
static boolean accept(File pathName, String[] fileExtensions) { static boolean accept(File pathName, String[] fileExtensions) {
return StringUtils.endsWithAny(pathName.getAbsolutePath().toLowerCase(), fileExtensions) if (StringUtils.endsWithAny(pathName.getAbsolutePath().toLowerCase(), fileExtensions)
&& Config.getInstance().getIncludePattern().matcher(pathName.getName()).matches(); && Config.getInstance().getIncludePattern().matcher(pathName.getName()).matches()) {
return true;
}
ResultStatistic.getInstance().excluded();
return false;
} }
} }

View File

@@ -29,10 +29,10 @@ public abstract class AttributeUpdaterKernel {
protected final FileCollector collector; protected final FileCollector collector;
protected final FileProcessor processor; protected final FileProcessor processor;
protected final ResultStatistic statistic = new ResultStatistic(); protected final ResultStatistic statistic = ResultStatistic.getInstance();
private final ExecutorService executor = Executors.newFixedThreadPool(Config.getInstance().getThreads()); private final ExecutorService executor = Executors.newFixedThreadPool(Config.getInstance().getThreads());
private static ProgressBarBuilder pbBuilder() { protected ProgressBarBuilder pbBuilder() {
return new ProgressBarBuilder() return new ProgressBarBuilder()
.setStyle(ProgressBarStyle.ASCII) .setStyle(ProgressBarStyle.ASCII)
.setUpdateIntervalMillis(250) .setUpdateIntervalMillis(250)

View File

@@ -7,6 +7,7 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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;
@@ -22,6 +23,12 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
super(collector, processor); super(collector, processor);
} }
@Override
protected ProgressBarBuilder pbBuilder() {
return super.pbBuilder()
.setUnit(" directories", 1);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@@ -43,10 +50,17 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
} }
/** /**
* {@inheritDoc} * Update files in directory, if possible, with the same {@link AttributeConfig}.
* If {@link Config#isForceCoherent()} then there will be no changes to the file if they don't match the same config.
* Otherwise, the default behaviour is executed.
* This method is called by the executor and is run in parallel.
*
* @param file directory containing files
*/ */
@Override @Override
void process(File file) { void process(File file) {
// 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()) List<FileInfoDto> fileInfos = collector.loadFiles(file.getAbsolutePath())
.stream().map(FileInfoDto::new) .stream().map(FileInfoDto::new)
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -85,7 +99,7 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
}); });
} }
for(FileInfoDto fileInfo: fileInfos) { for (FileInfoDto fileInfo : fileInfos) {
statistic.total(); statistic.total();
if (Config.getInstance().isForceCoherent()) { if (Config.getInstance().isForceCoherent()) {
super.process(fileInfo.getFile()); super.process(fileInfo.getFile());

View File

@@ -4,6 +4,7 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileCollector; import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileCollector;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileProcessor; import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileProcessor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.tongfei.progressbar.ProgressBarBuilder;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@@ -16,6 +17,12 @@ public class DefaultAttributeUpdaterKernel extends AttributeUpdaterKernel {
super(collector, processor); super(collector, processor);
} }
@Override
protected ProgressBarBuilder pbBuilder() {
return super.pbBuilder()
.setUnit(" files", 1);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@@ -16,7 +16,7 @@ public class ResultStatistic {
"├─ Already fit config: %s%n" + "├─ Already fit config: %s%n" +
"└─ Failed: %s%n" + "└─ Failed: %s%n" +
"Runtime: %s"; "Runtime: %s";
private static ResultStatistic instance;
private int filesTotal = 0; private int filesTotal = 0;
private int excluded = 0; private int excluded = 0;
@@ -32,6 +32,13 @@ public class ResultStatistic {
private long startTime = 0; private long startTime = 0;
private long runtime = 0; private long runtime = 0;
public static ResultStatistic getInstance() {
if (instance == null) {
instance = new ResultStatistic();
}
return instance;
}
public void increaseTotalBy(int amount) { public void increaseTotalBy(int amount) {
filesTotal += amount; filesTotal += amount;
} }
@@ -81,7 +88,7 @@ public class ResultStatistic {
} }
public void printResult() { public void printResult() {
System.out.println(this); System.out.println(prettyPrint());
log.info(this.toString()); log.info(this.toString());
} }
@@ -96,15 +103,29 @@ public class ResultStatistic {
} else if (hours >= 1) { } else if (hours >= 1) {
return String.format("%sh %sm %ss", hours, minutes % 60, seconds % 60); return String.format("%sh %sm %ss", hours, minutes % 60, seconds % 60);
} else if (minutes >= 1) { } else if (minutes >= 1) {
return String.format("%sm %ss", minutes , seconds % 60); return String.format("%sm %ss", minutes, seconds % 60);
} else { } else {
return String.format("%ss", seconds % 60); return String.format("%ss", seconds % 60);
} }
} }
@Override public String prettyPrint() {
public String toString() {
return String.format(result, filesTotal, excluded, shouldChange, failedChanging, successfullyChanged, return String.format(result, filesTotal, excluded, shouldChange, failedChanging, successfullyChanged,
noSuitableConfigFound, alreadyFits, failed, formatTimer()); noSuitableConfigFound, alreadyFits, failed, formatTimer());
} }
@Override
public String toString() {
String sb = "ResultStatistic[" + "filesTotal=" + filesTotal +
", excluded=" + excluded +
", shouldChange=" + shouldChange +
" (failedChanging=" + failedChanging +
", successfullyChanged=" + successfullyChanged +
"), noSuitableConfigFound=" + noSuitableConfigFound +
", alreadyFits=" + alreadyFits +
", failed=" + failed +
", runtime=" + formatTimer() +
']';
return sb;
}
} }