Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Revered back to subsonic

Added indexer configuration back-end
  • Loading branch information...
commit 6f2dcbf83853d9ebf82e1570a6b8673883935a7e 1 parent 129be92
Keivan Beigi kayone authored
65 NzbDrone.Core.Test/HistoryProviderTest.cs
@@ -17,25 +17,17 @@ public class HistoryProviderTest
17 17 public void AllItems()
18 18 {
19 19 //Setup
20   - var indexer = new Indexer
21   - {
22   - Enabled = true,
23   - IndexerId = 0,
24   - IndexerName = "NzbMatrix",
25   - Order = 1,
26   - RssUrl = "http://www.nzbmatrix.com"
27   - };
28 20 var series = new Series
29   - {
30   - SeriesId = 5656,
31   - CleanTitle = "rock",
32   - Monitored = true,
33   - Overview = "Series Overview",
34   - QualityProfileId = 1,
35   - Title = "30 Rock",
36   - Path = @"C:\Test\TV\30 Rock"
37   - };
38   - var season = new Season {SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true};
  21 + {
  22 + SeriesId = 5656,
  23 + CleanTitle = "rock",
  24 + Monitored = true,
  25 + Overview = "Series Overview",
  26 + QualityProfileId = 1,
  27 + Title = "30 Rock",
  28 + Path = @"C:\Test\TV\30 Rock"
  29 + };
  30 + var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
39 31 var episode = new Episode
40 32 {
41 33 AirDate = DateTime.Today.AddDays(-1),
@@ -56,7 +48,6 @@ public void AllItems()
56 48 Date = DateTime.Now,
57 49 IsProper = false,
58 50 Quality = QualityTypes.TV,
59   - IndexerId = indexer.IndexerId,
60 51 EpisodeId = episode.EpisodeId
61 52 });
62 53
@@ -78,13 +69,6 @@ public void Exists_True()
78 69 {
79 70 //Todo: This test fails... Moq Setup doesn't return the expected value
80 71 //Setup
81   - var indexer = new Indexer
82   - {
83   - Enabled = true,
84   - IndexerName = "NzbMatrix",
85   - Order = 1,
86   - RssUrl = "http://www.nzbmatrix.com"
87   - };
88 72 var series = new Series
89 73 {
90 74 SeriesId = 5656,
@@ -95,7 +79,7 @@ public void Exists_True()
95 79 Title = "30 Rock",
96 80 Path = @"C:\Test\TV\30 Rock"
97 81 };
98   - var season = new Season {SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true};
  82 + var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
99 83 var episode = new Episode
100 84 {
101 85 AirDate = DateTime.Today.AddDays(-1),
@@ -116,7 +100,6 @@ public void Exists_True()
116 100 Date = DateTime.Now,
117 101 IsProper = false,
118 102 Quality = QualityTypes.TV,
119   - IndexerId = indexer.IndexerId,
120 103 EpisodeId = episode.EpisodeId
121 104 });
122 105
@@ -142,24 +125,17 @@ public void Exists_False()
142 125 //Todo: This test fails... Moq Setup doesn't return the expected value
143 126
144 127 //Setup
145   - var indexer = new Indexer
  128 + var series = new Series
146 129 {
147   - Enabled = true,
148   - IndexerName = "NzbMatrix",
149   - Order = 1,
150   - RssUrl = "http://www.nzbmatrix.com"
  130 + SeriesId = 5656,
  131 + CleanTitle = "rock",
  132 + Monitored = true,
  133 + Overview = "Series Overview",
  134 + QualityProfileId = 1,
  135 + Title = "30 Rock",
  136 + Path = @"C:\Test\TV\30 Rock"
151 137 };
152   - var series = new Series
153   - {
154   - SeriesId = 5656,
155   - CleanTitle = "rock",
156   - Monitored = true,
157   - Overview = "Series Overview",
158   - QualityProfileId = 1,
159   - Title = "30 Rock",
160   - Path = @"C:\Test\TV\30 Rock"
161   - };
162   - var season = new Season {SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true};
  138 + var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
163 139 var episode = new Episode
164 140 {
165 141 AirDate = DateTime.Today.AddDays(-1),
@@ -180,7 +156,6 @@ public void Exists_False()
180 156 Date = DateTime.Now,
181 157 IsProper = false,
182 158 Quality = QualityTypes.TV,
183   - IndexerId = indexer.IndexerId,
184 159 EpisodeId = episode.EpisodeId
185 160 });
186 161
98 NzbDrone.Core.Test/IndexerProviderTest.cs
... ... @@ -1,9 +1,15 @@
1   -using System.Collections.Generic;
2   -using System.Linq;
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.IO;
  4 +using System.ServiceModel.Syndication;
  5 +using System.Xml;
  6 +using AutoMoq;
  7 +using FizzWare.NBuilder;
3 8 using MbUnit.Framework;
4 9 using Moq;
5 10 using NzbDrone.Core.Providers;
6 11 using NzbDrone.Core.Providers.Core;
  12 +using NzbDrone.Core.Providers.Indexer;
