diff --git a/CHANGELOG.md b/CHANGELOG.md index 4951c3d7..dc40e5d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,9 @@ JSON files][sonarrjson]. This breaks existing `trash.yml` and manual changes *ar Docker. - Sonarr: Ability to include or exclude specific optional Required, Ignored, or Preferred terms in release profiles. +- Sonarr: New `--list-release-profiles` command line option which can be used to quickly and + conveniently get a list of release profiles (and their Trash IDs) so you know what to add in your + YAML config under `release_profiles`. [#17]: https://github.com/rcdailey/trash-updater/issues/17 [Upgrade Guide]: https://github.com/rcdailey/trash-updater/wiki/Upgrade-Guide diff --git a/README.md b/README.md index a9e7a48a..370c8b04 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ Automatically mirror TRaSH guides to your Sonarr/Radarr instance. - Ability to convert preferred with negative scores to "Must not contain" terms. - Terms mentioned as "optional" in the guide can be selectively included or excluded; based entirely on user preference. +- Convenient command line options to get information from the guide to more easily add it to your + YAML configuration. ### Quality Definitions diff --git a/src/Trash/Command/SonarrCommand.cs b/src/Trash/Command/SonarrCommand.cs index f23a5512..93c3e273 100644 --- a/src/Trash/Command/SonarrCommand.cs +++ b/src/Trash/Command/SonarrCommand.cs @@ -6,6 +6,7 @@ using Serilog.Core; using Trash.Config; using TrashLib.Config.Settings; using TrashLib.Repo; +using TrashLib.Sonarr; using TrashLib.Sonarr.Config; using TrashLib.Sonarr.QualityDefinition; using TrashLib.Sonarr.ReleaseProfile; @@ -20,6 +21,11 @@ public class SonarrCommand : ServiceCommand private readonly ILogger _log; private readonly Func _profileUpdaterFactory; private readonly Func _qualityUpdaterFactory; + private readonly IReleaseProfileLister _lister; + + [CommandOption("list-release-profiles", Description = + "List available release profiles from the guide in YAML format.")] + public bool ListReleaseProfiles { get; [UsedImplicitly] set; } = false; public SonarrCommand( ILogger log, @@ -30,13 +36,15 @@ public class SonarrCommand : ServiceCommand IRepoUpdater repoUpdater, IConfigurationLoader configLoader, Func profileUpdaterFactory, - Func qualityUpdaterFactory) + Func qualityUpdaterFactory, + IReleaseProfileLister lister) : base(log, loggingLevelSwitch, logJanitor, settingsPersister, settingsProvider, repoUpdater) { _log = log; _configLoader = configLoader; _profileUpdaterFactory = profileUpdaterFactory; _qualityUpdaterFactory = qualityUpdaterFactory; + _lister = lister; } public override string CacheStoragePath { get; } = @@ -46,6 +54,12 @@ public class SonarrCommand : ServiceCommand { try { + if (ListReleaseProfiles) + { + _lister.ListReleaseProfiles(); + return; + } + foreach (var config in _configLoader.LoadMany(Config, "sonarr")) { _log.Information("Processing server {Url}", config.BaseUrl); diff --git a/src/TrashLib/Sonarr/IReleaseProfileLister.cs b/src/TrashLib/Sonarr/IReleaseProfileLister.cs new file mode 100644 index 00000000..f3065bef --- /dev/null +++ b/src/TrashLib/Sonarr/IReleaseProfileLister.cs @@ -0,0 +1,6 @@ +namespace TrashLib.Sonarr; + +public interface IReleaseProfileLister +{ + void ListReleaseProfiles(); +} diff --git a/src/TrashLib/Sonarr/ReleaseProfileLister.cs b/src/TrashLib/Sonarr/ReleaseProfileLister.cs new file mode 100644 index 00000000..1439006c --- /dev/null +++ b/src/TrashLib/Sonarr/ReleaseProfileLister.cs @@ -0,0 +1,32 @@ +using CliFx.Infrastructure; +using JetBrains.Annotations; +using TrashLib.Sonarr.ReleaseProfile.Guide; + +namespace TrashLib.Sonarr; + +[UsedImplicitly] +public class ReleaseProfileLister : IReleaseProfileLister +{ + private readonly IConsole _console; + private readonly ISonarrGuideService _guide; + + public ReleaseProfileLister(IConsole console, ISonarrGuideService guide) + { + _console = console; + _guide = guide; + } + + public void ListReleaseProfiles() + { + _console.Output.WriteLine("\nList of Release Profiles in the TRaSH Guides:\n"); + + var profilesFromGuide = _guide.GetReleaseProfileData(); + foreach (var profile in profilesFromGuide) + { + _console.Output.WriteLine($" - {profile.TrashId} # {profile.Name}"); + } + + _console.Output.WriteLine( + "\nThe above Release Profiles are in YAML format and ready to be copied & pasted under the `trash_ids:` property."); + } +} diff --git a/src/TrashLib/Sonarr/SonarrAutofacModule.cs b/src/TrashLib/Sonarr/SonarrAutofacModule.cs index 671f2592..607d0848 100644 --- a/src/TrashLib/Sonarr/SonarrAutofacModule.cs +++ b/src/TrashLib/Sonarr/SonarrAutofacModule.cs @@ -13,10 +13,8 @@ public class SonarrAutofacModule : Module { builder.RegisterType().As(); builder.RegisterType().As(); - - builder.RegisterType() - .As() - .SingleInstance(); + builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As(); // Release Profile Support builder.RegisterType().As(); diff --git a/src/TrashLib/TrashLib.csproj b/src/TrashLib/TrashLib.csproj index 74eb4b5e..2f5275d9 100644 --- a/src/TrashLib/TrashLib.csproj +++ b/src/TrashLib/TrashLib.csproj @@ -3,6 +3,7 @@ +