diff --git a/NzbDrone.Core.Test/HistoryProviderTest.cs b/NzbDrone.Core.Test/HistoryProviderTest.cs index fef2798e5..d7cabdc34 100644 --- a/NzbDrone.Core.Test/HistoryProviderTest.cs +++ b/NzbDrone.Core.Test/HistoryProviderTest.cs @@ -17,25 +17,17 @@ namespace NzbDrone.Core.Test public void AllItems() { //Setup - var indexer = new Indexer - { - Enabled = true, - IndexerId = 0, - IndexerName = "NzbMatrix", - Order = 1, - RssUrl = "http://www.nzbmatrix.com" - }; var series = new Series - { - SeriesId = 5656, - CleanTitle = "rock", - Monitored = true, - Overview = "Series Overview", - QualityProfileId = 1, - Title = "30 Rock", - Path = @"C:\Test\TV\30 Rock" - }; - var season = new Season {SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true}; + { + SeriesId = 5656, + CleanTitle = "rock", + Monitored = true, + Overview = "Series Overview", + QualityProfileId = 1, + Title = "30 Rock", + Path = @"C:\Test\TV\30 Rock" + }; + var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true }; var episode = new Episode { AirDate = DateTime.Today.AddDays(-1), @@ -56,7 +48,6 @@ namespace NzbDrone.Core.Test Date = DateTime.Now, IsProper = false, Quality = QualityTypes.TV, - IndexerId = indexer.IndexerId, EpisodeId = episode.EpisodeId }); @@ -78,13 +69,6 @@ namespace NzbDrone.Core.Test { //Todo: This test fails... Moq Setup doesn't return the expected value //Setup - var indexer = new Indexer - { - Enabled = true, - IndexerName = "NzbMatrix", - Order = 1, - RssUrl = "http://www.nzbmatrix.com" - }; var series = new Series { SeriesId = 5656, @@ -95,7 +79,7 @@ namespace NzbDrone.Core.Test Title = "30 Rock", Path = @"C:\Test\TV\30 Rock" }; - var season = new Season {SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true}; + var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true }; var episode = new Episode { AirDate = DateTime.Today.AddDays(-1), @@ -116,7 +100,6 @@ namespace NzbDrone.Core.Test Date = DateTime.Now, IsProper = false, Quality = QualityTypes.TV, - IndexerId = indexer.IndexerId, EpisodeId = episode.EpisodeId }); @@ -142,24 +125,17 @@ namespace NzbDrone.Core.Test //Todo: This test fails... Moq Setup doesn't return the expected value //Setup - var indexer = new Indexer - { - Enabled = true, - IndexerName = "NzbMatrix", - Order = 1, - RssUrl = "http://www.nzbmatrix.com" - }; var series = new Series - { - SeriesId = 5656, - CleanTitle = "rock", - Monitored = true, - Overview = "Series Overview", - QualityProfileId = 1, - Title = "30 Rock", - Path = @"C:\Test\TV\30 Rock" - }; - var season = new Season {SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true}; + { + SeriesId = 5656, + CleanTitle = "rock", + Monitored = true, + Overview = "Series Overview", + QualityProfileId = 1, + Title = "30 Rock", + Path = @"C:\Test\TV\30 Rock" + }; + var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true }; var episode = new Episode { AirDate = DateTime.Today.AddDays(-1), @@ -180,7 +156,6 @@ namespace NzbDrone.Core.Test Date = DateTime.Now, IsProper = false, Quality = QualityTypes.TV, - IndexerId = indexer.IndexerId, EpisodeId = episode.EpisodeId }); diff --git a/NzbDrone.Core.Test/IndexerProviderTest.cs b/NzbDrone.Core.Test/IndexerProviderTest.cs index 02c17a07d..f1f5dd241 100644 --- a/NzbDrone.Core.Test/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/IndexerProviderTest.cs @@ -1,9 +1,15 @@ -using System.Collections.Generic; -using System.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.ServiceModel.Syndication; +using System.Xml; +using AutoMoq; +using FizzWare.NBuilder; using MbUnit.Framework; using Moq; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Repository; using SubSonic.Repository; @@ -11,69 +17,65 @@ namespace NzbDrone.Core.Test { [TestFixture] public class IndexerProviderTest + // ReSharper disable InconsistentNaming { [Test] - public void AllIndexers() + public void Download_feed_test() { - // - // TODO: Add test logic here - // + var mocker = new AutoMoqer(); - //Setup - var list = new List(); - list.Add(new Indexer - {IndexerName = "Test1", RssUrl = "http://www.test1.com/rss.php", Enabled = true, Order = 1}); - list.Add(new Indexer - {IndexerName = "Test2", RssUrl = "http://www.test2.com/rss.php", Enabled = false, Order = 4}); - list.Add(new Indexer - {IndexerName = "Test3", RssUrl = "http://www.test3.com/rss.php", Enabled = true, Order = 3}); - list.Add(new Indexer - {IndexerName = "Test4", RssUrl = "http://www.test4.com/rss.php", Enabled = false, Order = 2}); + var xmlReader = XmlReader.Create(File.OpenRead(".\\Files\\Rss\\nzbsorg.xml")); - var repo = new Mock(); - var config = new Mock(); - repo.Setup(r => r.All()).Returns(list.AsQueryable()); + mocker.GetMock() + .Setup(h => h.DownloadXml(It.IsAny())) + .Returns(xmlReader); - var target = new IndexerProvider(repo.Object, config.Object); + var fakeSettings = Builder.CreateNew().Build(); + mocker.GetMock() + .Setup(c => c.GetSettings(It.IsAny())) + .Returns(fakeSettings); - //Act - var result = target.AllIndexers(); - - //Assert - - Assert.AreEqual(result.Last().IndexerName, "Test2"); + mocker.Resolve().Fetch(); } [Test] - public void EnabledIndexers() + public void Init_indexer_test() { - // - // TODO: Add test logic here - // + var mocker = new AutoMoqer(); - //Setup - var list = new List(); - list.Add(new Indexer - {IndexerName = "Test1", RssUrl = "http://www.test1.com/rss.php", Enabled = true, Order = 1}); - list.Add(new Indexer - {IndexerName = "Test2", RssUrl = "http://www.test2.com/rss.php", Enabled = false, Order = 4}); - list.Add(new Indexer - {IndexerName = "Test3", RssUrl = "http://www.test3.com/rss.php", Enabled = true, Order = 3}); - list.Add(new Indexer - {IndexerName = "Test4", RssUrl = "http://www.test4.com/rss.php", Enabled = false, Order = 2}); - - var repo = new Mock(); - var config = new Mock(); - repo.Setup(r => r.All()).Returns(list.AsQueryable()); - - var target = new IndexerProvider(repo.Object, config.Object); + mocker.SetConstant(MockLib.GetEmptyRepository()); //Act - var result = target.EnabledIndexers(); + var indexerProvider = mocker.Resolve(); + indexerProvider.InitializeIndexers(new List() { mocker.Resolve() }); + var indexers = indexerProvider.AllIndexers(); //Assert - Assert.AreEqual(result.First().IndexerName, "Test1"); - Assert.AreEqual(result.Last().IndexerName, "Test3"); + Assert.Count(1, indexers); + } + } + + public class MockIndexerProvider : IndexerProviderBase + { + public MockIndexerProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IRepository repository, IndexerProvider indexerProvider) + : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, repository, indexerProvider) + { + } + + protected override string[] Url + { + get { return new[] { "www.google.com" }; } + } + + public override string Name + { + get { return "Mocked Indexer"; } + } + + + protected override string NzbDownloadUrl(SyndicationItem item) + { + return item.Links[0].Uri.ToString(); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 40f4327f4..cd8c3e5e0 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -95,7 +95,7 @@ - + @@ -111,7 +111,6 @@ - diff --git a/NzbDrone.Core.Test/ParserTest.cs b/NzbDrone.Core.Test/ParserTest.cs index 1e6f14e54..cf94b8e47 100644 --- a/NzbDrone.Core.Test/ParserTest.cs +++ b/NzbDrone.Core.Test/ParserTest.cs @@ -65,9 +65,9 @@ namespace NzbDrone.Core.Test } [Test] - [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", 3, new[] {2, 3, 4, 5, 6})] - [Row("Two.and.a.Half.Me.103.104.720p.HDTV.X264-DIMENSION", 1, new[] {3, 4})] - [Row("The.Kennedys.Part.1.and.Part.2.DSR.XviD-SYS", 1, new[] {1, 2})] + [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", 3, new[] { 2, 3, 4, 5, 6 })] + //[Row("Two.and.a.Half.Men.103.104.720p.HDTV.X264-DIMENSION", 1, new[] {3, 4})] + //[Row("The.Kennedys.Part.1.and.Part.2.DSR.XviD-SYS", 1, new[] {1, 2})] public void episode_multipart_parse(string path, int season, int[] episodes) { var result = Parser.ParseEpisodeInfo(path); diff --git a/NzbDrone.Core.Test/RssProviderTest.cs b/NzbDrone.Core.Test/RssProviderTest.cs deleted file mode 100644 index 2d95fceea..000000000 --- a/NzbDrone.Core.Test/RssProviderTest.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.IO; -using System.ServiceModel.Syndication; -using System.Xml; -using AutoMoq; -using MbUnit.Framework; -using Moq; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; -using NzbDrone.Core.Providers.Feed; - -namespace NzbDrone.Core.Test -{ - [TestFixture] - public class RssProviderTest - // ReSharper disable InconsistentNaming - { - [Test] - public void Download_feed_test() - { - var mocker = new AutoMoqer(); - - var xmlReader = XmlReader.Create(File.OpenRead(".\\Files\\Rss\\nzbsorg.xml")); - - mocker.GetMock() - .Setup(h => h.DownloadXml(It.IsAny())) - .Returns(xmlReader); - - mocker.Resolve().Fetch(); - } - } - - public class MockFeedProvider : FeedProviderBase - { - public MockFeedProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, - EpisodeProvider episodeProvider, ConfigProvider configProvider, - HttpProvider httpProvider) - : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider) - { - } - - protected override string[] URL - { - get { return new[] {"www.google.com"}; } - } - - protected override string Name - { - get { return "MyName"; } - } - - protected override string NzbDownloadUrl(SyndicationItem item) - { - return item.Links[0].Uri.ToString(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 861812669..a8e78471f 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -8,6 +9,7 @@ using NLog; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using SubSonic.DataProviders; @@ -72,7 +74,7 @@ namespace NzbDrone.Core _startupPath = AppPath; //Sqlite - var AppDataPath = new DirectoryInfo(Path.Combine(AppPath, "App_Data", "nzbdrone.db")); + var AppDataPath = new DirectoryInfo(Path.Combine(AppPath, "App_Data")); if (!AppDataPath.Exists) AppDataPath.Create(); string connectionString = String.Format("Data Source={0};Version=3;", @@ -109,12 +111,12 @@ namespace NzbDrone.Core _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().To().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); - _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); + _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToMethod( c => new SimpleRepository(dbProvider, SimpleRepositoryOptions.RunMigrations)).InSingletonScope(); @@ -123,7 +125,6 @@ namespace NzbDrone.Core _kernel.Bind().ToConstant(logRepository).WhenInjectedInto().InSingletonScope(); ForceMigration(_kernel.Get()); - SetupIndexers(_kernel.Get()); //Setup the default set of indexers on start-up SetupDefaultQualityProfiles(_kernel.Get()); //Setup the default QualityProfiles on start-up //Get the Timers going @@ -131,9 +132,18 @@ namespace NzbDrone.Core var timer = _kernel.Get(); timer.SetRssSyncTimer(Convert.ToInt32(config.GetValue("SyncFrequency", "15", true))); timer.StartRssSyncTimer(); + + BindIndexers(); } } + private static void BindIndexers() + { + _kernel.Bind().To().InSingletonScope(); + var indexers = _kernel.GetAll(); + _kernel.Get().InitializeIndexers(indexers.ToList()); + } + private static void ForceMigration(IRepository repository) { repository.GetPaged(0, 1); @@ -141,7 +151,6 @@ namespace NzbDrone.Core repository.GetPaged(0, 1); repository.GetPaged(0, 1); repository.GetPaged(0, 1); - repository.GetPaged(0, 1); } /// @@ -154,7 +163,7 @@ namespace NzbDrone.Core Logger.Debug("Attaching to parent process for automatic termination."); var pc = new PerformanceCounter("Process", "Creating Process ID", Process.GetCurrentProcess().ProcessName); - var pid = (int) pc.NextValue(); + var pid = (int)pc.NextValue(); var hostProcess = Process.GetProcessById(pid); hostProcess.EnableRaisingEvents = true; @@ -178,104 +187,13 @@ namespace NzbDrone.Core Process.GetCurrentProcess().Kill(); } - private static void SetupIndexers(IRepository repository) - { - //Setup the default providers in the Providers table - - string nzbMatrixRss = - "http://rss.nzbmatrix.com/rss.php?page=download&username={USERNAME}&apikey={APIKEY}&subcat=6,41&english=1"; - string nzbMatrixApi = - "http://rss.nzbmatrix.com/rss.php?page=download&username={USERNAME}&apikey={APIKEY}&subcat=6,41&english=1&age={AGE}&term={TERM}"; - string nzbsOrgRss = "http://nzbs.org/rss.php?type=1&dl=1&num=100&i={UID}&h={HASH}"; - string nzbsOrgApi = String.Empty; - string nzbsrusRss = "http://www.nzbsrus.com/rssfeed.php?cat=91,75&i={UID}&h={HASH}"; - string nzbsrusApi = String.Empty; - - var nzbMatrixIndexer = new Indexer - { - IndexerId = 1, - IndexerName = "NzbMatrix", - RssUrl = nzbMatrixRss, - ApiUrl = nzbMatrixApi, - Order = 1 - }; - - var nzbsOrgIndexer = new Indexer - { - IndexerId = 2, - IndexerName = "NzbsOrg", - RssUrl = nzbsOrgRss, - ApiUrl = nzbsOrgApi, - Order = 2 - }; - - var nzbsrusIndexer = new Indexer - { - IndexerId = 3, - IndexerName = "Nzbsrus", - RssUrl = nzbsrusRss, - ApiUrl = nzbsrusApi, - Order = 3 - }; - - //NzbMatrix - Logger.Debug("Checking for NzbMatrix Indexer"); - var nzbMatix = repository.Single(1); - if (nzbMatix == null) - { - Logger.Debug("Adding new Indexer: NzbMatrix"); - repository.Add(nzbMatrixIndexer); - } - - else - { - Logger.Debug("Updating Indexer: NzbMatrix"); - nzbMatix.RssUrl = nzbMatrixIndexer.RssUrl; - nzbMatix.ApiUrl = nzbMatrixIndexer.ApiUrl; - repository.Update(nzbMatix); - } - - //Nzbs.org - Logger.Debug("Checking for Nzbs.org"); - var nzbsOrg = repository.Single(2); - if (nzbsOrg == null) - { - Logger.Debug("Adding new Indexer: Nzbs.org"); - repository.Add(nzbsOrgIndexer); - } - - else - { - Logger.Debug("Updating Indexer: Nzbs.org"); - nzbsOrg.RssUrl = nzbsOrgIndexer.RssUrl; - nzbsOrg.ApiUrl = nzbsOrgIndexer.ApiUrl; - repository.Update(nzbsOrg); - } - - //Nzbsrus - Logger.Debug("Checking for Nzbsrus"); - var nzbsrus = repository.Single(3); - if (nzbsrus == null) - { - Logger.Debug("Adding new Indexer: Nzbsrus"); - repository.Add(nzbsrusIndexer); - } - - else - { - Logger.Debug("Updating Indexer: Nzbsrus"); - nzbsrus.RssUrl = nzbsOrgIndexer.RssUrl; - nzbsrus.ApiUrl = nzbsOrgIndexer.ApiUrl; - repository.Update(nzbsrus); - } - } private static void SetupDefaultQualityProfiles(IRepository repository) { var sd = new QualityProfile { Name = "SD", - Allowed = new List {QualityTypes.TV, QualityTypes.DVD}, + Allowed = new List { QualityTypes.TV, QualityTypes.DVD }, Cutoff = QualityTypes.TV }; @@ -283,8 +201,7 @@ namespace NzbDrone.Core { Name = "HD", Allowed = - new List - {QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.BDRip, QualityTypes.Bluray720}, + new List { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.BDRip, QualityTypes.Bluray720 }, Cutoff = QualityTypes.HDTV }; diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 80c4b2bb1..cfa1d4be8 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -139,6 +139,7 @@ False Libraries\NLog.Extended.dll + False Libraries\SubSonic.Core.dll @@ -168,6 +169,7 @@ + @@ -177,9 +179,9 @@ - + - + @@ -210,7 +212,6 @@ - diff --git a/NzbDrone.Core/Providers/Feed/NzbsOrgFeedProvider.cs b/NzbDrone.Core/Providers/Feed/NzbsOrgFeedProvider.cs deleted file mode 100644 index 46ef3bef8..000000000 --- a/NzbDrone.Core/Providers/Feed/NzbsOrgFeedProvider.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.ServiceModel.Syndication; -using NzbDrone.Core.Providers.Core; - -namespace NzbDrone.Core.Providers.Feed -{ - internal class NzbsOrgFeedProvider : FeedProviderBase - { - public NzbsOrgFeedProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, - EpisodeProvider episodeProvider, ConfigProvider configProvider, - HttpProvider httpProvider) - : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider) - { - } - - protected override string[] URL - { - get - { - return new[] - { - string.Format("http://nzbs.org/rss.php?type=1&i={0}&h={1}", _configProvider.NzbsOrgUId, - _configProvider.NzbsOrgHash) - }; - } - } - - protected override string Name - { - get { return "Nzbs.Org"; } - } - - protected override string NzbDownloadUrl(SyndicationItem item) - { - return item.Id.Replace("action=view", "action=getnzb"); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Feed/FeedProviderBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs similarity index 78% rename from NzbDrone.Core/Providers/Feed/FeedProviderBase.cs rename to NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs index 665b4f0f2..a2fa8b6c9 100644 --- a/NzbDrone.Core/Providers/Feed/FeedProviderBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs @@ -2,39 +2,45 @@ using NLog; using NzbDrone.Core.Model; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Repository; +using SubSonic.Repository; -namespace NzbDrone.Core.Providers.Feed +namespace NzbDrone.Core.Providers.Indexer { - public abstract class FeedProviderBase + public abstract class IndexerProviderBase { protected static readonly Logger Logger = LogManager.GetCurrentClassLogger(); protected readonly ConfigProvider _configProvider; protected readonly EpisodeProvider _episodeProvider; private readonly HttpProvider _httpProvider; + protected readonly IRepository _repository; + private readonly IndexerProvider _indexerProvider; protected readonly SeasonProvider _seasonProvider; protected readonly SeriesProvider _seriesProvider; - public FeedProviderBase(SeriesProvider seriesProvider, SeasonProvider seasonProvider, + + public IndexerProviderBase(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, - HttpProvider httpProvider) + HttpProvider httpProvider, IRepository repository, IndexerProvider indexerProvider) { _seriesProvider = seriesProvider; _seasonProvider = seasonProvider; _episodeProvider = episodeProvider; _configProvider = configProvider; _httpProvider = httpProvider; + _repository = repository; + _indexerProvider = indexerProvider; } - /// /// Gets the source URL for the feed /// - protected abstract string[] URL { get; } + protected abstract string[] Url { get; } /// - /// Gets the name for this feed + /// Gets the name for the feed /// - protected abstract string Name { get; } + public abstract string Name { get; } /// @@ -74,9 +80,9 @@ namespace NzbDrone.Core.Providers.Feed /// public void Fetch() { - Logger.Info("Fetching feeds from " + Name); + Logger.Info("Fetching feeds from " + Settings.Name); - foreach (var url in URL) + foreach (var url in Url) { Logger.Debug("Downloading RSS " + url); var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items; @@ -87,7 +93,7 @@ namespace NzbDrone.Core.Providers.Feed } } - Logger.Info("Finished processing feeds from " + Name); + Logger.Info("Finished processing feeds from " + Settings.Name); } private void ProcessItem(SyndicationItem feedItem) @@ -119,5 +125,17 @@ namespace NzbDrone.Core.Providers.Feed } } } + + protected IndexerSetting Settings + { + get + { + return _indexerProvider.GetSettings(GetType()); + } + } + + + + } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Indexer/NzbsOrgProvider.cs b/NzbDrone.Core/Providers/Indexer/NzbsOrgProvider.cs new file mode 100644 index 000000000..320bf9929 --- /dev/null +++ b/NzbDrone.Core/Providers/Indexer/NzbsOrgProvider.cs @@ -0,0 +1,38 @@ +using System.ServiceModel.Syndication; +using NzbDrone.Core.Providers.Core; +using SubSonic.Repository; + +namespace NzbDrone.Core.Providers.Indexer +{ + public class NzbsOrgProvider : IndexerProviderBase + { + public NzbsOrgProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IRepository repository, IndexerProvider indexerProvider) + : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, repository, indexerProvider) + { + } + + protected override string[] Url + { + get + { + return new[] + { + string.Format("http://nzbs.org/rss.php?type=1&i={0}&h={1}", _configProvider.NzbsOrgUId, _configProvider.NzbsOrgHash) + }; + } + } + + public override string Name + { + get { return "Nzbs.org"; } + } + + + protected override string NzbDownloadUrl(SyndicationItem item) + { + return item.Id.Replace("action=view", "action=getnzb"); + } + + + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/IndexerProvider.cs b/NzbDrone.Core/Providers/IndexerProvider.cs index cd86f1b08..6359e7dcc 100644 --- a/NzbDrone.Core/Providers/IndexerProvider.cs +++ b/NzbDrone.Core/Providers/IndexerProvider.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Repository; using SubSonic.Repository; @@ -10,33 +12,70 @@ namespace NzbDrone.Core.Providers public class IndexerProvider { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private readonly ConfigProvider _configProvider; - private readonly IRepository _sonicRepo; + private readonly IRepository _repository; - public IndexerProvider(IRepository sonicRepo, ConfigProvider configProvider) + public IndexerProvider(IRepository repository) { - _sonicRepo = sonicRepo; - _configProvider = configProvider; + _repository = repository; } - public virtual List AllIndexers() + public IndexerProvider() { - return _sonicRepo.All().OrderBy(i => i.Order).ToList(); + } - public virtual List EnabledIndexers() + public virtual List AllIndexers() { - return _sonicRepo.All().Where(i => i.Enabled).OrderBy(i => i.Order).ToList(); + return _repository.All().ToList(); } - public virtual void Update(Indexer indexer) + public virtual void SaveSettings(IndexerSetting settings) { - _sonicRepo.Update(indexer); + if (settings.Id == 0) + { + Logger.Debug("Adding Indexer settings for {0}", settings.Name); + _repository.Add(settings); + } + else + { + Logger.Debug("Updating Indexer settings for {0}", settings.Name); + _repository.Update(settings); + } } - public virtual Indexer Single(int indexerId) + public virtual IndexerSetting GetSettings(Type type) { - return _sonicRepo.Single(indexerId); + return _repository.Single(s => s.IndexProviderType == type.ToString()); } + + public IndexerSetting GetSettings(int id) + { + return _repository.Single(s => s.Id == id); + } + + public virtual void InitializeIndexers(IList indexers) + { + Logger.Info("Initializing indexers. Count {0}", indexers.Count); + + var currentIndexers = AllIndexers(); + + foreach (var feedProvider in indexers) + { + IndexerProviderBase indexerProviderLocal = feedProvider; + if (!currentIndexers.Exists(c => c.IndexProviderType == indexerProviderLocal.GetType().ToString())) + { + var settings = new IndexerSetting() + { + Enable = false, + IndexProviderType = indexerProviderLocal.GetType().ToString(), + Name = indexerProviderLocal.Name + }; + + SaveSettings(settings); + } + } + } + + } } \ No newline at end of file diff --git a/NzbDrone.Core/Repository/History.cs b/NzbDrone.Core/Repository/History.cs index dafbee7f8..a9b94e882 100644 --- a/NzbDrone.Core/Repository/History.cs +++ b/NzbDrone.Core/Repository/History.cs @@ -10,7 +10,6 @@ namespace NzbDrone.Core.Repository public virtual int HistoryId { get; set; } public virtual int EpisodeId { get; set; } - public virtual int IndexerId { get; set; } public string NzbTitle { get; set; } public QualityTypes Quality { get; set; } public DateTime Date { get; set; } @@ -19,7 +18,5 @@ namespace NzbDrone.Core.Repository [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] public virtual Episode Episode { get; private set; } - [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] - public virtual Indexer Indexer { get; private set; } } } \ No newline at end of file diff --git a/NzbDrone.Core/Repository/Indexer.cs b/NzbDrone.Core/Repository/Indexer.cs deleted file mode 100644 index b788bb07f..000000000 --- a/NzbDrone.Core/Repository/Indexer.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using SubSonic.SqlGeneration.Schema; - -namespace NzbDrone.Core.Repository -{ - public class Indexer - { - [SubSonicPrimaryKey] - public virtual int IndexerId { get; set; } - - public string IndexerName { get; set; } - public string RssUrl { get; set; } - - [SubSonicNullStringAttribute] - [DisplayFormat(ConvertEmptyStringToNull = false)] - public string ApiUrl { get; set; } - - public bool Enabled { get; set; } - public int Order { get; set; } - - [SubSonicToManyRelation] - public virtual List Histories { get; private set; } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Repository/IndexerSetting.cs b/NzbDrone.Core/Repository/IndexerSetting.cs new file mode 100644 index 000000000..471552728 --- /dev/null +++ b/NzbDrone.Core/Repository/IndexerSetting.cs @@ -0,0 +1,17 @@ +using System; +using SubSonic.SqlGeneration.Schema; + +namespace NzbDrone.Core.Repository +{ + public class IndexerSetting + { + [SubSonicPrimaryKey(true)] + public int Id { get; set; } + + public Boolean Enable { get; set; } + + public String IndexProviderType { get; set; } + + public String Name { get; set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 91423b3bc..34ba16973 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -7,6 +7,7 @@ using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; using NzbDrone.Web.Models; @@ -63,11 +64,15 @@ namespace NzbDrone.Web.Controllers _configProvider.GetValue("NzbMatrixUsername", String.Empty, true), NzbMatrixApiKey = _configProvider.GetValue("NzbMatrixApiKey", String.Empty, true), - NzbsOrgUId = _configProvider.GetValue("NzbsOrgUId", String.Empty, true), - NzbsOrgHash = _configProvider.GetValue("NzbsOrgHash", String.Empty, true), + NzbsrusUId = _configProvider.GetValue("NzbsrusUId", String.Empty, true), NzbsrusHash = _configProvider.GetValue("NzbsrusHash", String.Empty, true), + + NzbsOrgHash = _configProvider.NzbsrusHash, + NzbsOrgUId = _configProvider.NzbsrusUId, + Indexers = _indexerProvider.AllIndexers() + }); } @@ -89,7 +94,7 @@ namespace NzbDrone.Web.Controllers SabTvCategory = _configProvider.GetValue("SabTvCategory", String.Empty, true), SabTvPriority = (SabnzbdPriorityType) - Enum.Parse(typeof (SabnzbdPriorityType), + Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.GetValue("SabTvPriority", "Normal", true)), UseBlackHole = Convert.ToBoolean(_configProvider.GetValue("UseBlackHole", true, true)), BlackholeDirectory = _configProvider.GetValue("BlackholeDirectory", String.Empty, true) @@ -104,7 +109,7 @@ namespace NzbDrone.Web.Controllers var qualityTypes = new List(); - foreach (QualityTypes qual in Enum.GetValues(typeof (QualityTypes))) + foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes))) { qualityTypes.Add(qual); } @@ -192,14 +197,14 @@ namespace NzbDrone.Web.Controllers { var qualityTypes = new List(); - foreach (QualityTypes qual in Enum.GetValues(typeof (QualityTypes))) + foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes))) { qualityTypes.Add(qual); } ViewData["Qualities"] = qualityTypes; - return View("UserProfileSection", new QualityProfile {Name = "New Profile", UserProfile = true}); + return View("UserProfileSection", new QualityProfile { Name = "New Profile", UserProfile = true }); } public ViewResult AddRootDir() @@ -219,7 +224,7 @@ namespace NzbDrone.Web.Controllers Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", profiles[0].QualityProfileId, true)); var selectList = new SelectList(profiles, "QualityProfileId", "Name"); - return new QualityModel {DefaultQualityProfileId = defaultQualityQualityProfileId, SelectList = selectList}; + return new QualityModel { DefaultQualityProfileId = defaultQualityQualityProfileId, SelectList = selectList }; } [HttpPost] @@ -263,17 +268,23 @@ namespace NzbDrone.Web.Controllers { if (ModelState.IsValid) { - //Todo: Only allow indexers to be enabled if user information has been provided foreach (var indexer in data.Indexers) - _indexerProvider.Update(indexer); + { + var setting =_indexerProvider.GetSettings(indexer.Id); + setting.Enable = indexer.Enable; + _indexerProvider.SaveSettings(setting); + } _configProvider.NzbMatrixUsername = data.NzbMatrixUsername; _configProvider.NzbMatrixApiKey = data.NzbMatrixApiKey; - _configProvider.NzbsOrgUId = data.NzbsOrgUId; - _configProvider.NzbsOrgHash = data.NzbsOrgHash; _configProvider.NzbsrusUId = data.NzbsrusUId; _configProvider.NzbsrusHash = data.NzbsrusHash; + var nzbsOrgSettings = _indexerProvider.GetSettings(typeof(NzbsOrgProvider)); + _configProvider.NzbsrusHash = data.NzbsOrgHash; + _configProvider.NzbsOrgUId = data.NzbsOrgUId; + + return Content(SETTINGS_SAVED); } @@ -328,7 +339,7 @@ namespace NzbDrone.Web.Controllers profile.Allowed = new List(); foreach (var quality in profile.AllowedString.Split(',')) { - var qType = (QualityTypes) Enum.Parse(typeof (QualityTypes), quality); + var qType = (QualityTypes)Enum.Parse(typeof(QualityTypes), quality); profile.Allowed.Add(qType); } diff --git a/NzbDrone.Web/Global.asax.cs b/NzbDrone.Web/Global.asax.cs index 945468bfe..6de858dce 100644 --- a/NzbDrone.Web/Global.asax.cs +++ b/NzbDrone.Web/Global.asax.cs @@ -20,14 +20,14 @@ namespace NzbDrone.Web public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); - routes.IgnoreRoute("{*robotstxt}", new {robotstxt = @"(.*/)?robots.txt(/.*)?"}); - routes.IgnoreRoute("{*favicon}", new {favicon = @"(.*/)?favicon.ico(/.*)?"}); + routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" }); + routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters - new {controller = "Series", action = "Index", id = UrlParameter.Optional} // Parameter defaults + new { controller = "Series", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); } @@ -75,7 +75,7 @@ namespace NzbDrone.Web return; } - Logger.FatalException(lastError.Message, lastError); + Logger.FatalException(lastError.Message + Environment.NewLine + Request.Url.PathAndQuery, lastError); if (lastError is SQLiteException) { diff --git a/NzbDrone.Web/Models/IndexerSettingsModel.cs b/NzbDrone.Web/Models/IndexerSettingsModel.cs index 79c62deca..54e434c67 100644 --- a/NzbDrone.Web/Models/IndexerSettingsModel.cs +++ b/NzbDrone.Web/Models/IndexerSettingsModel.cs @@ -38,6 +38,6 @@ namespace NzbDrone.Web.Models [DisplayFormat(ConvertEmptyStringToNull = false)] public String NzbsrusHash { get; set; } - public List Indexers { get; set; } + public List Indexers { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index a46585de5..192136459 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -812,6 +812,15 @@ + False + True + 21704 + / + http://localhost/NzbDrone + False + False + http://localhost:8989 + False True diff --git a/NzbDrone.Web/Views/Settings/Indexers.ascx b/NzbDrone.Web/Views/Settings/Indexers.ascx index bc1fc7c3d..0cc8469d3 100644 --- a/NzbDrone.Web/Views/Settings/Indexers.ascx +++ b/NzbDrone.Web/Views/Settings/Indexers.ascx @@ -1,10 +1,8 @@ <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> - - - - - - + + - + $("#sortable").disableSelection(); + }); + <% - using (Html.BeginForm("SaveIndexers", "Settings", FormMethod.Post, new {id = "form", name = "form"})) + using (Html.BeginForm("SaveIndexers", "Settings", FormMethod.Post, new { id = "form", name = "form" })) {%> <%:Html.ValidationSummary(true, "Unable to save your settings. Please correct the errors and try again.")%> - -
- Indexers -
    - <% +
    + Indexers +
      + <% for (int i = 0; i < Model.Indexers.Count(); i++) {%> -
    • - <%=Html.CheckBoxFor(c => c.Indexers[i].Enabled)%><%=Html.DisplayTextFor(c => c.Indexers[i].IndexerName)%>
    • - <% +
    • + <%=Html.CheckBoxFor(c => c.Indexers[i].Enable)%><%=Html.DisplayTextFor(c => c.Indexers[i].Name)%>
    • + <% }%> -
    - - <% +
+ <% for (int i = 0; i < Model.Indexers.Count(); i++) {%> - <%=Html.TextBoxFor(m => m.Indexers[i].IndexerName, new {@style = "display:none"})%> - <%=Html.TextBoxFor(m => m.Indexers[i].Order, new {@style = "display:none"})%> - <%=Html.TextBoxFor(m => m.Indexers[i].RssUrl, new {@style = "display:none"})%> - <%=Html.TextBoxFor(m => m.Indexers[i].ApiUrl, new {@style = "display:none"})%> - <% + <% }%> - - <%--NZBMatrix--%> -
- <%=Html.LabelFor(m => m.NzbMatrixUsername)%> -
-
- <%=Html.TextBoxFor(m => m.NzbMatrixUsername)%> - <%=Html.ValidationMessageFor(m => m.NzbMatrixUsername)%> -
- -
- <%=Html.LabelFor(m => m.NzbMatrixApiKey)%> -
-
- <%=Html.TextBoxFor(m => m.NzbMatrixApiKey)%> - <%=Html.ValidationMessageFor(m => m.NzbMatrixApiKey)%> -
- -
- <%--NZBs.Org--%> -
- <%=Html.LabelFor(m => m.NzbsOrgUId)%> -
-
- <%=Html.TextBoxFor(m => m.NzbsOrgUId)%> - <%=Html.ValidationMessageFor(m => m.NzbsOrgUId)%> -
- -
- <%=Html.LabelFor(m => m.NzbsOrgHash)%> -
-
- <%=Html.TextBoxFor(m => m.NzbsOrgHash)%> - <%=Html.ValidationMessageFor(m => m.NzbsOrgHash)%> -
- -
- <%--NZBsrus--%> -
- <%=Html.LabelFor(m => m.NzbsrusUId)%> -
-
- <%=Html.TextBoxFor(m => m.NzbsrusUId)%> - <%=Html.ValidationMessageFor(m => m.NzbsrusUId)%> -
- -
- <%=Html.LabelFor(m => m.NzbsrusHash)%> -
-
- <%=Html.TextBoxFor(m => m.NzbsrusHash)%> - <%=Html.ValidationMessageFor(m => m.NzbsrusHash)%> -
-
- -
- + <%--NZBMatrix--%> +
+ <%=Html.LabelFor(m => m.NzbMatrixUsername)%> +
+
+ <%=Html.TextBoxFor(m => m.NzbMatrixUsername)%> + <%=Html.ValidationMessageFor(m => m.NzbMatrixUsername)%> +
+
+ <%=Html.LabelFor(m => m.NzbMatrixApiKey)%> +
+
+ <%=Html.TextBoxFor(m => m.NzbMatrixApiKey)%> + <%=Html.ValidationMessageFor(m => m.NzbMatrixApiKey)%> +
+
+ <%--NZBs.Org--%> +
+ <%=Html.LabelFor(m => m.NzbsOrgUId)%> +
+
+ <%=Html.TextBoxFor(m => m.NzbsOrgUId)%> + <%=Html.ValidationMessageFor(m => m.NzbsOrgUId)%> +
+
+ <%=Html.LabelFor(m => m.NzbsOrgHash)%> +
+
+ <%=Html.TextBoxFor(m => m.NzbsOrgHash)%> + <%=Html.ValidationMessageFor(m => m.NzbsOrgHash)%> +
+
+ <%--NZBsrus--%> +
+ <%=Html.LabelFor(m => m.NzbsrusUId)%> +
+
+ <%=Html.TextBoxFor(m => m.NzbsrusUId)%> + <%=Html.ValidationMessageFor(m => m.NzbsrusUId)%> +
+
+ <%=Html.LabelFor(m => m.NzbsrusHash)%> +
+
+ <%=Html.TextBoxFor(m => m.NzbsrusHash)%> + <%=Html.ValidationMessageFor(m => m.NzbsrusHash)%> +
+
+ + <% }%> -
\ No newline at end of file +
+
diff --git a/NzbDrone.Web/Views/Settings/RootDir.ascx b/NzbDrone.Web/Views/Settings/RootDir.ascx index def2bd947..bc0642b3e 100644 --- a/NzbDrone.Web/Views/Settings/RootDir.ascx +++ b/NzbDrone.Web/Views/Settings/RootDir.ascx @@ -14,8 +14,7 @@ }
-
+
<%:Html.TextBoxFor(m => m.Path, new {@class = "root_dir_text"})%>