Fix person bug
This commit is contained in:
parent
54e9288dfa
commit
a799454787
|
@ -70,7 +70,7 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
Regex regCelebrityRole = new Regex(@"职业: \n(.+?)\n", RegexOptions.Compiled);
|
Regex regCelebrityRole = new Regex(@"职业: \n(.+?)\n", RegexOptions.Compiled);
|
||||||
Regex regNickname = new Regex(@"更多外文名: \n(.+?)\n", RegexOptions.Compiled);
|
Regex regNickname = new Regex(@"更多外文名: \n(.+?)\n", RegexOptions.Compiled);
|
||||||
Regex regFamily = new Regex(@"家庭成员: \n(.+?)\n", RegexOptions.Compiled);
|
Regex regFamily = new Regex(@"家庭成员: \n(.+?)\n", RegexOptions.Compiled);
|
||||||
Regex regCelebrityImdb = new Regex(@"imdb编号: \n(.+?)\n", RegexOptions.Compiled);
|
Regex regCelebrityImdb = new Regex(@"imdb编号:\s+?(nm\d+)", RegexOptions.Compiled);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="DoubanApi"/> class.
|
/// Initializes a new instance of the <see cref="DoubanApi"/> class.
|
||||||
|
|
|
@ -202,15 +202,12 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
||||||
extraMethods: TvSeasonMethods.Credits | TvSeasonMethods.Images | TvSeasonMethods.ExternalIds | TvSeasonMethods.Videos,
|
extraMethods: TvSeasonMethods.Credits | TvSeasonMethods.Images | TvSeasonMethods.ExternalIds | TvSeasonMethods.Videos,
|
||||||
cancellationToken: cancellationToken).ConfigureAwait(false);
|
cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (season != null)
|
_memoryCache.Set(key, season, TimeSpan.FromHours(CacheDurationInHours));
|
||||||
{
|
|
||||||
_memoryCache.Set(key, season, TimeSpan.FromHours(CacheDurationInHours));
|
|
||||||
}
|
|
||||||
|
|
||||||
return season;
|
return season;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
_memoryCache.Set(key, season, TimeSpan.FromHours(CacheDurationInHours));
|
||||||
this._logger.LogError(ex, ex.Message);
|
this._logger.LogError(ex, ex.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Providers;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using MediaBrowser.Model.Providers;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MetaShark.Providers.ExternalId
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public class DoubanPersonExternalId : IExternalId
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string ProviderName => BaseProvider.DoubanProviderName;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string Key => BaseProvider.DoubanProviderId;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ExternalIdMediaType? Type => ExternalIdMediaType.Person;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string UrlFormatString => "https://movie.douban.com/celebrity/{0}/";
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool Supports(IHasProviderIds item) => item is Person;
|
||||||
|
}
|
||||||
|
}
|
|
@ -129,7 +129,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
||||||
movie.SetProviderId(MetadataProvider.Imdb, subject.Imdb);
|
movie.SetProviderId(MetadataProvider.Imdb, subject.Imdb);
|
||||||
|
|
||||||
// 通过imdb获取TMDB id
|
// 通过imdb获取TMDB id
|
||||||
var movieResult = await this._tmdbApi.FindByExternalIdAsync(subject.Imdb, FindExternalSource.Imdb, null, cancellationToken).ConfigureAwait(false);
|
var movieResult = await this._tmdbApi.FindByExternalIdAsync(subject.Imdb, FindExternalSource.Imdb, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
|
||||||
if (movieResult?.MovieResults != null && movieResult.MovieResults.Count > 0)
|
if (movieResult?.MovieResults != null && movieResult.MovieResults.Count > 0)
|
||||||
{
|
{
|
||||||
this.Log($"GetMovieMetadata of found tmdb [id]: \"{movieResult.MovieResults[0].Id}\"");
|
this.Log($"GetMovieMetadata of found tmdb [id]: \"{movieResult.MovieResults[0].Id}\"");
|
||||||
|
|
|
@ -15,6 +15,7 @@ using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using TMDbLib.Objects.Find;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.MetaShark.Providers
|
namespace Jellyfin.Plugin.MetaShark.Providers
|
||||||
{
|
{
|
||||||
|
@ -30,7 +31,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
||||||
/// <param name="logger">Instance of the <see cref="ILogger{OddbImageProvider}"/> interface.</param>
|
/// <param name="logger">Instance of the <see cref="ILogger{OddbImageProvider}"/> interface.</param>
|
||||||
/// <param name="doubanApi">Instance of <see cref="DoubanApi"/>.</param>
|
/// <param name="doubanApi">Instance of <see cref="DoubanApi"/>.</param>
|
||||||
public PersonProvider(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, ILibraryManager libraryManager, DoubanApi doubanApi, TmdbApi tmdbApi, OmdbApi omdbApi)
|
public PersonProvider(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, ILibraryManager libraryManager, DoubanApi doubanApi, TmdbApi tmdbApi, OmdbApi omdbApi)
|
||||||
: base(httpClientFactory, loggerFactory.CreateLogger<SeriesProvider>(), libraryManager, doubanApi, tmdbApi, omdbApi)
|
: base(httpClientFactory, loggerFactory.CreateLogger<PersonProvider>(), libraryManager, doubanApi, tmdbApi, omdbApi)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,44 +41,51 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken)
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
this.Log($"GetPersonSearchResults of [name]: {searchInfo.Name}");
|
||||||
return await Task.FromResult<IEnumerable<RemoteSearchResult>>(new List<RemoteSearchResult>());
|
return await Task.FromResult<IEnumerable<RemoteSearchResult>>(new List<RemoteSearchResult>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<MetadataResult<Person>> GetMetadata(PersonLookupInfo info, CancellationToken cancellationToken)
|
public async Task<MetadataResult<Person>?> GetMetadata(PersonLookupInfo info, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
MetadataResult<Person> result = new MetadataResult<Person>();
|
var result = new MetadataResult<Person>();
|
||||||
|
|
||||||
var cid = info.GetProviderId(DoubanProviderId);
|
var cid = info.GetProviderId(DoubanProviderId);
|
||||||
this.Log($"GetPersonMetadata of [cid]: {cid}");
|
this.Log($"GetPersonMetadata of [name]: {info.Name} [cid]: {cid}");
|
||||||
if (!string.IsNullOrEmpty(cid))
|
if (!string.IsNullOrEmpty(cid))
|
||||||
{
|
{
|
||||||
|
|
||||||
var c = await this._doubanApi.GetCelebrityAsync(cid, cancellationToken).ConfigureAwait(false);
|
var c = await this._doubanApi.GetCelebrityAsync(cid, cancellationToken).ConfigureAwait(false);
|
||||||
if (c != null)
|
if (c != null)
|
||||||
{
|
{
|
||||||
Person p = new Person
|
var item = new Person
|
||||||
{
|
{
|
||||||
Name = c.Name,
|
// Name = c.Name.Trim(), // 名称需保持和info.Name一致,不然会导致关联不到影片,自动被删除
|
||||||
HomePageUrl = c.Site,
|
HomePageUrl = c.Site,
|
||||||
Overview = c.Intro,
|
Overview = c.Intro,
|
||||||
PremiereDate = DateTime.ParseExact(c.Birthdate, "yyyy年MM月dd日", System.Globalization.CultureInfo.CurrentCulture)
|
PremiereDate = DateTime.ParseExact(c.Birthdate, "yyyy年MM月dd日", System.Globalization.CultureInfo.CurrentCulture)
|
||||||
};
|
};
|
||||||
|
|
||||||
p.SetProviderId(Plugin.ProviderId, c.Id);
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(c.Birthplace))
|
if (!string.IsNullOrWhiteSpace(c.Birthplace))
|
||||||
{
|
{
|
||||||
p.ProductionLocations = new[] { c.Birthplace };
|
item.ProductionLocations = new[] { c.Birthplace };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item.SetProviderId(DoubanProviderId, cid);
|
||||||
if (!string.IsNullOrEmpty(c.Imdb))
|
if (!string.IsNullOrEmpty(c.Imdb))
|
||||||
{
|
{
|
||||||
p.SetProviderId(MetadataProvider.Imdb, c.Imdb);
|
item.SetProviderId(MetadataProvider.Imdb, c.Imdb);
|
||||||
|
// 通过imdb获取TMDB id
|
||||||
|
var findResult = await this._tmdbApi.FindByExternalIdAsync(c.Imdb, FindExternalSource.Imdb, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (findResult?.PersonResults != null && findResult.PersonResults.Count > 0)
|
||||||
|
{
|
||||||
|
this.Log($"GetPersonMetadata of found tmdb [id]: {findResult.PersonResults[0].Id}");
|
||||||
|
item.SetProviderId(MetadataProvider.Tmdb, $"{findResult.PersonResults[0].Id}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
result.Item = p;
|
result.Item = item;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,14 +97,9 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
||||||
var person = await this._tmdbApi.GetPersonAsync(personTmdbId.ToInt(), cancellationToken).ConfigureAwait(false);
|
var person = await this._tmdbApi.GetPersonAsync(personTmdbId.ToInt(), cancellationToken).ConfigureAwait(false);
|
||||||
if (person != null)
|
if (person != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
result.HasMetadata = true;
|
|
||||||
|
|
||||||
var item = new Person
|
var item = new Person
|
||||||
{
|
{
|
||||||
// Take name from incoming info, don't rename the person
|
// Name = info.Name.Trim(), // 名称需保持和info.Name一致,不然会导致关联不到影片,自动被删除
|
||||||
// TODO: This should go in PersonMetadataService, not each person provider
|
|
||||||
Name = info.Name,
|
|
||||||
HomePageUrl = person.Homepage,
|
HomePageUrl = person.Homepage,
|
||||||
Overview = person.Biography,
|
Overview = person.Biography,
|
||||||
PremiereDate = person.Birthday?.ToUniversalTime(),
|
PremiereDate = person.Birthday?.ToUniversalTime(),
|
||||||
|
@ -109,7 +112,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
||||||
}
|
}
|
||||||
|
|
||||||
item.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture));
|
item.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture));
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(person.ImdbId))
|
if (!string.IsNullOrEmpty(person.ImdbId))
|
||||||
{
|
{
|
||||||
item.SetProviderId(MetadataProvider.Imdb, person.ImdbId);
|
item.SetProviderId(MetadataProvider.Imdb, person.ImdbId);
|
||||||
|
@ -117,6 +119,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
||||||
|
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
result.Item = item;
|
result.Item = item;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,15 +128,10 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
this.Log("Person GetImageResponse url: {0}", url);
|
this.Log("Person GetImageResponse url: {0}", url);
|
||||||
return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false);
|
return this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken);
|
||||||
}
|
|
||||||
|
|
||||||
private void Log(string? message, params object?[] args)
|
|
||||||
{
|
|
||||||
this._logger.LogInformation($"[MetaShark] {message}", args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue