Fix person bug

This commit is contained in:
cxfksword 2022-10-26 17:56:57 +08:00
parent 54e9288dfa
commit 2d1341f30b
5 changed files with 54 additions and 33 deletions

View File

@ -70,7 +70,7 @@ namespace Jellyfin.Plugin.MetaShark.Api
Regex regCelebrityRole = new Regex(@"职业: \n(.+?)\n", RegexOptions.Compiled);
Regex regNickname = 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>
/// Initializes a new instance of the <see cref="DoubanApi"/> class.

View File

@ -202,15 +202,12 @@ namespace Jellyfin.Plugin.MetaShark.Api
extraMethods: TvSeasonMethods.Credits | TvSeasonMethods.Images | TvSeasonMethods.ExternalIds | TvSeasonMethods.Videos,
cancellationToken: cancellationToken).ConfigureAwait(false);
if (season != null)
{
_memoryCache.Set(key, season, TimeSpan.FromHours(CacheDurationInHours));
}
_memoryCache.Set(key, season, TimeSpan.FromHours(CacheDurationInHours));
return season;
}
catch (Exception ex)
{
_memoryCache.Set(key, season, TimeSpan.FromHours(CacheDurationInHours));
this._logger.LogError(ex, ex.Message);
return null;
}

View File

@ -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;
}
}

View File

@ -129,7 +129,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
movie.SetProviderId(MetadataProvider.Imdb, subject.Imdb);
// 通过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)
{
this.Log($"GetMovieMetadata of found tmdb [id]: \"{movieResult.MovieResults[0].Id}\"");

View File

@ -15,6 +15,7 @@ using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TMDbLib.Objects.Find;
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="doubanApi">Instance of <see cref="DoubanApi"/>.</param>
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 />
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>());
}
/// <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);
this.Log($"GetPersonMetadata of [cid]: {cid}");
this.Log($"GetPersonMetadata of [name]: {info.Name} [cid]: {cid}");
if (!string.IsNullOrEmpty(cid))
{
var c = await this._doubanApi.GetCelebrityAsync(cid, cancellationToken).ConfigureAwait(false);
if (c != null)
{
Person p = new Person
var item = new Person
{
Name = c.Name,
// Name = c.Name.Trim(), // 名称需保持和info.Name一致不然会导致关联不到影片自动被删除
HomePageUrl = c.Site,
Overview = c.Intro,
PremiereDate = DateTime.ParseExact(c.Birthdate, "yyyy年MM月dd日", System.Globalization.CultureInfo.CurrentCulture)
};
p.SetProviderId(Plugin.ProviderId, c.Id);
if (!string.IsNullOrWhiteSpace(c.Birthplace))
{
p.ProductionLocations = new[] { c.Birthplace };
item.ProductionLocations = new[] { c.Birthplace };
}
item.SetProviderId(DoubanProviderId, cid);
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.Item = p;
result.Item = item;
return result;
}
}
@ -89,14 +97,9 @@ namespace Jellyfin.Plugin.MetaShark.Providers
var person = await this._tmdbApi.GetPersonAsync(personTmdbId.ToInt(), cancellationToken).ConfigureAwait(false);
if (person != null)
{
result.HasMetadata = true;
var item = new Person
{
// Take name from incoming info, don't rename the person
// TODO: This should go in PersonMetadataService, not each person provider
Name = info.Name,
// Name = info.Name.Trim(), // 名称需保持和info.Name一致不然会导致关联不到影片自动被删除
HomePageUrl = person.Homepage,
Overview = person.Biography,
PremiereDate = person.Birthday?.ToUniversalTime(),
@ -109,7 +112,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
}
item.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture));
if (!string.IsNullOrEmpty(person.ImdbId))
{
item.SetProviderId(MetadataProvider.Imdb, person.ImdbId);
@ -117,6 +119,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
result.HasMetadata = true;
result.Item = item;
return result;
}
}
@ -125,15 +128,10 @@ namespace Jellyfin.Plugin.MetaShark.Providers
}
/// <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);
return await this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken).ConfigureAwait(false);
}
private void Log(string? message, params object?[] args)
{
this._logger.LogInformation($"[MetaShark] {message}", args);
return this._httpClientFactory.CreateClient().GetAsync(new Uri(url), cancellationToken);
}
}
}