From 6b6cab62c24265a0641a8ab8363b49849a29945a Mon Sep 17 00:00:00 2001 From: Carl Lewis Date: Tue, 1 Aug 2023 20:26:32 -0400 Subject: [PATCH] Additional code review items --- .../ImportLists/AniList/AniListImportBase.cs | 16 +++++++++------- .../ImportLists/AniList/AniListSettingsBase.cs | 3 --- .../ImportLists/AniList/List/AniListImport.cs | 2 +- .../ImportLists/AniList/List/AniListParser.cs | 10 ++++++---- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/AniList/AniListImportBase.cs b/src/NzbDrone.Core/ImportLists/AniList/AniListImportBase.cs index 849b1782a..f5d7c10da 100644 --- a/src/NzbDrone.Core/ImportLists/AniList/AniListImportBase.cs +++ b/src/NzbDrone.Core/ImportLists/AniList/AniListImportBase.cs @@ -28,6 +28,8 @@ namespace NzbDrone.Core.ImportLists.AniList public const string OAuthUrl = "https://anilist.co/api/v2/oauth/authorize"; 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 MapSourceUrl = "https://raw.githubusercontent.com/Fribb/anime-lists/master/anime-list-full.json"; + public const string ClientId = "13780"; private IImportListRepository _importListRepository; @@ -93,7 +95,7 @@ namespace NzbDrone.Core.ImportLists.AniList var result = new Dictionary(); try { - var request = new HttpRequest(Settings.MapSourceUrl, HttpAccept.Json); + var request = new HttpRequest(MapSourceUrl, HttpAccept.Json); var response = _httpClient.Execute(request); if (response.StatusCode == HttpStatusCode.OK) @@ -124,11 +126,11 @@ namespace NzbDrone.Core.ImportLists.AniList if (webException.Message.Contains("502") || webException.Message.Contains("503") || webException.Message.Contains("timed out")) { - _logger.Warn("{0} server is currently unavailable. {1} {2}", this, Settings.MapSourceUrl, webException.Message); + _logger.Warn("{0} server is currently unavailable. {1} {2}", this, MapSourceUrl, webException.Message); } else { - _logger.Warn("{0} {1} {2}", this, Settings.MapSourceUrl, webException.Message); + _logger.Warn("{0} {1} {2}", this, MapSourceUrl, webException.Message); } } catch (HttpException ex) @@ -139,14 +141,14 @@ namespace NzbDrone.Core.ImportLists.AniList catch (JsonSerializationException ex) { _importListStatusService.RecordFailure(Definition.Id); - ex.WithData("MappingUrl", Settings.MapSourceUrl); - _logger.Error(ex, "Mapping source data is invalid. {0}", Settings.MapSourceUrl); + ex.WithData("MappingUrl", MapSourceUrl); + _logger.Error(ex, "Mapping source data is invalid. {0}", MapSourceUrl); } catch (Exception ex) { _importListStatusService.RecordFailure(Definition.Id); - ex.WithData("MappingUrl", Settings.MapSourceUrl); - _logger.Error(ex, "An error occurred while downloading mapping file. {0}", Settings.MapSourceUrl); + ex.WithData("MappingUrl", MapSourceUrl); + _logger.Error(ex, "An error occurred while downloading mapping file. {0}", MapSourceUrl); } return result; diff --git a/src/NzbDrone.Core/ImportLists/AniList/AniListSettingsBase.cs b/src/NzbDrone.Core/ImportLists/AniList/AniListSettingsBase.cs index 9d1ebdb54..dceb6a7d8 100644 --- a/src/NzbDrone.Core/ImportLists/AniList/AniListSettingsBase.cs +++ b/src/NzbDrone.Core/ImportLists/AniList/AniListSettingsBase.cs @@ -38,13 +38,10 @@ namespace NzbDrone.Core.ImportLists.AniList { BaseUrl = "https://graphql.anilist.co"; SignIn = "startOAuth"; - MapSourceUrl = "https://raw.githubusercontent.com/Fribb/anime-lists/master/anime-list-full.json"; } public string BaseUrl { get; set; } - public string MapSourceUrl { get; set; } - [FieldDefinition(0, Label = "Access Token", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)] public string AccessToken { get; set; } diff --git a/src/NzbDrone.Core/ImportLists/AniList/List/AniListImport.cs b/src/NzbDrone.Core/ImportLists/AniList/List/AniListImport.cs index f8e0ccd0d..0f7f0e3d1 100644 --- a/src/NzbDrone.Core/ImportLists/AniList/List/AniListImport.cs +++ b/src/NzbDrone.Core/ImportLists/AniList/List/AniListImport.cs @@ -41,7 +41,7 @@ namespace NzbDrone.Core.ImportLists.AniList.List public override AniListParser GetParser() { - return new AniListParser(_logger, Settings, Mappings); + return new AniListParser(Settings, Mappings); } protected override IList FetchItems(Func pageableRequestChainSelector, bool isRecent = false) diff --git a/src/NzbDrone.Core/ImportLists/AniList/List/AniListParser.cs b/src/NzbDrone.Core/ImportLists/AniList/List/AniListParser.cs index 55162c5cd..d97bb627c 100644 --- a/src/NzbDrone.Core/ImportLists/AniList/List/AniListParser.cs +++ b/src/NzbDrone.Core/ImportLists/AniList/List/AniListParser.cs @@ -3,22 +3,24 @@ using System.Linq; using System.Net; using NLog; using NzbDrone.Common.Extensions; +using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Serializer; using NzbDrone.Core.ImportLists.Exceptions; +using NzbDrone.Core.ImportLists.Simkl; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.ImportLists.AniList.List { public class AniListParser : IParseImportListResponse { + private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(SimklParser)); + private readonly Dictionary _mappings; - private readonly Logger _logger; private readonly AniListSettings _settings; - public AniListParser(Logger logger, AniListSettings settings, Dictionary mappings) + public AniListParser(AniListSettings settings, Dictionary mappings) { _mappings = mappings; - _logger = logger; _settings = settings; } @@ -84,7 +86,7 @@ namespace NzbDrone.Core.ImportLists.AniList.List } else { - _logger.Warn("'{1}' (id:{0}) could not be imported, because there is no mapping available.", media.Id, media.Title.UserPreferred ?? media.Title.UserRomaji); + Logger.Warn("'{1}' (id:{0}) could not be imported, because there is no mapping available.", media.Id, media.Title.UserPreferred ?? media.Title.UserRomaji); } }