Added support for Simkl anime list import

Added anime importing, still fixing bugs

Removed some print statements, and renamed the User Import to Shows Import

Removed unused import

Refactored the anime importing to existing SimklUser files

Using workaround for fixing the simkl anime list import by using the animeplanet ID

Cleaned up SimklUserRequestGenerator

Removed animeplanet workaround.

Changed importing so anime movies and non-first season anime are not considered.

Edited console message for unsupported imports

Updated variable names and deleted unnecessary code

Changed Simkl anime importing to a dropdown menu
Removed useless code and fixed some formatting

JsonProperty does not work, using the snake case workaround for now.

More code reformatting in SimklUserRequestGenerator.
Bug: SimklAPI.cs The AnimeType property does not correctly serialize.

Changed class AnimeType to an enum, and renamed to SimklAnimeType and also using the snake case without the attribute

Fixed issue with AnimeType deserialization

Added quotes for the title of the show that the SimklParser will not info grab.

Changed more formatting.
Formatted the warning message as well as made it a little more clear

Fixed and updated SimklAnimeType

Removed an extra comma in SimklUserShowType
This commit is contained in:
iceypotato 2023-06-28 15:19:09 -07:00
parent dee8820b1f
commit f03603db9f
6 changed files with 65 additions and 8 deletions

View File

@ -11,6 +11,7 @@ namespace NzbDrone.Core.ImportLists.Simkl
public string Imdb { get; set; } public string Imdb { get; set; }
public string Tmdb { get; set; } public string Tmdb { get; set; }
public string Tvdb { get; set; } public string Tvdb { get; set; }
public string Mal { get; set; }
} }
public class SimklSeriesPropsResource public class SimklSeriesPropsResource
@ -23,11 +24,15 @@ namespace NzbDrone.Core.ImportLists.Simkl
public class SimklSeriesResource public class SimklSeriesResource
{ {
public SimklSeriesPropsResource Show { get; set; } public SimklSeriesPropsResource Show { get; set; }
[JsonProperty("anime_type")]
public SimklAnimeType AnimeType { get; set; }
} }
public class SimklResponse public class SimklResponse
{ {
public List<SimklSeriesResource> Shows { get; set; } public List<SimklSeriesResource> Shows { get; set; }
public List<SimklSeriesResource> Anime { get; set; }
} }
public class RefreshRequestResponse public class RefreshRequestResponse
@ -66,4 +71,10 @@ namespace NzbDrone.Core.ImportLists.Simkl
{ {
public DateTime All { get; set; } public DateTime All { get; set; }
} }
public enum SimklAnimeType
{
Tv,
Movie
}
} }

View File

@ -1,6 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
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.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -10,6 +12,11 @@ namespace NzbDrone.Core.ImportLists.Simkl
public class SimklParser : IParseImportListResponse public class SimklParser : IParseImportListResponse
{ {
private ImportListResponse _importResponse; private ImportListResponse _importResponse;
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(SimklParser));
public SimklParser()
{
}
public virtual IList<ImportListItemInfo> ParseResponse(ImportListResponse importResponse) public virtual IList<ImportListItemInfo> ParseResponse(ImportListResponse importResponse)
{ {
@ -22,7 +29,7 @@ namespace NzbDrone.Core.ImportLists.Simkl
return series; return series;
} }
var jsonResponse = STJson.Deserialize<SimklResponse>(_importResponse.Content); var jsonResponse = Json.Deserialize<SimklResponse>(_importResponse.Content);
// no shows were return // no shows were return
if (jsonResponse == null) if (jsonResponse == null)
@ -30,14 +37,40 @@ namespace NzbDrone.Core.ImportLists.Simkl
return series; return series;
} }
foreach (var show in jsonResponse.Shows) if (jsonResponse.Anime != null)
{ {
series.AddIfNotNull(new ImportListItemInfo() foreach (var show in jsonResponse.Anime)
{ {
Title = show.Show.Title, var tentativeTvdbId = int.TryParse(show.Show.Ids.Tvdb, out var tvdbId) ? tvdbId : 0;
TvdbId = int.TryParse(show.Show.Ids.Tvdb, out var tvdbId) ? tvdbId : 0,
ImdbId = show.Show.Ids.Imdb if (tentativeTvdbId > 0 && show.AnimeType == SimklAnimeType.Tv)
}); {
series.AddIfNotNull(new ImportListItemInfo()
{
Title = show.Show.Title,
ImdbId = show.Show.Ids.Imdb,
TvdbId = tvdbId,
MalId = int.TryParse(show.Show.Ids.Mal, out var malId) ? malId : 0
});
}
else
{
Logger.Warn("Skipping info grabbing for '{0}' because it is a movie or it is not the first season of the show", show.Show.Title);
}
}
}
if (jsonResponse.Shows != null)
{
foreach (var show in jsonResponse.Shows)
{
series.AddIfNotNull(new ImportListItemInfo()
{
Title = show.Show.Title,
TvdbId = int.TryParse(show.Show.Ids.Tvdb, out var tvdbId) ? tvdbId : 0,
ImdbId = show.Show.Ids.Imdb
});
}
} }
return series; return series;

View File

@ -21,7 +21,7 @@ namespace NzbDrone.Core.ImportLists.Simkl.User
private IEnumerable<ImportListRequest> GetSeriesRequest() private IEnumerable<ImportListRequest> GetSeriesRequest()
{ {
var link = $"{Settings.BaseUrl.Trim()}/sync/all-items/shows/{((SimklUserListType)Settings.ListType).ToString().ToLowerInvariant()}"; var link = $"{Settings.BaseUrl.Trim()}/sync/all-items/{((SimklUserShowType)Settings.ShowType).ToString().ToLowerInvariant()}/{((SimklUserListType)Settings.ListType).ToString().ToLowerInvariant()}";
var request = new ImportListRequest(link, HttpAccept.Json); var request = new ImportListRequest(link, HttpAccept.Json);

View File

@ -19,9 +19,13 @@ namespace NzbDrone.Core.ImportLists.Simkl.User
public SimklUserSettings() public SimklUserSettings()
{ {
ListType = (int)SimklUserListType.Watching; ListType = (int)SimklUserListType.Watching;
ShowType = (int)SimklUserShowType.Shows;
} }
[FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(SimklUserListType), HelpText = "Type of list you're seeking to import from")] [FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(SimklUserListType), HelpText = "Type of list you're seeking to import from")]
public int ListType { get; set; } public int ListType { get; set; }
[FieldDefinition(1, Label = "Show Type", Type = FieldType.Select, SelectOptions = typeof(SimklUserShowType), HelpText = "Type of show you're seeking to import from")]
public int ShowType { get; set; }
} }
} }

View File

@ -0,0 +1,8 @@
namespace NzbDrone.Core.ImportLists.Simkl.User
{
public enum SimklUserShowType
{
Shows = 0,
Anime = 1
}
}

View File

@ -11,6 +11,7 @@ namespace NzbDrone.Core.Parser.Model
public int TvdbId { get; set; } public int TvdbId { get; set; }
public int TmdbId { get; set; } public int TmdbId { get; set; }
public string ImdbId { get; set; } public string ImdbId { get; set; }
public int MalId { get; set; }
public DateTime ReleaseDate { get; set; } public DateTime ReleaseDate { get; set; }
public override string ToString() public override string ToString()