From 9560fa74ca5a09b0862c348349f356cc456a1378 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Wed, 8 Jun 2022 00:11:12 +0800 Subject: [PATCH] align api endpoints --- Jellyfin.Plugin.JavTube/ApiClient.cs | 73 +++++++------------ .../Providers/ActorImageProvider.cs | 4 +- .../Providers/ActorProvider.cs | 8 +- .../Providers/MovieImageProvider.cs | 14 ++-- .../Providers/MovieProvider.cs | 6 +- 5 files changed, 44 insertions(+), 61 deletions(-) diff --git a/Jellyfin.Plugin.JavTube/ApiClient.cs b/Jellyfin.Plugin.JavTube/ApiClient.cs index 2509d3d..4a7abbd 100644 --- a/Jellyfin.Plugin.JavTube/ApiClient.cs +++ b/Jellyfin.Plugin.JavTube/ApiClient.cs @@ -8,10 +8,10 @@ namespace Jellyfin.Plugin.JavTube; public static class ApiClient { - private const string ActorInfoApi = "/api/actors"; - private const string MovieInfoApi = "/api/movies"; - private const string ActorSearchApi = "/api/actors/search"; - private const string MovieSearchApi = "/api/movies/search"; + private const string ActorInfoApi = "/v1/actors"; + private const string MovieInfoApi = "/v1/movies"; + private const string ActorSearchApi = "/v1/actors/search"; + private const string MovieSearchApi = "/v1/movies/search"; private const string PrimaryImageApi = "/images/primary"; private const string ThumbImageApi = "/images/thumb"; private const string BackdropImageApi = "/images/backdrop"; @@ -30,26 +30,21 @@ public static class ApiClient return uriBuilder.ToString(); } - private static string ComposeImageApiUrl(string path, string id, string provider, string url, double position, + private static string ComposeImageApiUrl(string path, string provider, string id, string url, double position, bool auto) { - return ComposeUrl(path, new NameValueCollection + return ComposeUrl(Path.Combine(path, provider, id), new NameValueCollection { - { "id", id }, - { "provider", provider }, { "url", url }, { "pos", position.ToString("R") }, { "auto", auto.ToString() } }); } - private static string ComposeInfoApiUrl(string path, string id, string provider, string url, bool lazy) + private static string ComposeInfoApiUrl(string path, string provider, string id, bool lazy) { - return ComposeUrl(path, new NameValueCollection + return ComposeUrl(Path.Combine(path, provider, id), new NameValueCollection { - { "id", id }, - { "provider", provider }, - { "url", url }, { "lazy", lazy.ToString() } }); } @@ -64,74 +59,62 @@ public static class ApiClient }); } - public static string GetPrimaryImageApiUrl(string id, string provider, double position = -1) + public static string GetPrimaryImageApiUrl(string provider, string id, double position = -1) { - return ComposeImageApiUrl(PrimaryImageApi, id, provider, string.Empty, position, false); + return ComposeImageApiUrl(PrimaryImageApi, provider, id, string.Empty, position, false); } - public static string GetPrimaryImageApiUrl(string id, string provider, string url, double position = -1, + public static string GetPrimaryImageApiUrl(string provider, string id, string url, double position = -1, bool auto = false) { - return ComposeImageApiUrl(PrimaryImageApi, id, provider, url, position, auto); + return ComposeImageApiUrl(PrimaryImageApi, provider, id, url, position, auto); } - public static string GetThumbImageApiUrl(string id, string provider) + public static string GetThumbImageApiUrl(string provider, string id) { - return ComposeImageApiUrl(ThumbImageApi, id, provider, string.Empty, -1, false); + return ComposeImageApiUrl(ThumbImageApi, provider, id, string.Empty, -1, false); } - public static string GetThumbImageApiUrl(string id, string provider, string url, double position = -1, + public static string GetThumbImageApiUrl(string provider, string id, string url, double position = -1, bool auto = false) { - return ComposeImageApiUrl(ThumbImageApi, id, provider, url, position, auto); + return ComposeImageApiUrl(ThumbImageApi, provider, id, url, position, auto); } - public static string GetBackdropImageApiUrl(string id, string provider) + public static string GetBackdropImageApiUrl(string provider, string id) { - return ComposeImageApiUrl(BackdropImageApi, id, provider, string.Empty, -1, false); + return ComposeImageApiUrl(BackdropImageApi, provider, id, string.Empty, -1, false); } - public static string GetBackdropImageApiUrl(string id, string provider, string url, double position = -1, + public static string GetBackdropImageApiUrl(string provider, string id, string url, double position = -1, bool auto = false) { - return ComposeImageApiUrl(BackdropImageApi, id, provider, url, position, auto); + return ComposeImageApiUrl(BackdropImageApi, provider, id, url, position, auto); } - public static async Task GetActorInfo(string id, string provider, + public static async Task GetActorInfo(string provider, string id, CancellationToken cancellationToken) { - return await GetActorInfo(id, provider, string.Empty, true, cancellationToken); + return await GetActorInfo(provider, id, true, cancellationToken); } - public static async Task GetActorInfo(string id, string provider, bool lazy, + public static async Task GetActorInfo(string provider, string id, bool lazy, CancellationToken cancellationToken) { - return await GetActorInfo(id, provider, string.Empty, lazy, cancellationToken); - } - - public static async Task GetActorInfo(string id, string provider, string url, bool lazy, - CancellationToken cancellationToken) - { - var apiUrl = ComposeInfoApiUrl(ActorInfoApi, id, provider, url, lazy); + var apiUrl = ComposeInfoApiUrl(ActorInfoApi, provider, id, lazy); return await GetDataFromApi(apiUrl, cancellationToken); } - public static async Task GetMovieInfo(string id, string provider, + public static async Task GetMovieInfo(string provider, string id, CancellationToken cancellationToken) { - return await GetMovieInfo(id, provider, string.Empty, true, cancellationToken); + return await GetMovieInfo(provider, id, true, cancellationToken); } - public static async Task GetMovieInfo(string id, string provider, bool lazy, + public static async Task GetMovieInfo(string provider, string id, bool lazy, CancellationToken cancellationToken) { - return await GetMovieInfo(id, provider, string.Empty, lazy, cancellationToken); - } - - public static async Task GetMovieInfo(string id, string provider, string url, bool lazy, - CancellationToken cancellationToken) - { - var apiUrl = ComposeInfoApiUrl(MovieInfoApi, id, provider, url, lazy); + var apiUrl = ComposeInfoApiUrl(MovieInfoApi, provider, id, lazy); return await GetDataFromApi(apiUrl, cancellationToken); } diff --git a/Jellyfin.Plugin.JavTube/Providers/ActorImageProvider.cs b/Jellyfin.Plugin.JavTube/Providers/ActorImageProvider.cs index a65a9c5..2c75901 100644 --- a/Jellyfin.Plugin.JavTube/Providers/ActorImageProvider.cs +++ b/Jellyfin.Plugin.JavTube/Providers/ActorImageProvider.cs @@ -38,13 +38,13 @@ public class ActorImageProvider : BaseProvider, IRemoteImageProvider, IHasOrder if (string.IsNullOrWhiteSpace(pid.Id) || string.IsNullOrWhiteSpace(pid.Provider)) return new List(); - var actorInfo = await ApiClient.GetActorInfo(pid.Id, pid.Provider, cancellationToken); + var actorInfo = await ApiClient.GetActorInfo(pid.Provider, pid.Id, cancellationToken); return actorInfo.Images.Select(image => new RemoteImageInfo { ProviderName = Name, Type = ImageType.Primary, - Url = ApiClient.GetPrimaryImageApiUrl(actorInfo.Id, actorInfo.Provider, image, 0.5, true) + Url = ApiClient.GetPrimaryImageApiUrl(actorInfo.Provider, actorInfo.Id, image, 0.5, true) }).ToList(); } diff --git a/Jellyfin.Plugin.JavTube/Providers/ActorProvider.cs b/Jellyfin.Plugin.JavTube/Providers/ActorProvider.cs index 2615296..ed5ed76 100644 --- a/Jellyfin.Plugin.JavTube/Providers/ActorProvider.cs +++ b/Jellyfin.Plugin.JavTube/Providers/ActorProvider.cs @@ -42,7 +42,7 @@ public class ActorProvider : BaseProvider, IRemoteMetadataProvider { @@ -86,8 +86,8 @@ public class ActorProvider : BaseProvider, IRemoteMetadataProvider(); @@ -104,7 +104,7 @@ public class ActorProvider : BaseProvider, IRemoteMetadataProvider 0 - ? ApiClient.GetPrimaryImageApiUrl(m.Id, m.Provider, m.Images[0], 0.5, true) + ? ApiClient.GetPrimaryImageApiUrl(m.Provider, m.Id, m.Images[0], 0.5, true) : string.Empty }; result.SetProviderIdModel(Name, new ProviderIdModel diff --git a/Jellyfin.Plugin.JavTube/Providers/MovieImageProvider.cs b/Jellyfin.Plugin.JavTube/Providers/MovieImageProvider.cs index 12ee9dc..91e805d 100644 --- a/Jellyfin.Plugin.JavTube/Providers/MovieImageProvider.cs +++ b/Jellyfin.Plugin.JavTube/Providers/MovieImageProvider.cs @@ -39,26 +39,26 @@ public class MovieImageProvider : BaseProvider, IRemoteImageProvider, IHasOrder if (string.IsNullOrWhiteSpace(pid.Id) || string.IsNullOrWhiteSpace(pid.Provider)) return new List(); - var m = await ApiClient.GetMovieInfo(pid.Id, pid.Provider, cancellationToken); + var m = await ApiClient.GetMovieInfo(pid.Provider, pid.Id, cancellationToken); var images = new List { new() { ProviderName = Name, Type = ImageType.Primary, - Url = ApiClient.GetPrimaryImageApiUrl(m.Id, m.Provider, pid.Position ?? -1) + Url = ApiClient.GetPrimaryImageApiUrl(m.Provider, m.Id, pid.Position ?? -1) }, new() { ProviderName = Name, Type = ImageType.Thumb, - Url = ApiClient.GetThumbImageApiUrl(m.Id, m.Provider) + Url = ApiClient.GetThumbImageApiUrl(m.Provider, m.Id) }, new() { ProviderName = Name, Type = ImageType.Backdrop, - Url = ApiClient.GetBackdropImageApiUrl(m.Id, m.Provider) + Url = ApiClient.GetBackdropImageApiUrl(m.Provider, m.Id) } }; @@ -68,21 +68,21 @@ public class MovieImageProvider : BaseProvider, IRemoteImageProvider, IHasOrder { ProviderName = Name, Type = ImageType.Primary, - Url = ApiClient.GetPrimaryImageApiUrl(m.Id, m.Provider, imageUrl) + Url = ApiClient.GetPrimaryImageApiUrl(m.Provider, m.Id, imageUrl) }); images.Add(new RemoteImageInfo { ProviderName = Name, Type = ImageType.Thumb, - Url = ApiClient.GetThumbImageApiUrl(m.Id, m.Provider, imageUrl) + Url = ApiClient.GetThumbImageApiUrl(m.Provider, m.Id, imageUrl) }); images.Add(new RemoteImageInfo { ProviderName = Name, Type = ImageType.Backdrop, - Url = ApiClient.GetBackdropImageApiUrl(m.Id, m.Provider, imageUrl) + Url = ApiClient.GetBackdropImageApiUrl(m.Provider, m.Id, imageUrl) }); } diff --git a/Jellyfin.Plugin.JavTube/Providers/MovieProvider.cs b/Jellyfin.Plugin.JavTube/Providers/MovieProvider.cs index 8603798..d90f9c9 100644 --- a/Jellyfin.Plugin.JavTube/Providers/MovieProvider.cs +++ b/Jellyfin.Plugin.JavTube/Providers/MovieProvider.cs @@ -52,7 +52,7 @@ public class MovieProvider : BaseProvider, IRemoteMetadataProvider { @@ -141,7 +141,7 @@ public class MovieProvider : BaseProvider, IRemoteMetadataProvider