7 13 using NzbDrone.Core.Repository;
8 14 using SubSonic.Repository;
9 15
@@ -11,69 +17,65 @@ namespace NzbDrone.Core.Test
11 17 {
12 18 [TestFixture]
13 19 public class IndexerProviderTest
  20 + // ReSharper disable InconsistentNaming
14 21 {
15 22 [Test]
16   - public void AllIndexers()
  23 + public void Download_feed_test()
17 24 {
18   - //
19   - // TODO: Add test logic here
20   - //
  25 + var mocker = new AutoMoqer();
21 26
22   - //Setup
23   - var list = new List<Indexer>();
24   - list.Add(new Indexer
25   - {IndexerName = "Test1", RssUrl = "http://www.test1.com/rss.php", Enabled = true, Order = 1});
26   - list.Add(new Indexer
27   - {IndexerName = "Test2", RssUrl = "http://www.test2.com/rss.php", Enabled = false, Order = 4});
28   - list.Add(new Indexer
29   - {IndexerName = "Test3", RssUrl = "http://www.test3.com/rss.php", Enabled = true, Order = 3});
30   - list.Add(new Indexer
31   - {IndexerName = "Test4", RssUrl = "http://www.test4.com/rss.php", Enabled = false, Order = 2});
  27 + var xmlReader = XmlReader.Create(File.OpenRead(".\\Files\\Rss\\nzbsorg.xml"));
32 28
33   - var repo = new Mock<IRepository>();
34   - var config = new Mock<ConfigProvider>();
35   - repo.Setup(r => r.All<Indexer>()).Returns(list.AsQueryable());
  29 + mocker.GetMock<HttpProvider>()
  30 + .Setup(h => h.DownloadXml(It.IsAny<String>()))
  31 + .Returns(xmlReader);
36 32
37   - var target = new IndexerProvider(repo.Object, config.Object);
  33 + var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
  34 + mocker.GetMock<IndexerProvider>()
  35 + .Setup(c => c.GetSettings(It.IsAny<Type>()))
  36 + .Returns(fakeSettings);
  37 +
  38 + mocker.Resolve<MockIndexerProvider>().Fetch();
  39 + }
  40 +
  41 + [Test]
  42 + public void Init_indexer_test()
  43 + {
  44 + var mocker = new AutoMoqer();
  45 +
  46 + mocker.SetConstant(MockLib.GetEmptyRepository());
38 47
39 48 //Act
40   - var result = target.AllIndexers();
  49 + var indexerProvider = mocker.Resolve<IndexerProvider>();
  50 + indexerProvider.InitializeIndexers(new List<IndexerProviderBase>() { mocker.Resolve<MockIndexerProvider>() });
  51 + var indexers = indexerProvider.AllIndexers();
41 52
42 53 //Assert
43   -
44   - Assert.AreEqual(result.Last().IndexerName, "Test2");
  54 + Assert.Count(1, indexers);
45 55 }
  56 + }
46 57
47   - [Test]
48   - public void EnabledIndexers()
  58 + public class MockIndexerProvider : IndexerProviderBase
  59 + {
  60 + public MockIndexerProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IRepository repository, IndexerProvider indexerProvider)
  61 + : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, repository, indexerProvider)
49 62 {
50   - //
51   - // TODO: Add test logic here
52   - //
53   -
54   - //Setup
55   - var list = new List<Indexer>();
56   - list.Add(new Indexer
57   - {IndexerName = "Test1", RssUrl = "http://www.test1.com/rss.php", Enabled = true, Order = 1});
58   - list.Add(new Indexer
59   - {IndexerName = "Test2", RssUrl = "http://www.test2.com/rss.php", Enabled = false, Order = 4});
60   - list.Add(new Indexer
61   - {IndexerName = "Test3", RssUrl = "http://www.test3.com/rss.php", Enabled = true, Order = 3});
62   - list.Add(new Indexer
63   - {IndexerName = "Test4", RssUrl = "http://www.test4.com/rss.php", Enabled = false, Order = 2});
  63 + }
64 64
65   - var repo = new Mock<IRepository>();
66   - var config = new Mock<ConfigProvider>();
67   - repo.Setup(r => r.All<Indexer>()).Returns(list.AsQueryable());
  65 + protected override string[] Url
  66 + {
  67 + get { return new[] { "www.google.com" }; }
  68 + }
68 69
69   - var target = new IndexerProvider(repo.Object, config.Object);
  70 + public override string Name
  71 + {
  72 + get { return "Mocked Indexer"; }
  73 + }
70 74
71   - //Act
72   - var result = target.EnabledIndexers();
73 75
74   - //Assert
75   - Assert.AreEqual(result.First().IndexerName, "Test1");
76   - Assert.AreEqual(result.Last().IndexerName, "Test3");
  76 + protected override string NzbDownloadUrl(SyndicationItem item)
  77 + {
  78 + return item.Links[0].Uri.ToString();
77 79 }
78 80 }
79 81 }
3  NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
@@ -95,7 +95,7 @@
95 95 </Compile>
96 96 <Compile Include="SyncProviderTest.cs" />
97 97 <Compile Include="RootDirProviderTest.cs" />
98   - <Compile Include="RssProviderTest.cs" />
  98 + <Compile Include="IndexerProviderTest.cs" />
