chapter downloading fixes

This commit is contained in:
Luke Pulverenti
2014-06-11 22:38:40 -04:00
parent a18f4e37ac
commit 29ed437d79
6 changed files with 48 additions and 12 deletions

View File

@@ -67,7 +67,8 @@ namespace MediaBrowser.Providers.Chapters
ParentIndexNumber = video.ParentIndexNumber,
ProductionYear = video.ProductionYear,
ProviderIds = video.ProviderIds,
RuntimeTicks = video.RunTimeTicks
RuntimeTicks = video.RunTimeTicks,
SearchAllProviders = false
};
var episode = video as Episode;
@@ -95,8 +96,12 @@ namespace MediaBrowser.Providers.Chapters
{
try
{
return await Search(request, provider, cancellationToken).ConfigureAwait(false);
var currentResults = await Search(request, provider, cancellationToken).ConfigureAwait(false);
if (currentResults.Count > 0)
{
return currentResults;
}
}
catch (Exception ex)
{
@@ -124,19 +129,21 @@ namespace MediaBrowser.Providers.Chapters
return results.SelectMany(i => i);
}
private async Task<IEnumerable<RemoteChapterResult>> Search(ChapterSearchRequest request,
private async Task<List<RemoteChapterResult>> Search(ChapterSearchRequest request,
IChapterProvider provider,
CancellationToken cancellationToken)
{
var searchResults = await provider.Search(request, cancellationToken).ConfigureAwait(false);
foreach (var result in searchResults)
var list = searchResults.ToList();
foreach (var result in list)
{
result.Id = GetProviderId(provider.Name) + "_" + result.Id;
result.ProviderName = provider.Name;
}
return searchResults;
return list;
}
public Task<ChapterResponse> GetChapters(string id, CancellationToken cancellationToken)
@@ -186,7 +193,7 @@ namespace MediaBrowser.Providers.Chapters
if (!includeDisabledProviders)
{
providers = providers
.Where(i => _config.Configuration.ChapterOptions.DisabledFetchers.Contains(i.Name))
.Where(i => !_config.Configuration.ChapterOptions.DisabledFetchers.Contains(i.Name))
.ToArray();
}

View File

@@ -240,7 +240,7 @@ namespace MediaBrowser.Providers.MediaInfo
if (options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh ||
options.MetadataRefreshMode == MetadataRefreshMode.EnsureMetadata)
{
var remoteChapters = await DownloadChapters(video, cancellationToken).ConfigureAwait(false);
var remoteChapters = await DownloadChapters(video, chapters, cancellationToken).ConfigureAwait(false);
if (remoteChapters.Count > 0)
{
@@ -487,7 +487,7 @@ namespace MediaBrowser.Providers.MediaInfo
currentStreams.AddRange(externalSubtitleStreams);
}
private async Task<List<ChapterInfo>> DownloadChapters(Video video, CancellationToken cancellationToken)
private async Task<List<ChapterInfo>> DownloadChapters(Video video, List<ChapterInfo> currentChapters, CancellationToken cancellationToken)
{
if ((_config.Configuration.ChapterOptions.DownloadEpisodeChapters &&
video is Episode) ||
@@ -502,12 +502,31 @@ namespace MediaBrowser.Providers.MediaInfo
{
var chapters = await _chapterManager.GetChapters(result.Id, cancellationToken).ConfigureAwait(false);
return chapters.Chapters.Select(i => new ChapterInfo
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;
}
}