2017-10-29 03:14:40 +00:00
|
|
|
using System;
|
2015-03-12 20:01:54 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2015-07-19 18:39:07 +00:00
|
|
|
using FluentValidation.Results;
|
2015-03-12 20:01:54 +00:00
|
|
|
using NLog;
|
2015-07-19 18:39:07 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2015-03-12 20:01:54 +00:00
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
using NzbDrone.Core.Configuration;
|
2015-09-26 08:45:13 +00:00
|
|
|
using NzbDrone.Core.Indexers.Newznab;
|
2015-03-12 20:01:54 +00:00
|
|
|
using NzbDrone.Core.Parser;
|
2021-12-08 22:08:10 +00:00
|
|
|
using NzbDrone.Core.ThingiProvider;
|
2019-03-24 14:22:50 +00:00
|
|
|
using NzbDrone.Core.Validation;
|
2015-03-12 20:01:54 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers.Torznab
|
|
|
|
{
|
|
|
|
public class Torznab : HttpIndexerBase<TorznabSettings>
|
|
|
|
{
|
2015-09-26 08:45:13 +00:00
|
|
|
private readonly INewznabCapabilitiesProvider _capabilitiesProvider;
|
2015-07-19 18:39:07 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public override string Name => "Torznab";
|
2015-04-25 16:19:23 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public override DownloadProtocol Protocol => DownloadProtocol.Torrent;
|
2023-02-12 22:34:04 +00:00
|
|
|
public override int PageSize => Math.Min(100, Math.Max(_capabilitiesProvider.GetCapabilities(Settings).DefaultPageSize, _capabilitiesProvider.GetCapabilities(Settings).MaxPageSize));
|
2015-03-12 20:01:54 +00:00
|
|
|
|
|
|
|
public override IIndexerRequestGenerator GetRequestGenerator()
|
|
|
|
{
|
2015-09-26 08:45:13 +00:00
|
|
|
return new NewznabRequestGenerator(_capabilitiesProvider)
|
2015-03-12 20:01:54 +00:00
|
|
|
{
|
2015-07-19 18:39:07 +00:00
|
|
|
PageSize = PageSize,
|
2015-03-12 20:01:54 +00:00
|
|
|
Settings = Settings
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public override IParseIndexerResponse GetParser()
|
|
|
|
{
|
|
|
|
return new TorznabRssParser();
|
|
|
|
}
|
|
|
|
|
2015-09-26 08:45:13 +00:00
|
|
|
public Torznab(INewznabCapabilitiesProvider capabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger)
|
2015-06-27 09:43:17 +00:00
|
|
|
: base(httpClient, indexerStatusService, configService, parsingService, logger)
|
2015-03-12 20:01:54 +00:00
|
|
|
{
|
2015-09-26 08:45:13 +00:00
|
|
|
_capabilitiesProvider = capabilitiesProvider;
|
2015-03-12 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
private IndexerDefinition GetDefinition(string name, TorznabSettings settings)
|
2015-03-12 20:01:54 +00:00
|
|
|
{
|
|
|
|
return new IndexerDefinition
|
2020-01-03 12:49:24 +00:00
|
|
|
{
|
|
|
|
EnableRss = false,
|
|
|
|
EnableAutomaticSearch = false,
|
|
|
|
EnableInteractiveSearch = false,
|
|
|
|
Name = name,
|
|
|
|
Implementation = GetType().Name,
|
|
|
|
Settings = settings,
|
|
|
|
Protocol = DownloadProtocol.Usenet,
|
|
|
|
SupportsRss = SupportsRss,
|
|
|
|
SupportsSearch = SupportsSearch
|
|
|
|
};
|
2015-03-12 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
private TorznabSettings GetSettings(string url, params int[] categories)
|
2015-03-12 20:01:54 +00:00
|
|
|
{
|
2017-10-08 03:54:13 +00:00
|
|
|
var settings = new TorznabSettings { BaseUrl = url };
|
2015-03-12 20:01:54 +00:00
|
|
|
|
|
|
|
if (categories.Any())
|
|
|
|
{
|
|
|
|
settings.Categories = categories;
|
|
|
|
}
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
2015-07-19 18:39:07 +00:00
|
|
|
|
|
|
|
protected override void Test(List<ValidationFailure> failures)
|
|
|
|
{
|
|
|
|
base.Test(failures);
|
2020-01-03 12:49:24 +00:00
|
|
|
if (failures.HasErrors())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-08 22:08:10 +00:00
|
|
|
failures.AddIfNotNull(JackettAll());
|
2015-07-19 18:39:07 +00:00
|
|
|
failures.AddIfNotNull(TestCapabilities());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual ValidationFailure TestCapabilities()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-09-26 08:45:13 +00:00
|
|
|
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
|
2015-07-19 18:39:07 +00:00
|
|
|
|
|
|
|
if (capabilities.SupportedSearchParameters != null && capabilities.SupportedSearchParameters.Contains("q"))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-09-23 02:19:07 +00:00
|
|
|
if (capabilities.SupportedAudioSearchParameters != null &&
|
|
|
|
new[] { "artist", "album" }.All(v => capabilities.SupportedAudioSearchParameters.Contains(v)))
|
2015-07-19 18:39:07 +00:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ValidationFailure(string.Empty, "Indexer does not support required search parameters");
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2016-02-11 21:13:42 +00:00
|
|
|
_logger.Warn(ex, "Unable to connect to indexer: " + ex.Message);
|
2015-07-19 18:39:07 +00:00
|
|
|
|
|
|
|
return new ValidationFailure(string.Empty, "Unable to connect to indexer, check the log for more details");
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 21:33:13 +00:00
|
|
|
|
2021-12-08 22:08:10 +00:00
|
|
|
protected virtual ValidationFailure JackettAll()
|
|
|
|
{
|
|
|
|
if (Settings.ApiPath.Contains("/torznab/all") ||
|
|
|
|
Settings.ApiPath.Contains("/api/v2.0/indexers/all/results/torznab") ||
|
|
|
|
Settings.BaseUrl.Contains("/torznab/all") ||
|
|
|
|
Settings.BaseUrl.Contains("/api/v2.0/indexers/all/results/torznab"))
|
|
|
|
{
|
|
|
|
return new NzbDroneValidationFailure("ApiPath", "Jackett's all endpoint is not supported, please add indexers individually")
|
|
|
|
{
|
|
|
|
IsWarning = true,
|
|
|
|
DetailedDescription = "Jackett's all endpoint is not supported, please add indexers individually"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-10-08 21:33:13 +00:00
|
|
|
public override object RequestAction(string action, IDictionary<string, string> query)
|
|
|
|
{
|
|
|
|
if (action == "newznabCategories")
|
|
|
|
{
|
|
|
|
List<NewznabCategory> categories = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
categories = _capabilitiesProvider.GetCapabilities(Settings).Categories;
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
// Use default categories
|
|
|
|
}
|
|
|
|
|
|
|
|
return new
|
|
|
|
{
|
|
|
|
options = NewznabCategoryFieldOptionsConverter.GetFieldSelectOptions(categories)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.RequestAction(action, query);
|
|
|
|
}
|
2015-03-12 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|