99 99 <Compile Include="HistoryProviderTest.cs" />
100 100 <Compile Include="MediaFileProviderTests.cs" />
101 101 <Compile Include="DbConfigControllerTest.cs" />
@@ -111,7 +111,6 @@
111 111 <Compile Include="RepoTest.cs" />
112 112 <Compile Include="SabControllerTest.cs" />
113 113 <Compile Include="SeriesProviderTest.cs" />
114   - <Compile Include="IndexerProviderTest.cs" />
115 114 <Compile Include="TvDbControllerTest.cs" />
116 115 </ItemGroup>
117 116 <ItemGroup>
6 NzbDrone.Core.Test/ParserTest.cs
@@ -65,9 +65,9 @@ public void quality_parse(string path, object quality)
65 65 }
66 66
67 67 [Test]
68   - [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", 3, new[] {2, 3, 4, 5, 6})]
69   - [Row("Two.and.a.Half.Me.103.104.720p.HDTV.X264-DIMENSION", 1, new[] {3, 4})]
70   - [Row("The.Kennedys.Part.1.and.Part.2.DSR.XviD-SYS", 1, new[] {1, 2})]
  68 + [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", 3, new[] { 2, 3, 4, 5, 6 })]
  69 + //[Row("Two.and.a.Half.Men.103.104.720p.HDTV.X264-DIMENSION", 1, new[] {3, 4})]
  70 + //[Row("The.Kennedys.Part.1.and.Part.2.DSR.XviD-SYS", 1, new[] {1, 2})]
71 71 public void episode_multipart_parse(string path, int season, int[] episodes)
72 72 {
73 73 var result = Parser.ParseEpisodeInfo(path);
57 NzbDrone.Core.Test/RssProviderTest.cs
... ... @@ -1,57 +0,0 @@
1   -using System;
2   -using System.IO;
3   -using System.ServiceModel.Syndication;
4   -using System.Xml;
5   -using AutoMoq;
6   -using MbUnit.Framework;
7   -using Moq;
8   -using NzbDrone.Core.Providers;
9   -using NzbDrone.Core.Providers.Core;
10   -using NzbDrone.Core.Providers.Feed;
11   -
12   -namespace NzbDrone.Core.Test
13   -{
14   - [TestFixture]
15   - public class RssProviderTest
16   - // ReSharper disable InconsistentNaming
17   - {
18   - [Test]
19   - public void Download_feed_test()
20   - {
21   - var mocker = new AutoMoqer();
22   -
23   - var xmlReader = XmlReader.Create(File.OpenRead(".\\Files\\Rss\\nzbsorg.xml"));
24   -
25   - mocker.GetMock<HttpProvider>()
26   - .Setup(h => h.DownloadXml(It.IsAny<String>()))
27   - .Returns(xmlReader);
28   -
29   - mocker.Resolve<MockFeedProvider>().Fetch();
30   - }
31   - }
32   -
33   - public class MockFeedProvider : FeedProviderBase
34   - {
35   - public MockFeedProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider,
36   - EpisodeProvider episodeProvider, ConfigProvider configProvider,
37   - HttpProvider httpProvider)
38   - : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider)
39   - {
40   - }
41   -
42   - protected override string[] URL
43   - {
44   - get { return new[] {"www.google.com"}; }
45   - }
46   -
47   - protected override string Name
48   - {
49   - get { return "MyName"; }
50   - }
51   -
52   - protected override string NzbDownloadUrl(SyndicationItem item)
53   - {
54   - return item.Links[0].Uri.ToString();
55   - }
56   - }
57   -}
115 NzbDrone.Core/CentralDispatch.cs
... ... @@ -1,4 +1,5 @@
1 1 using System;
  2 +using System.Linq;
2 3 using System.Collections.Generic;
3 4 using System.Diagnostics;
4 5 using System.IO;
@@ -8,6 +9,7 @@
8 9 using NzbDrone.Core.Instrumentation;
9 10 using NzbDrone.Core.Providers;
10 11 using NzbDrone.Core.Providers.Core;
  12 +using NzbDrone.Core.Providers.Indexer;
11 13 using NzbDrone.Core.Repository;
12 14 using NzbDrone.Core.Repository.Quality;
13 15 using SubSonic.DataProviders;
@@ -72,7 +74,7 @@ public static void BindKernel()
72 74 _startupPath = AppPath;
73 75
74 76 //Sqlite
75   - var AppDataPath = new DirectoryInfo(Path.Combine(AppPath, "App_Data", "nzbdrone.db"));
  77 + var AppDataPath = new DirectoryInfo(Path.Combine(AppPath, "App_Data"));
76 78 if (!AppDataPath.Exists) AppDataPath.Create();
77 79
78 80 string connectionString = String.Format("Data Source={0};Version=3;",
@@ -109,12 +111,12 @@ public static void BindKernel()
109 111 _kernel.Bind<PostProcessingProvider>().ToSelf().InSingletonScope();
110 112 _kernel.Bind<ConfigProvider>().To<ConfigProvider>().InSingletonScope();
111 113 _kernel.Bind<SyncProvider>().ToSelf().InSingletonScope();
112   - _kernel.Bind<IndexerProvider>().ToSelf().InSingletonScope();
113 114 _kernel.Bind<RenameProvider>().ToSelf().InSingletonScope();
114 115 _kernel.Bind<NotificationProvider>().ToSelf().InSingletonScope();
115 116 _kernel.Bind<LogProvider>().ToSelf().InSingletonScope();
116 117 _kernel.Bind<MediaFileProvider>().ToSelf().InSingletonScope();
117 118 _kernel.Bind<TimerProvider>().ToSelf().InSingletonScope();
  119 + _kernel.Bind<IndexerProvider>().ToSelf().InSingletonScope();
118 120 _kernel.Bind<IRepository>().ToMethod(
119 121 c => new SimpleRepository(dbProvider, SimpleRepositoryOptions.RunMigrations)).InSingletonScope();
120 122
@@ -123,7 +125,6 @@ public static void BindKernel()
123 125 _kernel.Bind<IRepository>().ToConstant(logRepository).WhenInjectedInto<LogProvider>().InSingletonScope();
124 126
125 127 ForceMigration(_kernel.Get<IRepository>());
126   - SetupIndexers(_kernel.Get<IRepository>()); //Setup the default set of indexers on start-up
127 128 SetupDefaultQualityProfiles(_kernel.Get<IRepository>()); //Setup the default QualityProfiles on start-up
128 129
129 130 //Get the Timers going
@@ -131,9 +132,18 @@ public static void BindKernel()
131 132 var timer = _kernel.Get<TimerProvider>();
132 133 timer.SetRssSyncTimer(Convert.ToInt32(config.GetValue("SyncFrequency", "15", true)));
133 134 timer.StartRssSyncTimer();
  135 +
  136 + BindIndexers();
134 137 }
135 138 }
136 139
  140 + private static void BindIndexers()
  141 + {
  142 + _kernel.Bind<IndexerProviderBase>().To<NzbsOrgProvider>().InSingletonScope();
  143 + var indexers = _kernel.GetAll<IndexerProviderBase>();
  144 + _kernel.Get<IndexerProvider>().InitializeIndexers(indexers.ToList());
  145 + }
  146 +
137 147 private static void ForceMigration(IRepository repository)
138 148 {
139 149 repository.GetPaged<Series>(0, 1);
@@ -141,7 +151,6 @@ private static void ForceMigration(IRepository repository)
141 151 repository.GetPaged<Episode>(0, 1);
142 152 repository.GetPaged<Season>(0, 1);
143 153 repository.GetPaged<History>(0, 1);
144   - repository.GetPaged<Indexer>(0, 1);
145 154 }
146 155
147 156 /// <summary>
@@ -154,7 +163,7 @@ public static void DedicateToHost()
154 163 Logger.Debug("Attaching to parent process for automatic termination.");
155 164 var pc = new PerformanceCounter("Process", "Creating Process ID",
156 165 Process.GetCurrentProcess().ProcessName);
157   - var pid = (int) pc.NextValue();
  166 + var pid = (int)pc.NextValue();
