From 3e9a6ed0ef1a256508c6d58acb7fca4f49e55b40 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 22 Sep 2013 13:00:29 -0700 Subject: [PATCH] indexer cleanup. --- NzbDrone.Core/Indexers/Eztv/Eztv.cs | 23 +++-------- NzbDrone.Core/Indexers/IIndexer.cs | 2 +- NzbDrone.Core/Indexers/IndexerBase.cs | 24 ++++++++---- NzbDrone.Core/Indexers/IndexerFetchService.cs | 19 +++++----- NzbDrone.Core/Indexers/IndexerService.cs | 21 ++++++++++ NzbDrone.Core/Indexers/Newznab/Newznab.cs | 16 ++------ .../Indexers/Omgwtfnzbs/Omgwtfnzbs.cs | 9 +---- NzbDrone.Core/Indexers/Wombles/Wombles.cs | 11 ++---- NzbDrone.Core/ThingiProvider/IProvider.cs | 7 ++-- .../ThingiProvider/ProviderService.cs | 38 ++++++++----------- 10 files changed, 81 insertions(+), 89 deletions(-) diff --git a/NzbDrone.Core/Indexers/Eztv/Eztv.cs b/NzbDrone.Core/Indexers/Eztv/Eztv.cs index 8b514f255..52c55df60 100644 --- a/NzbDrone.Core/Indexers/Eztv/Eztv.cs +++ b/NzbDrone.Core/Indexers/Eztv/Eztv.cs @@ -4,26 +4,16 @@ using NzbDrone.Core.ThingiProvider; namespace NzbDrone.Core.Indexers.Eztv { - public class Eztv : IndexerBase + public class Eztv : IndexerBase { - public override string Name - { - get { return "Eztv"; } - } - - public override IndexerKind Kind + public override DownloadProtocol Protocol { get { - return IndexerKind.Torrent; + return DownloadProtocol.Torrent; } } - public override bool EnableByDefault - { - get { return false; } - } - public override IParseFeed Parser { get @@ -36,10 +26,7 @@ namespace NzbDrone.Core.Indexers.Eztv { get { - return new[] - { - "http://www.ezrss.it/feed/" - }; + yield return "http://www.ezrss.it/feed/"; } } @@ -56,7 +43,7 @@ namespace NzbDrone.Core.Indexers.Eztv public override IEnumerable GetDailyEpisodeSearchUrls(string seriesTitle, int tvRageId, DateTime date) { - //EZTV doesn't support searching based on actual epidose airdate. they only support release date. + //EZTV doesn't support searching based on actual episode airdate. they only support release date. return new string[0]; } } diff --git a/NzbDrone.Core/Indexers/IIndexer.cs b/NzbDrone.Core/Indexers/IIndexer.cs index 9e77b433d..34daa6a26 100644 --- a/NzbDrone.Core/Indexers/IIndexer.cs +++ b/NzbDrone.Core/Indexers/IIndexer.cs @@ -7,7 +7,7 @@ namespace NzbDrone.Core.Indexers public interface IIndexer : IProvider { IParseFeed Parser { get; } - IndexerKind Kind { get; } + DownloadProtocol Protocol { get; } IEnumerable RecentFeed { get; } IEnumerable GetEpisodeSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int episodeNumber); diff --git a/NzbDrone.Core/Indexers/IndexerBase.cs b/NzbDrone.Core/Indexers/IndexerBase.cs index 604f536c9..ddedc098c 100644 --- a/NzbDrone.Core/Indexers/IndexerBase.cs +++ b/NzbDrone.Core/Indexers/IndexerBase.cs @@ -6,7 +6,13 @@ namespace NzbDrone.Core.Indexers { public abstract class IndexerBase : IIndexer { - public abstract string Name { get; } + public Type ConfigContract + { + get + { + return typeof(TSettings); + } + } public virtual IEnumerable DefaultDefinitions { @@ -14,19 +20,17 @@ namespace NzbDrone.Core.Indexers { yield return new IndexerDefinition { - Name = Name, + Name = this.GetType().Name, Enable = false, Implementation = GetType().Name, - Settings = NullSetting.Instance + Settings = NullConfig.Instance }; } } public ProviderDefinition Definition { get; set; } - public abstract IndexerKind Kind { get; } - - public virtual bool EnableByDefault { get { return true; } } + public abstract DownloadProtocol Protocol { get; } protected TSettings Settings { @@ -42,9 +46,15 @@ namespace NzbDrone.Core.Indexers public abstract IEnumerable GetEpisodeSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int episodeNumber); public abstract IEnumerable GetDailyEpisodeSearchUrls(string seriesTitle, int tvRageId, DateTime date); public abstract IEnumerable GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int offset); + + + public override string ToString() + { + return GetType().Name; + } } - public enum IndexerKind + public enum DownloadProtocol { Usenet, Torrent diff --git a/NzbDrone.Core/Indexers/IndexerFetchService.cs b/NzbDrone.Core/Indexers/IndexerFetchService.cs index ba284c8b7..d9457f58b 100644 --- a/NzbDrone.Core/Indexers/IndexerFetchService.cs +++ b/NzbDrone.Core/Indexers/IndexerFetchService.cs @@ -33,11 +33,11 @@ namespace NzbDrone.Core.Indexers public virtual IList FetchRss(IIndexer indexer) { - _logger.Debug("Fetching feeds from " + indexer.Name); + _logger.Debug("Fetching feeds from " + indexer); var result = Fetch(indexer, indexer.RecentFeed); - _logger.Debug("Finished processing feeds from " + indexer.Name); + _logger.Debug("Finished processing feeds from " + indexer); return result; } @@ -48,7 +48,7 @@ namespace NzbDrone.Core.Indexers var result = Fetch(indexer, searchCriteria, 0).DistinctBy(c => c.DownloadUrl).ToList(); - _logger.Info("Finished searching {0} for {1}. Found {2}", indexer.Name, searchCriteria, result.Count); + _logger.Info("Finished searching {0} for {1}. Found {2}", indexer, searchCriteria, result.Count); return result; } @@ -61,7 +61,7 @@ namespace NzbDrone.Core.Indexers var result = Fetch(indexer, searchUrls); - _logger.Info("{0} offset {1}. Found {2}", indexer.Name, searchCriteria, result.Count); + _logger.Info("{0} offset {1}. Found {2}", indexer, searchCriteria, result.Count); if (result.Count > 90) { @@ -79,7 +79,7 @@ namespace NzbDrone.Core.Indexers var result = Fetch(indexer, searchUrls); - _logger.Info("Finished searching {0} for {1}. Found {2}", indexer.Name, searchCriteria, result.Count); + _logger.Info("Finished searching {0} for {1}. Found {2}", indexer, searchCriteria, result.Count); return result; } @@ -90,7 +90,7 @@ namespace NzbDrone.Core.Indexers var searchUrls = indexer.GetDailyEpisodeSearchUrls(searchCriteria.QueryTitle, searchCriteria.Series.TvRageId, searchCriteria.Airtime); var result = Fetch(indexer, searchUrls); - _logger.Info("Finished searching {0} for {1}. Found {2}", indexer.Name, searchCriteria, result.Count); + _logger.Info("Finished searching {0} for {1}. Found {2}", indexer, searchCriteria, result.Count); return result; } @@ -119,12 +119,11 @@ namespace NzbDrone.Core.Indexers if (webException.Message.Contains("502") || webException.Message.Contains("503") || webException.Message.Contains("timed out")) { - _logger.Warn("{0} server is currently unavailable. {1} {2}", indexer.Name, url, - webException.Message); + _logger.Warn("{0} server is currently unavailable. {1} {2}", indexer, url, webException.Message); } else { - _logger.Warn("{0} {1} {2}", indexer.Name, url, webException.Message); + _logger.Warn("{0} {1} {2}", indexer, url, webException.Message); } } catch (ApiKeyException) @@ -138,7 +137,7 @@ namespace NzbDrone.Core.Indexers } } - result.ForEach(c => c.Indexer = indexer.Name); + result.ForEach(c => c.Indexer = indexer.Definition.Name); return result; } diff --git a/NzbDrone.Core/Indexers/IndexerService.cs b/NzbDrone.Core/Indexers/IndexerService.cs index cd4a8a11e..e56531438 100644 --- a/NzbDrone.Core/Indexers/IndexerService.cs +++ b/NzbDrone.Core/Indexers/IndexerService.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using NLog; using NzbDrone.Core.ThingiProvider; @@ -11,9 +12,29 @@ namespace NzbDrone.Core.Indexers public class IndexerService : ProviderFactory { + private readonly IProviderRepository _providerRepository; + private readonly IEnumerable _providers; + public IndexerService(IProviderRepository providerRepository, IEnumerable providers, Logger logger) : base(providerRepository, providers, logger) { + _providerRepository = providerRepository; + _providers = providers; + } + + protected override void InitializeProviders() + { + var definitions = _providers.SelectMany(indexer => indexer.DefaultDefinitions); + + var currentProviders = All(); + + var newProviders = definitions.Where(def => currentProviders.All(c => c.Implementation != def.Implementation)).ToList(); + + + if (newProviders.Any()) + { + _providerRepository.InsertMany(newProviders.Cast().ToList()); + } } } } \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/NzbDrone.Core/Indexers/Newznab/Newznab.cs index 980513aa0..a4c106846 100644 --- a/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -69,7 +69,7 @@ namespace NzbDrone.Core.Indexers.Newznab get { //Todo: We should be able to update settings on start - if (Name.Equals("nzbs.org", StringComparison.InvariantCultureIgnoreCase)) + if (Settings.Url.Contains("nzbs.org")) { Settings.Categories = new List { 5000 }; } @@ -115,19 +115,11 @@ namespace NzbDrone.Core.Indexers.Newznab return RecentFeed.Select(url => String.Format("{0}&limit=100&q={1}&season={2}&offset={3}", url, NewsnabifyTitle(seriesTitle), seasonNumber, offset)); } - public override string Name + public override DownloadProtocol Protocol { get { - return Definition.Name; - } - } - - public override IndexerKind Kind - { - get - { - return IndexerKind.Usenet; + return DownloadProtocol.Usenet; } } @@ -136,4 +128,4 @@ namespace NzbDrone.Core.Indexers.Newznab return title.Replace("+", "%20"); } } -} \ No newline at end of file +} diff --git a/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs b/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs index 4c281910e..c4daeab66 100644 --- a/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs +++ b/NzbDrone.Core/Indexers/Omgwtfnzbs/Omgwtfnzbs.cs @@ -5,16 +5,11 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs { public class Omgwtfnzbs : IndexerBase { - public override string Name - { - get { return "omgwtfnzbs"; } - } - - public override IndexerKind Kind + public override DownloadProtocol Protocol { get { - return IndexerKind.Usenet; + return DownloadProtocol.Usenet; } } diff --git a/NzbDrone.Core/Indexers/Wombles/Wombles.cs b/NzbDrone.Core/Indexers/Wombles/Wombles.cs index 2f455219e..5355d853d 100644 --- a/NzbDrone.Core/Indexers/Wombles/Wombles.cs +++ b/NzbDrone.Core/Indexers/Wombles/Wombles.cs @@ -4,18 +4,13 @@ using NzbDrone.Core.ThingiProvider; namespace NzbDrone.Core.Indexers.Wombles { - public class Wombles : IndexerBase + public class Wombles : IndexerBase { - public override string Name - { - get { return "WomblesIndex"; } - } - - public override IndexerKind Kind + public override DownloadProtocol Protocol { get { - return IndexerKind.Usenet; + return DownloadProtocol.Usenet; } } diff --git a/NzbDrone.Core/ThingiProvider/IProvider.cs b/NzbDrone.Core/ThingiProvider/IProvider.cs index 4d64ea8ec..7baeb4bc7 100644 --- a/NzbDrone.Core/ThingiProvider/IProvider.cs +++ b/NzbDrone.Core/ThingiProvider/IProvider.cs @@ -30,7 +30,7 @@ namespace NzbDrone.Core.ThingiProvider public interface IProvider { - string Name { get; } + Type ConfigContract { get; } IEnumerable DefaultDefinitions { get; } ProviderDefinition Definition { get; set; } @@ -51,7 +51,6 @@ namespace NzbDrone.Core.ThingiProvider } set { - } } @@ -63,9 +62,9 @@ namespace NzbDrone.Core.ThingiProvider ValidationResult Validate(); } - public class NullSetting : IProviderConfig + public class NullConfig : IProviderConfig { - public static readonly NullSetting Instance = new NullSetting(); + public static readonly NullConfig Instance = new NullConfig(); public ValidationResult Validate() { diff --git a/NzbDrone.Core/ThingiProvider/ProviderService.cs b/NzbDrone.Core/ThingiProvider/ProviderService.cs index c55529ec1..c09a1d79c 100644 --- a/NzbDrone.Core/ThingiProvider/ProviderService.cs +++ b/NzbDrone.Core/ThingiProvider/ProviderService.cs @@ -52,21 +52,21 @@ namespace NzbDrone.Core.ThingiProvider return _providerRepository.Get(id); } - /* public List Schema() - { - var indexers = new List(); + /* public List Schema() + { + var indexers = new List(); - var newznab = new Indexer(); - newznab.Instance = new Newznab.Newznab(); - newznab.Id = 1; - newznab.Name = "Newznab"; - newznab.Settings = new NewznabSettings(); - newznab.Implementation = "Newznab"; + var newznab = new Indexer(); + newznab.Instance = new Newznab.Newznab(); + newznab.Id = 1; + newznab.Name = "Newznab"; + newznab.Settings = new NewznabSettings(); + newznab.Implementation = "Newznab"; - indexers.Add(newznab); + indexers.Add(newznab); - return indexers; - }*/ + return indexers; + }*/ public TProviderDefinition Create(TProviderDefinition provider) { @@ -102,17 +102,11 @@ namespace NzbDrone.Core.ThingiProvider RemoveMissingImplementations(); - var definitions = _providers.SelectMany(indexer => indexer.DefaultDefinitions); - - var currentProviders = All(); - - var newProviders = definitions.Where(def => currentProviders.All(c => c.Implementation != def.Implementation)).ToList(); - + InitializeProviders(); + } - if (newProviders.Any()) - { - _providerRepository.InsertMany(newProviders.Cast().ToList()); - } + protected virtual void InitializeProviders() + { } private void RemoveMissingImplementations()