Changes to address code review items

This commit is contained in:
Carl Lewis 2023-07-30 21:10:32 -04:00
parent d4c063df56
commit 2765122da6
6 changed files with 25 additions and 93 deletions

View File

@ -26,9 +26,9 @@ namespace NzbDrone.Core.ImportLists.AniList
private readonly ICached<Dictionary<int, MediaMapping>> _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<List<MediaMapping>>(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);
}

View File

@ -3,73 +3,34 @@ using Newtonsoft.Json;
namespace NzbDrone.Core.ImportLists.AniList
{
/// <summary>
/// Media list status types
/// </summary>
public static class MediaListStatus
{
/// <summary>
/// Currently Watching Anime Series
/// </summary>
public const string Current = "CURRENT";
/// <summary>
/// Plan to Watch Anime Series
/// </summary>
public const string Planning = "PLANNING";
/// <summary>
/// Completed Anime Series
/// </summary>
public const string Completed = "COMPLETED";
/// <summary>
/// Dropped Anime Series
/// </summary>
public const string Dropped = "DROPPED";
/// <summary>
/// On Hold Anime Series
/// </summary>
public const string Paused = "PAUSED";
/// <summary>
/// Rewatching Anime Series
/// </summary>
public const string Repeating = "REPEATING";
}
public static class MediaStatus
{
/// <summary>
/// Anime series has finished airing
/// </summary>
public const string Finished = "FINISHED";
/// <summary>
/// Anime series is currently airing
/// </summary>
public const string Releasing = "RELEASING";
/// <summary>
/// Anime series had not yet begun airing
/// </summary>
public const string Unreleased = "NOT_YET_RELEASED";
/// <summary>
/// Anime series was cancelled
/// </summary>
public const string Cancelled = "CANCELLED";
/// <summary>
/// Anime series is currently on hiatus
/// </summary>
public const string Hiatus = "HIATUS";
}
/// <summary>
/// Data during token refresh cycles
/// </summary>
public class RefreshRequestResponse
{
[JsonProperty("access_token")]
@ -80,40 +41,20 @@ namespace NzbDrone.Core.ImportLists.AniList
public string RefreshToken { get; set; }
}
/// <summary>
/// Mapping data between anime service providers
/// </summary>
public class MediaMapping
{
/// <summary>
/// Anilist ID
/// </summary>
[JsonPropertyName("anilist_id")]
public int? Anilist { get; set; }
/// <summary>
/// The TVDB ID
/// </summary>
[JsonPropertyName("thetvdb_id")]
public int? TVDB { get; set; }
public int? Tvdb { get; set; }
/// <summary>
/// My Anime List ID
/// </summary>
[JsonPropertyName("mal_id")]
public int? MyAnimeList { get; set; }
/// <summary>
/// IMDB ID
/// </summary>
[JsonPropertyName("imdb_id")]
public string IMDB { get; set; }
public string Imdb { get; set; }
/// <summary>
/// Entry type such as TV or MOVIE.
///
/// Required when mapping between services that reuse ids for different content types.
/// </summary>
[JsonPropertyName("type")]
public string ItemType { get; set; }
}

View File

@ -44,11 +44,6 @@ namespace NzbDrone.Core.ImportLists.AniList.List
return new AniListParser(_logger, Settings, Mappings);
}
/// <summary>
/// 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.
/// </summary>
protected override IList<ImportListItemInfo> FetchItems(Func<IImportListRequestGenerator, ImportListPageableRequestChain> pageableRequestChainSelector, bool isRecent = false)
{
var releases = new List<ImportListItemInfo>();
@ -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

View File

@ -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;
}
/// <summary>
/// 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.
/// </summary>
private bool ValidateMediaStatus(MediaInfo media)
{
if (media.Status == MediaStatus.Finished && _settings.ImportFinished)

View File

@ -19,8 +19,6 @@ namespace NzbDrone.Core.ImportLists.AniList.List
public class AniListSettings : AniListSettingsBase<AniListSettings>
{
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; }
}
}

View File

@ -37,7 +37,7 @@ namespace NzbDrone.Core.ImportLists.Trakt
public override IList<ImportListItemInfo> 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))
{