Optimize identity
This commit is contained in:
parent
c5fa522be5
commit
f1a1587ff3
|
@ -0,0 +1,60 @@
|
|||
using Jellyfin.Plugin.MetaShark.Api;
|
||||
using Jellyfin.Plugin.MetaShark.Core;
|
||||
using Jellyfin.Plugin.MetaShark.Model;
|
||||
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;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jellyfin.Plugin.MetaShark.Test
|
||||
{
|
||||
[TestClass]
|
||||
public class SeriesImageProviderTest
|
||||
{
|
||||
|
||||
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
|
||||
builder.AddSimpleConsole(options =>
|
||||
{
|
||||
options.IncludeScopes = true;
|
||||
options.SingleLine = true;
|
||||
options.TimestampFormat = "hh:mm:ss ";
|
||||
}));
|
||||
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestGetMovieImageFromTMDB()
|
||||
{
|
||||
var info = new MediaBrowser.Controller.Entities.Movies.Movie()
|
||||
{
|
||||
PreferredMetadataLanguage = "zh",
|
||||
ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), "67534" }, { Plugin.ProviderId, MetaSource.Tmdb } }
|
||||
};
|
||||
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 provider = new SeriesImageProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi);
|
||||
var result = await provider.GetImages(info, CancellationToken.None);
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
var str = result.ToJson();
|
||||
Console.WriteLine(result.ToJson());
|
||||
}).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -650,6 +650,11 @@ namespace Jellyfin.Plugin.MetaShark.Api
|
|||
|
||||
public string GetImageLanguagesParam(string preferredLanguage)
|
||||
{
|
||||
if (string.IsNullOrEmpty(preferredLanguage))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var languages = new List<string>();
|
||||
|
||||
if (!string.IsNullOrEmpty(preferredLanguage))
|
||||
|
|
|
@ -141,7 +141,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
result = await this._doubanApi.SearchAsync(searchName, cancellationToken).ConfigureAwait(false);
|
||||
var cat = info is MovieInfo ? "电影" : "电视剧";
|
||||
|
||||
// 优先返回对应年份的电影
|
||||
// 存在年份时,返回对应年份的电影
|
||||
if (info.Year != null && info.Year > 0)
|
||||
{
|
||||
item = result.Where(x => x.Category == cat && x.Year == info.Year).FirstOrDefault();
|
||||
|
@ -150,6 +150,11 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
this.Log($"Found douban [id]: {item.Name}({item.Sid})");
|
||||
return item.Sid;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 有年份找不到,直接返回(还是返回第一个好????)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//// 不存在年份,计算相似度,返回相似度大于0.8的第一个(可能出现冷门资源名称更相同的情况。。。)
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
|
||||
// 利用season缓存取剧集信息会更快
|
||||
var seasonResult = await this._tmdbApi
|
||||
.GetSeasonAsync(seriesTmdbId, seasonNumber.Value, language, language, cancellationToken)
|
||||
.GetSeasonAsync(seriesTmdbId, seasonNumber.Value, null, null, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (seasonResult == null || seasonResult.Episodes.Count < episodeNumber.Value)
|
||||
{
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
{
|
||||
var language = item.GetPreferredMetadataLanguage();
|
||||
var movie = await _tmdbApi
|
||||
.GetMovieAsync(tmdbId.ToInt(), language, language, cancellationToken)
|
||||
.GetMovieAsync(tmdbId.ToInt(), null, null, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (movie?.Images == null)
|
||||
|
@ -126,7 +126,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
return remoteImages.OrderByLanguageDescending(language);
|
||||
}
|
||||
|
||||
this.Log($"Got images failed because the sid of \"{item.Name}\" is empty!");
|
||||
this.Log($"Got images failed because the images of \"{item.Name}\" is empty!");
|
||||
return new List<RemoteImageInfo>();
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
{
|
||||
return new RemoteSearchResult
|
||||
{
|
||||
SearchProviderName = DoubanProviderName,
|
||||
ProviderIds = new Dictionary<string, string> { { DoubanProviderId, x.Sid } },
|
||||
ImageUrl = this.GetProxyImageUrl(x.Img),
|
||||
ProductionYear = x.Year,
|
||||
|
@ -75,7 +74,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
{
|
||||
return new RemoteSearchResult
|
||||
{
|
||||
SearchProviderName = TmdbProviderName,
|
||||
ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), x.Id.ToString(CultureInfo.InvariantCulture) } },
|
||||
Name = string.Format("[TMDB]{0}", x.Title ?? x.OriginalTitle),
|
||||
ImageUrl = this._tmdbApi.GetPosterUrl(x.PosterPath),
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
}
|
||||
}
|
||||
|
||||
this.Log($"Got images failed because the sid of \"{item.Name}\" is empty!");
|
||||
this.Log($"Got images failed because the images of \"{item.Name}\" is empty!");
|
||||
return new List<RemoteImageInfo>();
|
||||
}
|
||||
|
||||
|
|
|
@ -87,9 +87,8 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
}
|
||||
|
||||
var language = item.GetPreferredMetadataLanguage();
|
||||
|
||||
var seasonResult = await this._tmdbApi
|
||||
.GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, language, language, cancellationToken)
|
||||
.GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, null, null, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
var posters = seasonResult?.Images?.Posters;
|
||||
if (posters == null)
|
||||
|
@ -108,6 +107,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
VoteCount = image.VoteCount,
|
||||
Width = image.Width,
|
||||
Height = image.Height,
|
||||
Language = AdjustImageLanguage(image.Iso_639_1, language),
|
||||
ProviderName = Name,
|
||||
Type = ImageType.Primary,
|
||||
};
|
||||
|
|
|
@ -128,7 +128,12 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
|
||||
// series使用TMDB元数据来源
|
||||
// tmdb季级没有对应id,只通过indexNumber区分
|
||||
return await this.GetMetadataByTmdb(info, seriesTmdbId, seasonNumber, cancellationToken).ConfigureAwait(false);
|
||||
if (metaSource == MetaSource.Tmdb && !string.IsNullOrEmpty(seriesTmdbId))
|
||||
{
|
||||
return await this.GetMetadataByTmdb(info, seriesTmdbId, seasonNumber, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
{
|
||||
var language = item.GetPreferredMetadataLanguage();
|
||||
var movie = await _tmdbApi
|
||||
.GetSeriesAsync(tmdbId.ToInt(), language, language, cancellationToken)
|
||||
.GetSeriesAsync(tmdbId.ToInt(), null, null, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (movie?.Images == null)
|
||||
|
@ -126,7 +126,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
return remoteImages.OrderByLanguageDescending(language);
|
||||
}
|
||||
|
||||
this.Log($"Got images failed because the sid of \"{item.Name}\" is empty!");
|
||||
this.Log($"Got images failed because the images of \"{item.Name}\" is empty!");
|
||||
return new List<RemoteImageInfo>();
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
{
|
||||
return new RemoteSearchResult
|
||||
{
|
||||
SearchProviderName = DoubanProviderName,
|
||||
ProviderIds = new Dictionary<string, string> { { DoubanProviderId, x.Sid } },
|
||||
ImageUrl = this.GetProxyImageUrl(x.Img),
|
||||
ProductionYear = x.Year,
|
||||
|
@ -65,7 +64,6 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
{
|
||||
return new RemoteSearchResult
|
||||
{
|
||||
SearchProviderName = TmdbProviderName,
|
||||
ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), x.Id.ToString(CultureInfo.InvariantCulture) } },
|
||||
Name = string.Format("[TMDB]{0}", x.Name ?? x.OriginalName),
|
||||
ImageUrl = this._tmdbApi.GetPosterUrl(x.PosterPath),
|
||||
|
@ -167,8 +165,12 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
return result;
|
||||
}
|
||||
|
||||
if (metaSource == MetaSource.Tmdb && !string.IsNullOrEmpty(tmdbId))
|
||||
{
|
||||
return await this.GetMetadataByTmdb(tmdbId, info, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return await this.GetMetadataByTmdb(tmdbId, info, cancellationToken).ConfigureAwait(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<MetadataResult<Series>> GetMetadataByTmdb(string? tmdbId, ItemLookupInfo info, CancellationToken cancellationToken)
|
||||
|
|
Loading…
Reference in New Issue