From 2765122da64989a1e491d05f0378761c1c525bc7 Mon Sep 17 00:00:00 2001 From: Carl Lewis Date: Sun, 30 Jul 2023 21:10:32 -0400 Subject: [PATCH] Changes to address code review items --- .../ImportLists/AniList/AniListImportBase.cs | 9 +-- .../ImportLists/AniList/AniListTypes.cs | 63 +------------------ .../ImportLists/AniList/List/AniListImport.cs | 7 +-- .../ImportLists/AniList/List/AniListParser.cs | 13 ++-- .../AniList/List/AniListSettings.cs | 24 ++++--- .../ImportLists/Trakt/TraktImportBase.cs | 2 +- 6 files changed, 25 insertions(+), 93 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/AniList/AniListImportBase.cs b/src/NzbDrone.Core/ImportLists/AniList/AniListImportBase.cs index ab971ae1a..fb30f6fd0 100644 --- a/src/NzbDrone.Core/ImportLists/AniList/AniListImportBase.cs +++ b/src/NzbDrone.Core/ImportLists/AniList/AniListImportBase.cs @@ -26,9 +26,9 @@ namespace NzbDrone.Core.ImportLists.AniList private readonly ICached> _cache; public const string OAuthUrl = "https://anilist.co/api/v2/oauth/authorize"; - public const string RedirectUri = "http://localhost:5000/anilist/auth"; - public const string RenewUri = "http://localhost:5000/anilist/renew"; - public const string ClientId = "13737"; + public const string RedirectUri = "https://auth.servarr.com/v1/anilist_sonarr/auth"; + public const string RenewUri = "https://auth.servarr.com/v1/anilist_sonarr/renew"; + public const string ClientId = "13780"; private IImportListRepository _importListRepository; @@ -99,9 +99,10 @@ namespace NzbDrone.Core.ImportLists.AniList if (response.StatusCode == HttpStatusCode.OK) { var mappingList = STJson.Deserialize>(response.Content); + foreach (var item in mappingList) { - if (item.Anilist.HasValue && item.Anilist > 0 && item.TVDB.HasValue && item.TVDB > 0) + if (item.Anilist.HasValue && item.Anilist > 0 && item.Tvdb.HasValue && item.Tvdb > 0) { result.Add((int)item.Anilist, item); } diff --git a/src/NzbDrone.Core/ImportLists/AniList/AniListTypes.cs b/src/NzbDrone.Core/ImportLists/AniList/AniListTypes.cs index 7ed22af59..357654374 100644 --- a/src/NzbDrone.Core/ImportLists/AniList/AniListTypes.cs +++ b/src/NzbDrone.Core/ImportLists/AniList/AniListTypes.cs @@ -3,73 +3,34 @@ using Newtonsoft.Json; namespace NzbDrone.Core.ImportLists.AniList { - /// - /// Media list status types - /// public static class MediaListStatus { - /// - /// Currently Watching Anime Series - /// public const string Current = "CURRENT"; - /// - /// Plan to Watch Anime Series - /// public const string Planning = "PLANNING"; - /// - /// Completed Anime Series - /// public const string Completed = "COMPLETED"; - /// - /// Dropped Anime Series - /// public const string Dropped = "DROPPED"; - /// - /// On Hold Anime Series - /// public const string Paused = "PAUSED"; - /// - /// Rewatching Anime Series - /// public const string Repeating = "REPEATING"; } public static class MediaStatus { - /// - /// Anime series has finished airing - /// public const string Finished = "FINISHED"; - /// - /// Anime series is currently airing - /// public const string Releasing = "RELEASING"; - /// - /// Anime series had not yet begun airing - /// public const string Unreleased = "NOT_YET_RELEASED"; - /// - /// Anime series was cancelled - /// public const string Cancelled = "CANCELLED"; - /// - /// Anime series is currently on hiatus - /// public const string Hiatus = "HIATUS"; } - /// - /// Data during token refresh cycles - /// public class RefreshRequestResponse { [JsonProperty("access_token")] @@ -80,40 +41,20 @@ namespace NzbDrone.Core.ImportLists.AniList public string RefreshToken { get; set; } } - /// - /// Mapping data between anime service providers - /// public class MediaMapping { - /// - /// Anilist ID - /// [JsonPropertyName("anilist_id")] public int? Anilist { get; set; } - /// - /// The TVDB ID - /// [JsonPropertyName("thetvdb_id")] - public int? TVDB { get; set; } + public int? Tvdb { get; set; } - /// - /// My Anime List ID - /// [JsonPropertyName("mal_id")] public int? MyAnimeList { get; set; } - /// - /// IMDB ID - /// [JsonPropertyName("imdb_id")] - public string IMDB { get; set; } + public string Imdb { get; set; } - /// - /// Entry type such as TV or MOVIE. - /// - /// Required when mapping between services that reuse ids for different content types. - /// [JsonPropertyName("type")] public string ItemType { get; set; } } diff --git a/src/NzbDrone.Core/ImportLists/AniList/List/AniListImport.cs b/src/NzbDrone.Core/ImportLists/AniList/List/AniListImport.cs index cc241b20b..f8e0ccd0d 100644 --- a/src/NzbDrone.Core/ImportLists/AniList/List/AniListImport.cs +++ b/src/NzbDrone.Core/ImportLists/AniList/List/AniListImport.cs @@ -44,11 +44,6 @@ namespace NzbDrone.Core.ImportLists.AniList.List return new AniListParser(_logger, Settings, Mappings); } - /// - /// Anilist caps the result list to 50 items at maximum per query, so the data must be pulled in batches. - /// - /// The number of pages are not known upfront, so the fetch logic must be changed to look at the returned page data. - /// protected override IList FetchItems(Func pageableRequestChainSelector, bool isRecent = false) { var releases = new List(); @@ -62,6 +57,8 @@ namespace NzbDrone.Core.ImportLists.AniList.List var hasNextPage = false; ImportListRequest currentRequest = null; + // Anilist caps the result list to 50 items at maximum per query, so the data must be pulled in batches. + // The number of pages are not known upfront, so the fetch logic must be changed to look at the returned page data. do { // Build the query for the current page diff --git a/src/NzbDrone.Core/ImportLists/AniList/List/AniListParser.cs b/src/NzbDrone.Core/ImportLists/AniList/List/AniListParser.cs index f59fbd4e9..55162c5cd 100644 --- a/src/NzbDrone.Core/ImportLists/AniList/List/AniListParser.cs +++ b/src/NzbDrone.Core/ImportLists/AniList/List/AniListParser.cs @@ -45,7 +45,7 @@ namespace NzbDrone.Core.ImportLists.AniList.List return result; } - // Filter out unwanted series status types + // Anilist currently does not support filtering this at the query level, they will get filtered out here. var filtered = jsonResponse.Data.Page.MediaList .Where(x => ValidateMediaStatus(x.Media)); @@ -58,7 +58,7 @@ namespace NzbDrone.Core.ImportLists.AniList.List // Base required data var entry = new ImportListItemInfo() { - TvdbId = mapping.TVDB.Value, + TvdbId = mapping.Tvdb.Value, Title = media.Title.UserPreferred ?? media.Title.UserRomaji ?? default }; @@ -68,9 +68,9 @@ namespace NzbDrone.Core.ImportLists.AniList.List entry.MalId = mapping.MyAnimeList.Value; } - if (!string.IsNullOrEmpty(mapping.IMDB)) + if (!string.IsNullOrEmpty(mapping.Imdb)) { - entry.ImdbId = mapping.IMDB; + entry.ImdbId = mapping.Imdb; } // Optional Year/ReleaseDate data @@ -92,11 +92,6 @@ namespace NzbDrone.Core.ImportLists.AniList.List return result; } - /// - /// Filter by media status, based on user settings. - /// - /// Anilist currently does not support filtering this at the query level, so it must be done in post. - /// private bool ValidateMediaStatus(MediaInfo media) { if (media.Status == MediaStatus.Finished && _settings.ImportFinished) diff --git a/src/NzbDrone.Core/ImportLists/AniList/List/AniListSettings.cs b/src/NzbDrone.Core/ImportLists/AniList/List/AniListSettings.cs index 1b7fae84e..c160892e6 100644 --- a/src/NzbDrone.Core/ImportLists/AniList/List/AniListSettings.cs +++ b/src/NzbDrone.Core/ImportLists/AniList/List/AniListSettings.cs @@ -19,8 +19,6 @@ namespace NzbDrone.Core.ImportLists.AniList.List public class AniListSettings : AniListSettingsBase { public const string sectionImport = "Import List Status"; - public const string unitListStatus = "List Status"; - public const string unitMediaStatus = "Media Status"; public AniListSettings() : base() @@ -36,37 +34,37 @@ namespace NzbDrone.Core.ImportLists.AniList.List [FieldDefinition(1, Label = "Username", HelpText = "Username for the List to import from")] public string Username { get; set; } - [FieldDefinition(0, Label = "Import Watching", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)] + [FieldDefinition(2, Label = "Import Watching", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "List: Currently Watching")] public bool ImportCurrent { get; set; } - [FieldDefinition(0, Label = "Import Planning", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)] + [FieldDefinition(3, Label = "Import Planning", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "List: Planning to Watch")] public bool ImportPlanning { get; set; } - [FieldDefinition(0, Label = "Import Completed", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)] + [FieldDefinition(4, Label = "Import Completed", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "List: Completed Watching")] public bool ImportCompleted { get; set; } - [FieldDefinition(0, Label = "Import Dropped", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)] + [FieldDefinition(5, Label = "Import Dropped", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "List: Dropped")] public bool ImportDropped { get; set; } - [FieldDefinition(0, Label = "Import Paused", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)] + [FieldDefinition(6, Label = "Import Paused", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "List: On Hold")] public bool ImportPaused { get; set; } - [FieldDefinition(0, Label = "Import Repeating", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitListStatus)] + [FieldDefinition(7, Label = "Import Repeating", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "List: Currently Rewatching")] public bool ImportRepeating { get; set; } - [FieldDefinition(0, Label = "Import Finished Airing Series", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitMediaStatus)] + [FieldDefinition(8, Label = "Import Finished", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "Media: All episodes have aired")] public bool ImportFinished { get; set; } - [FieldDefinition(0, Label = "Import Currently Airing Series", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitMediaStatus)] + [FieldDefinition(9, Label = "Import Releasing", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "Media: Currently airing new episodes")] public bool ImportReleasing { get; set; } - [FieldDefinition(0, Label = "Import Not Yet Airing Series", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitMediaStatus)] + [FieldDefinition(10, Label = "Import Not Yet Released", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "Media: Airing has not yet started")] public bool ImportUnreleased { get; set; } - [FieldDefinition(0, Label = "Import Cancelled Series", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitMediaStatus)] + [FieldDefinition(11, Label = "Import Cancelled", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "Media: Series is cancelled")] public bool ImportCancelled { get; set; } - [FieldDefinition(0, Label = "Import Series on Hiatus", Type = FieldType.Checkbox, Section = sectionImport, Unit = unitMediaStatus)] + [FieldDefinition(12, Label = "Import Hiatus", Type = FieldType.Checkbox, Section = sectionImport, HelpText = "Media: Series on Hiatus")] public bool ImportHiatus { get; set; } } } diff --git a/src/NzbDrone.Core/ImportLists/Trakt/TraktImportBase.cs b/src/NzbDrone.Core/ImportLists/Trakt/TraktImportBase.cs index 79922f3f4..f10f1713d 100644 --- a/src/NzbDrone.Core/ImportLists/Trakt/TraktImportBase.cs +++ b/src/NzbDrone.Core/ImportLists/Trakt/TraktImportBase.cs @@ -37,7 +37,7 @@ namespace NzbDrone.Core.ImportLists.Trakt public override IList Fetch() { Settings.Validate().Filter("AccessToken", "RefreshToken").ThrowOnError(); - _logger.Trace($"Access token expires at {Settings.Expires}"); + _logger.Trace("Access token expires at {0}", Settings.Expires); if (Settings.Expires < DateTime.UtcNow.AddMinutes(5)) {