diff --git a/NzbDrone.Core.Test/IndexerProviderTest.cs b/NzbDrone.Core.Test/IndexerProviderTest.cs index ed38159ab..c7f0318b7 100644 --- a/NzbDrone.Core.Test/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/IndexerProviderTest.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net; using System.ServiceModel.Syndication; using System.Xml; using AutoMoq; @@ -11,6 +12,7 @@ using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; using SubSonic.Repository; namespace NzbDrone.Core.Test @@ -29,7 +31,7 @@ public void parse_feed_xml(string fileName) var mocker = new AutoMoqer(); mocker.GetMock() - .Setup(h => h.DownloadStream(It.IsAny())) + .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) .Returns(File.OpenRead(".\\Files\\Rss\\" + fileName)); var fakeSettings = Builder.CreateNew().Build(); @@ -47,6 +49,63 @@ public void parse_feed_xml(string fileName) Assert.IsEmpty(exceptions); } + + + [Test] + [Row("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)] + public void parse_feed_test_success(string title, int season, int episode, QualityTypes quality) + { + var mocker = new AutoMoqer(); + + var summary = "My fake summary"; + + var fakeSettings = Builder.CreateNew().Build(); + mocker.GetMock() + .Setup(c => c.GetSettings(It.IsAny())) + .Returns(fakeSettings); + + mocker.GetMock() + .Setup(c => c.FindSeries(It.IsAny())) + .Returns(Builder.CreateNew().Build()); + + + var fakeRssItem = Builder.CreateNew() + .With(c => c.Title = new TextSyndicationContent(title)) + .With(c => c.Summary = new TextSyndicationContent(summary)) + .Build(); + + var result = mocker.Resolve().ParseFeed(fakeRssItem); + + Assert.IsNotNull(result); + Assert.AreEqual(summary, result.EpisodeTitle); + } + + [Test] + [Row("Adventure.Inc.DVDRip.XviD-OSiTV")] + public void parse_feed_test_fail(string title) + { + var mocker = new AutoMoqer(); + + + + var fakeSettings = Builder.CreateNew().Build(); + mocker.GetMock() + .Setup(c => c.GetSettings(It.IsAny())) + .Returns(fakeSettings); + + mocker.GetMock(MockBehavior.Strict); + + + var fakeRssItem = Builder.CreateNew() + .With(c => c.Title = new TextSyndicationContent(title)) + .Build(); + + var result = mocker.Resolve().ParseFeed(fakeRssItem); + + Assert.IsNull(result); + } + + [Test] public void downloadFeed() { @@ -102,6 +161,11 @@ protected override string[] Urls get { return new[] { "www.google.com" }; } } + protected override NetworkCredential Credentials + { + get { return null; } + } + public override string Name { get { return "Mocked Indexer"; } @@ -137,4 +201,33 @@ protected override string NzbDownloadUrl(SyndicationItem item) } } + public class CustomParserIndexer : IndexerProviderBase + { + public CustomParserIndexer(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) + : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider) + { + } + + public override string Name + { + get { return "Custom parser"; } + } + + protected override string[] Urls + { + get { return new[] { "http://www.google.com" }; } + } + + protected override string NzbDownloadUrl(SyndicationItem item) + { + return "http://www.google.com"; + } + + protected override Model.EpisodeParseResult CustomParser(SyndicationItem item, Model.EpisodeParseResult currentResult) + { + currentResult.EpisodeTitle = item.Summary.Text; + return currentResult; + } + } + } \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index ebd2c3da9..0f9621696 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -166,6 +166,7 @@ + diff --git a/NzbDrone.Core/Providers/Core/HttpProvider.cs b/NzbDrone.Core/Providers/Core/HttpProvider.cs index 91ff84661..6e440632d 100644 --- a/NzbDrone.Core/Providers/Core/HttpProvider.cs +++ b/NzbDrone.Core/Providers/Core/HttpProvider.cs @@ -40,10 +40,11 @@ public virtual string DownloadString(string address, string username, string pas } } - public virtual Stream DownloadStream(string url) + public virtual Stream DownloadStream(string url, NetworkCredential credential) { var request = WebRequest.Create(url); + request.Credentials = credential; var response = request.GetResponse(); return response.GetResponseStream(); diff --git a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs index 82c9aedf7..aa7ed2111 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net; using System.ServiceModel.Syndication; using NLog; using NzbDrone.Core.Model; @@ -48,6 +49,15 @@ protected IndexerProviderBase(SeriesProvider seriesProvider, SeasonProvider seas protected abstract string[] Urls { get; } + /// + /// Gets the credential. + /// + protected virtual NetworkCredential Credentials + { + get { return null; } + } + + public IndexerSetting Settings { get @@ -70,7 +80,7 @@ public List Fetch() { _logger.Trace("Downloading RSS " + url); - var reader = new SyndicationFeedXmlReader(_httpProvider.DownloadStream(url)); + var reader = new SyndicationFeedXmlReader(_httpProvider.DownloadStream(url, Credentials)); var feed = SyndicationFeed.Load(reader).Items; foreach (var item in feed) @@ -168,10 +178,10 @@ internal void ProcessItem(SyndicationItem feedItem) /// /// RSS feed item to parse /// Detailed episode info - protected EpisodeParseResult ParseFeed(SyndicationItem item) + public EpisodeParseResult ParseFeed(SyndicationItem item) { var episodeParseResult = Parser.ParseEpisodeInfo(item.Title.Text); - if (episodeParseResult == null) return CustomParser(item, null); + if (episodeParseResult == null) return null; var seriesInfo = _seriesProvider.FindSeries(episodeParseResult.CleanTitle); @@ -185,7 +195,7 @@ protected EpisodeParseResult ParseFeed(SyndicationItem item) } _logger.Debug("Unable to map {0} to any of series in database", episodeParseResult.CleanTitle); - return CustomParser(item, episodeParseResult); + return null; } /// diff --git a/NzbDrone.Core/Providers/Indexer/NewzbinProvider.cs b/NzbDrone.Core/Providers/Indexer/NewzbinProvider.cs index a2bca27e2..843753420 100644 --- a/NzbDrone.Core/Providers/Indexer/NewzbinProvider.cs +++ b/NzbDrone.Core/Providers/Indexer/NewzbinProvider.cs @@ -1,4 +1,7 @@ -using System.ServiceModel.Syndication; +using System; +using System.Net; +using System.ServiceModel.Syndication; +using System.Web; using NzbDrone.Core.Model; using NzbDrone.Core.Providers.Core; using SubSonic.Repository; @@ -7,7 +10,8 @@ namespace NzbDrone.Core.Providers.Indexer { public class NewzbinProvider : IndexerProviderBase { - public NewzbinProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider) + public NewzbinProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) + : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider) { } @@ -17,11 +21,16 @@ protected override string[] Urls { return new[] { - string.Format("http://{0}:{1}@www.newzbin.com/browse/category/p/tv?feed=rss&hauth=1", _configProvider.NewzbinUsername, _configProvider.NewzbinPassword) + "http://www.newzbin.com/browse/category/p/tv?feed=rss&hauth=1" }; } } + protected override NetworkCredential Credentials + { + get { return new NetworkCredential(_configProvider.NewzbinUsername, _configProvider.NewzbinPassword); } + } + public override string Name { get { return "Newzbin"; } diff --git a/NzbDrone.Core/Providers/Indexer/NzbMatrixProvider.cs b/NzbDrone.Core/Providers/Indexer/NzbMatrixProvider.cs index b4fe6c134..686fbddd1 100644 --- a/NzbDrone.Core/Providers/Indexer/NzbMatrixProvider.cs +++ b/NzbDrone.Core/Providers/Indexer/NzbMatrixProvider.cs @@ -1,4 +1,6 @@ -using System.ServiceModel.Syndication; +using System; +using System.Net; +using System.ServiceModel.Syndication; using NzbDrone.Core.Providers.Core; using SubSonic.Repository; @@ -6,7 +8,8 @@ namespace NzbDrone.Core.Providers.Indexer { public class NzbMatrixProvider : IndexerProviderBase { - public NzbMatrixProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider) + public NzbMatrixProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) + : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider) { } @@ -23,7 +26,6 @@ protected override string[] Urls }; } } - public override string Name { diff --git a/NzbDrone.Core/Providers/Indexer/NzbsOrgProvider.cs b/NzbDrone.Core/Providers/Indexer/NzbsOrgProvider.cs index ac0d99919..aa918173e 100644 --- a/NzbDrone.Core/Providers/Indexer/NzbsOrgProvider.cs +++ b/NzbDrone.Core/Providers/Indexer/NzbsOrgProvider.cs @@ -1,4 +1,5 @@ -using System.ServiceModel.Syndication; +using System.Net; +using System.ServiceModel.Syndication; using NzbDrone.Core.Providers.Core; using SubSonic.Repository; @@ -6,7 +7,8 @@ namespace NzbDrone.Core.Providers.Indexer { public class NzbsOrgProvider : IndexerProviderBase { - public NzbsOrgProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider) + public NzbsOrgProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) + : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider) { } @@ -26,7 +28,6 @@ public override string Name get { return "Nzbs.org"; } } - protected override string NzbDownloadUrl(SyndicationItem item) { return item.Id; diff --git a/NzbDrone.Core/Providers/Indexer/NzbsRUsProvider.cs b/NzbDrone.Core/Providers/Indexer/NzbsRUsProvider.cs index d90a1c30a..8e193b220 100644 --- a/NzbDrone.Core/Providers/Indexer/NzbsRUsProvider.cs +++ b/NzbDrone.Core/Providers/Indexer/NzbsRUsProvider.cs @@ -1,4 +1,5 @@ -using System.ServiceModel.Syndication; +using System.Net; +using System.ServiceModel.Syndication; using NzbDrone.Core.Providers.Core; using SubSonic.Repository; @@ -6,7 +7,8 @@ namespace NzbDrone.Core.Providers.Indexer { public class NzbsRUsProvider : IndexerProviderBase { - public NzbsRUsProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider) + public NzbsRUsProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IndexerProvider indexerProvider, HistoryProvider historyProvider, SabProvider sabProvider) + : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, indexerProvider, historyProvider, sabProvider) { }