Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Def rework - Cardigann v8 #823

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace NzbDrone.Core.Test.IndexerTests.AvistazTests
{
[TestFixture]
public class AvistazFixture : CoreTest<AvistaZ>
public class AvistazFixture : CoreTest<Avistaz>
{
[SetUp]
public void Setup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace NzbDrone.Core.Test.IndexerTests.AvistazTests
{
[TestFixture]
public class PrivateHDFixture : CoreTest<PrivateHD>
public class PrivateHDFixture : CoreTest<Avistaz>
{
[SetUp]
public void Setup()
Expand Down
5 changes: 3 additions & 2 deletions src/NzbDrone.Core.Test/IndexerTests/TestIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.IndexerVersions;
using NzbDrone.Core.Messaging.Events;

namespace NzbDrone.Core.Test.IndexerTests
Expand All @@ -20,8 +21,8 @@ public class TestIndexer : UsenetIndexerBase<TestIndexerSettings>
public int _supportedPageSize;
public override int PageSize => _supportedPageSize;

public TestIndexer(IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IConfigService configService, IValidateNzbs nzbValidationService, Logger logger)
: base(httpClient, eventAggregator, indexerStatusService, configService, nzbValidationService, logger)
public TestIndexer(IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IIndexerDefinitionUpdateService definitionService, IConfigService configService, IValidateNzbs nzbValidationService, Logger logger)
: base(httpClient, eventAggregator, indexerStatusService, definitionService, configService, nzbValidationService, logger)
{
}

Expand Down
87 changes: 87 additions & 0 deletions src/NzbDrone.Core/Datastore/Migration/022_indexer_definition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System.Collections.Generic;
using System.Data;
using System.Text.Json;
using Dapper;
using FluentMigrator;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;

namespace NzbDrone.Core.Datastore.Migration
{
[Migration(22)]
public class indexer_definition : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Indexers")
.AddColumn("DefinitionFile").AsString().Nullable();

Execute.WithConnection(MigrateCardigannDefinitions);
}

private void MigrateCardigannDefinitions(IDbConnection conn, IDbTransaction tran)
{
var indexers = new List<Indexer017>();

using (var cmd = conn.CreateCommand())
{
cmd.Transaction = tran;
cmd.CommandText = "SELECT \"Id\", \"Settings\", \"Implementation\", \"ConfigContract\" FROM \"Indexers\"";

using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var id = reader.GetInt32(0);
var settings = reader.GetString(1);
var implementation = reader.GetString(2);
var configContract = reader.GetString(3);
var defFile = implementation.ToLowerInvariant();

if (implementation == "Cardigann")
{
if (!string.IsNullOrWhiteSpace(settings))
{
var jsonObject = STJson.Deserialize<JsonElement>(settings);

if (jsonObject.TryGetProperty("definitionFile", out JsonElement jsonDef))
{
defFile = jsonDef.GetString();
}
}
}
else if (configContract == "AvistazSettings")
{
implementation = "Avistaz";
}
else if (configContract == "Unit3dSettings")
{
implementation = "Unit3d";
}
else if (configContract == "Newznab")
{
defFile = "";
}

indexers.Add(new Indexer017
{
DefinitionFile = defFile,
Implementation = implementation,
Id = id
});
}
}
}

var updateSql = "UPDATE \"Indexers\" SET \"DefinitionFile\" = @DefinitionFile, \"Implementation\" = @Implementation WHERE \"Id\" = @Id";
conn.Execute(updateSql, indexers, transaction: tran);
}

public class Indexer017
{
public int Id { get; set; }
public string DefinitionFile { get; set; }
public string Implementation { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion src/NzbDrone.Core/HealthCheck/Checks/NoDefinitionCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override HealthCheck Check()
var currentDefs = _indexerDefinitionUpdateService.All();

var noDefIndexers = _indexerFactory.AllProviders(false)
.Where(i => i.Definition.Implementation == "Cardigann" && !currentDefs.Any(d => d.File == ((CardigannSettings)i.Definition.Settings).DefinitionFile)).ToList();
.Where(i => i.Definition.Implementation == "Cardigann" && !currentDefs.Any(d => d.File == ((IndexerDefinition)i.Definition).DefinitionFile)).ToList();

if (noDefIndexers.Count == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override HealthCheck Check()
var blocklist = _indexerDefinitionUpdateService.GetBlocklist();

var oldIndexers = _indexerFactory.AllProviders(false)
.Where(i => i.IsObsolete() || (i.Definition.Implementation == "Cardigann" && blocklist.Contains(((CardigannSettings)i.Definition.Settings).DefinitionFile))).ToList();
.Where(i => i.IsObsolete() || (i.Definition.Implementation == "Cardigann" && blocklist.Contains(((IndexerDefinition)i.Definition).DefinitionFile))).ToList();

if (oldIndexers.Count == 0)
{
Expand Down
31 changes: 21 additions & 10 deletions src/NzbDrone.Core/IndexerVersions/IndexerDefinitionUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ namespace NzbDrone.Core.IndexerVersions
{
public interface IIndexerDefinitionUpdateService
{
List<CardigannMetaDefinition> All();
List<IndexerMetaDefinition> All();
List<IndexerMetaDefinition> AllForImplementation(string implementation);
CardigannDefinition GetCachedDefinition(string fileKey);
List<string> GetBlocklist();
}

public class IndexerDefinitionUpdateService : IIndexerDefinitionUpdateService, IExecute<IndexerDefinitionUpdateCommand>, IHandle<ApplicationStartedEvent>
{
/* Update Service will fall back if version # does not exist for an indexer per Ta */
/* Update Service will fall back if version # does not exist for an indexer per Ta */

private const string DEFINITION_BRANCH = "master";
private const int DEFINITION_VERSION = 7;
private const string DEFINITION_BRANCH = "newznab-xml-to-yml-scriptupdates";
private const int DEFINITION_VERSION = 8;

//Used when moving yml to C#
private readonly List<string> _defintionBlocklist = new List<string>()
Expand Down Expand Up @@ -77,17 +78,17 @@ public class IndexerDefinitionUpdateService : IIndexerDefinitionUpdateService, I
_logger = logger;
}

public List<CardigannMetaDefinition> All()
public List<IndexerMetaDefinition> All()
{
var indexerList = new List<CardigannMetaDefinition>();
var indexerList = new List<IndexerMetaDefinition>();

try
{
// Grab latest def list from server or fallback to disk
try
{
var request = new HttpRequest($"https://indexers.prowlarr.com/{DEFINITION_BRANCH}/{DEFINITION_VERSION}");
var response = _httpClient.Get<List<CardigannMetaDefinition>>(request);
var response = _httpClient.Get<List<IndexerMetaDefinition>>(request);
indexerList = response.Resource.Where(i => !_defintionBlocklist.Contains(i.File)).ToList();
}
catch
Expand All @@ -110,6 +111,11 @@ public List<CardigannMetaDefinition> All()
return indexerList;
}

public List<IndexerMetaDefinition> AllForImplementation(string implementation)
{
return All().Where(d => d.Implementation == implementation).ToList();
}

public CardigannDefinition GetCachedDefinition(string fileKey)
{
if (string.IsNullOrEmpty(fileKey))
Expand All @@ -127,7 +133,7 @@ public List<string> GetBlocklist()
return _defintionBlocklist;
}

private List<CardigannMetaDefinition> ReadDefinitionsFromDisk(List<CardigannMetaDefinition> defs, string path, SearchOption options = SearchOption.TopDirectoryOnly)
private List<IndexerMetaDefinition> ReadDefinitionsFromDisk(List<IndexerMetaDefinition> defs, string path, SearchOption options = SearchOption.TopDirectoryOnly)
{
var indexerList = defs;

Expand All @@ -144,7 +150,7 @@ private List<CardigannMetaDefinition> ReadDefinitionsFromDisk(List<CardigannMeta
try
{
var definitionString = File.ReadAllText(file.FullName);
var definition = _deserializer.Deserialize<CardigannMetaDefinition>(definitionString);
var definition = _deserializer.Deserialize<IndexerMetaDefinition>(definitionString);

definition.File = Path.GetFileNameWithoutExtension(file.Name);

Expand Down Expand Up @@ -242,6 +248,11 @@ private CardigannDefinition CleanIndexerDefinition(CardigannDefinition definitio
definition.Login.Method = "form";
}

if (definition.Search == null)
{
definition.Search = new SearchBlock();
}

if (definition.Search.Paths == null)
{
definition.Search.Paths = new List<SearchPathBlock>();
Expand Down Expand Up @@ -283,7 +294,7 @@ private void UpdateLocalDefinitions()
var startupFolder = _appFolderInfo.AppDataFolder;

var request = new HttpRequest($"https://indexers.prowlarr.com/{DEFINITION_BRANCH}/{DEFINITION_VERSION}");
var response = _httpClient.Get<List<CardigannMetaDefinition>>(request);
var response = _httpClient.Get<List<IndexerMetaDefinition>>(request);

var currentDefs = _versionService.All().ToDictionary(x => x.DefinitionId, x => x.Sha);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
using System.Collections.Generic;
using NzbDrone.Core.Indexers.Cardigann;

namespace NzbDrone.Core.Indexers.Cardigann
namespace NzbDrone.Core.IndexerVersions
{
public class CardigannMetaDefinition
public class IndexerMetaDefinition
{
public CardigannMetaDefinition()
public IndexerMetaDefinition()
{
Legacylinks = new List<string>();
}

public string Id { get; set; }
public string File { get; set; }
public string Implementation { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Type { get; set; }
public string Language { get; set; }
public string Encoding { get; set; }
public List<string> Links { get; set; }
public List<string> Legacylinks { get; set; }
public List<SettingsField> Settings { get; set; }
public string Sha { get; set; }
public List<SettingsField> Settings { get; set; }
public LoginBlock Login { get; set; }
}
}
56 changes: 3 additions & 53 deletions src/NzbDrone.Core/Indexers/Definitions/AlphaRatio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
using NLog;
using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.IndexerVersions;
using NzbDrone.Core.Messaging.Events;

namespace NzbDrone.Core.Indexers.Definitions
{
public class AlphaRatio : Gazelle.Gazelle
{
public override string Name => "AlphaRatio";
public override string[] IndexerUrls => new string[] { "https://alpharatio.cc/" };
public override string Description => "AlphaRatio(AR) is a Private Torrent Tracker for 0DAY / GENERAL";
public override IndexerPrivacy Privacy => IndexerPrivacy.Private;

public AlphaRatio(IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IConfigService configService, Logger logger)
: base(httpClient, eventAggregator, indexerStatusService, configService, logger)
public AlphaRatio(IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IIndexerDefinitionUpdateService definitionService, IConfigService configService, Logger logger)
: base(httpClient, eventAggregator, indexerStatusService, definitionService, configService, logger)
{
}

Expand All @@ -28,54 +26,6 @@ public override IIndexerRequestGenerator GetRequestGenerator()
Capabilities = Capabilities
};
}

protected override IndexerCapabilities SetCapabilities()
{
var caps = new IndexerCapabilities
{
TvSearchParams = new List<TvSearchParam>
{
TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep
},
MovieSearchParams = new List<MovieSearchParam>
{
MovieSearchParam.Q
}
};

caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.TVSD, "TvSD");
caps.Categories.AddCategoryMapping(2, NewznabStandardCategory.TVHD, "TvHD");
caps.Categories.AddCategoryMapping(3, NewznabStandardCategory.TVUHD, "TvUHD");
caps.Categories.AddCategoryMapping(4, NewznabStandardCategory.TVSD, "TvDVDRip");
caps.Categories.AddCategoryMapping(5, NewznabStandardCategory.TVSD, "TvPackSD");
caps.Categories.AddCategoryMapping(6, NewznabStandardCategory.TVHD, "TvPackHD");
caps.Categories.AddCategoryMapping(7, NewznabStandardCategory.TVUHD, "TvPackUHD");
caps.Categories.AddCategoryMapping(8, NewznabStandardCategory.MoviesSD, "MovieSD");
caps.Categories.AddCategoryMapping(9, NewznabStandardCategory.MoviesHD, "MovieHD");
caps.Categories.AddCategoryMapping(10, NewznabStandardCategory.MoviesUHD, "MovieUHD");
caps.Categories.AddCategoryMapping(11, NewznabStandardCategory.MoviesSD, "MoviePackSD");
caps.Categories.AddCategoryMapping(12, NewznabStandardCategory.MoviesHD, "MoviePackHD");
caps.Categories.AddCategoryMapping(13, NewznabStandardCategory.MoviesUHD, "MoviePackUHD");
caps.Categories.AddCategoryMapping(14, NewznabStandardCategory.XXX, "MovieXXX");
caps.Categories.AddCategoryMapping(15, NewznabStandardCategory.MoviesBluRay, "Bluray");
caps.Categories.AddCategoryMapping(16, NewznabStandardCategory.TVAnime, "AnimeSD");
caps.Categories.AddCategoryMapping(17, NewznabStandardCategory.TVAnime, "AnimeHD");
caps.Categories.AddCategoryMapping(18, NewznabStandardCategory.PCGames, "GamesPC");
caps.Categories.AddCategoryMapping(19, NewznabStandardCategory.ConsoleXBox, "GamesxBox");
caps.Categories.AddCategoryMapping(20, NewznabStandardCategory.ConsolePS4, "GamesPS");
caps.Categories.AddCategoryMapping(21, NewznabStandardCategory.ConsoleWii, "GamesNin");
caps.Categories.AddCategoryMapping(22, NewznabStandardCategory.PC0day, "AppsWindows");
caps.Categories.AddCategoryMapping(23, NewznabStandardCategory.PCMac, "AppsMAC");
caps.Categories.AddCategoryMapping(24, NewznabStandardCategory.PC0day, "AppsLinux");
caps.Categories.AddCategoryMapping(25, NewznabStandardCategory.PCMobileOther, "AppsMobile");
caps.Categories.AddCategoryMapping(26, NewznabStandardCategory.XXX, "0dayXXX");
caps.Categories.AddCategoryMapping(27, NewznabStandardCategory.Books, "eBook");
caps.Categories.AddCategoryMapping(28, NewznabStandardCategory.AudioAudiobook, "AudioBook");
caps.Categories.AddCategoryMapping(29, NewznabStandardCategory.AudioOther, "Music");
caps.Categories.AddCategoryMapping(30, NewznabStandardCategory.Other, "Misc");

return caps;
}
}

public class AlphaRatioRequestGenerator : Gazelle.GazelleRequestGenerator
Expand Down
Loading