diff --git a/Jellyfin.Plugin.MetaShark.Test/PersonProviderTest.cs b/Jellyfin.Plugin.MetaShark.Test/PersonProviderTest.cs new file mode 100644 index 0000000..bfe9b91 --- /dev/null +++ b/Jellyfin.Plugin.MetaShark.Test/PersonProviderTest.cs @@ -0,0 +1,56 @@ +using Jellyfin.Plugin.MetaShark.Api; +using Jellyfin.Plugin.MetaShark.Core; +using Jellyfin.Plugin.MetaShark.Providers; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Providers; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using Moq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Jellyfin.Plugin.MetaShark.Test +{ + [TestClass] + public class PersonProviderTest + { + + ILoggerFactory loggerFactory = LoggerFactory.Create(builder => + builder.AddSimpleConsole(options => + { + options.IncludeScopes = true; + options.SingleLine = true; + options.TimestampFormat = "hh:mm:ss "; + })); + + + + [TestMethod] + public void TestGetMetadata() + { + + var doubanApi = new DoubanApi(loggerFactory); + var tmdbApi = new TmdbApi(loggerFactory); + var omdbApi = new OmdbApi(loggerFactory); + var httpClientFactory = new DefaultHttpClientFactory(); + var libraryManagerStub = new Mock(); + var httpContextAccessorStub = new Mock(); + + Task.Run(async () => + { + var info = new PersonLookupInfo() { Name = "柊瑠美", ProviderIds = new Dictionary() { { BaseProvider.DoubanProviderId, "1023337" } } }; + 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(); + } + + + } +} diff --git a/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs b/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs index bd88d09..d2177e2 100644 --- a/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs +++ b/Jellyfin.Plugin.MetaShark/Api/DoubanApi.cs @@ -79,7 +79,8 @@ namespace Jellyfin.Plugin.MetaShark.Api Regex regFamily = new Regex(@"家庭成员: \n(.+?)\n", RegexOptions.Compiled); Regex regCelebrityImdb = new Regex(@"imdb编号:\s+?(nm\d+)", RegexOptions.Compiled); Regex regImgHost = new Regex(@"\/\/(img\d+?)\.", RegexOptions.Compiled); - Regex regIntroduceSpace = new Regex(@"\n\s+", RegexOptions.Compiled); + // 匹配除了换行符之外所有空白 + Regex regOverviewSpace = new Regex(@"\n[^\S\n]+", RegexOptions.Compiled); // 默认200毫秒请求1次 private TimeLimiter _defaultTimeConstraint = TimeLimiter.GetFromMaxCountByInterval(1, TimeSpan.FromMilliseconds(200)); @@ -332,7 +333,7 @@ namespace Jellyfin.Plugin.MetaShark.Api var img = contentNode.GetAttr("a.nbgnbg>img", "src") ?? string.Empty; var category = contentNode.QuerySelector("div.episode_list") == null ? "电影" : "电视剧"; var intro = contentNode.GetText("div.indent>span") ?? string.Empty; - intro = formatIntroduce(intro); + intro = formatOverview(intro); @@ -536,7 +537,7 @@ namespace Jellyfin.Plugin.MetaShark.Api celebrity.Imdb = imdb; celebrity.Birthplace = birthplace; celebrity.Name = name; - celebrity.Intro = intro; + celebrity.Intro = formatOverview(intro); celebrity.Constellation = constellation; celebrity.Role = role; _memoryCache.Set(cacheKey, celebrity, expiredOption); @@ -819,10 +820,10 @@ namespace Jellyfin.Plugin.MetaShark.Api return string.Empty; } - private string formatIntroduce(string intro) + private string formatOverview(string intro) { intro = intro.Replace("©豆瓣", string.Empty); - return regIntroduceSpace.Replace(intro, "\n"); + return regOverviewSpace.Replace(intro, "\n").Trim(); } private bool IsEnableAvoidRiskControl()