1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

added torrent feature toggle.

dropped NzbClub.
This commit is contained in:
Keivan Beigi 2013-09-13 17:10:39 -07:00
parent 771e366441
commit 5fc4cd29a3
14 changed files with 71 additions and 174 deletions

View File

@ -6,7 +6,6 @@
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 @@ public void Setup()
_indexers = new List<IIndexer>();
_indexers.Add(new Newznab());
_indexers.Add(new NzbClub());
_indexers.Add(new Omgwtfnzbs());
_indexers.Add(new Wombles());

View File

@ -3,7 +3,6 @@
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 @@ public void SetUp()
}
[Test]
[Explicit]
public void nzbclub_rss()
{
var indexer = new NzbClub();
var result = Subject.FetchRss(indexer);
ValidateResult(result);
}
[Test]
public void wombles_rss()
{

View File

@ -26,13 +26,13 @@ public interface IConfigFileProvider : IHandleAsync<ApplicationStartedEvent>
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 @@ public class ConfigFileProvider : IConfigFileProvider
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 @@ public bool LaunchBrowser
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 @@ public int GetValueInt(string key, int defaultValue)
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 @@ public T GetValueEnum<T>(string key, T defaultValue)
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 @@ public string GetValue(string key, object defaultValue)
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 @@ private XDocument LoadConfigFile()
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);
}
}

View File

@ -10,6 +10,14 @@ public override string Name
get { return "Eztv"; }
}
public override IndexerKind Kind
{
get
{
return IndexerKind.Torrent;
}
}
public override bool EnableByDefault
{
get { return false; }

View File

@ -16,6 +16,7 @@ public interface IIndexer
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);

View File

@ -7,6 +7,8 @@ public abstract class IndexerBase : IIndexer
{
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 @@ public virtual IEnumerable<IndexerDefinition> DefaultDefinitions
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
}
}

View File

@ -3,6 +3,7 @@
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 @@ public interface IIndexerService
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()

View File

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

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -10,6 +10,14 @@ public override string Name
get { return "omgwtfnzbs"; }
}
public override IndexerKind Kind
{
get
{
return IndexerKind.Usenet;
}
}
public override IParseFeed Parser
{
get

View File

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

View File

@ -10,6 +10,14 @@ public override string Name
get { return "WomblesIndex"; }
}
public override IndexerKind Kind
{
get
{
return IndexerKind.Usenet;
}
}
public override IParseFeed Parser
{
get

View File

@ -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" />