mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Fixed: Finding files with unexpected quality in the filename
This commit is contained in:
parent
575c5af1f8
commit
7e79ccd710
@ -345,6 +345,7 @@
|
||||
<Compile Include="ParserTests\ValidateParsedEpisodeInfoFixture.cs" />
|
||||
<Compile Include="Profiles\Delay\DelayProfileServiceFixture.cs" />
|
||||
<Compile Include="Profiles\Qualities\QualityIndexCompareToFixture.cs" />
|
||||
<Compile Include="Qualities\QualityFinderFixture.cs" />
|
||||
<Compile Include="Qualities\RevisionComparableFixture.cs" />
|
||||
<Compile Include="QueueTests\QueueServiceFixture.cs" />
|
||||
<Compile Include="RemotePathMappingsTests\RemotePathMappingServiceFixture.cs" />
|
||||
|
38
src/NzbDrone.Core.Test/Qualities/QualityFinderFixture.cs
Normal file
38
src/NzbDrone.Core.Test/Qualities/QualityFinderFixture.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -53,7 +53,9 @@ public LocalEpisode Aggregate(LocalEpisode localEpisode, bool otherFiles)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -114,6 +114,13 @@ private List<ManualImportItem> ProcessFolder(string rootFolder, string baseFolde
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
var files = _diskScanService.FilterFiles(baseFolder, _diskScanService.GetVideoFiles(baseFolder, false));
|
||||
@ -175,8 +182,7 @@ private ManualImportItem ProcessFile(string rootFolder, string baseFolder, strin
|
||||
return MapItem(new ImportDecision(localEpisode, new Rejection("Unknown Series")), rootFolder, downloadId, null);
|
||||
}
|
||||
|
||||
var importDecisions = _importDecisionMaker.GetImportDecisions(new List<string> {file},
|
||||
series, downloadClientItem, null, SceneSource(series, baseFolder));
|
||||
var importDecisions = _importDecisionMaker.GetImportDecisions(new List<string> {file}, series, downloadClientItem, null, SceneSource(series, baseFolder));
|
||||
|
||||
if (importDecisions.Any())
|
||||
{
|
||||
|
@ -1006,6 +1006,7 @@
|
||||
<Compile Include="Profiles\Qualities\QualityIndex.cs" />
|
||||
<Compile Include="ProgressMessaging\ProgressMessageContext.cs" />
|
||||
<Compile Include="Qualities\QualityDetectionSource.cs" />
|
||||
<Compile Include="Qualities\QualityFinder.cs" />
|
||||
<Compile Include="Qualities\QualitySource.cs" />
|
||||
<Compile Include="Qualities\Revision.cs" />
|
||||
<Compile Include="Queue\EstimatedCompletionTimeComparer.cs" />
|
||||
|
@ -109,11 +109,7 @@ static Quality()
|
||||
Bluray2160pRemux
|
||||
};
|
||||
|
||||
AllLookup = new Quality[All.Select(v => v.Id).Max() + 1];
|
||||
foreach (var quality in All)
|
||||
{
|
||||
AllLookup[quality.Id] = quality;
|
||||
}
|
||||
AllLookup = All.ToDictionary(q => q.Id, q => q);
|
||||
|
||||
DefaultQualityDefinitions = new HashSet<QualityDefinition>
|
||||
{
|
||||
@ -143,7 +139,7 @@ static Quality()
|
||||
|
||||
public static readonly List<Quality> All;
|
||||
|
||||
public static readonly Quality[] AllLookup;
|
||||
public static readonly Dictionary<int, Quality> AllLookup;
|
||||
|
||||
public static readonly HashSet<QualityDefinition> DefaultQualityDefinitions;
|
||||
|
||||
@ -151,10 +147,10 @@ public static Quality FindById(int id)
|
||||
{
|
||||
if (id == 0) return Unknown;
|
||||
|
||||
var quality = AllLookup[id];
|
||||
|
||||
if (quality == null)
|
||||
if (!AllLookup.TryGetValue(id, out var quality))
|
||||
{
|
||||
throw new ArgumentException("ID does not match a known quality", nameof(id));
|
||||
}
|
||||
|
||||
return quality;
|
||||
}
|
||||
@ -168,10 +164,5 @@ public static explicit operator int(Quality quality)
|
||||
{
|
||||
return quality.Id;
|
||||
}
|
||||
|
||||
public static Quality FindBySourceAndResolution(QualitySource source, int resolution)
|
||||
{
|
||||
return All.SingleOrDefault(q => q.Source == source && q.Resolution == resolution);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
src/NzbDrone.Core/Qualities/QualityFinder.cs
Normal file
40
src/NzbDrone.Core/Qualities/QualityFinder.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
@ -12,6 +12,7 @@ public interface ISeriesRepository : IBasicRepository<Series>
|
||||
Series FindByTitle(string cleanTitle, int year);
|
||||
Series FindByTvdbId(int tvdbId);
|
||||
Series FindByTvRageId(int tvRageId);
|
||||
Series FindByPath(string path);
|
||||
}
|
||||
|
||||
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
|
||||
@ -52,5 +53,11 @@ public Series FindByTvRageId(int tvRageId)
|
||||
{
|
||||
return Query.Where(s => s.TvRageId == tvRageId).SingleOrDefault();
|
||||
}
|
||||
|
||||
public Series FindByPath(string path)
|
||||
{
|
||||
return Query.Where(s => s.Path == path)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ public interface ISeriesService
|
||||
Series FindByTitle(string title);
|
||||
Series FindByTitle(string title, int year);
|
||||
Series FindByTitleInexact(string title);
|
||||
Series FindByPath(string path);
|
||||
void DeleteSeries(int seriesId, bool deleteFiles);
|
||||
List<Series> GetAllSeries();
|
||||
List<Series> AllForTag(int tagId);
|
||||
@ -134,6 +135,11 @@ public Series FindByTitleInexact(string title)
|
||||
return match;
|
||||
}
|
||||
|
||||
public Series FindByPath(string path)
|
||||
{
|
||||
return _seriesRepository.FindByPath(path);
|
||||
}
|
||||
|
||||
public Series FindByTitle(string title, int year)
|
||||
{
|
||||
return _seriesRepository.FindByTitle(title.CleanSeriesTitle(), year);
|
||||
|
Loading…
Reference in New Issue
Block a user