Skip to content

Commit 863aadb

Browse files
committed
ChapterService: support de-duplication for all chapters
1 parent 5075194 commit 863aadb

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

OKEGui/OKEGui/Task/ChapterService.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ public static ChapterInfo LoadChapter(TaskDetail task)
139139

140140
if (chapterInfo == null) return null;
141141

142+
Logger.Debug($"chapter: {string.Join(", ", chapterInfo.Chapters.Select(x => x.Time.TotalMilliseconds))}");
143+
142144
// 丢弃末尾1秒的章节
143145
chapterInfo.Chapters.Sort((a, b) => a.Time.CompareTo(b.Time));
144146
chapterInfo.Chapters = chapterInfo.Chapters
@@ -153,8 +155,36 @@ public static ChapterInfo LoadChapter(TaskDetail task)
153155
removeBegin = true;
154156
}
155157

158+
// 删除相同的章节
159+
bool removeDup = false;
160+
List<Chapter> newChapters = new List<Chapter>();
161+
List<int> removeIndex = new List<int>();
162+
if (chapterInfo.Chapters.Count >= 2)
163+
{
164+
for (int i = 0; i < chapterInfo.Chapters.Count - 1; i++)
165+
{
166+
if (Equals(chapterInfo.Chapters[i].Time, chapterInfo.Chapters[i + 1].Time))
167+
{
168+
removeIndex.Add(i);
169+
}
170+
else
171+
{
172+
newChapters.Add(chapterInfo.Chapters[i]);
173+
}
174+
}
175+
newChapters.Add(chapterInfo.Chapters[chapterInfo.Chapters.Count - 1]);
176+
if (removeIndex.Count > 0)
177+
{
178+
removeDup = true;
179+
chapterInfo.Chapters = newChapters;
180+
Logger.Debug($"章节去重:{string.Join(", ", removeIndex)}");
181+
}
182+
}
183+
184+
Logger.Debug($"chapter: {string.Join(", ", chapterInfo.Chapters.Select(x => x.Time.TotalMilliseconds))}");
185+
156186
// 章节重命名
157-
if (task.Taskfile.RenumberChapters || removeBegin)
187+
if (task.Taskfile.RenumberChapters || removeBegin || removeDup)
158188
{
159189
for (int i = 0; i < chapterInfo.Chapters.Count; i++)
160190
{
@@ -163,10 +193,10 @@ public static ChapterInfo LoadChapter(TaskDetail task)
163193
task.ChapterLanguage = "en";
164194
}
165195

166-
if (task.ChapterStatus == ChapterStatus.Yes && removeBegin)
196+
if (task.ChapterStatus == ChapterStatus.Yes && (removeBegin || removeDup))
167197
{
168198
task.ChapterStatus = ChapterStatus.Warn;
169-
Logger.Warn($"{task.InputFile} 使用外挂章节,但触发了开头章节去重,这可能导致章节内容和语言不符合预期,请注意检查。");
199+
Logger.Warn($"{task.InputFile} 使用外挂章节,但触发了章节去重,这可能导致章节内容和语言不符合预期,请注意检查。");
170200
}
171201

172202
// 章节序号重排序

0 commit comments

Comments
 (0)