158 167 var hostProcess = Process.GetProcessById(pid);
159 168
160 169 hostProcess.EnableRaisingEvents = true;
@@ -178,104 +187,13 @@ private static void ShutDown()
178 187 Process.GetCurrentProcess().Kill();
179 188 }
180 189
181   - private static void SetupIndexers(IRepository repository)
182   - {
183   - //Setup the default providers in the Providers table
184   -
185   - string nzbMatrixRss =
186   - "http://rss.nzbmatrix.com/rss.php?page=download&username={USERNAME}&apikey={APIKEY}&subcat=6,41&english=1";
187   - string nzbMatrixApi =
188   - "http://rss.nzbmatrix.com/rss.php?page=download&username={USERNAME}&apikey={APIKEY}&subcat=6,41&english=1&age={AGE}&term={TERM}";
189   - string nzbsOrgRss = "http://nzbs.org/rss.php?type=1&dl=1&num=100&i={UID}&h={HASH}";
190   - string nzbsOrgApi = String.Empty;
191   - string nzbsrusRss = "http://www.nzbsrus.com/rssfeed.php?cat=91,75&i={UID}&h={HASH}";
192   - string nzbsrusApi = String.Empty;
193   -
194   - var nzbMatrixIndexer = new Indexer
195   - {
196   - IndexerId = 1,
197   - IndexerName = "NzbMatrix",
198   - RssUrl = nzbMatrixRss,
199   - ApiUrl = nzbMatrixApi,
200   - Order = 1
201   - };
202   -
203   - var nzbsOrgIndexer = new Indexer
204   - {
205   - IndexerId = 2,
206   - IndexerName = "NzbsOrg",
207   - RssUrl = nzbsOrgRss,
208   - ApiUrl = nzbsOrgApi,
209   - Order = 2
210   - };
211   -
212   - var nzbsrusIndexer = new Indexer
213   - {
214   - IndexerId = 3,
215   - IndexerName = "Nzbsrus",
216   - RssUrl = nzbsrusRss,
217   - ApiUrl = nzbsrusApi,
218   - Order = 3
219   - };
220   -
221   - //NzbMatrix
222   - Logger.Debug("Checking for NzbMatrix Indexer");
223   - var nzbMatix = repository.Single<Indexer>(1);
224   - if (nzbMatix == null)
225   - {
226   - Logger.Debug("Adding new Indexer: NzbMatrix");
227   - repository.Add(nzbMatrixIndexer);
228   - }
229   -
230   - else
231   - {
232   - Logger.Debug("Updating Indexer: NzbMatrix");
233   - nzbMatix.RssUrl = nzbMatrixIndexer.RssUrl;
234   - nzbMatix.ApiUrl = nzbMatrixIndexer.ApiUrl;
235   - repository.Update(nzbMatix);
236   - }
237   -
238   - //Nzbs.org
239   - Logger.Debug("Checking for Nzbs.org");
240   - var nzbsOrg = repository.Single<Indexer>(2);
241   - if (nzbsOrg == null)
242   - {
243   - Logger.Debug("Adding new Indexer: Nzbs.org");
244   - repository.Add(nzbsOrgIndexer);
245   - }
246   -
247   - else
248   - {
249   - Logger.Debug("Updating Indexer: Nzbs.org");
250   - nzbsOrg.RssUrl = nzbsOrgIndexer.RssUrl;
251   - nzbsOrg.ApiUrl = nzbsOrgIndexer.ApiUrl;
252   - repository.Update(nzbsOrg);
253   - }
254   -
255   - //Nzbsrus
256   - Logger.Debug("Checking for Nzbsrus");
257   - var nzbsrus = repository.Single<Indexer>(3);
258   - if (nzbsrus == null)
259   - {
260   - Logger.Debug("Adding new Indexer: Nzbsrus");
261   - repository.Add(nzbsrusIndexer);
262   - }
263   -
264   - else
265   - {
266   - Logger.Debug("Updating Indexer: Nzbsrus");
267   - nzbsrus.RssUrl = nzbsOrgIndexer.RssUrl;
268   - nzbsrus.ApiUrl = nzbsOrgIndexer.ApiUrl;
269   - repository.Update(nzbsrus);
270   - }
271   - }
272 190
273 191 private static void SetupDefaultQualityProfiles(IRepository repository)
274 192 {
275 193 var sd = new QualityProfile
276 194 {
277 195 Name = "SD",
278   - Allowed = new List<QualityTypes> {QualityTypes.TV, QualityTypes.DVD},
  196 + Allowed = new List<QualityTypes> { QualityTypes.TV, QualityTypes.DVD },
279 197 Cutoff = QualityTypes.TV
280 198 };
281 199
@@ -283,8 +201,7 @@ private static void SetupDefaultQualityProfiles(IRepository repository)
283 201 {
284 202 Name = "HD",
285 203 Allowed =
286   - new List<QualityTypes>
287   - {QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.BDRip, QualityTypes.Bluray720},
  204 + new List<QualityTypes> { QualityTypes.HDTV, QualityTypes.WEBDL, QualityTypes.BDRip, QualityTypes.Bluray720 },
288 205 Cutoff = QualityTypes.HDTV
289 206 };
290 207
7 NzbDrone.Core/NzbDrone.Core.csproj
@@ -139,6 +139,7 @@
139 139 <SpecificVersion>False</SpecificVersion>
140 140 <HintPath>Libraries\NLog.Extended.dll</HintPath>
141 141 </Reference>
  142 + <Reference Include="NzbDrone.Core, Version=0.2.0.35870, Culture=neutral, processorArchitecture=MSIL" />
142 143 <Reference Include="SubSonic.Core, Version=3.0.0.3, Culture=neutral, processorArchitecture=MSIL">
143 144 <SpecificVersion>False</SpecificVersion>
144 145 <HintPath>Libraries\SubSonic.Core.dll</HintPath>
@@ -168,6 +169,7 @@
168 169 <Compile Include="Instrumentation\SubsonicTarget.cs" />
169 170 <Compile Include="Instrumentation\ExceptioneerTarget.cs" />
170 171 <Compile Include="Instrumentation\NlogWriter.cs" />
  172 + <Compile Include="Repository\IndexerSetting.cs" />
171 173 <Compile Include="Model\EpisodeParseResult.cs" />
172 174 <Compile Include="Model\EpisodeRenameModel.cs" />
173 175 <Compile Include="Model\EpisodeSortingType.cs" />
@@ -177,9 +179,9 @@
177 179 <Compile Include="Model\SceneNameModel.cs" />
178 180 <Compile Include="Model\SeasonParseResult.cs" />
179 181 <Compile Include="Model\UpcomingEpisodesModel.cs" />
180   - <Compile Include="Providers\Feed\FeedProviderBase.cs" />
  182 + <Compile Include="Providers\Indexer\IndexerProviderBase.cs" />
181 183 <Compile Include="Providers\ExternalNotificationProvider.cs" />
182   - <Compile Include="Providers\Feed\NzbsOrgFeedProvider.cs" />
  184 + <Compile Include="Providers\Indexer\NzbsOrgProvider.cs" />
183 185 <Compile Include="Providers\HistoryProvider.cs" />
184 186 <Compile Include="Providers\BacklogProvider.cs" />
185 187 <Compile Include="Providers\IndexerProvider.cs" />
@@ -210,7 +212,6 @@
210 212 <Compile Include="Repository\Episode.cs" />
211 213 <Compile Include="Instrumentation\Log.cs" />
212 214 <Compile Include="Repository\History.cs" />
213   - <Compile Include="Repository\Indexer.cs" />
214 215 <Compile Include="Repository\Config.cs" />
215 216 <Compile Include="Repository\Quality\QualityProfile.cs" />
216 217 <Compile Include="Repository\RootDir.cs" />
37 NzbDrone.Core/Providers/Feed/NzbsOrgFeedProvider.cs
... ... @@ -1,37 +0,0 @@
1   -using System.ServiceModel.Syndication;
2   -using NzbDrone.Core.Providers.Core;
3   -
4   -namespace NzbDrone.Core.Providers.Feed
5   -{
6   - internal class NzbsOrgFeedProvider : FeedProviderBase
7   - {
8   - public NzbsOrgFeedProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider,
9   - EpisodeProvider episodeProvider, ConfigProvider configProvider,
10   - HttpProvider httpProvider)
11   - : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider)
12   - {
13   - }
14   -
15   - protected override string[] URL
16   - {
17   - get
18   - {
19   - return new[]
20   - {
21   - string.Format("http://nzbs.org/rss.php?type=1&i={0}&h={1}", _configProvider.NzbsOrgUId,
22   - _configProvider.NzbsOrgHash)
23   - };
24   - }
25   - }
26   -
27   - protected override string Name
28   - {
29   - get { return "Nzbs.Org"; }
30   - }
31   -
32   - protected override string NzbDownloadUrl(SyndicationItem item)
33   - {
34   - return item.Id.Replace("action=view", "action=getnzb");
35   - }
36   - }
37   -}
40 NzbDrone.Core/Providers/Feed/FeedProviderBase.cs → ...one.Core/Providers/Indexer/IndexerProviderBase.cs
@@ -2,39 +2,45 @@
2 2 using NLog;
3 3 using NzbDrone.Core.Model;
4 4 using NzbDrone.Core.Providers.Core;
  5 +using NzbDrone.Core.Repository;
  6 +using SubSonic.Repository;
