mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-24 22:35:39 -04:00
New: Added support for newznab indexers using tvdbid for searching.
This commit is contained in:
@@ -6,6 +6,7 @@ using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Indexers.Newznab;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
@@ -13,7 +14,7 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
{
|
||||
public class Torznab : HttpIndexerBase<TorznabSettings>
|
||||
{
|
||||
private readonly ITorznabCapabilitiesProvider _torznabCapabilitiesProvider;
|
||||
private readonly INewznabCapabilitiesProvider _capabilitiesProvider;
|
||||
|
||||
public override string Name
|
||||
{
|
||||
@@ -28,7 +29,7 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
|
||||
public override IIndexerRequestGenerator GetRequestGenerator()
|
||||
{
|
||||
return new TorznabRequestGenerator(_torznabCapabilitiesProvider)
|
||||
return new NewznabRequestGenerator(_capabilitiesProvider)
|
||||
{
|
||||
PageSize = PageSize,
|
||||
Settings = Settings
|
||||
@@ -48,10 +49,10 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
}
|
||||
}
|
||||
|
||||
public Torznab(ITorznabCapabilitiesProvider torznabCapabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger)
|
||||
public Torznab(INewznabCapabilitiesProvider capabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger)
|
||||
: base(httpClient, indexerStatusService, configService, parsingService, logger)
|
||||
{
|
||||
_torznabCapabilitiesProvider = torznabCapabilitiesProvider;
|
||||
_capabilitiesProvider = capabilitiesProvider;
|
||||
}
|
||||
|
||||
private IndexerDefinition GetDefinition(string name, TorznabSettings settings)
|
||||
@@ -92,7 +93,7 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
{
|
||||
try
|
||||
{
|
||||
var capabilities = _torznabCapabilitiesProvider.GetCapabilities(Settings);
|
||||
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
|
||||
|
||||
if (capabilities.SupportedSearchParameters != null && capabilities.SupportedSearchParameters.Contains("q"))
|
||||
{
|
||||
@@ -100,8 +101,8 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
}
|
||||
|
||||
if (capabilities.SupportedTvSearchParameters != null &&
|
||||
(capabilities.SupportedSearchParameters.Contains("q") || capabilities.SupportedSearchParameters.Contains("rid")) &&
|
||||
capabilities.SupportedTvSearchParameters.Contains("season") && capabilities.SupportedTvSearchParameters.Contains("ep"))
|
||||
new[] { "q", "tvdbid", "rid" }.Any(v => capabilities.SupportedTvSearchParameters.Contains(v)) &&
|
||||
new[] { "season", "ep" }.All(v => capabilities.SupportedTvSearchParameters.Contains(v)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Torznab
|
||||
{
|
||||
public class TorznabCapabilities
|
||||
{
|
||||
public string[] SupportedSearchParameters { get; set; }
|
||||
public string[] SupportedTvSearchParameters { get; set; }
|
||||
public List<TorznabCategory> Categories { get; set; }
|
||||
|
||||
public TorznabCapabilities()
|
||||
{
|
||||
SupportedSearchParameters = new[] { "q", "offset", "limit" };
|
||||
SupportedTvSearchParameters = new[] { "q", "rid", "season", "ep", "offset", "limit" };
|
||||
Categories = new List<TorznabCategory>();
|
||||
}
|
||||
}
|
||||
|
||||
public class TorznabCategory
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public List<TorznabCategory> Subcategories { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Common.Serializer;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Torznab
|
||||
{
|
||||
public interface ITorznabCapabilitiesProvider
|
||||
{
|
||||
TorznabCapabilities GetCapabilities(TorznabSettings settings);
|
||||
}
|
||||
|
||||
public class TorznabCapabilitiesProvider : ITorznabCapabilitiesProvider
|
||||
{
|
||||
private readonly ICached<TorznabCapabilities> _capabilitiesCache;
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public TorznabCapabilitiesProvider(ICacheManager cacheManager, IHttpClient httpClient, Logger logger)
|
||||
{
|
||||
_capabilitiesCache = cacheManager.GetCache<TorznabCapabilities>(GetType());
|
||||
_httpClient = httpClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public TorznabCapabilities GetCapabilities(TorznabSettings indexerSettings)
|
||||
{
|
||||
var key = indexerSettings.ToJson();
|
||||
var capabilities = _capabilitiesCache.Get(key, () => FetchCapabilities(indexerSettings), TimeSpan.FromDays(7));
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
private TorznabCapabilities FetchCapabilities(TorznabSettings indexerSettings)
|
||||
{
|
||||
var capabilities = new TorznabCapabilities();
|
||||
|
||||
var url = string.Format("{0}/api?t=caps", indexerSettings.Url.TrimEnd('/'));
|
||||
|
||||
if (indexerSettings.ApiKey.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
url += "&apikey=" + indexerSettings.ApiKey;
|
||||
}
|
||||
|
||||
var request = new HttpRequest(url, HttpAccept.Rss);
|
||||
|
||||
try
|
||||
{
|
||||
var response = _httpClient.Get(request);
|
||||
|
||||
capabilities = ParseCapabilities(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.DebugException(string.Format("Failed to get capabilities from {0}: {1}", indexerSettings.Url, ex.Message), ex);
|
||||
}
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
private TorznabCapabilities ParseCapabilities(HttpResponse response)
|
||||
{
|
||||
var capabilities = new TorznabCapabilities();
|
||||
|
||||
var xmlRoot = XDocument.Parse(response.Content).Element("caps");
|
||||
|
||||
var xmlSearching = xmlRoot.Element("searching");
|
||||
if (xmlSearching != null)
|
||||
{
|
||||
var xmlBasicSearch = xmlSearching.Element("search");
|
||||
if (xmlBasicSearch == null || xmlBasicSearch.Attribute("available").Value != "yes")
|
||||
{
|
||||
capabilities.SupportedSearchParameters = null;
|
||||
}
|
||||
else if (xmlBasicSearch.Attribute("supportedParams") != null)
|
||||
{
|
||||
capabilities.SupportedSearchParameters = xmlBasicSearch.Attribute("supportedParams").Value.Split(',');
|
||||
}
|
||||
|
||||
var xmlTvSearch = xmlSearching.Element("tv-search");
|
||||
if (xmlTvSearch == null || xmlTvSearch.Attribute("available").Value != "yes")
|
||||
{
|
||||
capabilities.SupportedTvSearchParameters = null;
|
||||
}
|
||||
else if (xmlTvSearch.Attribute("supportedParams") != null)
|
||||
{
|
||||
capabilities.SupportedTvSearchParameters = xmlTvSearch.Attribute("supportedParams").Value.Split(',');
|
||||
}
|
||||
}
|
||||
|
||||
var xmlCategories = xmlRoot.Element("categories");
|
||||
if (xmlCategories != null)
|
||||
{
|
||||
foreach (var xmlCategory in xmlCategories.Elements("category"))
|
||||
{
|
||||
var cat = new TorznabCategory
|
||||
{
|
||||
Id = int.Parse(xmlCategory.Attribute("id").Value),
|
||||
Name = xmlCategory.Attribute("name").Value,
|
||||
Description = xmlCategory.Attribute("description") != null ? xmlCategory.Attribute("description").Value : string.Empty,
|
||||
Subcategories = new List<TorznabCategory>()
|
||||
};
|
||||
|
||||
foreach (var xmlSubcat in xmlCategory.Elements("subcat"))
|
||||
{
|
||||
cat.Subcategories.Add(new TorznabCategory
|
||||
{
|
||||
Id = int.Parse(xmlSubcat.Attribute("id").Value),
|
||||
Name = xmlSubcat.Attribute("name").Value,
|
||||
Description = xmlSubcat.Attribute("description") != null ? xmlCategory.Attribute("description").Value : string.Empty
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
capabilities.Categories.Add(cat);
|
||||
}
|
||||
}
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,7 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
{
|
||||
}
|
||||
|
||||
public TorznabException(string message)
|
||||
: base(message)
|
||||
public TorznabException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,228 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Torznab
|
||||
{
|
||||
public class TorznabRequestGenerator : IIndexerRequestGenerator
|
||||
{
|
||||
private readonly ITorznabCapabilitiesProvider _capabilitiesProvider;
|
||||
|
||||
public int MaxPages { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
|
||||
public TorznabSettings Settings { get; set; }
|
||||
|
||||
public TorznabRequestGenerator(ITorznabCapabilitiesProvider capabilitiesProvider)
|
||||
{
|
||||
_capabilitiesProvider = capabilitiesProvider;
|
||||
|
||||
MaxPages = 30;
|
||||
PageSize = 100;
|
||||
}
|
||||
|
||||
private bool SupportsSearch
|
||||
{
|
||||
get
|
||||
{
|
||||
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
|
||||
|
||||
return capabilities.SupportedSearchParameters != null
|
||||
&& capabilities.SupportedSearchParameters.Contains("q");
|
||||
}
|
||||
}
|
||||
|
||||
private bool SupportsTvSearch
|
||||
{
|
||||
get
|
||||
{
|
||||
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
|
||||
|
||||
return capabilities.SupportedTvSearchParameters != null
|
||||
&& capabilities.SupportedTvSearchParameters.Contains("q")
|
||||
&& capabilities.SupportedTvSearchParameters.Contains("season")
|
||||
&& capabilities.SupportedTvSearchParameters.Contains("ep");
|
||||
}
|
||||
}
|
||||
|
||||
private bool SupportsTvRageSearch
|
||||
{
|
||||
get
|
||||
{
|
||||
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
|
||||
|
||||
return capabilities.SupportedTvSearchParameters != null
|
||||
&& capabilities.SupportedTvSearchParameters.Contains("rid")
|
||||
&& capabilities.SupportedTvSearchParameters.Contains("season")
|
||||
&& capabilities.SupportedTvSearchParameters.Contains("ep")
|
||||
&& Settings.EnableRageIDLookup;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual IList<IEnumerable<IndexerRequest>> GetRecentRequests()
|
||||
{
|
||||
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
|
||||
|
||||
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
|
||||
|
||||
if (capabilities.SupportedTvSearchParameters != null)
|
||||
{
|
||||
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "tvsearch", ""));
|
||||
}
|
||||
|
||||
return pageableRequests;
|
||||
}
|
||||
|
||||
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SingleEpisodeSearchCriteria searchCriteria)
|
||||
{
|
||||
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
|
||||
|
||||
if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch)
|
||||
{
|
||||
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
|
||||
string.Format("&rid={0}&season={1}&ep={2}",
|
||||
searchCriteria.Series.TvRageId,
|
||||
searchCriteria.SeasonNumber,
|
||||
searchCriteria.EpisodeNumber)));
|
||||
}
|
||||
else if (SupportsTvSearch)
|
||||
{
|
||||
foreach (var queryTitle in searchCriteria.QueryTitles)
|
||||
{
|
||||
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
|
||||
string.Format("&q={0}&season={1}&ep={2}",
|
||||
NewsnabifyTitle(queryTitle),
|
||||
searchCriteria.SeasonNumber,
|
||||
searchCriteria.EpisodeNumber)));
|
||||
}
|
||||
}
|
||||
|
||||
return pageableRequests;
|
||||
}
|
||||
|
||||
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SeasonSearchCriteria searchCriteria)
|
||||
{
|
||||
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
|
||||
|
||||
if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch)
|
||||
{
|
||||
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
|
||||
string.Format("&rid={0}&season={1}",
|
||||
searchCriteria.Series.TvRageId,
|
||||
searchCriteria.SeasonNumber)));
|
||||
}
|
||||
else if (SupportsTvSearch)
|
||||
{
|
||||
foreach (var queryTitle in searchCriteria.QueryTitles)
|
||||
{
|
||||
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
|
||||
string.Format("&q={0}&season={1}",
|
||||
NewsnabifyTitle(queryTitle),
|
||||
searchCriteria.SeasonNumber)));
|
||||
}
|
||||
}
|
||||
|
||||
return pageableRequests;
|
||||
}
|
||||
|
||||
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(DailyEpisodeSearchCriteria searchCriteria)
|
||||
{
|
||||
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
|
||||
|
||||
if (searchCriteria.Series.TvRageId > 0 && SupportsTvRageSearch)
|
||||
{
|
||||
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
|
||||
string.Format("&rid={0}&season={1:yyyy}&ep={1:MM}/{1:dd}",
|
||||
searchCriteria.Series.TvRageId,
|
||||
searchCriteria.AirDate)));
|
||||
}
|
||||
else if (SupportsTvSearch)
|
||||
{
|
||||
foreach (var queryTitle in searchCriteria.QueryTitles)
|
||||
{
|
||||
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories, "tvsearch",
|
||||
string.Format("&q={0}&season={1:yyyy}&ep={1:MM}/{1:dd}",
|
||||
NewsnabifyTitle(queryTitle),
|
||||
searchCriteria.AirDate)));
|
||||
}
|
||||
}
|
||||
|
||||
return pageableRequests;
|
||||
}
|
||||
|
||||
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(AnimeEpisodeSearchCriteria searchCriteria)
|
||||
{
|
||||
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
|
||||
|
||||
if (SupportsSearch)
|
||||
{
|
||||
foreach (var queryTitle in searchCriteria.QueryTitles)
|
||||
{
|
||||
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.AnimeCategories, "search",
|
||||
string.Format("&q={0}+{1:00}",
|
||||
NewsnabifyTitle(queryTitle),
|
||||
searchCriteria.AbsoluteEpisodeNumber)));
|
||||
}
|
||||
}
|
||||
|
||||
return pageableRequests;
|
||||
}
|
||||
|
||||
public virtual IList<IEnumerable<IndexerRequest>> GetSearchRequests(SpecialEpisodeSearchCriteria searchCriteria)
|
||||
{
|
||||
var pageableRequests = new List<IEnumerable<IndexerRequest>>();
|
||||
|
||||
if (SupportsSearch)
|
||||
{
|
||||
foreach (var queryTitle in searchCriteria.EpisodeQueryTitles)
|
||||
{
|
||||
var query = queryTitle.Replace('+', ' ');
|
||||
query = System.Web.HttpUtility.UrlEncode(query);
|
||||
|
||||
pageableRequests.AddIfNotNull(GetPagedRequests(MaxPages, Settings.Categories.Concat(Settings.AnimeCategories), "search",
|
||||
string.Format("&q={0}",
|
||||
query)));
|
||||
}
|
||||
}
|
||||
|
||||
return pageableRequests;
|
||||
}
|
||||
|
||||
private IEnumerable<IndexerRequest> GetPagedRequests(int maxPages, IEnumerable<int> categories, string searchType, string parameters)
|
||||
{
|
||||
if (categories.Empty())
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
var categoriesQuery = string.Join(",", categories.Distinct());
|
||||
|
||||
var baseUrl = string.Format("{0}/api?t={1}&cat={2}&extended=1{3}", Settings.Url.TrimEnd('/'), searchType, categoriesQuery, Settings.AdditionalParameters);
|
||||
|
||||
if (Settings.ApiKey.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
baseUrl += "&apikey=" + Settings.ApiKey;
|
||||
}
|
||||
|
||||
if (PageSize == 0)
|
||||
{
|
||||
yield return new IndexerRequest(string.Format("{0}{1}", baseUrl, parameters), HttpAccept.Rss);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var page = 0; page < maxPages; page++)
|
||||
{
|
||||
yield return new IndexerRequest(string.Format("{0}&offset={1}&limit={2}{3}", baseUrl, page * PageSize, PageSize, parameters), HttpAccept.Rss);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string NewsnabifyTitle(string title)
|
||||
{
|
||||
return title.Replace("+", "%20");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
|
||||
protected override bool PreProcess(IndexerResponse indexerResponse)
|
||||
{
|
||||
var xdoc = XDocument.Parse(indexerResponse.Content);
|
||||
var xdoc = LoadXmlDocument(indexerResponse);
|
||||
var error = xdoc.Descendants("error").FirstOrDefault();
|
||||
|
||||
if (error == null) return true;
|
||||
@@ -40,6 +40,7 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
{
|
||||
var torrentInfo = base.ProcessItem(item, releaseInfo) as TorrentInfo;
|
||||
|
||||
torrentInfo.TvdbId = GetTvdbId(item);
|
||||
torrentInfo.TvRageId = GetTvRageId(item);
|
||||
|
||||
return torrentInfo;
|
||||
@@ -67,12 +68,12 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
return ParseUrl(item.TryGetValue("comments"));
|
||||
}
|
||||
|
||||
protected override Int64 GetSize(XElement item)
|
||||
protected override long GetSize(XElement item)
|
||||
{
|
||||
Int64 size;
|
||||
long size;
|
||||
|
||||
var sizeString = TryGetTorznabAttribute(item, "size");
|
||||
if (!sizeString.IsNullOrWhiteSpace() && Int64.TryParse(sizeString, out size))
|
||||
if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out size))
|
||||
{
|
||||
return size;
|
||||
}
|
||||
@@ -99,12 +100,25 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
return url;
|
||||
}
|
||||
|
||||
protected virtual Int32 GetTvRageId(XElement item)
|
||||
protected virtual int GetTvdbId(XElement item)
|
||||
{
|
||||
var tvdbIdString = TryGetTorznabAttribute(item, "tvdbid");
|
||||
int tvdbId;
|
||||
|
||||
if (!tvdbIdString.IsNullOrWhiteSpace() && int.TryParse(tvdbIdString, out tvdbId))
|
||||
{
|
||||
return tvdbId;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected virtual int GetTvRageId(XElement item)
|
||||
{
|
||||
var tvRageIdString = TryGetTorznabAttribute(item, "rageid");
|
||||
Int32 tvRageId;
|
||||
int tvRageId;
|
||||
|
||||
if (!tvRageIdString.IsNullOrWhiteSpace() && Int32.TryParse(tvRageIdString, out tvRageId))
|
||||
if (!tvRageIdString.IsNullOrWhiteSpace() && int.TryParse(tvRageIdString, out tvRageId))
|
||||
{
|
||||
return tvRageId;
|
||||
}
|
||||
@@ -121,25 +135,25 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
return TryGetTorznabAttribute(item, "magneturl");
|
||||
}
|
||||
|
||||
protected override Int32? GetSeeders(XElement item)
|
||||
protected override int? GetSeeders(XElement item)
|
||||
{
|
||||
var seeders = TryGetTorznabAttribute(item, "seeders");
|
||||
|
||||
if (seeders.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return Int32.Parse(seeders);
|
||||
return int.Parse(seeders);
|
||||
}
|
||||
|
||||
return base.GetSeeders(item);
|
||||
}
|
||||
|
||||
protected override Int32? GetPeers(XElement item)
|
||||
protected override int? GetPeers(XElement item)
|
||||
{
|
||||
var peers = TryGetTorznabAttribute(item, "peers");
|
||||
|
||||
if (peers.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return Int32.Parse(peers);
|
||||
return int.Parse(peers);
|
||||
}
|
||||
|
||||
var seeders = TryGetTorznabAttribute(item, "seeders");
|
||||
@@ -147,7 +161,7 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
|
||||
if (seeders.IsNotNullOrWhiteSpace() && leechers.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return Int32.Parse(seeders) + Int32.Parse(leechers);
|
||||
return int.Parse(seeders) + int.Parse(leechers);
|
||||
}
|
||||
|
||||
return base.GetPeers(item);
|
||||
|
||||
@@ -3,8 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Results;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Indexers.Newznab;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
@@ -14,7 +16,6 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
{
|
||||
private static readonly string[] ApiKeyWhiteList =
|
||||
{
|
||||
"hdaccess.net",
|
||||
"hd4free.xyz",
|
||||
};
|
||||
|
||||
@@ -32,46 +33,27 @@ namespace NzbDrone.Core.Indexers.Torznab
|
||||
|
||||
public TorznabSettingsValidator()
|
||||
{
|
||||
Custom(newznab =>
|
||||
{
|
||||
if (newznab.Categories.Empty() && newznab.AnimeCategories.Empty())
|
||||
{
|
||||
return new ValidationFailure("", "Either 'Categories' or 'Anime Categories' must be provided");
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
RuleFor(c => c.Url).ValidRootUrl();
|
||||
RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey);
|
||||
RuleFor(c => c.Categories).NotEmpty().When(c => !c.AnimeCategories.Any());
|
||||
RuleFor(c => c.AnimeCategories).NotEmpty().When(c => !c.Categories.Any());
|
||||
RuleFor(c => c.AdditionalParameters)
|
||||
.Matches(AdditionalParametersRegex)
|
||||
.When(c => !c.AdditionalParameters.IsNullOrWhiteSpace());
|
||||
RuleFor(c => c.AdditionalParameters).Matches(AdditionalParametersRegex)
|
||||
.When(c => !c.AdditionalParameters.IsNullOrWhiteSpace());
|
||||
}
|
||||
}
|
||||
|
||||
public class TorznabSettings : IProviderConfig
|
||||
public class TorznabSettings : NewznabSettings
|
||||
{
|
||||
private static readonly TorznabSettingsValidator Validator = new TorznabSettingsValidator();
|
||||
|
||||
public TorznabSettings()
|
||||
{
|
||||
Categories = new[] { 5030, 5040 };
|
||||
AnimeCategories = Enumerable.Empty<int>();
|
||||
EnableRageIDLookup = true;
|
||||
}
|
||||
|
||||
[FieldDefinition(0, Label = "URL")]
|
||||
public string Url { get; set; }
|
||||
|
||||
[FieldDefinition(1, Label = "API Key")]
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
[FieldDefinition(2, Label = "Categories", HelpText = "Comma Separated list, leave blank to disable standard/daily shows", Advanced = true)]
|
||||
public IEnumerable<int> Categories { get; set; }
|
||||
|
||||
[FieldDefinition(3, Label = "Anime Categories", HelpText = "Comma Separated list, leave blank to disable anime", Advanced = true)]
|
||||
public IEnumerable<int> AnimeCategories { get; set; }
|
||||
|
||||
[FieldDefinition(4, Label = "Additional Parameters", HelpText = "Additional Torznab parameters", Advanced = true)]
|
||||
public string AdditionalParameters { get; set; }
|
||||
|
||||
// TODO: To be removed in the next version.
|
||||
[FieldDefinition(5, Type = FieldType.Checkbox, Label = "Enable RageID Lookup", HelpText = "Disable this if your tracker doesn't have tvrage ids, Sonarr will then use (more expensive) title queries.", Advanced = true)]
|
||||
public bool EnableRageIDLookup { get; set; }
|
||||
|
||||
public NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
|
||||
Reference in New Issue
Block a user