Skip to content

Commit b943ba0

Browse files
committed
refactor: include imdbfiles which dont have a year (0)
1 parent 565ac77 commit b943ba0

1 file changed

Lines changed: 35 additions & 7 deletions

File tree

src/Zilean.Database/Services/TorrentInfoService.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,21 +317,22 @@ private static double CalculateScore(TorrentInfo torrent, ImdbFile imdb) =>
317317
? CloseMatchTitleYearScore * 100
318318
: Fuzz.Ratio(torrent.ParsedTitle, imdb.Title, PreprocessMode.Full);
319319

320-
private bool HasFilteredPartitionsWithYear(ConcurrentDictionary<int, List<ImdbFile>> imdbTvFilesByYear, ConcurrentDictionary<int, List<ImdbFile>> imdbMovieFilesByYear, TorrentInfo torrent,
320+
private bool HasFilteredPartitionsWithYear(
321+
ConcurrentDictionary<int, List<ImdbFile>> imdbTvFilesByYear,
322+
ConcurrentDictionary<int, List<ImdbFile>> imdbMovieFilesByYear,
323+
TorrentInfo torrent,
321324
out IEnumerable<ImdbFile> relevantImdbFiles)
322325
{
323326
switch (torrent.Category)
324327
{
325328
case "tvSeries":
326-
relevantImdbFiles = Enumerable.Range(torrent.Year!.Value - 1, 3)
327-
.Where(year => imdbTvFilesByYear.TryGetValue(year, out var _))
328-
.SelectMany(year => imdbTvFilesByYear[year]);
329+
relevantImdbFiles = GetFilteredFiles(imdbTvFilesByYear, torrent.Year!.Value, includeYearZero: true);
329330
break;
331+
330332
case "movie":
331-
relevantImdbFiles = Enumerable.Range(torrent.Year!.Value - 1, 3)
332-
.Where(year => imdbMovieFilesByYear.TryGetValue(year, out var _))
333-
.SelectMany(year => imdbMovieFilesByYear[year]);
333+
relevantImdbFiles = GetFilteredFiles(imdbMovieFilesByYear, torrent.Year!.Value, includeYearZero: true);
334334
break;
335+
335336
default:
336337
logger.LogWarning("Torrent '{Title}' has an unknown category '{Category}', skipping", torrent.NormalizedTitle, torrent.Category);
337338
relevantImdbFiles = [];
@@ -341,6 +342,33 @@ private bool HasFilteredPartitionsWithYear(ConcurrentDictionary<int, List<ImdbFi
341342
return true;
342343
}
343344

345+
private static IEnumerable<ImdbFile> GetFilteredFiles(
346+
ConcurrentDictionary<int, List<ImdbFile>> filesByYear,
347+
int baseYear,
348+
bool includeYearZero)
349+
{
350+
var years = new[] { baseYear - 1, baseYear, baseYear + 1 };
351+
352+
foreach (var year in years)
353+
{
354+
if (filesByYear.TryGetValue(year, out var files))
355+
{
356+
foreach (var file in files)
357+
{
358+
yield return file;
359+
}
360+
}
361+
}
362+
363+
if (includeYearZero && filesByYear.TryGetValue(0, out var zeroYearFiles))
364+
{
365+
foreach (var file in zeroYearFiles)
366+
{
367+
yield return file;
368+
}
369+
}
370+
}
371+
344372
private IEnumerable<ImdbFile> GetAllImdbFilesWithoutYear(ConcurrentDictionary<int, List<ImdbFile>> imdbTvFilesByYear, ConcurrentDictionary<int, List<ImdbFile>> imdbMovieFilesByYear, TorrentInfo torrent)
345373
{
346374
switch (torrent.Category)

0 commit comments

Comments
 (0)