Skip to content

Commit f1a1587

Browse files
committed
Optimize identity
1 parent c5fa522 commit f1a1587

11 files changed

+90
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Jellyfin.Plugin.MetaShark.Api;
2+
using Jellyfin.Plugin.MetaShark.Core;
3+
using Jellyfin.Plugin.MetaShark.Model;
4+
using Jellyfin.Plugin.MetaShark.Providers;
5+
using MediaBrowser.Controller.Library;
6+
using MediaBrowser.Controller.Providers;
7+
using MediaBrowser.Model.Entities;
8+
using Microsoft.AspNetCore.Http;
9+
using Microsoft.Extensions.Logging;
10+
using Moq;
11+
using System;
12+
using System.Collections.Generic;
13+
using System.Linq;
14+
using System.Text;
15+
using System.Threading.Tasks;
16+
17+
namespace Jellyfin.Plugin.MetaShark.Test
18+
{
19+
[TestClass]
20+
public class SeriesImageProviderTest
21+
{
22+
23+
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
24+
builder.AddSimpleConsole(options =>
25+
{
26+
options.IncludeScopes = true;
27+
options.SingleLine = true;
28+
options.TimestampFormat = "hh:mm:ss ";
29+
}));
30+
31+
32+
33+
34+
[TestMethod]
35+
public void TestGetMovieImageFromTMDB()
36+
{
37+
var info = new MediaBrowser.Controller.Entities.Movies.Movie()
38+
{
39+
PreferredMetadataLanguage = "zh",
40+
ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), "67534" }, { Plugin.ProviderId, MetaSource.Tmdb } }
41+
};
42+
var doubanApi = new DoubanApi(loggerFactory);
43+
var tmdbApi = new TmdbApi(loggerFactory);
44+
var omdbApi = new OmdbApi(loggerFactory);
45+
var httpClientFactory = new DefaultHttpClientFactory();
46+
var libraryManagerStub = new Mock<ILibraryManager>();
47+
var httpContextAccessorStub = new Mock<IHttpContextAccessor>();
48+
49+
Task.Run(async () =>
50+
{
51+
var provider = new SeriesImageProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi);
52+
var result = await provider.GetImages(info, CancellationToken.None);
53+
Assert.IsNotNull(result);
54+
55+
var str = result.ToJson();
56+
Console.WriteLine(result.ToJson());
57+
}).GetAwaiter().GetResult();
58+
}
59+
}
60+
}

Jellyfin.Plugin.MetaShark/Api/TmdbApi.cs

+5
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,11 @@ public string NormalizeLanguage(string language)
650650

651651
public string GetImageLanguagesParam(string preferredLanguage)
652652
{
653+
if (string.IsNullOrEmpty(preferredLanguage))
654+
{
655+
return null;
656+
}
657+
653658
var languages = new List<string>();
654659

655660
if (!string.IsNullOrEmpty(preferredLanguage))

Jellyfin.Plugin.MetaShark/Providers/BaseProvider.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected BaseProvider(IHttpClientFactory httpClientFactory, ILogger logger, ILi
141141
result = await this._doubanApi.SearchAsync(searchName, cancellationToken).ConfigureAwait(false);
142142
var cat = info is MovieInfo ? "电影" : "电视剧";
143143

144-
// 优先返回对应年份的电影
144+
// 存在年份时,返回对应年份的电影
145145
if (info.Year != null && info.Year > 0)
146146
{
147147
item = result.Where(x => x.Category == cat && x.Year == info.Year).FirstOrDefault();
@@ -150,6 +150,11 @@ protected BaseProvider(IHttpClientFactory httpClientFactory, ILogger logger, ILi
150150
this.Log($"Found douban [id]: {item.Name}({item.Sid})");
151151
return item.Sid;
152152
}
153+
else
154+
{
155+
// 有年份找不到,直接返回(还是返回第一个好????)
156+
return null;
157+
}
153158
}
154159

155160
//// 不存在年份,计算相似度,返回相似度大于0.8的第一个(可能出现冷门资源名称更相同的情况。。。)

Jellyfin.Plugin.MetaShark/Providers/EpisodeImageProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
7979

8080
// 利用season缓存取剧集信息会更快
8181
var seasonResult = await this._tmdbApi
82-
.GetSeasonAsync(seriesTmdbId, seasonNumber.Value, language, language, cancellationToken)
82+
.GetSeasonAsync(seriesTmdbId, seasonNumber.Value, null, null, cancellationToken)
8383
.ConfigureAwait(false);
8484
if (seasonResult == null || seasonResult.Episodes.Count < episodeNumber.Value)
8585
{

Jellyfin.Plugin.MetaShark/Providers/MovieImageProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
8181
{
8282
var language = item.GetPreferredMetadataLanguage();
8383
var movie = await _tmdbApi
84-
.GetMovieAsync(tmdbId.ToInt(), language, language, cancellationToken)
84+
.GetMovieAsync(tmdbId.ToInt(), null, null, cancellationToken)
8585
.ConfigureAwait(false);
8686

8787
if (movie?.Images == null)
@@ -126,7 +126,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
126126
return remoteImages.OrderByLanguageDescending(language);
127127
}
128128

129-
this.Log($"Got images failed because the sid of \"{item.Name}\" is empty!");
129+
this.Log($"Got images failed because the images of \"{item.Name}\" is empty!");
130130
return new List<RemoteImageInfo>();
131131
}
132132

Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs

-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo in
5858
{
5959
return new RemoteSearchResult
6060
{
61-
SearchProviderName = DoubanProviderName,
6261
ProviderIds = new Dictionary<string, string> { { DoubanProviderId, x.Sid } },
6362
ImageUrl = this.GetProxyImageUrl(x.Img),
6463
ProductionYear = x.Year,
@@ -75,7 +74,6 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo in
7574
{
7675
return new RemoteSearchResult
7776
{
78-
SearchProviderName = TmdbProviderName,
7977
ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), x.Id.ToString(CultureInfo.InvariantCulture) } },
8078
Name = string.Format("[TMDB]{0}", x.Title ?? x.OriginalTitle),
8179
ImageUrl = this._tmdbApi.GetPosterUrl(x.PosterPath),

Jellyfin.Plugin.MetaShark/Providers/PersonImageProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
7070
}
7171
}
7272

73-
this.Log($"Got images failed because the sid of \"{item.Name}\" is empty!");
73+
this.Log($"Got images failed because the images of \"{item.Name}\" is empty!");
7474
return new List<RemoteImageInfo>();
7575
}
7676