5 7
6   -namespace NzbDrone.Core.Providers.Feed
  8 +namespace NzbDrone.Core.Providers.Indexer
7 9 {
8   - public abstract class FeedProviderBase
  10 + public abstract class IndexerProviderBase
9 11 {
10 12 protected static readonly Logger Logger = LogManager.GetCurrentClassLogger();
11 13 protected readonly ConfigProvider _configProvider;
12 14 protected readonly EpisodeProvider _episodeProvider;
13 15 private readonly HttpProvider _httpProvider;
  16 + protected readonly IRepository _repository;
  17 + private readonly IndexerProvider _indexerProvider;
14 18 protected readonly SeasonProvider _seasonProvider;
15 19 protected readonly SeriesProvider _seriesProvider;
16 20
17   - public FeedProviderBase(SeriesProvider seriesProvider, SeasonProvider seasonProvider,
  21 +
  22 + public IndexerProviderBase(SeriesProvider seriesProvider, SeasonProvider seasonProvider,
18 23 EpisodeProvider episodeProvider, ConfigProvider configProvider,
19   - HttpProvider httpProvider)
  24 + HttpProvider httpProvider, IRepository repository, IndexerProvider indexerProvider)
20 25 {
21 26 _seriesProvider = seriesProvider;
22 27 _seasonProvider = seasonProvider;
23 28 _episodeProvider = episodeProvider;
24 29 _configProvider = configProvider;
25 30 _httpProvider = httpProvider;
  31 + _repository = repository;
  32 + _indexerProvider = indexerProvider;
26 33 }
27 34
28   -
29 35 /// <summary>
30 36 /// Gets the source URL for the feed
31 37 /// </summary>
32   - protected abstract string[] URL { get; }
  38 + protected abstract string[] Url { get; }
33 39
34 40 /// <summary>
35   - /// Gets the name for this feed
  41 + /// Gets the name for the feed
36 42 /// </summary>
37   - protected abstract string Name { get; }
  43 + public abstract string Name { get; }
38 44
39 45
40 46 /// <summary>
@@ -74,9 +80,9 @@ protected EpisodeParseResult ParseFeed(SyndicationItem item)
74 80 /// </summary>
75 81 public void Fetch()
76 82 {
77   - Logger.Info("Fetching feeds from " + Name);
  83 + Logger.Info("Fetching feeds from " + Settings.Name);
78 84
79   - foreach (var url in URL)
  85 + foreach (var url in Url)
80 86 {
81 87 Logger.Debug("Downloading RSS " + url);
82 88 var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items;
@@ -87,7 +93,7 @@ public void Fetch()
87 93 }
88 94 }
89 95
90   - Logger.Info("Finished processing feeds from " + Name);
  96 + Logger.Info("Finished processing feeds from " + Settings.Name);
91 97 }
92 98
93 99 private void ProcessItem(SyndicationItem feedItem)
@@ -119,5 +125,17 @@ private void ProcessItem(SyndicationItem feedItem)
119 125 }
120 126 }
121 127 }
  128 +
  129 + protected IndexerSetting Settings
  130 + {
  131 + get
  132 + {
  133 + return _indexerProvider.GetSettings(GetType());
  134 + }
  135 + }
  136 +
  137 +
  138 +
  139 +
