mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-01-04 06:38:28 +02:00
Improve handling of multiple seasons in one file
Fixed: Invalid scene numbering leading to manual import failing to load Fixes #2255
This commit is contained in:
parent
3492d6bbaa
commit
e8c5e417b6
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -205,10 +205,23 @@ private ManualImportItem MapItem(ImportDecision decision, string folder, string
|
|||||||
item.Series = decision.LocalEpisode.Series;
|
item.Series = decision.LocalEpisode.Series;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decision.LocalEpisode.Episodes.Any())
|
if (decision.LocalEpisode.Episodes.Any() && decision.LocalEpisode.Episodes.Select(c => c.SeasonNumber).Distinct().Count() == 1)
|
||||||
{
|
{
|
||||||
item.SeasonNumber = decision.LocalEpisode.SeasonNumber;
|
var seasons = decision.LocalEpisode.Episodes.Select(c => c.SeasonNumber).Distinct().ToList();
|
||||||
item.Episodes = decision.LocalEpisode.Episodes;
|
|
||||||
|
if (seasons.Empty())
|
||||||
|
{
|
||||||
|
_logger.Warn("Expected one season, but found none for: {0}", decision.LocalEpisode.Path);
|
||||||
|
}
|
||||||
|
else if (seasons.Count > 1)
|
||||||
|
{
|
||||||
|
_logger.Warn("Expected one season, but found {0} ({1}) for: {2}", seasons.Count, string.Join(", ", seasons), decision.LocalEpisode.Path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item.SeasonNumber = decision.LocalEpisode.SeasonNumber;
|
||||||
|
item.Episodes = decision.LocalEpisode.Episodes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
item.Quality = decision.LocalEpisode.Quality;
|
item.Quality = decision.LocalEpisode.Quality;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using NLog;
|
using System;
|
||||||
|
using NLog;
|
||||||
using NzbDrone.Core.DecisionEngine;
|
using NzbDrone.Core.DecisionEngine;
|
||||||
using NzbDrone.Core.Download;
|
using NzbDrone.Core.Download;
|
||||||
|
using NzbDrone.Core.Parser;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
|
||||||
@ -25,18 +27,23 @@ public Decision IsSatisfiedBy(LocalEpisode localEpisode, DownloadClientItem down
|
|||||||
return Decision.Accept();
|
return Decision.Accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
var sample = _detectSample.IsSample(localEpisode.Series,
|
try
|
||||||
localEpisode.Path,
|
|
||||||
localEpisode.IsSpecial);
|
|
||||||
|
|
||||||
if (sample == DetectSampleResult.Sample)
|
|
||||||
{
|
{
|
||||||
return Decision.Reject("Sample");
|
var sample = _detectSample.IsSample(localEpisode.Series, localEpisode.Path, localEpisode.IsSpecial);
|
||||||
|
|
||||||
|
if (sample == DetectSampleResult.Sample)
|
||||||
|
{
|
||||||
|
return Decision.Reject("Sample");
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (sample == DetectSampleResult.Indeterminate)
|
||||||
|
{
|
||||||
|
return Decision.Reject("Unable to determine if file is a sample");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (InvalidSeasonException e)
|
||||||
else if (sample == DetectSampleResult.Indeterminate)
|
|
||||||
{
|
{
|
||||||
return Decision.Reject("Unable to determine if file is a sample");
|
_logger.Warn(e, "Invalid season detected during sample check");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Decision.Accept();
|
return Decision.Accept();
|
||||||
|
@ -936,6 +936,7 @@
|
|||||||
<Compile Include="Notifications\Twitter\Twitter.cs" />
|
<Compile Include="Notifications\Twitter\Twitter.cs" />
|
||||||
<Compile Include="Notifications\Twitter\TwitterService.cs" />
|
<Compile Include="Notifications\Twitter\TwitterService.cs" />
|
||||||
<Compile Include="Notifications\Twitter\TwitterSettings.cs" />
|
<Compile Include="Notifications\Twitter\TwitterSettings.cs" />
|
||||||
|
<Compile Include="Parser\InvalidSeasonException.cs" />
|
||||||
<Compile Include="Parser\IsoLanguage.cs" />
|
<Compile Include="Parser\IsoLanguage.cs" />
|
||||||
<Compile Include="Parser\IsoLanguages.cs" />
|
<Compile Include="Parser\IsoLanguages.cs" />
|
||||||
<Compile Include="Parser\LanguageParser.cs" />
|
<Compile Include="Parser\LanguageParser.cs" />
|
||||||
|
15
src/NzbDrone.Core/Parser/InvalidSeasonException.cs
Normal file
15
src/NzbDrone.Core/Parser/InvalidSeasonException.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using NzbDrone.Common.Exceptions;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Parser
|
||||||
|
{
|
||||||
|
public class InvalidSeasonException : NzbDroneException
|
||||||
|
{
|
||||||
|
public InvalidSeasonException(string message, params object[] args) : base(message, args)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidSeasonException(string message) : base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.Qualities;
|
using NzbDrone.Core.Qualities;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
using NzbDrone.Core.MediaFiles.MediaInfo;
|
using NzbDrone.Core.MediaFiles.MediaInfo;
|
||||||
@ -26,7 +27,19 @@ public int SeasonNumber
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return Episodes.Select(c => c.SeasonNumber).Distinct().Single();
|
var seasons = Episodes.Select(c => c.SeasonNumber).Distinct().ToList();
|
||||||
|
|
||||||
|
if (seasons.Empty())
|
||||||
|
{
|
||||||
|
throw new InvalidSeasonException("Expected one season, but found none");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seasons.Count > 1)
|
||||||
|
{
|
||||||
|
throw new InvalidSeasonException("Expected one season, but found {0} ({1})", seasons.Count, string.Join(", ", seasons));
|
||||||
|
}
|
||||||
|
|
||||||
|
return seasons.Single();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,4 +50,4 @@ public override string ToString()
|
|||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user