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

@ -598,7 +598,7 @@ namespace MediaBrowser.Api.Playback
return string.Format(",subtitles='{0}:si={1}',setpts=PTS -{2}/TB",
state.MediaPath.Replace('\\', '/').Replace(":/", "\\:/"),
state.SubtitleStream.Index.ToString(UsCulture),
state.InternalSubtitleStreamOffset.ToString(UsCulture),
Math.Round(seconds).ToString(UsCulture));
}
@ -1474,7 +1474,7 @@ namespace MediaBrowser.Api.Playback
state.IsoType = mediaSource.IsoType;
//state.PlayableStreamFileNames = mediaSource.PlayableStreamFileNames.ToList();
state.PlayableStreamFileNames = mediaSource.PlayableStreamFileNames.ToList();
if (mediaSource.Timestamp.HasValue)
{
@ -1552,6 +1552,11 @@ namespace MediaBrowser.Api.Playback
state.SubtitleStream = GetMediaStream(mediaStreams, videoRequest.SubtitleStreamIndex, MediaStreamType.Subtitle, false);
state.AudioStream = GetMediaStream(mediaStreams, videoRequest.AudioStreamIndex, MediaStreamType.Audio);
if (state.SubtitleStream != null && !state.SubtitleStream.IsExternal)
{
state.InternalSubtitleStreamOffset = mediaStreams.Where(i => i.Type == MediaStreamType.Subtitle && !i.IsExternal).ToList().IndexOf(state.SubtitleStream);
}
if (state.VideoStream != null && state.VideoStream.IsInterlaced)
{
state.DeInterlace = true;

View File

@ -163,6 +163,8 @@ namespace MediaBrowser.Api.Playback
}
}
public int InternalSubtitleStreamOffset { get; set; }
public string OutputFilePath { get; set; }
public string OutputVideoCodec { get; set; }
public string OutputAudioCodec { get; set; }

View File

@ -560,7 +560,8 @@ namespace MediaBrowser.Controller.Entities
Size = i.Size,
Formats = (i.FormatName ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(),
Timestamp = i.Timestamp,
Type = type
Type = type,
PlayableStreamFileNames = i.PlayableStreamFileNames.ToList()
};
if (string.IsNullOrEmpty(info.Container))

View File

@ -30,6 +30,7 @@ namespace MediaBrowser.Model.Dto
public Video3DFormat? Video3DFormat { get; set; }
public List<MediaStream> MediaStreams { get; set; }
public List<string> PlayableStreamFileNames { get; set; }
public List<string> Formats { get; set; }
@ -43,6 +44,7 @@ namespace MediaBrowser.Model.Dto
Formats = new List<string>();
MediaStreams = new List<MediaStream>();
RequiredHttpHeaders = new Dictionary<string, string>();
PlayableStreamFileNames = new List<string>();
}
public int? DefaultAudioStreamIndex { get; set; }

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;
}
}