122 140 }
123 141 }
38 NzbDrone.Core/Providers/Indexer/NzbsOrgProvider.cs
... ... @@ -0,0 +1,38 @@
  1 +using System.ServiceModel.Syndication;
  2 +using NzbDrone.Core.Providers.Core;
  3 +using SubSonic.Repository;
  4 +
  5 +namespace NzbDrone.Core.Providers.Indexer
  6 +{
  7 + public class NzbsOrgProvider : IndexerProviderBase
  8 + {
  9 + public NzbsOrgProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, ConfigProvider configProvider, HttpProvider httpProvider, IRepository repository, IndexerProvider indexerProvider)
  10 + : base(seriesProvider, seasonProvider, episodeProvider, configProvider, httpProvider, repository, indexerProvider)
  11 + {
  12 + }
  13 +
  14 + protected override string[] Url
  15 + {
  16 + get
  17 + {
  18 + return new[]
  19 + {
  20 + string.Format("http://nzbs.org/rss.php?type=1&i={0}&h={1}", _configProvider.NzbsOrgUId, _configProvider.NzbsOrgHash)
  21 + };
  22 + }
  23 + }
  24 +
  25 + public override string Name
  26 + {
  27 + get { return "Nzbs.org"; }
  28 + }
  29 +
  30 +
  31 + protected override string NzbDownloadUrl(SyndicationItem item)
  32 + {
  33 + return item.Id.Replace("action=view", "action=getnzb");
  34 + }
  35 +
  36 +
  37 + }
  38 +}
67 NzbDrone.Core/Providers/IndexerProvider.cs
... ... @@ -1,7 +1,9 @@
1   -using System.Collections.Generic;
  1 +using System;
  2 +using System.Collections.Generic;
2 3 using System.Linq;
3 4 using NLog;
4 5 using NzbDrone.Core.Providers.Core;
  6 +using NzbDrone.Core.Providers.Indexer;
5 7 using NzbDrone.Core.Repository;
6 8 using SubSonic.Repository;
7 9
@@ -10,33 +12,70 @@ namespace NzbDrone.Core.Providers
10 12 public class IndexerProvider
11 13 {
12 14 private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
13   - private readonly ConfigProvider _configProvider;
14   - private readonly IRepository _sonicRepo;
  15 + private readonly IRepository _repository;
15 16
16   - public IndexerProvider(IRepository sonicRepo, ConfigProvider configProvider)
  17 + public IndexerProvider(IRepository repository)
17 18 {
18   - _sonicRepo = sonicRepo;
19   - _configProvider = configProvider;
  19 + _repository = repository;
20 20 }
21 21
22   - public virtual List<Indexer> AllIndexers()
  22 + public IndexerProvider()
23 23 {
24   - return _sonicRepo.All<Indexer>().OrderBy(i => i.Order).ToList();
  24 +
  25 + }
  26 +
  27 + public virtual List<IndexerSetting> AllIndexers()
  28 + {
  29 + return _repository.All<IndexerSetting>().ToList();
  30 + }
  31 +
  32 + public virtual void SaveSettings(IndexerSetting settings)
  33 + {
  34 + if (settings.Id == 0)
  35 + {
  36 + Logger.Debug("Adding Indexer settings for {0}", settings.Name);
  37 + _repository.Add(settings);
  38 + }
  39 + else
  40 + {
  41 + Logger.Debug("Updating Indexer settings for {0}", settings.Name);
  42 + _repository.Update(settings);
  43 + }
25 44 }
26 45
27   - public virtual List<Indexer> EnabledIndexers()
  46 + public virtual IndexerSetting GetSettings(Type type)
28 47 {
29   - return _sonicRepo.All<Indexer>().Where(i => i.Enabled).OrderBy(i => i.Order).ToList();
  48 + return _repository.Single<IndexerSetting>(s => s.IndexProviderType == type.ToString());
30 49 }
31 50
32   - public virtual void Update(Indexer indexer)
  51 + public IndexerSetting GetSettings(int id)
33 52 {
34   - _sonicRepo.Update(indexer);
  53 + return _repository.Single<IndexerSetting>(s => s.Id == id);
35 54 }
36 55
37   - public virtual Indexer Single(int indexerId)
  56 + public virtual void InitializeIndexers(IList<IndexerProviderBase> indexers)
38 57 {
39   - return _sonicRepo.Single<Indexer>(indexerId);
  58 + Logger.Info("Initializing indexers. Count {0}", indexers.Count);
  59 +
  60 + var currentIndexers = AllIndexers();
  61 +
  62 + foreach (var feedProvider in indexers)
  63 + {
  64 + IndexerProviderBase indexerProviderLocal = feedProvider;
  65 + if (!currentIndexers.Exists(c => c.IndexProviderType == indexerProviderLocal.GetType().ToString()))
  66 + {
  67 + var settings = new IndexerSetting()
  68 + {
  69 + Enable = false,
  70 + IndexProviderType = indexerProviderLocal.GetType().ToString(),
  71 + Name = indexerProviderLocal.Name
  72 + };
  73 +
  74 + SaveSettings(settings);
  75 + }
  76 + }
40 77 }
  78 +
  79 +
41 80 }
42 81 }
3  NzbDrone.Core/Repository/History.cs
@@ -10,7 +10,6 @@ public class History
10 10 public virtual int HistoryId { get; set; }
11 11
12 12 public virtual int EpisodeId { get; set; }
13   - public virtual int IndexerId { get; set; }
14 13 public string NzbTitle { get; set; }
15 14 public QualityTypes Quality { get; set; }
16 15 public DateTime Date { get; set; }
@@ -19,7 +18,5 @@ public class History
19 18 [SubSonicToOneRelation(ThisClassContainsJoinKey = true)]
20 19 public virtual Episode Episode { get; private set; }
21 20
22   - [SubSonicToOneRelation(ThisClassContainsJoinKey = true)]
23   - public virtual Indexer Indexer { get; private set; }
24 21 }
25 22 }
25 NzbDrone.Core/Repository/Indexer.cs
... ... @@ -1,25 +0,0 @@
1   -using System.Collections.Generic;
2   -using System.ComponentModel.DataAnnotations;
3   -using SubSonic.SqlGeneration.Schema;
4   -
5   -namespace NzbDrone.Core.Repository
6   -{
7   - public class Indexer
8   - {
9   - [SubSonicPrimaryKey]
10   - public virtual int IndexerId { get; set; }
11   -
12   - public string IndexerName { get; set; }
13   - public string RssUrl { get; set; }
14   -
15   - [SubSonicNullStringAttribute]
16   - [DisplayFormat(ConvertEmptyStringToNull = false)]
17   - public string ApiUrl { get; set; }
18   -
19   - public bool Enabled { get; set; }
20   - public int Order { get; set; }
21   -
22   - [SubSonicToManyRelation]
23   - public virtual List<History> Histories { get; private set; }
24   - }
25   -}
17 NzbDrone.Core/Repository/IndexerSetting.cs
... ... @@ -0,0 +1,17 @@
  1 +using System;
  2 +using SubSonic.SqlGeneration.Schema;
  3 +
  4 +namespace NzbDrone.Core.Repository
  5 +{
  6 + public class IndexerSetting
  7 + {
  8 + [SubSonicPrimaryKey(true)]
  9 + public int Id { get; set; }
  10 +
  11 + public Boolean Enable { get; set; }
  12 +
  13 + public String IndexProviderType { get; set; }
  14 +
  15 + public String Name { get; set; }
  16 + }
  17 +}
