refactor: Consolidate quality parser into guide service

pull/113/head
Robert Dailey 2 years ago
parent 07c4b48578
commit fef596d5d4

@ -14,14 +14,14 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Guide;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class LocalRepoCustomFormatJsonParserTest
public class LocalRepoRadarrGuideServiceTest
{
[Test, AutoMockData]
public void Get_custom_format_json_works(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen] IAppPaths appPaths,
[Frozen] IRepoPaths repoPaths,
LocalRepoCustomFormatJsonParser sut)
LocalRepoRadarrGuideService sut)
{
var jsonDir = appPaths.RepoDirectory
.SubDirectory("docs")

@ -36,7 +36,7 @@ public class GuideProcessorTest
public ResourceDataReader Data { get; }
public CustomFormatData ReadCustomFormat(string textFile) =>
LocalRepoCustomFormatJsonParser.ParseCustomFormatData(ReadText(textFile));
LocalRepoRadarrGuideService.ParseCustomFormatData(ReadText(textFile));
public string ReadText(string textFile) => Data.ReadData(textFile);
public JObject ReadJson(string jsonFile) => JObject.Parse(ReadText(jsonFile));

@ -16,14 +16,14 @@ namespace TrashLib.Tests.Sonarr.ReleaseProfile.Guide;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class LocalRepoReleaseProfileJsonParserTest
public class LocalRepoSonarrGuideServiceTest
{
[Test, AutoMockData]
public void Get_custom_format_json_works(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen] IAppPaths appPaths,
[Frozen] IRepoPaths repoPaths,
LocalRepoReleaseProfileJsonParser sut)
LocalRepoSonarrGuideService sut)
{
static ReleaseProfileData MakeMockObject(string term) => new()
{
@ -65,7 +65,7 @@ public class LocalRepoReleaseProfileJsonParserTest
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen] IAppPaths appPaths,
[Frozen] IRepoPaths repoPaths,
LocalRepoReleaseProfileJsonParser sut)
LocalRepoSonarrGuideService sut)
{
var rootPath = appPaths.RepoDirectory
.SubDirectory("docs")

@ -1,8 +1,10 @@
using TrashLib.Services.Radarr.CustomFormat.Models;
using TrashLib.Services.Radarr.QualityDefinition;
namespace TrashLib.Services.Radarr.CustomFormat.Guide;
public interface IRadarrGuideService
{
ICollection<CustomFormatData> GetCustomFormatData();
ICollection<RadarrQualityData> GetQualities();
}

@ -6,21 +6,28 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Serilog;
using TrashLib.Repo;
using TrashLib.Services.Common.QualityDefinition;
using TrashLib.Services.Radarr.CustomFormat.Models;
using TrashLib.Services.Radarr.QualityDefinition;
namespace TrashLib.Services.Radarr.CustomFormat.Guide;
public class LocalRepoCustomFormatJsonParser : IRadarrGuideService
public class LocalRepoRadarrGuideService : IRadarrGuideService
{
private readonly IRepoPathsFactory _pathsFactory;
private readonly ILogger _log;
private readonly QualityGuideParser<RadarrQualityData> _parser;
public LocalRepoCustomFormatJsonParser(IRepoPathsFactory pathsFactory, ILogger log)
public LocalRepoRadarrGuideService(IRepoPathsFactory pathsFactory, ILogger log)
{
_pathsFactory = pathsFactory;
_log = log;
_parser = new QualityGuideParser<RadarrQualityData>(log);
}
public ICollection<RadarrQualityData> GetQualities()
=> _parser.GetQualities(_pathsFactory.Create().RadarrQualityPaths);
public ICollection<CustomFormatData> GetCustomFormatData()
{
var paths = _pathsFactory.Create();

@ -1,6 +0,0 @@
namespace TrashLib.Services.Radarr.QualityDefinition;
public interface IRadarrQualityGuideParser
{
ICollection<RadarrQualityData> GetQualities();
}

@ -2,6 +2,7 @@ using CliFx.Infrastructure;
using Common.Extensions;
using Serilog;
using TrashLib.Services.Radarr.Config;
using TrashLib.Services.Radarr.CustomFormat.Guide;
using TrashLib.Services.Radarr.QualityDefinition.Api;
using TrashLib.Services.Radarr.QualityDefinition.Api.Objects;
@ -12,16 +13,16 @@ internal class RadarrQualityDefinitionUpdater : IRadarrQualityDefinitionUpdater
private readonly ILogger _log;
private readonly IQualityDefinitionService _api;
private readonly IConsole _console;
private readonly IRadarrQualityGuideParser _parser;
private readonly IRadarrGuideService _guide;
public RadarrQualityDefinitionUpdater(
ILogger logger,
IRadarrQualityGuideParser parser,
IRadarrGuideService guide,
IQualityDefinitionService api,
IConsole console)
{
_log = logger;
_parser = parser;
_guide = guide;
_api = api;
_console = console;
}
@ -29,7 +30,7 @@ internal class RadarrQualityDefinitionUpdater : IRadarrQualityDefinitionUpdater
public async Task Process(bool isPreview, RadarrConfiguration config)
{
_log.Information("Processing Quality Definition: {QualityDefinition}", config.QualityDefinition!.Type);
var qualityDefinitions = _parser.GetQualities();
var qualityDefinitions = _guide.GetQualities();
var qualityTypeInConfig = config.QualityDefinition!.Type;
var selectedQuality = qualityDefinitions

@ -1,20 +0,0 @@
using Serilog;
using TrashLib.Repo;
using TrashLib.Services.Common.QualityDefinition;
namespace TrashLib.Services.Radarr.QualityDefinition;
internal class RadarrQualityGuideParser : IRadarrQualityGuideParser
{
private readonly QualityGuideParser<RadarrQualityData> _parser;
private readonly IRepoPathsFactory _pathFactory;
public RadarrQualityGuideParser(ILogger log, IRepoPathsFactory pathFactory)
{
_parser = new QualityGuideParser<RadarrQualityData>(log);
_pathFactory = pathFactory;
}
public ICollection<RadarrQualityData> GetQualities()
=> _parser.GetQualities(_pathFactory.Create().RadarrQualityPaths);
}

@ -28,11 +28,10 @@ public class RadarrAutofacModule : Module
// Quality Definition Support
builder.RegisterType<RadarrQualityDefinitionUpdater>().As<IRadarrQualityDefinitionUpdater>();
builder.RegisterType<RadarrQualityGuideParser>().As<IRadarrQualityGuideParser>();
// Custom Format Support
builder.RegisterType<CustomFormatUpdater>().As<ICustomFormatUpdater>();
builder.RegisterType<LocalRepoCustomFormatJsonParser>().As<IRadarrGuideService>();
builder.RegisterType<LocalRepoRadarrGuideService>().As<IRadarrGuideService>();
builder.RegisterType<CachePersister>().As<ICachePersister>();
builder.RegisterType<CustomFormatLister>().As<ICustomFormatLister>();

@ -1,6 +0,0 @@
namespace TrashLib.Services.Sonarr.QualityDefinition;
public interface ISonarrQualityGuideParser
{
ICollection<SonarrQualityData> GetQualities();
}

@ -6,6 +6,7 @@ using TrashLib.Services.Common.QualityDefinition;
using TrashLib.Services.Sonarr.Api;
using TrashLib.Services.Sonarr.Api.Objects;
using TrashLib.Services.Sonarr.Config;
using TrashLib.Services.Sonarr.ReleaseProfile.Guide;
namespace TrashLib.Services.Sonarr.QualityDefinition;
@ -14,17 +15,17 @@ internal class SonarrQualityDefinitionUpdater : ISonarrQualityDefinitionUpdater
private readonly ILogger _log;
private readonly ISonarrApi _api;
private readonly IConsole _console;
private readonly ISonarrQualityGuideParser _parser;
private readonly ISonarrGuideService _guide;
private readonly Regex _regexHybrid = new(@"720|1080", RegexOptions.Compiled);
public SonarrQualityDefinitionUpdater(
ILogger logger,
ISonarrQualityGuideParser parser,
ISonarrGuideService guide,
ISonarrApi api,
IConsole console)
{
_log = logger;
_parser = parser;
_guide = guide;
_api = api;
_console = console;
}
@ -45,7 +46,7 @@ internal class SonarrQualityDefinitionUpdater : ISonarrQualityDefinitionUpdater
public async Task Process(bool isPreview, SonarrConfiguration config)
{
_log.Information("Processing Quality Definition: {QualityDefinition}", config.QualityDefinition);
var qualityDefinitions = _parser.GetQualities();
var qualityDefinitions = _guide.GetQualities();
var qualityTypeInConfig = config.QualityDefinition;
// var qualityDefinitions = _parser.ParseMarkdown(await _parser.GetMarkdownData());

@ -1,20 +0,0 @@
using Serilog;
using TrashLib.Repo;
using TrashLib.Services.Common.QualityDefinition;
namespace TrashLib.Services.Sonarr.QualityDefinition;
internal class SonarrQualityGuideParser : ISonarrQualityGuideParser
{
private readonly QualityGuideParser<SonarrQualityData> _parser;
private readonly IRepoPathsFactory _pathFactory;
public SonarrQualityGuideParser(ILogger log, IRepoPathsFactory pathFactory)
{
_parser = new QualityGuideParser<SonarrQualityData>(log);
_pathFactory = pathFactory;
}
public ICollection<SonarrQualityData> GetQualities()
=> _parser.GetQualities(_pathFactory.Create().SonarrQualityPaths);
}

@ -1,7 +1,10 @@
using TrashLib.Services.Sonarr.QualityDefinition;
namespace TrashLib.Services.Sonarr.ReleaseProfile.Guide;
public interface ISonarrGuideService
{
IReadOnlyCollection<ReleaseProfileData> GetReleaseProfileData();
ReleaseProfileData? GetUnfilteredProfileById(string trashId);
ICollection<SonarrQualityData> GetQualities();
}

@ -4,23 +4,30 @@ using MoreLinq;
using Newtonsoft.Json;
using Serilog;
using TrashLib.Repo;
using TrashLib.Services.Common.QualityDefinition;
using TrashLib.Services.Sonarr.QualityDefinition;
using TrashLib.Services.Sonarr.ReleaseProfile.Filters;
namespace TrashLib.Services.Sonarr.ReleaseProfile.Guide;
public class LocalRepoReleaseProfileJsonParser : ISonarrGuideService
public class LocalRepoSonarrGuideService : ISonarrGuideService
{
private readonly IRepoPathsFactory _pathFactory;
private readonly ILogger _log;
private readonly Lazy<IEnumerable<ReleaseProfileData>> _data;
private readonly QualityGuideParser<SonarrQualityData> _parser;
public LocalRepoReleaseProfileJsonParser(IRepoPathsFactory pathFactory, ILogger log)
public LocalRepoSonarrGuideService(IRepoPathsFactory pathFactory, ILogger log)
{
_pathFactory = pathFactory;
_log = log;
_data = new Lazy<IEnumerable<ReleaseProfileData>>(GetReleaseProfileDataImpl);
_parser = new QualityGuideParser<SonarrQualityData>(log);
}
public ICollection<SonarrQualityData> GetQualities()
=> _parser.GetQualities(_pathFactory.Create().SonarrQualityPaths);
private IEnumerable<ReleaseProfileData> GetReleaseProfileDataImpl()
{
var converter = new TermDataConverter();

@ -20,7 +20,7 @@ public class SonarrAutofacModule : Module
// Release Profile Support
builder.RegisterType<ReleaseProfileUpdater>().As<IReleaseProfileUpdater>();
builder.RegisterType<LocalRepoReleaseProfileJsonParser>().As<ISonarrGuideService>();
builder.RegisterType<LocalRepoSonarrGuideService>().As<ISonarrGuideService>();
builder.RegisterType<SonarrReleaseProfileCompatibilityHandler>()
.As<ISonarrReleaseProfileCompatibilityHandler>();
builder.RegisterType<ReleaseProfileFilterPipeline>().As<IReleaseProfileFilterPipeline>();
@ -34,6 +34,5 @@ public class SonarrAutofacModule : Module
// Quality Definition Support
builder.RegisterType<SonarrQualityDefinitionUpdater>().As<ISonarrQualityDefinitionUpdater>();
builder.RegisterType<SonarrQualityGuideParser>().As<ISonarrQualityGuideParser>();
}
}

Loading…
Cancel
Save