diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index c2faea375..25e2c53cb 100644 Binary files a/NzbDrone.Core.Test/EpisodeProviderTest.cs and b/NzbDrone.Core.Test/EpisodeProviderTest.cs differ diff --git a/NzbDrone.Core.Test/InventoryProviderTest.cs b/NzbDrone.Core.Test/InventoryProviderTest.cs index 843545024..fdad3973b 100644 --- a/NzbDrone.Core.Test/InventoryProviderTest.cs +++ b/NzbDrone.Core.Test/InventoryProviderTest.cs @@ -54,7 +54,7 @@ namespace NzbDrone.Core.Test .Build(); base.Setup(); - + } @@ -183,6 +183,45 @@ namespace NzbDrone.Core.Test mocker.VerifyAllMocks(); } + + [Test] + public void file_in_history_should_be_skipped() + { + var mocker = new AutoMoqer(MockBehavior.Strict); + + mocker.GetMock() + .Setup(p => p.FindSeries(It.IsAny())) + .Returns(series); + + mocker.GetMock() + .Setup(p => p.GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber)) + .Returns(episode); + + + mocker.GetMock() + .Setup(p => p.QualityWanted(series.SeriesId, parseResult.Quality)) + .Returns(true); + + mocker.GetMock() + .Setup(p => p.IsIgnored(series.SeriesId, parseResult.SeasonNumber)) + .Returns(false); + + mocker.GetMock() + .Setup(p => p.IsNeeded(parseResult, episode)) + .Returns(true); + + mocker.GetMock() + .Setup(p => p.Exists(episode.EpisodeId, parseResult.Quality, parseResult.Proper)) + .Returns(true); + + //Act + var result = mocker.Resolve().IsNeeded(parseResult); + + //Assert + Assert.IsFalse(result); + mocker.VerifyAllMocks(); + } + [Test] public void dailyshow_should_do_daily_lookup() { @@ -254,7 +293,7 @@ namespace NzbDrone.Core.Test mocker.GetMock() .Setup(p => p.IsNeeded(parseResult, It.IsAny())) .Returns(false); - + //Act var result = mocker.Resolve().IsNeeded(parseResult); @@ -262,6 +301,47 @@ namespace NzbDrone.Core.Test Assert.IsFalse(result); mocker.VerifyAllMocks(); } + + + [Test] + public void file_needed_should_return_true() + { + var mocker = new AutoMoqer(MockBehavior.Strict); + + mocker.GetMock() + .Setup(p => p.FindSeries(It.IsAny())) + .Returns(series); + + mocker.GetMock() + .Setup(p => p.GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber)) + .Returns(episode); + + + mocker.GetMock() + .Setup(p => p.QualityWanted(series.SeriesId, parseResult.Quality)) + .Returns(true); + + mocker.GetMock() + .Setup(p => p.IsIgnored(series.SeriesId, parseResult.SeasonNumber)) + .Returns(false); + + mocker.GetMock() + .Setup(p => p.IsNeeded(parseResult, episode)) + .Returns(true); + + mocker.GetMock() + .Setup(p => p.Exists(episode.EpisodeId, parseResult.Quality, parseResult.Proper)) + .Returns(false); + + //Act + var result = mocker.Resolve().IsNeeded(parseResult); + + //Assert + Assert.IsTrue(result); + Assert.IsNotNull(parseResult.Series); + Assert.AreEqual(series, parseResult.Series); + mocker.VerifyAllMocks(); + } } diff --git a/NzbDrone.Core.Test/SabProviderTest.cs b/NzbDrone.Core.Test/SabProviderTest.cs index 8f4f37494..1b38317ef 100644 --- a/NzbDrone.Core.Test/SabProviderTest.cs +++ b/NzbDrone.Core.Test/SabProviderTest.cs @@ -2,11 +2,13 @@ using System.IO; using System.Linq; using AutoMoq; +using FizzWare.NBuilder; using MbUnit.Framework; using Moq; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Test.Framework; @@ -219,6 +221,10 @@ namespace NzbDrone.Core.Test { var mocker = new AutoMoqer(); + var series = Builder.CreateNew() + .With(c => c.Path = @"d:\tv shows\My Series Name") + .Build(); + var parsResult = new EpisodeParseResult() { AirDate = DateTime.Now, @@ -227,10 +233,11 @@ namespace NzbDrone.Core.Test Quality = quality, SeasonNumber = seasons, EpisodeTitle = title, + Series = series }; - + //Act - var actual = mocker.Resolve().GetSabTitle(parsResult, "My Series Name"); + var actual = mocker.Resolve().GetSabTitle(parsResult); //Assert Assert.AreEqual(excpected, actual); diff --git a/NzbDrone.Core/Helpers/SceneNameHelper.cs b/NzbDrone.Core/Helpers/SceneNameHelper.cs index 47e07ef2c..d514fafe2 100644 --- a/NzbDrone.Core/Helpers/SceneNameHelper.cs +++ b/NzbDrone.Core/Helpers/SceneNameHelper.cs @@ -311,17 +311,5 @@ namespace NzbDrone.Core.Helpers return map.SeriesId; } - - public static List FindById(int seriesId) - { - List results = new List(); - - var maps = SceneNameMappings.Where(s => s.SeriesId == seriesId); - - foreach (var map in maps) - results.Add(map.Name); - - return results; - } } } \ No newline at end of file diff --git a/NzbDrone.Core/Model/EpisodeParseResult.cs b/NzbDrone.Core/Model/EpisodeParseResult.cs index 4bbbf891a..d5892dc9d 100644 --- a/NzbDrone.Core/Model/EpisodeParseResult.cs +++ b/NzbDrone.Core/Model/EpisodeParseResult.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; namespace NzbDrone.Core.Model @@ -24,6 +25,8 @@ namespace NzbDrone.Core.Model public string NzbUrl { get; set; } + public Series Series { get; set; } + public override string ToString() { if (Episodes == null) diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index d52027eeb..f49b192ec 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -170,6 +170,7 @@ + diff --git a/NzbDrone.Core/Providers/DownloadProvider.cs b/NzbDrone.Core/Providers/DownloadProvider.cs new file mode 100644 index 000000000..f249b1c1e --- /dev/null +++ b/NzbDrone.Core/Providers/DownloadProvider.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NLog; +using NzbDrone.Core.Model; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Providers.Indexer; +using NzbDrone.Core.Repository; +using SubSonic.Repository; + +namespace NzbDrone.Core.Providers +{ + public class DownloadProvider + { + private readonly SabProvider _sabProvider; + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + public DownloadProvider(SabProvider sabProvider) + { + _sabProvider = sabProvider; + } + + public DownloadProvider() + { + } + + public virtual bool DownloadReport(EpisodeParseResult parseResult) + { + var sabTitle = _sabProvider.GetSabTitle(parseResult); + + if (_sabProvider.IsInQueue(sabTitle)) + { + Logger.Warn("Episode {0} is already in sab's queue. skipping.", parseResult); + return false; + } + + return _sabProvider.AddByUrl(parseResult.NzbUrl, sabTitle); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Indexer/InventoryProvider.cs b/NzbDrone.Core/Providers/Indexer/InventoryProvider.cs index 0e883ca97..191c4b5f6 100644 --- a/NzbDrone.Core/Providers/Indexer/InventoryProvider.cs +++ b/NzbDrone.Core/Providers/Indexer/InventoryProvider.cs @@ -35,6 +35,8 @@ namespace NzbDrone.Core.Providers.Indexer return false; } + parseResult.Series = series; + foreach (var episodeNumber in parseResult.Episodes) { //Todo: How to handle full season files? Currently the episode list is completely empty for these releases @@ -96,16 +98,8 @@ namespace NzbDrone.Core.Providers.Indexer return false; } - parseResult.EpisodeTitle = episodeInfo.Title; - var sabTitle = _sabProvider.GetSabTitle(parseResult, new DirectoryInfo(series.Path).Name); - - if (_sabProvider.IsInQueue(sabTitle)) - { - Logger.Debug("Episode {0} is already in sab's queue. skipping.", parseResult); - return false; - } - //Congragulations younge feed item! you have made it this far. you are truly special!!! + Logger.Debug("Episode {0} is needed", parseResult); return true; } diff --git a/NzbDrone.Core/Providers/Jobs/RssSyncJob.cs b/NzbDrone.Core/Providers/Jobs/RssSyncJob.cs index f34133134..053b2daab 100644 --- a/NzbDrone.Core/Providers/Jobs/RssSyncJob.cs +++ b/NzbDrone.Core/Providers/Jobs/RssSyncJob.cs @@ -1,6 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers.Indexer; @@ -9,13 +11,17 @@ namespace NzbDrone.Core.Providers.Jobs public class RssSyncJob : IJob { private readonly IEnumerable _indexers; + private readonly InventoryProvider _inventoryProvider; + private readonly DownloadProvider _downloadProvider; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public RssSyncJob(IEnumerable indexers) + public RssSyncJob(IEnumerable indexers, InventoryProvider inventoryProvider, DownloadProvider downloadProvider) { _indexers = indexers; + _inventoryProvider = inventoryProvider; + _downloadProvider = downloadProvider; } public string Name @@ -30,10 +36,39 @@ namespace NzbDrone.Core.Providers.Jobs public void Start(ProgressNotification notification, int targetId) { + var reports = new List(); + foreach (var indexer in _indexers.Where(i => i.Settings.Enable)) { - indexer.Fetch(); + try + { + notification.CurrentMessage = "Fetching RSS from " + indexer.Name; + reports.AddRange(indexer.Fetch()); + } + catch (Exception e) + { + Logger.ErrorException("An error has occured while fetching items from " + indexer.Name, e); + } } + + Logger.Debug("Finished fetching reports from all indexers. Total {0}", reports.Count); + notification.CurrentMessage = "Proccessing downloaded RSS"; + + foreach (var episodeParseResult in reports) + { + try + { + if (_inventoryProvider.IsNeeded(episodeParseResult)) + { + _downloadProvider.DownloadReport(episodeParseResult); + } + } + catch (Exception e) + { + Logger.ErrorException("An error has occured while processing parse result items from " + episodeParseResult, e); + } + } + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/SabProvider.cs b/NzbDrone.Core/Providers/SabProvider.cs index e3e9c8610..6a7c52f0b 100644 --- a/NzbDrone.Core/Providers/SabProvider.cs +++ b/NzbDrone.Core/Providers/SabProvider.cs @@ -92,7 +92,7 @@ namespace NzbDrone.Core.Providers _configProvider.SabPassword); } - public String GetSabTitle(EpisodeParseResult parseResult, String folderName) + public String GetSabTitle(EpisodeParseResult parseResult) { //Show Name - 1x01-1x02 - Episode Name //Show Name - 1x01 - Episode Name @@ -105,7 +105,7 @@ namespace NzbDrone.Core.Providers var epNumberString = String.Join("-", episodeString); - var result = String.Format("{0} - {1} - {2} [{3}]", folderName, epNumberString, parseResult.EpisodeTitle, parseResult.Quality); + var result = String.Format("{0} - {1} - {2} [{3}]", new DirectoryInfo(parseResult.Series.Path).Name, epNumberString, parseResult.EpisodeTitle, parseResult.Quality); if (parseResult.Proper) {