35 NzbDrone.Web/Controllers/SettingsController.cs
@@ -7,6 +7,7 @@
7 7 using NzbDrone.Core.Model;
8 8 using NzbDrone.Core.Providers;
9 9 using NzbDrone.Core.Providers.Core;
  10 +using NzbDrone.Core.Providers.Indexer;
10 11 using NzbDrone.Core.Repository;
11 12 using NzbDrone.Core.Repository.Quality;
12 13 using NzbDrone.Web.Models;
@@ -63,11 +64,15 @@ public ActionResult Indexers()
63 64 _configProvider.GetValue("NzbMatrixUsername", String.Empty, true),
64 65 NzbMatrixApiKey =
65 66 _configProvider.GetValue("NzbMatrixApiKey", String.Empty, true),
66   - NzbsOrgUId = _configProvider.GetValue("NzbsOrgUId", String.Empty, true),
67   - NzbsOrgHash = _configProvider.GetValue("NzbsOrgHash", String.Empty, true),
  67 +
68 68 NzbsrusUId = _configProvider.GetValue("NzbsrusUId", String.Empty, true),
69 69 NzbsrusHash = _configProvider.GetValue("NzbsrusHash", String.Empty, true),
  70 +
  71 + NzbsOrgHash = _configProvider.NzbsrusHash,
  72 + NzbsOrgUId = _configProvider.NzbsrusUId,
  73 +
70 74 Indexers = _indexerProvider.AllIndexers()
  75 +
71 76 });
72 77 }
73 78
@@ -89,7 +94,7 @@ public ActionResult Downloads()
89 94 SabTvCategory = _configProvider.GetValue("SabTvCategory", String.Empty, true),
90 95 SabTvPriority =
91 96 (SabnzbdPriorityType)
92   - Enum.Parse(typeof (SabnzbdPriorityType),
  97 + Enum.Parse(typeof(SabnzbdPriorityType),
93 98 _configProvider.GetValue("SabTvPriority", "Normal", true)),
94 99 UseBlackHole = Convert.ToBoolean(_configProvider.GetValue("UseBlackHole", true, true)),
95 100 BlackholeDirectory = _configProvider.GetValue("BlackholeDirectory", String.Empty, true)
@@ -104,7 +109,7 @@ public ActionResult Quality()
104 109
105 110 var qualityTypes = new List<QualityTypes>();
106 111
107   - foreach (QualityTypes qual in Enum.GetValues(typeof (QualityTypes)))
  112 + foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes)))
108 113 {
109 114 qualityTypes.Add(qual);
110 115 }
@@ -192,14 +197,14 @@ public ViewResult AddUserProfile()
192 197 {
193 198 var qualityTypes = new List<QualityTypes>();
194 199
195   - foreach (QualityTypes qual in Enum.GetValues(typeof (QualityTypes)))
  200 + foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes)))
196 201 {
197 202 qualityTypes.Add(qual);
198 203 }
199 204
200 205 ViewData["Qualities"] = qualityTypes;
201 206
202   - return View("UserProfileSection", new QualityProfile {Name = "New Profile", UserProfile = true});
  207 + return View("UserProfileSection", new QualityProfile { Name = "New Profile", UserProfile = true });
203 208 }
204 209
205 210 public ViewResult AddRootDir()
@@ -219,7 +224,7 @@ public QualityModel GetUpdatedProfileList()
219 224 Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", profiles[0].QualityProfileId, true));
220 225 var selectList = new SelectList(profiles, "QualityProfileId", "Name");
221 226
222   - return new QualityModel {DefaultQualityProfileId = defaultQualityQualityProfileId, SelectList = selectList};
  227 + return new QualityModel { DefaultQualityProfileId = defaultQualityQualityProfileId, SelectList = selectList };
