Skip to content

Commit c5fa522

Browse files
committed
Fix search only return one result
1 parent a51c145 commit c5fa522

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Jellyfin.Plugin.MetaShark.Test/MovieProviderTest.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public void TestGetMetadata()
4242

4343
Task.Run(async () =>
4444
{
45-
var info = new MovieInfo() { Name = "南极料理人", MetadataLanguage = "zh" };
45+
var info = new MovieInfo() { Name = "", MetadataLanguage = "zh" };
4646
var provider = new MovieProvider(httpClientFactory, loggerFactory, libraryManagerStub.Object, httpContextAccessorStub.Object, doubanApi, tmdbApi, omdbApi);
47-
var result = await provider.GetMetadata(info, CancellationToken.None);
47+
var result = await provider.GetSearchResults(info, CancellationToken.None);
4848
Assert.IsNotNull(result);
4949

5050
var str = result.ToJson();

Jellyfin.Plugin.MetaShark/Providers/MovieProvider.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo in
5252
}
5353

5454
// 从douban搜索
55+
// BUG注意:ProviderIds传多个meta值,会导致识别搜索时只返回一个结果
5556
var res = await this._doubanApi.SearchAsync(info.Name, cancellationToken).ConfigureAwait(false);
5657
result.AddRange(res.Take(Configuration.PluginConfiguration.MAX_SEARCH_RESULT).Select(x =>
5758
{
5859
return new RemoteSearchResult
5960
{
6061
SearchProviderName = DoubanProviderName,
61-
ProviderIds = new Dictionary<string, string> { { DoubanProviderId, x.Sid }, { Plugin.ProviderId, MetaSource.Douban } },
62+
ProviderIds = new Dictionary<string, string> { { DoubanProviderId, x.Sid } },
6263
ImageUrl = this.GetProxyImageUrl(x.Img),
6364
ProductionYear = x.Year,
6465
Name = x.Name,
@@ -75,7 +76,7 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo in
7576
return new RemoteSearchResult
7677
{
7778
SearchProviderName = TmdbProviderName,
78-
ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), x.Id.ToString(CultureInfo.InvariantCulture) }, { Plugin.ProviderId, MetaSource.Tmdb } },
79+
ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), x.Id.ToString(CultureInfo.InvariantCulture) } },
7980
Name = string.Format("[TMDB]{0}", x.Title ?? x.OriginalTitle),
8081
ImageUrl = this._tmdbApi.GetPosterUrl(x.PosterPath),
8182
Overview = x.Overview,
@@ -97,6 +98,11 @@ public async Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, Cancellatio
9798
var sid = info.GetProviderId(DoubanProviderId);
9899
var tmdbId = info.GetProviderId(MetadataProvider.Tmdb);
99100
var metaSource = info.GetProviderId(Plugin.ProviderId);
101+
// 用于修正识别时指定tmdb,没法读取tmdb数据的BUG。。。两个合在一起太难了。。。
102+
if (string.IsNullOrEmpty(metaSource) && info.Name.StartsWith("[TMDB]"))
103+
{
104+
metaSource = MetaSource.Tmdb;
105+
}
100106
// 注意:会存在元数据有tmdbId,但metaSource没值的情况(之前由TMDB插件刮削导致)
101107
var hasTmdbMeta = metaSource == MetaSource.Tmdb && !string.IsNullOrEmpty(tmdbId);
102108
var hasDoubanMeta = metaSource != MetaSource.Tmdb && !string.IsNullOrEmpty(sid);

Jellyfin.Plugin.MetaShark/Providers/SeriesProvider.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo i
5050
return new RemoteSearchResult
5151
{
5252
SearchProviderName = DoubanProviderName,
53-
ProviderIds = new Dictionary<string, string> { { DoubanProviderId, x.Sid }, { Plugin.ProviderId, MetaSource.Douban } },
53+
ProviderIds = new Dictionary<string, string> { { DoubanProviderId, x.Sid } },
5454
ImageUrl = this.GetProxyImageUrl(x.Img),
5555
ProductionYear = x.Year,
5656
Name = x.Name,
@@ -66,7 +66,7 @@ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo i
6666
return new RemoteSearchResult
6767
{
6868
SearchProviderName = TmdbProviderName,
69-
ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), x.Id.ToString(CultureInfo.InvariantCulture) }, { Plugin.ProviderId, MetaSource.Tmdb } },
69+
ProviderIds = new Dictionary<string, string> { { MetadataProvider.Tmdb.ToString(), x.Id.ToString(CultureInfo.InvariantCulture) } },
7070
Name = string.Format("[TMDB]{0}", x.Name ?? x.OriginalName),
7171
ImageUrl = this._tmdbApi.GetPosterUrl(x.PosterPath),
7272
Overview = x.Overview,
@@ -87,6 +87,11 @@ public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, Cancellat
8787
var sid = info.GetProviderId(DoubanProviderId);
8888
var tmdbId = info.GetProviderId(MetadataProvider.Tmdb);
8989
var metaSource = info.GetProviderId(Plugin.ProviderId);
90+
// 用于修正识别时指定tmdb,没法读取tmdb数据的BUG。。。两个合在一起太难了。。。
91+
if (string.IsNullOrEmpty(metaSource) && info.Name.StartsWith("[TMDB]"))
92+
{
93+
metaSource = MetaSource.Tmdb;
94+
}
9095
// 注意:会存在元数据有tmdbId,但metaSource没值的情况(之前由TMDB插件刮削导致)
9196
var hasTmdbMeta = metaSource == MetaSource.Tmdb && !string.IsNullOrEmpty(tmdbId);
9297
var hasDoubanMeta = metaSource != MetaSource.Tmdb && !string.IsNullOrEmpty(sid);

0 commit comments

Comments
 (0)