diff --git a/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs b/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs index 6be65a5e9..912b60335 100644 --- a/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs @@ -48,8 +48,8 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads }; Mocker.GetMock() - .Setup(s => s.Map(It.Is(i => i.SeasonNumber == 1 && i.SeriesTitle == "TV Series"), It.IsAny(), It.IsAny>())) - .Returns(remoteEpisode); + .Setup(s => s.Map(It.Is(i => i.SeasonNumber == 1 && i.SeriesTitle == "TV Series"), It.IsAny(), It.IsAny>())) + .Returns(remoteEpisode); var client = new DownloadClientDefinition() { @@ -72,5 +72,61 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads trackedDownload.RemoteEpisode.Episodes.First().Id.Should().Be(4); trackedDownload.RemoteEpisode.ParsedEpisodeInfo.SeasonNumber.Should().Be(1); } + + [Test] + public void should_parse_as_special_when_source_title_parsing_fails() + { + var remoteEpisode = new RemoteEpisode + { + Series = new Series() { Id = 5 }, + Episodes = new List { new Episode { Id = 4 } }, + ParsedEpisodeInfo = new ParsedEpisodeInfo() + { + SeriesTitle = "TV Series", + SeasonNumber = 0, + EpisodeNumbers = new []{ 1 } + } + }; + + Mocker.GetMock() + .Setup(s => s.FindByDownloadId(It.Is(sr => sr == "35238"))) + .Returns(new List(){ + new History.History(){ + DownloadId = "35238", + SourceTitle = "TV Series Special", + SeriesId = 5, + EpisodeId = 4 + } + }); + + Mocker.GetMock() + .Setup(s => s.Map(It.Is(i => i.SeasonNumber == 0 && i.SeriesTitle == "TV Series"), It.IsAny(), It.IsAny>())) + .Returns(remoteEpisode); + + Mocker.GetMock() + .Setup(s => s.ParseSpecialEpisodeTitle(It.IsAny(), It.IsAny(), It.IsAny(), null)) + .Returns(remoteEpisode.ParsedEpisodeInfo); + + var client = new DownloadClientDefinition() + { + Id = 1, + Protocol = DownloadProtocol.Torrent + }; + + var item = new DownloadClientItem() + { + Title = "The torrent release folder", + DownloadId = "35238", + }; + + var trackedDownload = Subject.TrackDownload(client, item); + + trackedDownload.Should().NotBeNull(); + trackedDownload.RemoteEpisode.Should().NotBeNull(); + trackedDownload.RemoteEpisode.Series.Should().NotBeNull(); + trackedDownload.RemoteEpisode.Series.Id.Should().Be(5); + trackedDownload.RemoteEpisode.Episodes.First().Id.Should().Be(4); + trackedDownload.RemoteEpisode.ParsedEpisodeInfo.SeasonNumber.Should().Be(0); + } } } diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs index 00bad1ab8..96dca27cd 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs @@ -75,7 +75,10 @@ namespace NzbDrone.Core.Download.TrackedDownloads trackedDownload.RemoteEpisode.Series == null || trackedDownload.RemoteEpisode.Episodes.Empty()) { - parsedEpisodeInfo = Parser.Parser.ParseTitle(firstHistoryItem.SourceTitle); + // Try parsing the original source title and if that fails, try parsing it as a special + // TODO: Pass the TVDB ID and TVRage IDs in as well so we have a better chance for finding the item + parsedEpisodeInfo = Parser.Parser.ParseTitle(firstHistoryItem.SourceTitle) ?? _parsingService.ParseSpecialEpisodeTitle(firstHistoryItem.SourceTitle, 0, 0); + if (parsedEpisodeInfo != null) { trackedDownload.RemoteEpisode = _parsingService.Map(parsedEpisodeInfo, firstHistoryItem.SeriesId, historyItems.Where(v => v.EventType == HistoryEventType.Grabbed).Select(h => h.EpisodeId).Distinct()); diff --git a/src/NzbDrone.Core/Parser/ParsingService.cs b/src/NzbDrone.Core/Parser/ParsingService.cs index b703d09d2..9b66aa6cf 100644 --- a/src/NzbDrone.Core/Parser/ParsingService.cs +++ b/src/NzbDrone.Core/Parser/ParsingService.cs @@ -305,14 +305,17 @@ namespace NzbDrone.Core.Parser } var series = GetSeries(title); + if (series == null) { series = _seriesService.FindByTitleInexact(title); } + if (series == null && tvdbId > 0) { series = _seriesService.FindByTvdbId(tvdbId); } + if (series == null && tvRageId > 0) { series = _seriesService.FindByTvRageId(tvRageId);