From 6d6c88a2830f3ee87bd13574446b7b146f599fa2 Mon Sep 17 00:00:00 2001 From: iceypotato Date: Thu, 27 Jul 2023 13:59:24 -0700 Subject: [PATCH] added dropdown menu for importing anime based on the list status for MAL import --- .../ImportLists/MyAnimeList/MalApi.cs | 17 ++++++++++++++++- .../ImportLists/MyAnimeList/MalListSettings.cs | 4 ++++ .../MyAnimeList/MalRequestGenerator.cs | 14 ++++---------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/MyAnimeList/MalApi.cs b/src/NzbDrone.Core/ImportLists/MyAnimeList/MalApi.cs index e166358b2..821f5f42b 100644 --- a/src/NzbDrone.Core/ImportLists/MyAnimeList/MalApi.cs +++ b/src/NzbDrone.Core/ImportLists/MyAnimeList/MalApi.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Runtime.Serialization; using Newtonsoft.Json; namespace NzbDrone.Core.ImportLists.MyAnimeList @@ -26,6 +27,20 @@ namespace NzbDrone.Core.ImportLists.MyAnimeList public class MalAnimeListStatus { - public string Status { get; set; } + public MalAnimeStatus Status { get; set; } + } + + public enum MalAnimeStatus + { + [EnumMember(Value = "watching")] + Watching, + [EnumMember(Value = "completed")] + Completed, + [EnumMember(Value = "on_hold")] + OnHold, + [EnumMember(Value = "dropped")] + Dropped, + [EnumMember(Value = "plan_to_watch")] + PlanToWatch } } diff --git a/src/NzbDrone.Core/ImportLists/MyAnimeList/MalListSettings.cs b/src/NzbDrone.Core/ImportLists/MyAnimeList/MalListSettings.cs index 9c742e21e..a5efb001e 100644 --- a/src/NzbDrone.Core/ImportLists/MyAnimeList/MalListSettings.cs +++ b/src/NzbDrone.Core/ImportLists/MyAnimeList/MalListSettings.cs @@ -22,8 +22,12 @@ namespace NzbDrone.Core.ImportLists.MyAnimeList public MalListSettings() { BaseUrl = "https://api.myanimelist.net/v2"; + ListStatus = MalAnimeStatus.Watching; } + [FieldDefinition(0, Label = "List Status", Type = FieldType.Select, SelectOptions = typeof(MalAnimeStatus), HelpText = "Type of list status you're seeking to import from")] + public MalAnimeStatus ListStatus { get; set; } + [FieldDefinition(0, Label = "Client ID", Type = FieldType.Textbox)] public string ClientId { get; set; } diff --git a/src/NzbDrone.Core/ImportLists/MyAnimeList/MalRequestGenerator.cs b/src/NzbDrone.Core/ImportLists/MyAnimeList/MalRequestGenerator.cs index b38180d72..88b47631a 100644 --- a/src/NzbDrone.Core/ImportLists/MyAnimeList/MalRequestGenerator.cs +++ b/src/NzbDrone.Core/ImportLists/MyAnimeList/MalRequestGenerator.cs @@ -1,17 +1,10 @@ using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using NzbDrone.Common.Http; namespace NzbDrone.Core.ImportLists.MyAnimeList { - public enum MalUserListType - { - Watching, - Completed, - OnHold, - Dropped, - PlanToWatch - } - public class MalRequestGenerator : IImportListRequestGenerator { public MalListSettings Settings { get; set; } @@ -27,7 +20,8 @@ namespace NzbDrone.Core.ImportLists.MyAnimeList private IEnumerable GetSeriesRequest() { - var url = $"{Settings.BaseUrl.Trim()}/users/@me/animelist?fields=list_status"; + var selectedListStatus = JsonConvert.SerializeObject(Settings.ListStatus, new StringEnumConverter()).Replace("\"", ""); + var url = $"{Settings.BaseUrl.Trim()}/users/@me/animelist?fields=list_status&limit=1000&status={selectedListStatus}"; var httpReq = new ImportListRequest(url, HttpAccept.Json);