start looking for files
This commit is contained in:
parent
bb2b7234f8
commit
d59940c028
|
@ -3,19 +3,43 @@ package tv.mangrana.worker;
|
|||
import tv.mangrana.sonarr.api.schema.queue.Record;
|
||||
import tv.mangrana.sonarr.api.schema.series.SonarrSerie;
|
||||
|
||||
public class FailedImportFixer {
|
||||
private final Record queueRecord;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
private FailedImportFixer(Record queueRecord) {
|
||||
public class FailedImportFixer {
|
||||
public static final int MINIMUM_FILE_SIZE_TO_BE_CONSIDERED_A_VIDEO = 300000;
|
||||
private final Record queueRecord;
|
||||
private final SonarrSerie serie;
|
||||
|
||||
private FailedImportFixer(Record queueRecord, SonarrSerie serie) {
|
||||
this.queueRecord = queueRecord;
|
||||
this.serie = serie;
|
||||
}
|
||||
|
||||
static FailedImportFixer of(Record queueRecord, SonarrSerie serie) {
|
||||
return new FailedImportFixer(queueRecord);
|
||||
return new FailedImportFixer(queueRecord, serie);
|
||||
}
|
||||
|
||||
void fix() {
|
||||
System.out.printf("fixing: %s%n" ,queueRecord.getTitle());
|
||||
System.out.printf(">> located in: %s%n%n", queueRecord.getOutputPath());
|
||||
void fix() throws IOException {
|
||||
System.out.printf("%nfixing: %s%n" ,queueRecord.getTitle());
|
||||
System.out.printf(">> located in: %s%n", queueRecord.getOutputPath());
|
||||
|
||||
var torrentPath = Path.of(queueRecord.getOutputPath());
|
||||
List<Path> torrentFiles = getVideoFilesFrom(torrentPath);
|
||||
|
||||
var sonarPath = Path.of(serie.getPath());
|
||||
List<Path> sonarFiles = getVideoFilesFrom(sonarPath);
|
||||
}
|
||||
|
||||
private List<Path> getVideoFilesFrom(Path torrentPath) throws IOException {
|
||||
try (var pathWalk = Files.walk(torrentPath, 3)) {
|
||||
return pathWalk
|
||||
.filter(p -> p.toFile().isFile())
|
||||
.filter(p -> p.toFile().length() > MINIMUM_FILE_SIZE_TO_BE_CONSIDERED_A_VIDEO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import tv.mangrana.sonarr.api.client.gateway.SonarrApiGateway;
|
|||
import tv.mangrana.sonarr.api.schema.queue.Record;
|
||||
import tv.mangrana.sonarr.api.schema.series.SonarrSerie;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -23,7 +24,7 @@ public class QueueFixer {
|
|||
List<Record> sonarQueue = retrieveQueueRecordsFromSonarr();
|
||||
Collection<Record> records = deduplicate(sonarQueue);
|
||||
List<Record> recordsToFix = filterFailedImportsOfIdProblem(records);
|
||||
recordsToFix.forEach(this::fixFailedImport);
|
||||
recordsToFix.forEach(this::try2FixFailedImport);
|
||||
}
|
||||
|
||||
private List<Record> retrieveQueueRecordsFromSonarr() {
|
||||
|
@ -49,12 +50,18 @@ public class QueueFixer {
|
|||
.anyMatch(IMPORT_FAILURE_BECAUSE_MATCHED_BY_ID::equals);
|
||||
}
|
||||
|
||||
private void fixFailedImport(Record record) {
|
||||
var seriesId = record.getSeriesId();
|
||||
SonarrSerie serie = getSerieFromSonarr(seriesId);
|
||||
FailedImportFixer
|
||||
.of(record, serie)
|
||||
.fix();
|
||||
private void try2FixFailedImport(Record record) {
|
||||
try {
|
||||
var seriesId = record.getSeriesId();
|
||||
SonarrSerie serie = getSerieFromSonarr(seriesId);
|
||||
if (serie == null) return;
|
||||
|
||||
FailedImportFixer
|
||||
.of(record, serie)
|
||||
.fix();
|
||||
} catch (IOException e) {
|
||||
System.out.printf("!! could not fix the import %s%n", record.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
private SonarrSerie getSerieFromSonarr(Integer seriesId) {
|
||||
|
|
Loading…
Reference in New Issue