Fixed: Parsing of special episodes that lack a series title

Closes #4688
This commit is contained in:
Mark McDowall 2021-10-17 21:36:26 -07:00
parent a83ed3bcce
commit a97e83ea4d
2 changed files with 30 additions and 9 deletions

View File

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions.Equivalency;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
@ -28,6 +29,10 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators
new Mock<IAggregateLocalEpisode>() new Mock<IAggregateLocalEpisode>()
}; };
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetEpisodes(It.IsAny<ParsedEpisodeInfo>(), _series, It.IsAny<bool>(), null))
.Returns(Builder<Episode>.CreateListOfSize(1).BuildList());
Mocker.SetConstant(augmenters.Select(c => c.Object)); Mocker.SetConstant(augmenters.Select(c => c.Object));
} }
@ -140,6 +145,10 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators
Series = _series Series = _series
}; };
Mocker.GetMock<IParsingService>()
.Setup(s => s.GetEpisodes(fileEpisodeInfo, _series, It.IsAny<bool>(), null))
.Returns(new List<Episode>());
Mocker.GetMock<IParsingService>() Mocker.GetMock<IParsingService>()
.Setup(s => s.ParseSpecialEpisodeTitle(fileEpisodeInfo, It.IsAny<string>(), _series)) .Setup(s => s.ParseSpecialEpisodeTitle(fileEpisodeInfo, It.IsAny<string>(), _series))
.Returns(specialEpisodeInfo); .Returns(specialEpisodeInfo);

View File

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -45,18 +46,20 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators
} }
} }
if (parsedEpisodeInfo == null || parsedEpisodeInfo.IsPossibleSpecialEpisode) if (parsedEpisodeInfo == null)
{
parsedEpisodeInfo = GetSpecialEpisodeInfo(localEpisode, parsedEpisodeInfo);
}
return parsedEpisodeInfo;
}
private ParsedEpisodeInfo GetSpecialEpisodeInfo(LocalEpisode localEpisode, ParsedEpisodeInfo parsedEpisodeInfo)
{ {
var title = Path.GetFileNameWithoutExtension(localEpisode.Path); var title = Path.GetFileNameWithoutExtension(localEpisode.Path);
var specialEpisodeInfo = _parsingService.ParseSpecialEpisodeTitle(parsedEpisodeInfo, title, localEpisode.Series); var specialEpisodeInfo = _parsingService.ParseSpecialEpisodeTitle(parsedEpisodeInfo, title, localEpisode.Series);
if (specialEpisodeInfo != null) return specialEpisodeInfo;
{
parsedEpisodeInfo = specialEpisodeInfo;
}
}
return parsedEpisodeInfo;
} }
private List<Episode> GetEpisodes(LocalEpisode localEpisode) private List<Episode> GetEpisodes(LocalEpisode localEpisode)
@ -71,7 +74,16 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators
if (ValidateParsedEpisodeInfo.ValidateForSeriesType(bestEpisodeInfoForEpisodes, localEpisode.Series, isMediaFile)) if (ValidateParsedEpisodeInfo.ValidateForSeriesType(bestEpisodeInfoForEpisodes, localEpisode.Series, isMediaFile))
{ {
return _parsingService.GetEpisodes(bestEpisodeInfoForEpisodes, localEpisode.Series, localEpisode.SceneSource); var episodes = _parsingService.GetEpisodes(bestEpisodeInfoForEpisodes, localEpisode.Series, localEpisode.SceneSource);
if (episodes.Empty() && bestEpisodeInfoForEpisodes.IsPossibleSpecialEpisode)
{
var parsedEpisodeInfo = GetSpecialEpisodeInfo(localEpisode, bestEpisodeInfoForEpisodes);
episodes = _parsingService.GetEpisodes(parsedEpisodeInfo, localEpisode.Series, localEpisode.SceneSource);
}
return episodes;
} }
return new List<Episode>(); return new List<Episode>();