Skip to content

Commit

Permalink
chore: add config for BFS season guess search count
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomNamer authored and kookxiang committed Jul 1, 2024
1 parent c135e4f commit d1ad29d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions Jellyfin.Plugin.Bangumi.Test/Util/ServiceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static void Init(TestContext context)

var plugin = GetService<Bangumi.Plugin>();
plugin.Configuration.TranslationPreference = TranslationPreferenceType.Original;
plugin.Configuration.SeasonGuessMaxSearchCount = 10;
}

public static T GetService<T>()
Expand Down
19 changes: 8 additions & 11 deletions Jellyfin.Plugin.Bangumi/BangumiApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RelatedSubject>(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);
Expand All @@ -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<List<PersonInfo>> GetSubjectCharacters(int id, CancellationToken token)
Expand Down
12 changes: 12 additions & 0 deletions Jellyfin.Plugin.Bangumi/Configuration/ConfigPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ <h2 class="sectionTitle">网络</h2>
<option value="60000">1 分钟</option>
</select>
</div>
<div class="selectContainer">
<label class="selectLabel" for="SeasonGuessMaxSearchCount">季度搜索最大请求数</label>
<select class="emby-select-withcolor emby-select" id="SeasonGuessMaxSearchCount" is="emby-select">
<option value="1">1</option>
<option value="2">2</option>
<option value="5">5</option>
<option value="10">10</option>
<!-- <option value="114514">无限制</option>-->
</select>
<div class="fieldDescription">本插件使用遍历搜索关联条目的方式匹配TV动画季度。大部分情况下只需一次搜索即可完成,但某些条目可能需要多次搜索才能匹配到下一季。默认最多搜索两次,如果某些季度匹配错误,您可以尝试增加最大搜索次数。</div>
</div>

<div class="verticalSection verticalSection">
<div class="sectionTitleContainer flex align-items-center">
<h2 class="sectionTitle">元数据</h2>
Expand Down
2 changes: 2 additions & 0 deletions Jellyfin.Plugin.Bangumi/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit d1ad29d

Please sign in to comment.