first bugfix
This commit is contained in:
parent
81c288725e
commit
7cc6596f01
|
@ -1,7 +1,9 @@
|
|||
package tv.mangrana.worker;
|
||||
|
||||
import tv.mangrana.exception.IncorrectWorkingReferencesException;
|
||||
import tv.mangrana.sonarr.api.schema.queue.Record;
|
||||
import tv.mangrana.sonarr.api.schema.series.SonarrSerie;
|
||||
import tv.mangrana.utils.StringCaptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -29,15 +31,26 @@ public class FailedImportFixer {
|
|||
System.out.printf(">> located in: %s%n", queueRecord.getOutputPath());
|
||||
|
||||
var torrentPath = Path.of(queueRecord.getOutputPath());
|
||||
var sonarPath = Path.of(serie.getPath());
|
||||
List<Path> torrentFiles = getVideoFilesFrom(torrentPath);
|
||||
List<Path> sonarFiles = getVideoFilesFrom(sonarPath);
|
||||
|
||||
var seasonFolderName = calculateSeasonPathFrom(torrentPath);
|
||||
var sonarPath = Path.of(serie.getPath());
|
||||
List<Path> sonarFiles = getVideoFilesFrom(sonarPath.resolve(seasonFolderName));
|
||||
|
||||
missingFilesDetector.printDifferencesBetween(torrentFiles, sonarFiles);
|
||||
}
|
||||
|
||||
private List<Path> getVideoFilesFrom(Path torrentPath) throws IOException {
|
||||
try (var pathWalk = Files.walk(torrentPath, 3)) {
|
||||
private String calculateSeasonPathFrom(Path torrentPath) {
|
||||
try {
|
||||
return StringCaptor.getSeasonFolderNameFromSeason(torrentPath.getFileName().toString());
|
||||
} catch (IncorrectWorkingReferencesException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Path> getVideoFilesFrom(Path path) throws IOException {
|
||||
System.out.println("going to explore "+path);
|
||||
try (var pathWalk = Files.walk(path, 3)) {
|
||||
return pathWalk
|
||||
.filter(p -> p.toFile().isFile())
|
||||
.filter(p -> p.toFile().length() > MINIMUM_FILE_SIZE_TO_BE_CONSIDERED_A_VIDEO)
|
||||
|
|
|
@ -8,6 +8,8 @@ import java.util.stream.Collectors;
|
|||
public class MissingFilesDetector {
|
||||
|
||||
void printDifferencesBetween(List<Path> torrentFiles, List<Path> sonarrFiles) {
|
||||
System.out.printf("going to compare %d torrent files with %d sonar files%n",
|
||||
torrentFiles.size(), sonarrFiles.size());
|
||||
Map<Long, List<Path>> torrentFileLengths = getFileLengthsMapFrom(torrentFiles);
|
||||
if (hasFilesWithSameSize(torrentFileLengths))
|
||||
return;
|
||||
|
@ -15,8 +17,9 @@ public class MissingFilesDetector {
|
|||
if (hasFilesWithSameSize(sonarrFileLengths))
|
||||
return;
|
||||
|
||||
torrentFileLengths.keySet().forEach(fileSize ->
|
||||
takeDecisionForMismatch(fileSize, torrentFileLengths));
|
||||
torrentFileLengths.keySet().stream()
|
||||
.filter(fileSize -> missingAtDestination(fileSize, sonarrFileLengths))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
}
|
||||
|
||||
|
@ -35,17 +38,14 @@ public class MissingFilesDetector {
|
|||
boolean hasMultipleElements(List<Path> paths) {
|
||||
if (paths.size() > 1) {
|
||||
var sampleFile = paths.get(0).toFile();
|
||||
System.out.printf("There is more than one file with the same size of %s. Name: %s %n",
|
||||
System.out.printf("There is more than one file with the same size of %d. Name: %s %n",
|
||||
sampleFile.length(), sampleFile.getName());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void takeDecisionForMismatch(Long fileSize, Map<Long, List<Path>> torrentFileLengths) {
|
||||
var alreadyExists = torrentFileLengths.containsKey(fileSize);
|
||||
if (!alreadyExists) {
|
||||
System.out.printf("- needs to copy %s%n", torrentFileLengths.get(fileSize));
|
||||
}
|
||||
boolean missingAtDestination(Long fileSize, Map<Long, List<Path>> torrentFileLengths) {
|
||||
return !torrentFileLengths.containsKey(fileSize);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import java.util.stream.Collectors;
|
|||
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.";
|
||||
private final SonarrApiGateway sonarrApiGateway;
|
||||
private FailedImportFixer failedImportFixer;
|
||||
|
||||
QueueFixer() {
|
||||
sonarrApiGateway = Sonarr.api();
|
||||
|
@ -56,9 +57,8 @@ public class QueueFixer {
|
|||
SonarrSerie serie = getSerieFromSonarr(seriesId);
|
||||
if (serie == null) return;
|
||||
|
||||
FailedImportFixer
|
||||
.of(record, serie)
|
||||
.fix();
|
||||
failedImportFixer = FailedImportFixer.of(record, serie);
|
||||
failedImportFixer.fix();
|
||||
} catch (IOException e) {
|
||||
System.out.printf("!! could not fix the import %s%n", record.getTitle());
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in New Issue