mirror of
https://github.com/metatube-community/jellyfin-plugin-metatube.git
synced 2026-02-02 18:21:48 +08:00
Feature(Api): add lang option (#252)
This commit is contained in:
@@ -56,12 +56,13 @@ public static class ApiClient
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ComposeSearchApiUrl(string path, string q, string provider, bool fallback)
|
private static string ComposeSearchApiUrl(string path, string q, string provider, string lang, bool fallback)
|
||||||
{
|
{
|
||||||
return ComposeUrl(path, new NameValueCollection
|
return ComposeUrl(path, new NameValueCollection
|
||||||
{
|
{
|
||||||
{ "q", q },
|
{ "q", q },
|
||||||
{ "provider", provider },
|
{ "provider", provider },
|
||||||
|
{ "lang", lang },
|
||||||
{ "fallback", fallback.ToString() }
|
{ "fallback", fallback.ToString() }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -178,7 +179,7 @@ public static class ApiClient
|
|||||||
public static async Task<List<ActorSearchResult>> SearchActorAsync(string q, string provider,
|
public static async Task<List<ActorSearchResult>> SearchActorAsync(string q, string provider,
|
||||||
bool fallback, CancellationToken cancellationToken)
|
bool fallback, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var apiUrl = ComposeSearchApiUrl(ActorSearchApi, q, provider, fallback);
|
var apiUrl = ComposeSearchApiUrl(ActorSearchApi, q, provider, string.Empty, fallback);
|
||||||
return await GetDataAsync<List<ActorSearchResult>>(apiUrl, true, cancellationToken);
|
return await GetDataAsync<List<ActorSearchResult>>(apiUrl, true, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,13 +192,19 @@ public static class ApiClient
|
|||||||
public static async Task<List<MovieSearchResult>> SearchMovieAsync(string q, string provider,
|
public static async Task<List<MovieSearchResult>> SearchMovieAsync(string q, string provider,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return await SearchMovieAsync(q, provider, true /* default */, cancellationToken);
|
return await SearchMovieAsync(q, provider, string.Empty, true /* default */, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<List<MovieSearchResult>> SearchMovieAsync(string q, string provider,
|
public static async Task<List<MovieSearchResult>> SearchMovieAsync(string q, string provider, string lang,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return await SearchMovieAsync(q, provider, lang, true /* default */, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<List<MovieSearchResult>> SearchMovieAsync(string q, string provider, string lang,
|
||||||
bool fallback, CancellationToken cancellationToken)
|
bool fallback, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var apiUrl = ComposeSearchApiUrl(MovieSearchApi, q, provider, fallback);
|
var apiUrl = ComposeSearchApiUrl(MovieSearchApi, q, provider, lang, fallback);
|
||||||
return await GetDataAsync<List<MovieSearchResult>>(apiUrl, true, cancellationToken);
|
return await GetDataAsync<List<MovieSearchResult>>(apiUrl, true, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class MovieProvider : BaseProvider, IRemoteMetadataProvider<Movie, MovieI
|
|||||||
m.Genres = Configuration.GetGenreSubstitutionTable().Substitute(m.Genres).ToArray();
|
m.Genres = Configuration.GetGenreSubstitutionTable().Substitute(m.Genres).ToArray();
|
||||||
|
|
||||||
// Translate movie info.
|
// Translate movie info.
|
||||||
if (Configuration.TranslationMode != TranslationMode.Disabled)
|
if (Configuration.TranslationMode != TranslationMode.Disabled && info.MetadataCountryCode != "CN")
|
||||||
await TranslateMovieInfo(m, info.MetadataLanguage, cancellationToken);
|
await TranslateMovieInfo(m, info.MetadataLanguage, cancellationToken);
|
||||||
|
|
||||||
// Distinct and clean blank list
|
// Distinct and clean blank list
|
||||||
@@ -177,12 +177,19 @@ public class MovieProvider : BaseProvider, IRemoteMetadataProvider<Movie, MovieI
|
|||||||
{
|
{
|
||||||
var pid = info.GetPid(Name);
|
var pid = info.GetPid(Name);
|
||||||
|
|
||||||
|
var lang = info.MetadataCountryCode switch
|
||||||
|
{
|
||||||
|
"CN" => "zh",
|
||||||
|
"JP" => "ja",
|
||||||
|
_ => string.Empty
|
||||||
|
};
|
||||||
|
|
||||||
var searchResults = new List<MovieSearchResult>();
|
var searchResults = new List<MovieSearchResult>();
|
||||||
if (string.IsNullOrWhiteSpace(pid.Id) || string.IsNullOrWhiteSpace(pid.Provider))
|
if (string.IsNullOrWhiteSpace(pid.Id) || string.IsNullOrWhiteSpace(pid.Provider))
|
||||||
{
|
{
|
||||||
// Search movie by name.
|
// Search movie by name.
|
||||||
Logger.Info("Search for movie: {0}", info.Name);
|
Logger.Info("Search for movie: {0}", info.Name);
|
||||||
searchResults.AddRange(await ApiClient.SearchMovieAsync(info.Name, pid.Provider, cancellationToken));
|
searchResults.AddRange(await ApiClient.SearchMovieAsync(info.Name, pid.Provider, lang, cancellationToken));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user