indexer cleanup.

pull/4/head
kay.one 11 years ago committed by kayone
parent 9dbfc6804f
commit 3e9a6ed0ef

@ -4,26 +4,16 @@ using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers.Eztv
{
public class Eztv : IndexerBase<NullSetting>
public class Eztv : IndexerBase<NullConfig>
{
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<string> 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];
}
}

@ -7,7 +7,7 @@ namespace NzbDrone.Core.Indexers
public interface IIndexer : IProvider
{
IParseFeed Parser { get; }
IndexerKind Kind { get; }
DownloadProtocol Protocol { get; }
IEnumerable<string> RecentFeed { get; }
IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int episodeNumber);

@ -6,7 +6,13 @@ namespace NzbDrone.Core.Indexers
{
public abstract class IndexerBase<TSettings> : IIndexer
{
public abstract string Name { get; }
public Type ConfigContract
{
get
{
return typeof(TSettings);
}
}
public virtual IEnumerable<ProviderDefinition> 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<string> GetEpisodeSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int episodeNumber);
public abstract IEnumerable<string> GetDailyEpisodeSearchUrls(string seriesTitle, int tvRageId, DateTime date);
public abstract IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int offset);
public override string ToString()
{
return GetType().Name;
}
}
public enum IndexerKind
public enum DownloadProtocol
{
Usenet,
Torrent

@ -33,11 +33,11 @@ namespace NzbDrone.Core.Indexers
public virtual IList<ReleaseInfo> 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;
}

@ -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<IIndexer, IndexerDefinition>
{
private readonly IProviderRepository<IndexerDefinition> _providerRepository;
private readonly IEnumerable<IIndexer> _providers;
public IndexerService(IProviderRepository<IndexerDefinition> providerRepository, IEnumerable<IIndexer> 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<IndexerDefinition>().ToList());
}
}
}
}

@ -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<int> { 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");
}
}
}
}

@ -5,16 +5,11 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
{
public class Omgwtfnzbs : IndexerBase<OmgwtfnzbsSettings>
{
public override string Name
{
get { return "omgwtfnzbs"; }
}
public override IndexerKind Kind
public override DownloadProtocol Protocol
{
get
{
return IndexerKind.Usenet;
return DownloadProtocol.Usenet;
}
}

@ -4,18 +4,13 @@ using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers.Wombles
{
public class Wombles : IndexerBase<NullSetting>
public class Wombles : IndexerBase<NullConfig>
{
public override string Name
{
get { return "WomblesIndex"; }
}
public override IndexerKind Kind
public override DownloadProtocol Protocol
{
get
{
return IndexerKind.Usenet;
return DownloadProtocol.Usenet;
}
}

@ -30,7 +30,7 @@ namespace NzbDrone.Core.ThingiProvider
public interface IProvider
{
string Name { get; }
Type ConfigContract { get; }
IEnumerable<ProviderDefinition> 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()
{

@ -52,21 +52,21 @@ namespace NzbDrone.Core.ThingiProvider
return _providerRepository.Get(id);
}
/* public List<TProvider> Schema()
{
var indexers = new List<Indexer>();
/* public List<TProvider> Schema()
{
var indexers = new List<Indexer>();
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<TProviderDefinition>().ToList());
}
protected virtual void InitializeProviders()
{
}
private void RemoveMissingImplementations()

Loading…
Cancel
Save