fromSkipRanges static method

List<SenzuChapter> fromSkipRanges({
  1. required Duration opStart,
  2. required Duration opEnd,
  3. required Duration edStart,
  4. required Duration edEnd,
})

Implementation

static List<SenzuChapter> fromSkipRanges({
  required Duration opStart,
  required Duration opEnd,
  required Duration edStart,
  required Duration edEnd,
}) {
  final chapters = <SenzuChapter>[];

  if (opEnd > Duration.zero && opEnd > opStart) {
    // OP эхлэл — skip товч харуулна
    chapters.add(SenzuChapter(
      startMs: opStart.inMilliseconds,
      title: 'OP',
      showOnProgressBar: true,
      isSkippable: true,
      skipToMs: opEnd.inMilliseconds,
    ));
    // OP төгсгөл — separator зурна, skip хийхгүй
    chapters.add(SenzuChapter(
      startMs: opEnd.inMilliseconds,
      title: '',
      showOnProgressBar: false,
      isSkippable: false,
    ));
  }

  if (edEnd > Duration.zero && edEnd > edStart) {
    // ED эхлэл — skip товч харуулна
    chapters.add(SenzuChapter(
      startMs: edStart.inMilliseconds,
      title: 'ED',
      showOnProgressBar: true,
      isSkippable: true,
      skipToMs: edEnd.inMilliseconds,
    ));
    // ED төгсгөл — separator
    chapters.add(SenzuChapter(
      startMs: edEnd.inMilliseconds,
      title: '',
      showOnProgressBar: false,
      isSkippable: false,
    ));
  }

  // Binary search-д зориулж startMs-р эрэмбэлнэ
  chapters.sort((a, b) => a.startMs.compareTo(b.startMs));
  return chapters;
}