Optimize person identity
This commit is contained in:
parent
bf97db9fb4
commit
097b0514c4
|
@ -3,6 +3,7 @@ using Jellyfin.Plugin.MetaShark.Core;
|
|||
using Jellyfin.Plugin.MetaShark.Providers;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
|
@ -41,7 +42,30 @@ namespace Jellyfin.Plugin.MetaShark.Test
|
|||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var info = new PersonLookupInfo() { Name = "柊瑠美", ProviderIds = new Dictionary<string, string>() { { BaseProvider.DoubanProviderId, "1023337" } } };
|
||||
var info = new PersonLookupInfo() { ProviderIds = new Dictionary<string, string>() { { BaseProvider.DoubanProviderId, "1016771" } } };
|
||||
var provider = new PersonProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi);
|
||||
var result = await provider.GetMetadata(info, CancellationToken.None);
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
var str = result.ToJson();
|
||||
Console.WriteLine(result.ToJson());
|
||||
}).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestGetMetadataByTmdb()
|
||||
{
|
||||
|
||||
var doubanApi = new DoubanApi(loggerFactory);
|
||||
var tmdbApi = new TmdbApi(loggerFactory);
|
||||
var omdbApi = new OmdbApi(loggerFactory);
|
||||
var httpClientFactory = new DefaultHttpClientFactory();
|
||||
var libraryManagerStub = new Mock<ILibraryManager>();
|
||||
var httpContextAccessorStub = new Mock<IHttpContextAccessor>();
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var info = new PersonLookupInfo() { ProviderIds = new Dictionary<string, string>() { { MetadataProvider.Tmdb.ToString(), "78871" } } };
|
||||
var provider = new PersonProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi);
|
||||
var result = await provider.GetMetadata(info, CancellationToken.None);
|
||||
Assert.IsNotNull(result);
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
|||
Regex regGender = new Regex(@"性别: \n(.+?)\n", RegexOptions.Compiled);
|
||||
Regex regConstellation = new Regex(@"星座: \n(.+?)\n", RegexOptions.Compiled);
|
||||
Regex regBirthdate = new Regex(@"出生日期: \n(.+?)\n", RegexOptions.Compiled);
|
||||
Regex regLifedate = new Regex(@"生卒日期: \n(.+?) 至", RegexOptions.Compiled);
|
||||
Regex regLifedate = new Regex(@"生卒日期: \n(.+?) 至 (.+)", RegexOptions.Compiled);
|
||||
Regex regBirthplace = new Regex(@"出生地: \n(.+?)\n", RegexOptions.Compiled);
|
||||
Regex regCelebrityRole = new Regex(@"职业: \n(.+?)\n", RegexOptions.Compiled);
|
||||
Regex regNickname = new Regex(@"更多外文名: \n(.+?)\n", RegexOptions.Compiled);
|
||||
|
@ -523,10 +523,14 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
|||
var gender = info.GetMatchGroup(this.regGender);
|
||||
var constellation = info.GetMatchGroup(this.regConstellation);
|
||||
var birthdate = info.GetMatchGroup(this.regBirthdate);
|
||||
var lifedate = info.GetMatchGroup(this.regLifedate);
|
||||
if (string.IsNullOrEmpty(birthdate))
|
||||
|
||||
// 生卒日期
|
||||
var enddate = string.Empty;
|
||||
var match = this.regLifedate.Match(info);
|
||||
if (match.Success && match.Groups.Count > 2)
|
||||
{
|
||||
birthdate = lifedate;
|
||||
birthdate = match.Groups[1].Value.Trim();
|
||||
enddate = match.Groups[2].Value.Trim();
|
||||
}
|
||||
|
||||
var birthplace = info.GetMatchGroup(this.regBirthplace);
|
||||
|
@ -538,6 +542,7 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
|||
celebrity.Img = img;
|
||||
celebrity.Gender = gender;
|
||||
celebrity.Birthdate = birthdate;
|
||||
celebrity.Enddate = enddate;
|
||||
celebrity.Nickname = nickname;
|
||||
celebrity.Imdb = imdb;
|
||||
celebrity.Birthplace = birthplace;
|
||||
|
|
|
@ -120,6 +120,7 @@ namespace Jellyfin.Plugin.MetaShark.Model
|
|||
public string Gender { get; set; }
|
||||
public string Constellation { get; set; }
|
||||
public string Birthdate { get; set; }
|
||||
public string Enddate { get; set; }
|
||||
public string Birthplace { get; set; }
|
||||
public string Nickname { get; set; }
|
||||
public string Imdb { get; set; }
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
using Jellyfin.Plugin.MetaShark.Api;
|
||||
using Jellyfin.Plugin.MetaShark.Core;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TMDbLib.Objects.Find;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Jellyfin.Plugin.MetaShark.Api;
|
||||
using Jellyfin.Plugin.MetaShark.Core;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using TMDbLib.Objects.Find;
|
||||
|
||||
namespace Jellyfin.Plugin.MetaShark.Providers
|
||||
{
|
||||
|
@ -97,8 +97,16 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
// Name = c.Name.Trim(), // 名称需保持和info.Name一致,不然会导致关联不到影片,自动被删除
|
||||
HomePageUrl = c.Site,
|
||||
Overview = c.Intro,
|
||||
PremiereDate = DateTime.ParseExact(c.Birthdate, "yyyy年MM月dd日", System.Globalization.CultureInfo.CurrentCulture)
|
||||
};
|
||||
if (DateTime.TryParseExact(c.Birthdate, "yyyy年MM月dd日", null, DateTimeStyles.None, out var premiereDate))
|
||||
{
|
||||
item.PremiereDate = premiereDate;
|
||||
item.ProductionYear = premiereDate.Year;
|
||||
}
|
||||
if (DateTime.TryParseExact(c.Enddate, "yyyy年MM月dd日", null, DateTimeStyles.None, out var endDate))
|
||||
{
|
||||
item.EndDate = endDate;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(c.Birthplace))
|
||||
{
|
||||
item.ProductionLocations = new[] { c.Birthplace };
|
||||
|
@ -125,38 +133,47 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
}
|
||||
}
|
||||
|
||||
// jellyfin强制最后一定使用默认的TheMovieDb插件获取一次,这里不太必要(除了使用自己的域名)
|
||||
var personTmdbId = info.GetProviderId(MetadataProvider.Tmdb);
|
||||
this.Log($"GetPersonMetadata of [personTmdbId]: {personTmdbId}");
|
||||
if (!string.IsNullOrEmpty(personTmdbId))
|
||||
{
|
||||
var person = await this._tmdbApi.GetPersonAsync(personTmdbId.ToInt(), cancellationToken).ConfigureAwait(false);
|
||||
if (person != null)
|
||||
return await this.GetMetadataByTmdb(personTmdbId.ToInt(), info, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<MetadataResult<Person>> GetMetadataByTmdb(int personTmdbId, PersonLookupInfo info, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new MetadataResult<Person>();
|
||||
var person = await this._tmdbApi.GetPersonAsync(personTmdbId, cancellationToken).ConfigureAwait(false);
|
||||
if (person != null)
|
||||
{
|
||||
var item = new Person
|
||||
{
|
||||
var item = new Person
|
||||
{
|
||||
// Name = info.Name.Trim(), // 名称需保持和info.Name一致,不然会导致关联不到影片,自动被删除
|
||||
HomePageUrl = person.Homepage,
|
||||
Overview = person.Biography,
|
||||
PremiereDate = person.Birthday?.ToUniversalTime(),
|
||||
EndDate = person.Deathday?.ToUniversalTime()
|
||||
};
|
||||
// Name = info.Name.Trim(), // 名称需保持和info.Name一致,不然会导致关联不到影片,自动被删除
|
||||
HomePageUrl = person.Homepage,
|
||||
Overview = person.Biography,
|
||||
PremiereDate = person.Birthday?.ToUniversalTime(),
|
||||
EndDate = person.Deathday?.ToUniversalTime()
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(person.PlaceOfBirth))
|
||||
{
|
||||
item.ProductionLocations = new[] { person.PlaceOfBirth };
|
||||
}
|
||||
|
||||
item.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture));
|
||||
if (!string.IsNullOrEmpty(person.ImdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Imdb, person.ImdbId);
|
||||
}
|
||||
|
||||
result.HasMetadata = true;
|
||||
result.Item = item;
|
||||
|
||||
return result;
|
||||
if (!string.IsNullOrWhiteSpace(person.PlaceOfBirth))
|
||||
{
|
||||
item.ProductionLocations = new[] { person.PlaceOfBirth };
|
||||
}
|
||||
|
||||
item.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture));
|
||||
if (!string.IsNullOrEmpty(person.ImdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Imdb, person.ImdbId);
|
||||
}
|
||||
|
||||
result.HasMetadata = true;
|
||||
result.Item = item;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue