Fixed: Finding files with unexpected quality in the filename

This commit is contained in:
Mark McDowall 2018-09-21 12:30:09 -07:00 committed by Taloth Saldono
parent 575c5af1f8
commit 7e79ccd710
9 changed files with 112 additions and 20 deletions

View File

@ -345,6 +345,7 @@
<Compile Include="ParserTests\ValidateParsedEpisodeInfoFixture.cs" /> <Compile Include="ParserTests\ValidateParsedEpisodeInfoFixture.cs" />
<Compile Include="Profiles\Delay\DelayProfileServiceFixture.cs" /> <Compile Include="Profiles\Delay\DelayProfileServiceFixture.cs" />
<Compile Include="Profiles\Qualities\QualityIndexCompareToFixture.cs" /> <Compile Include="Profiles\Qualities\QualityIndexCompareToFixture.cs" />
<Compile Include="Qualities\QualityFinderFixture.cs" />
<Compile Include="Qualities\RevisionComparableFixture.cs" /> <Compile Include="Qualities\RevisionComparableFixture.cs" />
<Compile Include="QueueTests\QueueServiceFixture.cs" /> <Compile Include="QueueTests\QueueServiceFixture.cs" />
<Compile Include="RemotePathMappingsTests\RemotePathMappingServiceFixture.cs" /> <Compile Include="RemotePathMappingsTests\RemotePathMappingServiceFixture.cs" />

View File

@ -0,0 +1,38 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Test.Qualities
{
[TestFixture]
public class QualityFinderFixture
{
[TestCase(QualitySource.Television, 480)]
[TestCase(QualitySource.Unknown, 480)]
public void should_return_SDTV(QualitySource source, int resolution)
{
QualityFinder.FindBySourceAndResolution(source, resolution).Should().Be(Quality.SDTV);
}
[TestCase(QualitySource.Television, 720)]
[TestCase(QualitySource.Unknown, 720)]
public void should_return_HDTV_720p(QualitySource source, int resolution)
{
QualityFinder.FindBySourceAndResolution(source, resolution).Should().Be(Quality.HDTV720p);
}
[TestCase(QualitySource.Television, 1080)]
[TestCase(QualitySource.Unknown, 1080)]
public void should_return_HDTV_1080p(QualitySource source, int resolution)
{
QualityFinder.FindBySourceAndResolution(source, resolution).Should().Be(Quality.HDTV1080p);
}
[TestCase(QualitySource.Bluray, 720)]
[TestCase(QualitySource.DVD, 720)]
public void should_return_Bluray720p(QualitySource source, int resolution)
{
QualityFinder.FindBySourceAndResolution(source, resolution).Should().Be(Quality.Bluray720p);
}
}
}

View File

@ -53,7 +53,9 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators
} }
} }
var quality = new QualityModel(Quality.FindBySourceAndResolution(source, resolution), revison); _logger.Trace("Finding quality. Source: {0}. Resolution: {1}", source, resolution);
var quality = new QualityModel(QualityFinder.FindBySourceAndResolution(source, resolution), revison);
if (resolutionConfidence == Confidence.MediaInfo) if (resolutionConfidence == Confidence.MediaInfo)
{ {

View File

@ -114,6 +114,13 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
} }
} }
// Try a lookup by the path if the series is still unknown, this will handle
// the case where the series folder doesn't match the series title.
if (series == null)
{
series = _seriesService.FindByPath(rootFolder);
}
if (series == null) if (series == null)
{ {
var files = _diskScanService.FilterFiles(baseFolder, _diskScanService.GetVideoFiles(baseFolder, false)); var files = _diskScanService.FilterFiles(baseFolder, _diskScanService.GetVideoFiles(baseFolder, false));
@ -175,8 +182,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
return MapItem(new ImportDecision(localEpisode, new Rejection("Unknown Series")), rootFolder, downloadId, null); return MapItem(new ImportDecision(localEpisode, new Rejection("Unknown Series")), rootFolder, downloadId, null);
} }
var importDecisions = _importDecisionMaker.GetImportDecisions(new List<string> {file}, var importDecisions = _importDecisionMaker.GetImportDecisions(new List<string> {file}, series, downloadClientItem, null, SceneSource(series, baseFolder));
series, downloadClientItem, null, SceneSource(series, baseFolder));
if (importDecisions.Any()) if (importDecisions.Any())
{ {

View File

@ -1006,6 +1006,7 @@
<Compile Include="Profiles\Qualities\QualityIndex.cs" /> <Compile Include="Profiles\Qualities\QualityIndex.cs" />
<Compile Include="ProgressMessaging\ProgressMessageContext.cs" /> <Compile Include="ProgressMessaging\ProgressMessageContext.cs" />
<Compile Include="Qualities\QualityDetectionSource.cs" /> <Compile Include="Qualities\QualityDetectionSource.cs" />
<Compile Include="Qualities\QualityFinder.cs" />
<Compile Include="Qualities\QualitySource.cs" /> <Compile Include="Qualities\QualitySource.cs" />
<Compile Include="Qualities\Revision.cs" /> <Compile Include="Qualities\Revision.cs" />
<Compile Include="Queue\EstimatedCompletionTimeComparer.cs" /> <Compile Include="Queue\EstimatedCompletionTimeComparer.cs" />

View File

@ -109,11 +109,7 @@ namespace NzbDrone.Core.Qualities
Bluray2160pRemux Bluray2160pRemux
}; };
AllLookup = new Quality[All.Select(v => v.Id).Max() + 1]; AllLookup = All.ToDictionary(q => q.Id, q => q);
foreach (var quality in All)
{
AllLookup[quality.Id] = quality;
}
DefaultQualityDefinitions = new HashSet<QualityDefinition> DefaultQualityDefinitions = new HashSet<QualityDefinition>
{ {
@ -143,7 +139,7 @@ namespace NzbDrone.Core.Qualities
public static readonly List<Quality> All; public static readonly List<Quality> All;
public static readonly Quality[] AllLookup; public static readonly Dictionary<int, Quality> AllLookup;
public static readonly HashSet<QualityDefinition> DefaultQualityDefinitions; public static readonly HashSet<QualityDefinition> DefaultQualityDefinitions;
@ -151,11 +147,11 @@ namespace NzbDrone.Core.Qualities
{ {
if (id == 0) return Unknown; if (id == 0) return Unknown;
var quality = AllLookup[id]; if (!AllLookup.TryGetValue(id, out var quality))
{
if (quality == null)
throw new ArgumentException("ID does not match a known quality", nameof(id)); throw new ArgumentException("ID does not match a known quality", nameof(id));
}
return quality; return quality;
} }
@ -168,10 +164,5 @@ namespace NzbDrone.Core.Qualities
{ {
return quality.Id; return quality.Id;
} }
public static Quality FindBySourceAndResolution(QualitySource source, int resolution)
{
return All.SingleOrDefault(q => q.Source == source && q.Resolution == resolution);
}
} }
} }

View File

@ -0,0 +1,40 @@
using System.Linq;
using NLog;
using NzbDrone.Common.Instrumentation;
namespace NzbDrone.Core.Qualities
{
public static class QualityFinder
{
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(QualityFinder));
public static Quality FindBySourceAndResolution(QualitySource source, int resolution)
{
var matchingQuality = Quality.All.SingleOrDefault(q => q.Source == source && q.Resolution == resolution);
if (matchingQuality != null)
{
return matchingQuality;
}
var matchingResolution = Quality.All.Where(q => q.Resolution == resolution)
.OrderBy(q => q.Source)
.ToList();
var nearestQuality = Quality.Unknown;
foreach (var quality in matchingResolution)
{
if (quality.Source >= source)
{
nearestQuality = quality;
break;
}
}
Logger.Warn("Unable to find exact quality for {0} and {1}. Using {2} as fallback", source, resolution, nearestQuality);
return nearestQuality;
}
}
}

View File

@ -1,4 +1,4 @@
using System.Linq; using System.Linq;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
@ -12,6 +12,7 @@ namespace NzbDrone.Core.Tv
Series FindByTitle(string cleanTitle, int year); Series FindByTitle(string cleanTitle, int year);
Series FindByTvdbId(int tvdbId); Series FindByTvdbId(int tvdbId);
Series FindByTvRageId(int tvRageId); Series FindByTvRageId(int tvRageId);
Series FindByPath(string path);
} }
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
@ -52,5 +53,11 @@ namespace NzbDrone.Core.Tv
{ {
return Query.Where(s => s.TvRageId == tvRageId).SingleOrDefault(); return Query.Where(s => s.TvRageId == tvRageId).SingleOrDefault();
} }
public Series FindByPath(string path)
{
return Query.Where(s => s.Path == path)
.FirstOrDefault();
}
} }
} }

View File

@ -21,6 +21,7 @@ namespace NzbDrone.Core.Tv
Series FindByTitle(string title); Series FindByTitle(string title);
Series FindByTitle(string title, int year); Series FindByTitle(string title, int year);
Series FindByTitleInexact(string title); Series FindByTitleInexact(string title);
Series FindByPath(string path);
void DeleteSeries(int seriesId, bool deleteFiles); void DeleteSeries(int seriesId, bool deleteFiles);
List<Series> GetAllSeries(); List<Series> GetAllSeries();
List<Series> AllForTag(int tagId); List<Series> AllForTag(int tagId);
@ -134,6 +135,11 @@ namespace NzbDrone.Core.Tv
return match; return match;
} }
public Series FindByPath(string path)
{
return _seriesRepository.FindByPath(path);
}
public Series FindByTitle(string title, int year) public Series FindByTitle(string title, int year)
{ {
return _seriesRepository.FindByTitle(title.CleanSeriesTitle(), year); return _seriesRepository.FindByTitle(title.CleanSeriesTitle(), year);