New: Simkl Anime List integration

Co-authored-by: iceypotato <nickyjedi@gmail.com>
Closes #5635
This commit is contained in:
Jessica Nguyen 2023-07-22 17:11:22 -07:00 committed by GitHub
parent 180153cd84
commit b779c92200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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()