From 29ed437d79797c4cc35b6591eb35cda021c70b37 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 11 Jun 2014 22:38:40 -0400 Subject: [PATCH] chapter downloading fixes --- .../Playback/BaseStreamingService.cs | 9 +++++-- MediaBrowser.Api/Playback/StreamState.cs | 2 ++ MediaBrowser.Controller/Entities/Video.cs | 3 ++- MediaBrowser.Model/Dto/MediaSourceInfo.cs | 2 ++ .../Chapters/ChapterManager.cs | 19 +++++++++----- .../MediaInfo/FFProbeVideoInfo.cs | 25 ++++++++++++++++--- 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index baf389168..8cf6474f2 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -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; diff --git a/MediaBrowser.Api/Playback/StreamState.cs b/MediaBrowser.Api/Playback/StreamState.cs index 08dfc87bd..aa3170173 100644 --- a/MediaBrowser.Api/Playback/StreamState.cs +++ b/MediaBrowser.Api/Playback/StreamState.cs @@ -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; } diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index ef12d46d6..3df3f7440 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -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)) diff --git a/MediaBrowser.Model/Dto/MediaSourceInfo.cs b/MediaBrowser.Model/Dto/MediaSourceInfo.cs index eb1ea7287..d7e756b43 100644 --- a/MediaBrowser.Model/Dto/MediaSourceInfo.cs +++ b/MediaBrowser.Model/Dto/MediaSourceInfo.cs @@ -30,6 +30,7 @@ namespace MediaBrowser.Model.Dto public Video3DFormat? Video3DFormat { get; set; } public List MediaStreams { get; set; } + public List PlayableStreamFileNames { get; set; } public List Formats { get; set; } @@ -43,6 +44,7 @@ namespace MediaBrowser.Model.Dto Formats = new List(); MediaStreams = new List(); RequiredHttpHeaders = new Dictionary(); + PlayableStreamFileNames = new List(); } public int? DefaultAudioStreamIndex { get; set; } diff --git a/MediaBrowser.Providers/Chapters/ChapterManager.cs b/MediaBrowser.Providers/Chapters/ChapterManager.cs index c020d0721..2da3197e7 100644 --- a/MediaBrowser.Providers/Chapters/ChapterManager.cs +++ b/MediaBrowser.Providers/Chapters/ChapterManager.cs @@ -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> Search(ChapterSearchRequest request, + private async Task> 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 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(); } diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs index 8729f68eb..0d8cce6f1 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs @@ -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> DownloadChapters(Video video, CancellationToken cancellationToken) + private async Task> DownloadChapters(Video video, List 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; } }