From d1ad29dfcc38dc60a48d39deda9d4801d80ad91f Mon Sep 17 00:00:00 2001 From: RandomNamer Date: Sun, 30 Jun 2024 00:48:41 -0400 Subject: [PATCH] chore: add config for BFS season guess search count --- .../Util/ServiceLocator.cs | 1 + Jellyfin.Plugin.Bangumi/BangumiApi.cs | 19 ++++++++----------- .../Configuration/ConfigPage.html | 12 ++++++++++++ .../Configuration/PluginConfiguration.cs | 2 ++ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Jellyfin.Plugin.Bangumi.Test/Util/ServiceLocator.cs b/Jellyfin.Plugin.Bangumi.Test/Util/ServiceLocator.cs index 1de43d8..15b0924 100644 --- a/Jellyfin.Plugin.Bangumi.Test/Util/ServiceLocator.cs +++ b/Jellyfin.Plugin.Bangumi.Test/Util/ServiceLocator.cs @@ -38,6 +38,7 @@ public static void Init(TestContext context) var plugin = GetService(); plugin.Configuration.TranslationPreference = TranslationPreferenceType.Original; + plugin.Configuration.SeasonGuessMaxSearchCount = 10; } public static T GetService() diff --git a/Jellyfin.Plugin.Bangumi/BangumiApi.cs b/Jellyfin.Plugin.Bangumi/BangumiApi.cs index ffdb485..279e11d 100644 --- a/Jellyfin.Plugin.Bangumi/BangumiApi.cs +++ b/Jellyfin.Plugin.Bangumi/BangumiApi.cs @@ -148,12 +148,17 @@ bool SeriesSequelUnqualified(Subject subject) || subject?.PopularTags.Contains("OVA") == true || subject?.PopularTags.Contains("剧场版") == true; } + + var requestCount = 0; + //What would happen in Emby if I use `_plugin`? + int maxRequestCount = Plugin.Instance?.Configuration?.SeasonGuessMaxSearchCount ?? 2; var relatedSubjects = await GetSubjectRelations(id, token); var subjectsQueue = new Queue(relatedSubjects?.Where(item => item.Relation == SubjectRelation.Sequel) ?? []); - while (subjectsQueue.Any()) + while (subjectsQueue.Any() && requestCount < maxRequestCount) { var relatedSubject = subjectsQueue.Dequeue(); var subjectCandidate = await GetSubject(relatedSubject.Id, token); + requestCount++; if (subjectCandidate != null && SeriesSequelUnqualified(subjectCandidate)) { var nextRelatedSubjects = await GetSubjectRelations(subjectCandidate.Id, token); @@ -165,20 +170,12 @@ bool SeriesSequelUnqualified(Subject subject) else { // BFS until meets criteria + Console.WriteLine($"BangumiApi: Season guess of id #{id} end with {requestCount} searches"); return subjectCandidate; } } - + Console.WriteLine($"BangumiApi: Season guess of id #{id} failed with {requestCount} searches"); return null; - // var relatedSubjects = await GetSubjectRelations(id, token); - // var subjectInfo = relatedSubjects?.FirstOrDefault(item => item.Relation == SubjectRelation.Sequel); - // if (subjectInfo == null) - // return null; - // var subject = await GetSubject(subjectInfo.Id, token); - // if (subject?.Platform == SubjectPlatform.Movie || subject?.Platform == SubjectPlatform.OVA - // || subject?.PopularTags.Contains("OVA") == true || subject?.PopularTags.Contains("剧场版") == true) - // subject = await SearchNextSubject(subject.Id, token); - // return subject; } public async Task> GetSubjectCharacters(int id, CancellationToken token) diff --git a/Jellyfin.Plugin.Bangumi/Configuration/ConfigPage.html b/Jellyfin.Plugin.Bangumi/Configuration/ConfigPage.html index f32862b..0604003 100644 --- a/Jellyfin.Plugin.Bangumi/Configuration/ConfigPage.html +++ b/Jellyfin.Plugin.Bangumi/Configuration/ConfigPage.html @@ -150,6 +150,18 @@

网络

+
+ + +
本插件使用遍历搜索关联条目的方式匹配TV动画季度。大部分情况下只需一次搜索即可完成,但某些条目可能需要多次搜索才能匹配到下一季。默认最多搜索两次,如果某些季度匹配错误,您可以尝试增加最大搜索次数。
+
+

元数据

diff --git a/Jellyfin.Plugin.Bangumi/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.Bangumi/Configuration/PluginConfiguration.cs index 4e035a5..d38e913 100644 --- a/Jellyfin.Plugin.Bangumi/Configuration/PluginConfiguration.cs +++ b/Jellyfin.Plugin.Bangumi/Configuration/PluginConfiguration.cs @@ -33,4 +33,6 @@ public class PluginConfiguration : BasePluginConfiguration public bool UseTestingSearchApi { get; set; } public bool ConvertLineBreaks { get; set; } = true; + + public int SeasonGuessMaxSearchCount { get; set; } = 2; } \ No newline at end of file