Jellyfin.Plugin.MetaShark/Providers/SeasonImageProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
8787
}
8888

8989
var language = item.GetPreferredMetadataLanguage();
90-
9190
var seasonResult = await this._tmdbApi
92-
.GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, language, language, cancellationToken)
91+
.GetSeasonAsync(seriesTmdbId, season.IndexNumber.Value, null, null, cancellationToken)
9392
.ConfigureAwait(false);
9493
var posters = seasonResult?.Images?.Posters;
9594
if (posters == null)
@@ -108,6 +107,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
108107
VoteCount = image.VoteCount,
109108
Width = image.Width,
110109
Height = image.Height,
110+
Language = AdjustImageLanguage(image.Iso_639_1, language),
111111
ProviderName = Name,
112112
Type = ImageType.Primary,
113113
};

Jellyfin.Plugin.MetaShark/Providers/SeasonProvider.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ public async Task<MetadataResult<Season>> GetMetadata(SeasonInfo info, Cancellat
128128

129129
// series使用TMDB元数据来源
130130
// tmdb季级没有对应id,只通过indexNumber区分
131-
return await this.GetMetadataByTmdb(info, seriesTmdbId, seasonNumber, cancellationToken).ConfigureAwait(false);
131+
if (metaSource == MetaSource.Tmdb && !string.IsNullOrEmpty(seriesTmdbId))
132+
{
133+
return await this.GetMetadataByTmdb(info, seriesTmdbId, seasonNumber, cancellationToken).ConfigureAwait(false);
134+
}
135+
136+
return result;
132137
}
133138

134139

Jellyfin.Plugin.MetaShark/Providers/SeriesImageProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
8181
{
8282
var language = item.GetPreferredMetadataLanguage();
8383
var movie = await _tmdbApi
84-
.GetSeriesAsync(tmdbId.ToInt(), language, language, cancellationToken)
84+
.GetSeriesAsync(tmdbId.ToInt(), null, null, cancellationToken)
8585
.ConfigureAwait(false);
8686

8787
if (movie?.Images == null)
@@ -126,7 +126,7 @@ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, Cancell
126126
return remoteImages.OrderByLanguageDescending(language);
127127
}
128128

129-
this.Log($"Got images failed because the sid of \"{item.Name}\" is empty!");
129+
this.Log($"Got images failed because the images of \"{item.Name}\" is empty!");
130130
return new List<RemoteImageInfo>();
131131
}
132132

Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo i
4949
{
5050
return new RemoteSearchResult
5151
{
52-
SearchProviderName = DoubanProviderName,
5352
ProviderIds = new Dictionary<string, string> { { DoubanProviderId, x.Sid } },
5453
ImageUrl = this.GetProxyImageUrl(x.Img),
5554
ProductionYear = x.Year,
@@ -65,7 +64,6 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo i
6564
{
6665
return new RemoteSearchResult
6766
{
68-
SearchProviderName = TmdbProviderName,
6967
ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), x.Id.ToString(CultureInfo.InvariantCulture) } },
7068
Name = string.Format("[TMDB]{0}", x.Name ?? x.OriginalName),
7169
ImageUrl = this._tmdbApi.GetPosterUrl(x.PosterPath),
@@ -167,8 +165,12 @@ public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, Cancellat
167165
return result;
168166
}
169167

168+
if (metaSource == MetaSource.Tmdb && !string.IsNullOrEmpty(tmdbId))
169+
{
170+
return await this.GetMetadataByTmdb(tmdbId, info, cancellationToken).ConfigureAwait(false);
171+
}
170172

171-
return await this.GetMetadataByTmdb(tmdbId, info, cancellationToken).ConfigureAwait(false);
173+
return result;
172174
}
173175

174176
private async Task<MetadataResult<Series>> GetMetadataByTmdb(string? tmdbId, ItemLookupInfo info, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)