Skip to content

Commit

Permalink
New: Allow users to use custom ymls
Browse files Browse the repository at this point in the history
  • Loading branch information
Qstick committed Jun 22, 2021
1 parent 8e597c8 commit 3435d9d
Showing 1 changed file with 36 additions and 1 deletion.
Expand Up @@ -6,6 +6,7 @@
using NzbDrone.Common.Cache;
using NzbDrone.Common.Disk;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.Indexers.Cardigann;
using NzbDrone.Core.Messaging.Commands;
Expand Down Expand Up @@ -59,6 +60,40 @@ public List<CardigannMetaDefinition> All()
var request = new HttpRequest($"https://indexers.prowlarr.com/master/{DEFINITION_VERSION}");
var response = _httpClient.Get<List<CardigannMetaDefinition>>(request);
indexerList = response.Resource.Where(i => !_defintionBlacklist.Contains(i.File)).ToList();

var definitionFolder = Path.Combine(_appFolderInfo.AppDataFolder, "Definitions", "Custom");

var directoryInfo = new DirectoryInfo(definitionFolder);

if (directoryInfo.Exists)
{
var files = directoryInfo.GetFiles($"*.yml");

foreach (var file in files)
{
_logger.Debug("Loading Custom Cardigann definition " + file.FullName);

try
{
var definitionString = File.ReadAllText(file.FullName);
var definition = _deserializer.Deserialize<CardigannMetaDefinition>(definitionString);

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

if (indexerList.Any(i => i.File == definition.File || i.Name == definition.Name))
{
_logger.Warn("Custom Cardigann definition {0} does not have unique file name or Indexer name", file.FullName);
continue;
}

indexerList.Add(definition);
}
catch (Exception e)
{
_logger.Error($"Error while parsing custom Cardigann definition {file.FullName}\n{e}");
}
}
}
}
catch
{
Expand Down Expand Up @@ -108,7 +143,7 @@ private CardigannDefinition LoadIndexerDef(string fileKey)

if (directoryInfo.Exists)
{
var files = directoryInfo.GetFiles($"{fileKey}.yml");
var files = directoryInfo.GetFiles($"{fileKey}.yml", SearchOption.AllDirectories);

if (files.Any())
{
Expand Down

0 comments on commit 3435d9d

Please sign in to comment.