Additional code review items

This commit is contained in:
Carl Lewis 2023-08-01 20:26:32 -04:00
parent edfe3692f7
commit 6b6cab62c2
4 changed files with 16 additions and 15 deletions

View File

@ -28,6 +28,8 @@ namespace NzbDrone.Core.ImportLists.AniList
public const string OAuthUrl = "https://anilist.co/api/v2/oauth/authorize"; 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 RedirectUri = "https://auth.servarr.com/v1/anilist_sonarr/auth";
public const string RenewUri = "https://auth.servarr.com/v1/anilist_sonarr/renew"; 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"; public const string ClientId = "13780";
private IImportListRepository _importListRepository; private IImportListRepository _importListRepository;
@ -93,7 +95,7 @@ namespace NzbDrone.Core.ImportLists.AniList
var result = new Dictionary<int, MediaMapping>(); var result = new Dictionary<int, MediaMapping>();
try try
{ {
var request = new HttpRequest(Settings.MapSourceUrl, HttpAccept.Json); var request = new HttpRequest(MapSourceUrl, HttpAccept.Json);
var response = _httpClient.Execute(request); var response = _httpClient.Execute(request);
if (response.StatusCode == HttpStatusCode.OK) if (response.StatusCode == HttpStatusCode.OK)
@ -124,11 +126,11 @@ namespace NzbDrone.Core.ImportLists.AniList
if (webException.Message.Contains("502") || webException.Message.Contains("503") || if (webException.Message.Contains("502") || webException.Message.Contains("503") ||
webException.Message.Contains("timed out")) 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 else
{ {
_logger.Warn("{0} {1} {2}", this, Settings.MapSourceUrl, webException.Message); _logger.Warn("{0} {1} {2}", this, MapSourceUrl, webException.Message);
} }
} }
catch (HttpException ex) catch (HttpException ex)
@ -139,14 +141,14 @@ namespace NzbDrone.Core.ImportLists.AniList
catch (JsonSerializationException ex) catch (JsonSerializationException ex)
{ {
_importListStatusService.RecordFailure(Definition.Id); _importListStatusService.RecordFailure(Definition.Id);
ex.WithData("MappingUrl", Settings.MapSourceUrl); ex.WithData("MappingUrl", MapSourceUrl);
_logger.Error(ex, "Mapping source data is invalid. {0}", Settings.MapSourceUrl); _logger.Error(ex, "Mapping source data is invalid. {0}", MapSourceUrl);
} }
catch (Exception ex) catch (Exception ex)
{ {
_importListStatusService.RecordFailure(Definition.Id); _importListStatusService.RecordFailure(Definition.Id);
ex.WithData("MappingUrl", Settings.MapSourceUrl); ex.WithData("MappingUrl", MapSourceUrl);
_logger.Error(ex, "An error occurred while downloading mapping file. {0}", Settings.MapSourceUrl); _logger.Error(ex, "An error occurred while downloading mapping file. {0}", MapSourceUrl);
} }
return result; return result;

View File

@ -38,13 +38,10 @@ namespace NzbDrone.Core.ImportLists.AniList
{ {
BaseUrl = "https://graphql.anilist.co"; BaseUrl = "https://graphql.anilist.co";
SignIn = "startOAuth"; SignIn = "startOAuth";
MapSourceUrl = "https://raw.githubusercontent.com/Fribb/anime-lists/master/anime-list-full.json";
} }
public string BaseUrl { get; set; } public string BaseUrl { get; set; }
public string MapSourceUrl { get; set; }
[FieldDefinition(0, Label = "Access Token", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)] [FieldDefinition(0, Label = "Access Token", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)]
public string AccessToken { get; set; } public string AccessToken { get; set; }

View File

@ -41,7 +41,7 @@ namespace NzbDrone.Core.ImportLists.AniList.List
public override AniListParser GetParser() public override AniListParser GetParser()
{ {
return new AniListParser(_logger, Settings, Mappings); return new AniListParser(Settings, Mappings);
} }
protected override IList<ImportListItemInfo> FetchItems(Func<IImportListRequestGenerator, ImportListPageableRequestChain> pageableRequestChainSelector, bool isRecent = false) protected override IList<ImportListItemInfo> FetchItems(Func<IImportListRequestGenerator, ImportListPageableRequestChain> pageableRequestChainSelector, bool isRecent = false)

View File

@ -3,22 +3,24 @@ using System.Linq;
using System.Net; using System.Net;
using NLog; using NLog;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Serializer; using NzbDrone.Common.Serializer;
using NzbDrone.Core.ImportLists.Exceptions; using NzbDrone.Core.ImportLists.Exceptions;
using NzbDrone.Core.ImportLists.Simkl;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.ImportLists.AniList.List namespace NzbDrone.Core.ImportLists.AniList.List
{ {
public class AniListParser : IParseImportListResponse public class AniListParser : IParseImportListResponse
{ {
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(SimklParser));
private readonly Dictionary<int, MediaMapping> _mappings; private readonly Dictionary<int, MediaMapping> _mappings;
private readonly Logger _logger;
private readonly AniListSettings _settings; private readonly AniListSettings _settings;
public AniListParser(Logger logger, AniListSettings settings, Dictionary<int, MediaMapping> mappings) public AniListParser(AniListSettings settings, Dictionary<int, MediaMapping> mappings)
{ {
_mappings = mappings; _mappings = mappings;
_logger = logger;
_settings = settings; _settings = settings;
} }
@ -84,7 +86,7 @@ namespace NzbDrone.Core.ImportLists.AniList.List
} }
else 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);
} }
} }