Change track selection

This commit is contained in:
2022-03-28 22:35:02 +02:00
parent 68e5b9e988
commit c11431d85b
15 changed files with 266 additions and 136 deletions

View File

@@ -0,0 +1,40 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import lombok.extern.log4j.Log4j2;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Log4j2
public class MkvFileCollector implements FileCollector {
@Override
public List<File> loadFiles(String path) {
File file = new File(path);
if (file.isFile() && file.getAbsolutePath().endsWith(".mkv")) {
return new ArrayList<File>() {{
add(file);
}};
} else if (file.isDirectory()) {
try (Stream<Path> paths = Files.walk(Paths.get(path))) {
return paths
.filter(Files::isRegularFile)
.map(Path::toFile)
.filter(f -> f.getAbsolutePath().endsWith(".mkv"))
.collect(Collectors.toList());
} catch (IOException e) {
log.error("Couldn't find file or directory!", e);
return new ArrayList<>();
}
} else {
return new ArrayList<>();
}
}
}