2018-03-14 20:41:36 +00:00
|
|
|
using System;
|
2013-04-07 07:30:37 +00:00
|
|
|
using System.Collections.Generic;
|
2014-09-07 11:44:24 +00:00
|
|
|
using System.Linq;
|
2023-04-23 23:11:43 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2023-07-16 18:07:31 +00:00
|
|
|
using System.Threading.Tasks;
|
2014-07-04 08:09:48 +00:00
|
|
|
using FluentValidation.Results;
|
2014-09-07 11:44:24 +00:00
|
|
|
using NLog;
|
2023-04-23 23:11:43 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2023-04-30 04:09:11 +00:00
|
|
|
using NzbDrone.Common.Http;
|
2014-09-07 11:44:24 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
2023-04-23 23:11:43 +00:00
|
|
|
using NzbDrone.Core.Languages;
|
2014-09-07 11:44:24 +00:00
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-09-21 07:09:26 +00:00
|
|
|
using NzbDrone.Core.ThingiProvider;
|
2013-04-07 07:30:37 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers
|
|
|
|
{
|
2014-09-07 11:44:24 +00:00
|
|
|
public abstract class IndexerBase<TSettings> : IIndexer
|
2019-06-14 03:54:25 +00:00
|
|
|
where TSettings : IIndexerSettings, new()
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
2024-04-16 03:24:05 +00:00
|
|
|
private static readonly Regex MultiRegex = new (@"[_. ](?<multi>multi)[_. ]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
2023-04-23 23:11:43 +00:00
|
|
|
|
2015-06-27 09:43:17 +00:00
|
|
|
protected readonly IIndexerStatusService _indexerStatusService;
|
2014-09-07 11:44:24 +00:00
|
|
|
protected readonly IConfigService _configService;
|
|
|
|
protected readonly IParsingService _parsingService;
|
|
|
|
protected readonly Logger _logger;
|
|
|
|
|
2015-04-25 16:19:23 +00:00
|
|
|
public abstract string Name { get; }
|
2014-09-07 11:44:24 +00:00
|
|
|
public abstract DownloadProtocol Protocol { get; }
|
2020-09-12 06:25:32 +00:00
|
|
|
public int Priority { get; set; }
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
public abstract bool SupportsRss { get; }
|
|
|
|
public abstract bool SupportsSearch { get; }
|
2014-09-07 11:44:24 +00:00
|
|
|
|
2015-06-27 09:43:17 +00:00
|
|
|
public IndexerBase(IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger)
|
2014-09-07 11:44:24 +00:00
|
|
|
{
|
2015-06-27 09:43:17 +00:00
|
|
|
_indexerStatusService = indexerStatusService;
|
2014-09-07 11:44:24 +00:00
|
|
|
_configService = configService;
|
|
|
|
_parsingService = parsingService;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public Type ConfigContract => typeof(TSettings);
|
2013-04-07 07:30:37 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public virtual ProviderMessage Message => null;
|
2015-06-28 21:06:03 +00:00
|
|
|
|
2019-04-13 03:25:58 +00:00
|
|
|
public virtual IEnumerable<ProviderDefinition> DefaultDefinitions
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
2019-04-13 03:25:58 +00:00
|
|
|
get
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
2019-04-13 03:25:58 +00:00
|
|
|
var config = (IProviderConfig)new TSettings();
|
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
yield return new IndexerDefinition
|
|
|
|
{
|
|
|
|
EnableRss = config.Validate().IsValid && SupportsRss,
|
|
|
|
EnableAutomaticSearch = config.Validate().IsValid && SupportsSearch,
|
|
|
|
EnableInteractiveSearch = config.Validate().IsValid && SupportsSearch,
|
|
|
|
Implementation = GetType().Name,
|
|
|
|
Settings = config
|
|
|
|
};
|
|
|
|
}
|
2013-04-07 07:30:37 +00:00
|
|
|
}
|
|
|
|
|
2013-10-13 02:46:36 +00:00
|
|
|
public virtual ProviderDefinition Definition { get; set; }
|
2016-08-10 18:45:48 +00:00
|
|
|
|
2019-12-22 22:08:53 +00:00
|
|
|
public virtual object RequestAction(string action, IDictionary<string, string> query)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2013-09-22 05:20:26 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
protected TSettings Settings => (TSettings)Definition.Settings;
|
2013-09-22 05:20:26 +00:00
|
|
|
|
2023-07-16 18:07:31 +00:00
|
|
|
public abstract Task<IList<ReleaseInfo>> FetchRecent();
|
|
|
|
public abstract Task<IList<ReleaseInfo>> Fetch(MovieSearchCriteria searchCriteria);
|
2023-04-30 04:09:11 +00:00
|
|
|
public abstract HttpRequest GetDownloadRequest(string link);
|
2014-09-07 11:44:24 +00:00
|
|
|
|
|
|
|
protected virtual IList<ReleaseInfo> CleanupReleases(IEnumerable<ReleaseInfo> releases)
|
|
|
|
{
|
|
|
|
var result = releases.DistinctBy(v => v.Guid).ToList();
|
2023-04-23 23:11:43 +00:00
|
|
|
var settings = Definition.Settings as IIndexerSettings;
|
2014-09-07 11:44:24 +00:00
|
|
|
|
|
|
|
result.ForEach(c =>
|
|
|
|
{
|
2023-04-23 23:11:43 +00:00
|
|
|
// Use multi languages from setting if ReleaseInfo languages is empty
|
|
|
|
if (c.Languages.Empty() && MultiRegex.IsMatch(c.Title) && settings.MultiLanguages.Any())
|
|
|
|
{
|
|
|
|
c.Languages = settings.MultiLanguages.Select(i => (Language)i).ToList();
|
|
|
|
}
|
|
|
|
|
2015-06-27 09:43:17 +00:00
|
|
|
c.IndexerId = Definition.Id;
|
2014-09-07 11:44:24 +00:00
|
|
|
c.Indexer = Definition.Name;
|
|
|
|
c.DownloadProtocol = Protocol;
|
2020-09-12 06:25:32 +00:00
|
|
|
c.IndexerPriority = ((IndexerDefinition)Definition).Priority;
|
2014-09-07 11:44:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ValidationResult Test()
|
|
|
|
{
|
|
|
|
var failures = new List<ValidationFailure>();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2023-07-16 18:07:31 +00:00
|
|
|
Test(failures).GetAwaiter().GetResult();
|
2014-09-07 11:44:24 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2016-02-11 21:13:42 +00:00
|
|
|
_logger.Error(ex, "Test aborted due to exception");
|
2014-09-07 11:44:24 +00:00
|
|
|
failures.Add(new ValidationFailure(string.Empty, "Test was aborted due to an error: " + ex.Message));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ValidationResult(failures);
|
|
|
|
}
|
|
|
|
|
2023-07-16 18:07:31 +00:00
|
|
|
protected abstract Task Test(List<ValidationFailure> failures);
|
2013-09-22 20:00:29 +00:00
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2014-02-05 04:20:00 +00:00
|
|
|
return Definition.Name;
|
2013-09-22 20:00:29 +00:00
|
|
|
}
|
2013-04-07 07:30:37 +00:00
|
|
|
}
|
2014-09-07 11:44:24 +00:00
|
|
|
}
|