mirror of
https://github.com/metatube-community/jellyfin-plugin-metatube.git
synced 2026-05-11 10:32:05 +08:00
align api endpoints
This commit is contained in:
@@ -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<ActorInfoModel> GetActorInfo(string id, string provider,
|
||||
public static async Task<ActorInfoModel> 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<ActorInfoModel> GetActorInfo(string id, string provider, bool lazy,
|
||||
public static async Task<ActorInfoModel> GetActorInfo(string provider, string id, bool lazy,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return await GetActorInfo(id, provider, string.Empty, lazy, cancellationToken);
|
||||
}
|
||||
|
||||
public static async Task<ActorInfoModel> 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<ActorInfoModel>(apiUrl, cancellationToken);
|
||||
}
|
||||
|
||||
public static async Task<MovieInfoModel> GetMovieInfo(string id, string provider,
|
||||
public static async Task<MovieInfoModel> 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<MovieInfoModel> GetMovieInfo(string id, string provider, bool lazy,
|
||||
public static async Task<MovieInfoModel> GetMovieInfo(string provider, string id, bool lazy,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return await GetMovieInfo(id, provider, string.Empty, lazy, cancellationToken);
|
||||
}
|
||||
|
||||
public static async Task<MovieInfoModel> 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<MovieInfoModel>(apiUrl, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,13 +38,13 @@ public class ActorImageProvider : BaseProvider, IRemoteImageProvider, IHasOrder
|
||||
if (string.IsNullOrWhiteSpace(pid.Id) || string.IsNullOrWhiteSpace(pid.Provider))
|
||||
return new List<RemoteImageInfo>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ActorProvider : BaseProvider, IRemoteMetadataProvider<Person, Perso
|
||||
|
||||
LogInfo("Get actor info: {0}", pid.Serialize());
|
||||
|
||||
var m = await ApiClient.GetActorInfo(pid.Id, pid.Provider, cancellationToken);
|
||||
var m = await ApiClient.GetActorInfo(pid.Provider, pid.Id, cancellationToken);
|
||||
|
||||
var result = new MetadataResult<Person>
|
||||
{
|
||||
@@ -86,8 +86,8 @@ public class ActorProvider : BaseProvider, IRemoteMetadataProvider<Person, Perso
|
||||
{
|
||||
// Exact search.
|
||||
LogInfo("Search for actor: {0}", pid.Serialize());
|
||||
searchResults.Add(await ApiClient.GetActorInfo(pid.Id, pid.Provider, pid.UpdateInfo != true,
|
||||
cancellationToken));
|
||||
searchResults.Add(await ApiClient.GetActorInfo(pid.Provider, pid.Id,
|
||||
pid.UpdateInfo != true, cancellationToken));
|
||||
}
|
||||
|
||||
var results = new List<RemoteSearchResult>();
|
||||
@@ -104,7 +104,7 @@ public class ActorProvider : BaseProvider, IRemoteMetadataProvider<Person, Perso
|
||||
Name = m.Name,
|
||||
SearchProviderName = Name,
|
||||
ImageUrl = m.Images.Length > 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
|
||||
|
||||
@@ -39,26 +39,26 @@ public class MovieImageProvider : BaseProvider, IRemoteImageProvider, IHasOrder
|
||||
if (string.IsNullOrWhiteSpace(pid.Id) || string.IsNullOrWhiteSpace(pid.Provider))
|
||||
return new List<RemoteImageInfo>();
|
||||
|
||||
var m = await ApiClient.GetMovieInfo(pid.Id, pid.Provider, cancellationToken);
|
||||
var m = await ApiClient.GetMovieInfo(pid.Provider, pid.Id, cancellationToken);
|
||||
var images = new List<RemoteImageInfo>
|
||||
{
|
||||
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)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class MovieProvider : BaseProvider, IRemoteMetadataProvider<Movie, MovieI
|
||||
// ? await ApiClient.GetMovieInfo(pid.Id, pid.Provider, info.MetadataLanguage, cancellationToken)
|
||||
// : await ApiClient.GetMovieInfo(pid.Id, pid.Provider, cancellationToken);
|
||||
|
||||
var m = await ApiClient.GetMovieInfo(pid.Id, pid.Provider, cancellationToken);
|
||||
var m = await ApiClient.GetMovieInfo(pid.Provider, pid.Id, cancellationToken);
|
||||
|
||||
var result = new MetadataResult<Movie>
|
||||
{
|
||||
@@ -141,7 +141,7 @@ public class MovieProvider : BaseProvider, IRemoteMetadataProvider<Movie, MovieI
|
||||
SearchProviderName = Name,
|
||||
PremiereDate = m.ReleaseDate.ValidDateTime(),
|
||||
ProductionYear = m.ReleaseDate.ValidDateTime()?.Year,
|
||||
ImageUrl = ApiClient.GetPrimaryImageApiUrl(m.Id, m.Provider, m.ThumbUrl, 1.0, true)
|
||||
ImageUrl = ApiClient.GetPrimaryImageApiUrl(m.Provider, m.Id, m.ThumbUrl, 1.0, true)
|
||||
};
|
||||
result.SetProviderIdModel(Name, new ProviderIdModel
|
||||
{
|
||||
@@ -160,7 +160,7 @@ public class MovieProvider : BaseProvider, IRemoteMetadataProvider<Movie, MovieI
|
||||
try
|
||||
{
|
||||
// Use GFriends as actor image provider.
|
||||
return (await ApiClient.GetActorInfo(name, GFriends, cancellationToken)).Images[0];
|
||||
return (await ApiClient.GetActorInfo(GFriends, name, cancellationToken)).Images[0];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user