223 228 }
224 229
225 230 [HttpPost]
@@ -263,17 +268,23 @@ public ActionResult SaveIndexers(IndexerSettingsModel data)
263 268 {
264 269 if (ModelState.IsValid)
265 270 {
266   - //Todo: Only allow indexers to be enabled if user information has been provided
267 271 foreach (var indexer in data.Indexers)
268   - _indexerProvider.Update(indexer);
  272 + {
  273 + var setting =_indexerProvider.GetSettings(indexer.Id);
  274 + setting.Enable = indexer.Enable;
  275 + _indexerProvider.SaveSettings(setting);
  276 + }
269 277
270 278 _configProvider.NzbMatrixUsername = data.NzbMatrixUsername;
271 279 _configProvider.NzbMatrixApiKey = data.NzbMatrixApiKey;
272   - _configProvider.NzbsOrgUId = data.NzbsOrgUId;
273   - _configProvider.NzbsOrgHash = data.NzbsOrgHash;
274 280 _configProvider.NzbsrusUId = data.NzbsrusUId;
275 281 _configProvider.NzbsrusHash = data.NzbsrusHash;
276 282
  283 + var nzbsOrgSettings = _indexerProvider.GetSettings(typeof(NzbsOrgProvider));
  284 + _configProvider.NzbsrusHash = data.NzbsOrgHash;
  285 + _configProvider.NzbsOrgUId = data.NzbsOrgUId;
  286 +
  287 +
277 288 return Content(SETTINGS_SAVED);
278 289 }
279 290
@@ -328,7 +339,7 @@ public ActionResult SaveQuality(QualityModel data)
328 339 profile.Allowed = new List<QualityTypes>();
329 340 foreach (var quality in profile.AllowedString.Split(','))
330 341 {
331   - var qType = (QualityTypes) Enum.Parse(typeof (QualityTypes), quality);
  342 + var qType = (QualityTypes)Enum.Parse(typeof(QualityTypes), quality);
332 343 profile.Allowed.Add(qType);
333 344 }
334 345
8 NzbDrone.Web/Global.asax.cs
@@ -20,14 +20,14 @@ public class MvcApplication : NinjectHttpApplication
20 20 public static void RegisterRoutes(RouteCollection routes)
21 21 {
22 22 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
23   - routes.IgnoreRoute("{*robotstxt}", new {robotstxt = @"(.*/)?robots.txt(/.*)?"});
24   - routes.IgnoreRoute("{*favicon}", new {favicon = @"(.*/)?favicon.ico(/.*)?"});
  23 + routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" });
  24 + routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
25 25
26 26
27 27 routes.MapRoute(
28 28 "Default", // Route name
29 29 "{controller}/{action}/{id}", // URL with parameters
30   - new {controller = "Series", action = "Index", id = UrlParameter.Optional} // Parameter defaults
  30 + new { controller = "Series", action = "Index", id = UrlParameter.Optional } // Parameter defaults
31 31 );
32 32 }
33 33
@@ -75,7 +75,7 @@ protected void Application_Error(object sender, EventArgs e)
75 75 return;
76 76 }
77 77
78   - Logger.FatalException(lastError.Message, lastError);
  78 + Logger.FatalException(lastError.Message + Environment.NewLine + Request.Url.PathAndQuery, lastError);
79 79
80 80 if (lastError is SQLiteException)
81 81 {
2  NzbDrone.Web/Models/IndexerSettingsModel.cs
@@ -38,6 +38,6 @@ public class IndexerSettingsModel
38 38 [DisplayFormat(ConvertEmptyStringToNull = false)]
39 39 public String NzbsrusHash { get; set; }
40 40
41   - public List<Indexer> Indexers { get; set; }
  41 + public List<IndexerSetting> Indexers { get; set; }
42 42 }
43 43 }
9 NzbDrone.Web/NzbDrone.Web.csproj
@@ -812,6 +812,15 @@
812 812 <VisualStudio>
813 813 <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
814 814 <WebProjectProperties>
  815 + <UseIIS>False</UseIIS>
  816 + <AutoAssignPort>True</AutoAssignPort>
  817 + <DevelopmentServerPort>21704</DevelopmentServerPort>
  818 + <DevelopmentServerVPath>/</DevelopmentServerVPath>
  819 + <IISUrl>http://localhost/NzbDrone</IISUrl>
  820 + <NTLMAuthentication>False</NTLMAuthentication>
  821 + <UseCustomServer>False</UseCustomServer>
  822 + <CustomServerUrl>http://localhost:8989</CustomServerUrl>
  823 + <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
815 824 <SaveServerSettingsInUserFile>True</SaveServerSettingsInUserFile>
816 825 </WebProjectProperties>
817 826 </FlavorProperties>
207 NzbDrone.Web/Views/Settings/Indexers.ascx
... ... @@ -1,10 +1,8 @@
1 1 <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NzbDrone.Web.Models.IndexerSettingsModel>" %>
2   -
3 2 <script type="text/javascript">
4 3 $(document).ready(function () {
5 4 var options = {
6 5 target: '#result',
7   - beforeSerialize: saveOrder,
8 6 beforeSubmit: showRequest,
9 7 success: showResponse,
10 8 type: 'post',
@@ -14,21 +12,6 @@
14 12 $('#save_button').attr('disabled', '');
15 13 });
16 14
17   - function saveOrder(jqForm, options) {
18   - //Save the order of the sortable
19   -
20   - var sortResult = $('#sortable').sortable("toArray");
21   -
22   - var firstPart = "Indexers_";
23   - var secondPart = "__Order";
24   -
25   - jQuery.each(sortResult, function (index, value) {
26   - var id = firstPart + value + secondPart;
27   - var newValue = index + 1;
28   - $("#" + id).val(newValue);