private async Task <List <ChapterInfo> > DownloadChapters(Video video, CancellationToken cancellationToken) { if ((_config.Configuration.ChapterOptions.DownloadEpisodeChapters && video is Episode) || (_config.Configuration.ChapterOptions.DownloadMovieChapters && video is Movie)) { var results = await _chapterManager.Search(video, cancellationToken).ConfigureAwait(false); var result = results.FirstOrDefault(); if (result != null) { var chapters = await _chapterManager.GetChapters(result.Id, cancellationToken).ConfigureAwait(false); return(chapters.Chapters.Select(i => new ChapterInfo { Name = i.Name, StartPositionTicks = i.StartPositionTicks }).ToList()); } } return(new List <ChapterInfo>()); }
private async Task <List <ChapterInfo> > DownloadChapters(Video video, List <ChapterInfo> currentChapters, CancellationToken cancellationToken) { var options = _chapterManager.GetConfiguration(); if ((options.DownloadEpisodeChapters && video is Episode) || (options.DownloadMovieChapters && video is Movie)) { var results = await _chapterManager.Search(video, cancellationToken).ConfigureAwait(false); var result = results.FirstOrDefault(); if (result != null) { var chapters = await _chapterManager.GetChapters(result.Id, cancellationToken).ConfigureAwait(false); var chapterInfos = chapters.Chapters.Select(i => new ChapterInfo { Name = i.Name, StartPositionTicks = i.StartPositionTicks }).ToList(); if (chapterInfos.All(i => i.StartPositionTicks == 0)) { if (currentChapters.Count >= chapterInfos.Count) { var index = 0; foreach (var info in chapterInfos) { info.StartPositionTicks = currentChapters[index].StartPositionTicks; index++; } } else { chapterInfos.Clear(); } } return(chapterInfos); } } return(new List <ChapterInfo>()); }