added torrent feature toggle.

dropped NzbClub.
pull/4/head
Keivan Beigi 11 years ago
parent 771e366441
commit 5fc4cd29a3

@ -6,7 +6,6 @@ using Moq;
using NUnit.Framework;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Indexers.NzbClub;
using NzbDrone.Core.Indexers.Omgwtfnzbs;
using NzbDrone.Core.Indexers.Wombles;
using NzbDrone.Core.Lifecycle;
@ -24,7 +23,6 @@ namespace NzbDrone.Core.Test.IndexerTests
_indexers = new List<IIndexer>();
_indexers.Add(new Newznab());
_indexers.Add(new NzbClub());
_indexers.Add(new Omgwtfnzbs());
_indexers.Add(new Wombles());

@ -3,7 +3,6 @@ using FluentAssertions;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Eztv;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Indexers.NzbClub;
using NzbDrone.Core.Indexers.Wombles;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
@ -23,17 +22,6 @@ namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests
}
[Test]
[Explicit]
public void nzbclub_rss()
{
var indexer = new NzbClub();
var result = Subject.FetchRss(indexer);
ValidateResult(result);
}
[Test]
public void wombles_rss()
{

@ -26,13 +26,13 @@ namespace NzbDrone.Core.Configuration
string Password { get; }
string LogLevel { get; }
string Branch { get; }
bool Torrent { get; }
}
public class ConfigFileProvider : IConfigFileProvider
{
private const string CONFIG_ELEMENT_NAME = "Config";
private readonly IAppFolderInfo _appFolderInfo;
private readonly IMessageAggregator _messageAggregator;
private readonly ICached<string> _cache;
@ -40,10 +40,9 @@ namespace NzbDrone.Core.Configuration
public ConfigFileProvider(IAppFolderInfo appFolderInfo, ICacheManger cacheManger, IMessageAggregator messageAggregator)
{
_appFolderInfo = appFolderInfo;
_cache = cacheManger.GetCache<string>(GetType());
_messageAggregator = messageAggregator;
_configFile = _appFolderInfo.GetConfigPath();
_configFile = appFolderInfo.GetConfigPath();
}
public Dictionary<string, object> GetConfigDictionary()
@ -96,6 +95,11 @@ namespace NzbDrone.Core.Configuration
get { return GetValueBoolean("LaunchBrowser", true); }
}
public bool Torrent
{
get { return GetValueBoolean("Torrent", false, persist: false); }
}
public bool AuthenticationEnabled
{
get { return GetValueBoolean("AuthenticationEnabled", false); }
@ -126,9 +130,9 @@ namespace NzbDrone.Core.Configuration
return Convert.ToInt32(GetValue(key, defaultValue));
}
public bool GetValueBoolean(string key, bool defaultValue)
public bool GetValueBoolean(string key, bool defaultValue, bool persist = true)
{
return Convert.ToBoolean(GetValue(key, defaultValue));
return Convert.ToBoolean(GetValue(key, defaultValue, persist));
}
public T GetValueEnum<T>(string key, T defaultValue)
@ -136,7 +140,7 @@ namespace NzbDrone.Core.Configuration
return (T)Enum.Parse(typeof(T), GetValue(key, defaultValue), true);
}
public string GetValue(string key, object defaultValue)
public string GetValue(string key, object defaultValue, bool persist = true)
{
return _cache.Get(key, () =>
{
@ -153,7 +157,10 @@ namespace NzbDrone.Core.Configuration
return valueHolder.First().Value;
//Save the value
SetValue(key, defaultValue);
if (persist)
{
SetValue(key, defaultValue);
}
//return the default value
return defaultValue.ToString();
@ -233,7 +240,7 @@ namespace NzbDrone.Core.Configuration
catch (XmlException ex)
{
throw new InvalidConfigFileException("config.xml is invalid, please see the wiki for steps to resolve this issue.", ex);
throw new InvalidConfigFileException(_configFile + " is invalid, please see the http://wiki.nzbdrone.com for steps to resolve this issue.", ex);
}
}

@ -10,6 +10,14 @@ namespace NzbDrone.Core.Indexers.Eztv
get { return "Eztv"; }
}
public override IndexerKind Kind
{
get
{
return IndexerKind.Torrent;
}
}
public override bool EnableByDefault
{
get { return false; }

@ -16,6 +16,7 @@ namespace NzbDrone.Core.Indexers
IEnumerable<string> RecentFeed { get; }
IParseFeed Parser { get; }
IndexerKind Kind { get; }
IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int episodeNumber);
IEnumerable<string> GetDailyEpisodeSearchUrls(string seriesTitle, int tvRageId, DateTime date);

@ -7,6 +7,8 @@ namespace NzbDrone.Core.Indexers
{
public abstract string Name { get; }
public abstract IndexerKind Kind { get; }
public virtual bool EnableByDefault { get { return true; } }
public IndexerDefinition InstanceDefinition { get; set; }
@ -32,4 +34,10 @@ namespace NzbDrone.Core.Indexers
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 enum IndexerKind
{
Usenet,
Torrent
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging;
@ -35,15 +36,26 @@ namespace NzbDrone.Core.Indexers
public class IndexerService : IIndexerService, IHandle<ApplicationStartedEvent>
{
private readonly IIndexerRepository _indexerRepository;
private readonly IConfigFileProvider _configFileProvider;
private readonly Logger _logger;
private readonly List<IIndexer> _indexers;
public IndexerService(IIndexerRepository indexerRepository, IEnumerable<IIndexer> indexers, Logger logger)
public IndexerService(IIndexerRepository indexerRepository, IEnumerable<IIndexer> indexers, IConfigFileProvider configFileProvider, Logger logger)
{
_indexerRepository = indexerRepository;
_configFileProvider = configFileProvider;
_logger = logger;
_indexers = indexers.ToList();
if (!configFileProvider.Torrent)
{
_indexers = indexers.Where(c => c.Kind != IndexerKind.Torrent).ToList();
}
else
{
_indexers = indexers.ToList();
}
}
public List<Indexer> All()

@ -123,6 +123,14 @@ namespace NzbDrone.Core.Indexers.Newznab
}
}
public override IndexerKind Kind
{
get
{
return IndexerKind.Usenet;
}
}
private static string NewsnabifyTitle(string title)
{

@ -1,74 +0,0 @@
using System;
using System.Collections.Generic;
namespace NzbDrone.Core.Indexers.NzbClub
{
public class NzbClub : IndexerBase
{
public override string Name
{
get { return "NzbClub"; }
}
public override bool EnableByDefault
{
get { return false; }
}
public override IParseFeed Parser
{
get
{
return new NzbClubParser();
}
}
public override IEnumerable<string> RecentFeed
{
get
{
return new[]
{
String.Format("http://www.nzbclub.com/nzbfeed.aspx?ig=2&gid=102952&st=1&ns=1&q=%23a.b.teevee"),
String.Format("http://www.nzbclub.com/nzbfeed.aspx?ig=2&gid=5542&st=1&ns=1&q=")
};
}
}
public override IEnumerable<string> GetEpisodeSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int episodeNumber)
{
var searchUrls = new List<string>();
foreach (var url in RecentFeed)
{
searchUrls.Add(String.Format("{0}+{1}+s{2:00}e{3:00}", url, seriesTitle, seasonNumber, episodeNumber));
}
return searchUrls;
}
public override IEnumerable<string> GetSeasonSearchUrls(string seriesTitle, int tvRageId, int seasonNumber, int offset)
{
var searchUrls = new List<string>();
foreach (var url in RecentFeed)
{
searchUrls.Add(String.Format("{0}+{1}+s{2:00}", url, seriesTitle, seasonNumber));
}
return searchUrls;
}
public override IEnumerable<string> GetDailyEpisodeSearchUrls(string seriesTitle, int tvRageId, DateTime date)
{
var searchUrls = new List<String>();
foreach (var url in RecentFeed)
{
searchUrls.Add(String.Format("{0}+{1}+{2:yyyy MM dd}", url, seriesTitle, date));
}
return searchUrls;
}
}
}

@ -1,73 +0,0 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace NzbDrone.Core.Indexers.NzbClub
{
public class NzbClubParser : RssParserBase
{
private static readonly Regex SizeRegex = new Regex(@"(?:Size:)\s(?<size>\d+.\d+\s[g|m]i?[b])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
protected override long GetSize(XElement item)
{
var match = SizeRegex.Match(item.Description());
if (match.Success && match.Groups["size"].Success)
{
return ParseSize(match.Groups["size"].Value);
}
return 0;
}
protected override string GetTitle(XElement item)
{
var title = ParseHeader(item.Title());
if (String.IsNullOrWhiteSpace(title))
return item.Title();
return title;
}
private static readonly Regex[] HeaderRegex = new[]
{
new Regex(@"(?:\[.+\]\-\[.+\]\-\[.+\]\-\[)(?<nzbTitle>.+)(?:\]\-.+)",
RegexOptions.IgnoreCase),
new Regex(@"(?:\[.+\]\W+\[.+\]\W+\[.+\]\W+\"")(?<nzbTitle>.+)(?:\"".+)",
RegexOptions.IgnoreCase),
new Regex(@"(?:\[)(?<nzbTitle>.+)(?:\]\-.+)",
RegexOptions.IgnoreCase),
};
private static string ParseHeader(string header)
{
foreach (var regex in HeaderRegex)
{
var match = regex.Matches(header);
if (match.Count != 0)
return match[0].Groups["nzbTitle"].Value.Trim();
}
return header;
}
protected override string GetNzbInfoUrl(XElement item)
{
return item.Links().First();
}
protected override string GetNzbUrl(XElement item)
{
var enclosure = item.Element("enclosure");
return enclosure.Attribute("url").Value;
}
}
}

@ -10,6 +10,14 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
get { return "omgwtfnzbs"; }
}
public override IndexerKind Kind
{
get
{
return IndexerKind.Usenet;
}
}
public override IParseFeed Parser
{
get

@ -15,7 +15,7 @@ namespace NzbDrone.Core.Indexers
{
public abstract class RssParserBase : IParseFeed
{
private Logger _logger;
private readonly Logger _logger;
protected virtual ReleaseInfo CreateNewReleaseInfo()
{

@ -10,6 +10,14 @@ namespace NzbDrone.Core.Indexers.Wombles
get { return "WomblesIndex"; }
}
public override IndexerKind Kind
{
get
{
return IndexerKind.Usenet;
}
}
public override IParseFeed Parser
{
get

@ -307,8 +307,6 @@
<Compile Include="Indexers\Newznab\Newznab.cs" />
<Compile Include="Indexers\Newznab\NewznabSettings.cs" />
<Compile Include="Indexers\Newznab\NewznabParser.cs" />
<Compile Include="Indexers\NzbClub\NzbClub.cs" />
<Compile Include="Indexers\NzbClub\NzbClubParser.cs" />
<Compile Include="Indexers\Omgwtfnzbs\Omgwtfnzbs.cs" />
<Compile Include="Indexers\Omgwtfnzbs\OmgwtfnzbsParser.cs" />
<Compile Include="Indexers\IIndexerSetting.cs" />

Loading…
Cancel
Save