last code review
This commit is contained in:
parent
aaf93df99d
commit
14c0573d1b
|
@ -45,7 +45,7 @@ public class FailedImportFixer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Path> resolveTorrentFiles() throws IOException {
|
private List<Path> resolveTorrentFiles() throws IOException {
|
||||||
return getVideoFilesFrom(Path.of(queueRecord.getOutputPath()));
|
return getVideoFilesFrom(torrentPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Path> resolveSonarrFiles() throws IOException {
|
private List<Path> resolveSonarrFiles() throws IOException {
|
||||||
|
|
|
@ -8,18 +8,24 @@ import java.util.stream.Collectors;
|
||||||
public class MissingFilesDetector {
|
public class MissingFilesDetector {
|
||||||
|
|
||||||
private Map<Long, List<Path>> sonarrFilesByLength;
|
private Map<Long, List<Path>> sonarrFilesByLength;
|
||||||
|
private Map<Long, List<Path>> torrentFileLengths;
|
||||||
|
|
||||||
List<Path> getMissingFilesAtDestination(List<Path> torrentFiles, List<Path> sonarrFiles) {
|
List<Path> getMissingFilesAtDestination(List<Path> torrentFiles, List<Path> sonarrFiles) {
|
||||||
System.out.printf("going to compare %d torrent files with %d sonar files%n",
|
System.out.printf("going to compare %d torrent files with %d sonar files%n",
|
||||||
torrentFiles.size(), sonarrFiles.size());
|
torrentFiles.size(), sonarrFiles.size());
|
||||||
Map<Long, List<Path>> torrentFileLengths = getFileLengthsMapFrom(torrentFiles);
|
digestTorrentFiles(torrentFiles);
|
||||||
if (hasFilesWithSameSize(torrentFileLengths))
|
digestSonarrFiles(sonarrFiles);
|
||||||
return torrentFiles;
|
return resolveMissingFiles();
|
||||||
sonarrFilesByLength = getFileLengthsMapFrom(sonarrFiles);
|
}
|
||||||
if (hasFilesWithSameSize(sonarrFilesByLength))
|
|
||||||
return torrentFiles;
|
|
||||||
|
|
||||||
return resolveMissingFiles(torrentFileLengths);
|
private void digestTorrentFiles(List<Path> torrentFiles) {
|
||||||
|
torrentFileLengths = getFileLengthsMapFrom(torrentFiles);
|
||||||
|
throwIfDuplicatedSizes(torrentFileLengths);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void digestSonarrFiles(List<Path> sonarrFiles) {
|
||||||
|
sonarrFilesByLength = getFileLengthsMapFrom(sonarrFiles);
|
||||||
|
throwIfDuplicatedSizes(sonarrFilesByLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Long, List<Path>> getFileLengthsMapFrom(List<Path> files) {
|
Map<Long, List<Path>> getFileLengthsMapFrom(List<Path> files) {
|
||||||
|
@ -27,6 +33,11 @@ public class MissingFilesDetector {
|
||||||
.collect(Collectors.groupingBy(p -> p.toFile().length()));
|
.collect(Collectors.groupingBy(p -> p.toFile().length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void throwIfDuplicatedSizes(Map<Long, List<Path>> torrentFileLengths) {
|
||||||
|
if (hasFilesWithSameSize(torrentFileLengths))
|
||||||
|
throw new InsecureScenario();
|
||||||
|
}
|
||||||
|
|
||||||
boolean hasFilesWithSameSize(Map<Long, List<Path>> torrentFileLengths) {
|
boolean hasFilesWithSameSize(Map<Long, List<Path>> torrentFileLengths) {
|
||||||
return torrentFileLengths
|
return torrentFileLengths
|
||||||
.values()
|
.values()
|
||||||
|
@ -44,8 +55,8 @@ public class MissingFilesDetector {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Path> resolveMissingFiles(Map<Long, List<Path>> torrentFilesByLength) {
|
private List<Path> resolveMissingFiles() {
|
||||||
return torrentFilesByLength.entrySet()
|
return torrentFileLengths.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(this::missingAtDestination)
|
.filter(this::missingAtDestination)
|
||||||
.map(Map.Entry::getValue)
|
.map(Map.Entry::getValue)
|
||||||
|
@ -57,4 +68,5 @@ public class MissingFilesDetector {
|
||||||
return !sonarrFilesByLength.containsKey(torrentFileEntry.getKey());
|
return !sonarrFilesByLength.containsKey(torrentFileEntry.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class InsecureScenario extends RuntimeException {}
|
||||||
}
|
}
|
|
@ -10,7 +10,6 @@ import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class QueueFixer {
|
public class QueueFixer {
|
||||||
final static String IMPORT_FAILURE_BECAUSE_MATCHED_BY_ID = "Found matching series via grab history, but release was matched to series by ID. Automatic import is not possible. See the FAQ for details.";
|
final static String IMPORT_FAILURE_BECAUSE_MATCHED_BY_ID = "Found matching series via grab history, but release was matched to series by ID. Automatic import is not possible. See the FAQ for details.";
|
||||||
|
@ -43,7 +42,7 @@ public class QueueFixer {
|
||||||
private List<Record> filterFailedImportsOfIdProblem(Collection<Record> records) {
|
private List<Record> filterFailedImportsOfIdProblem(Collection<Record> records) {
|
||||||
return records.stream()
|
return records.stream()
|
||||||
.filter(this::recordsWithImportFailureBecauseIdMatching)
|
.filter(this::recordsWithImportFailureBecauseIdMatching)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean recordsWithImportFailureBecauseIdMatching(Record record) {
|
private boolean recordsWithImportFailureBecauseIdMatching(Record record) {
|
||||||
|
|
Loading…
Reference in New Issue