From def34281994508213e5200fb150cdbcc817c55ab Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 12 Jun 2013 17:46:50 -0400 Subject: Added poor man's multi-file movie support --- MediaBrowser.Controller/Entities/Video.cs | 111 +++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Controller/Entities/Video.cs') diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index bac29f0f5..a15362037 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -1,8 +1,13 @@ -using MediaBrowser.Model.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Resolvers; +using MediaBrowser.Model.Entities; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization; +using System.Threading; +using System.Threading.Tasks; namespace MediaBrowser.Controller.Entities { @@ -11,11 +16,16 @@ namespace MediaBrowser.Controller.Entities /// public class Video : BaseItem, IHasMediaStreams { + public bool IsMultiPart { get; set; } + + public List AdditionalPartIds { get; set; } + public Video() { MediaStreams = new List(); Chapters = new List(); PlayableStreamFileNames = new List(); + AdditionalPartIds = new List(); } /// @@ -61,7 +71,7 @@ namespace MediaBrowser.Controller.Entities { return GetPlayableStreamFiles(Path); } - + /// /// Gets the playable stream files. /// @@ -112,5 +122,102 @@ namespace MediaBrowser.Controller.Entities return Model.Entities.MediaType.Video; } } + + /// + /// Overrides the base implementation to refresh metadata for local trailers + /// + /// The cancellation token. + /// if set to true [is new item]. + /// if set to true [force]. + /// if set to true [allow slow providers]. + /// true if a provider reports we changed + public override async Task RefreshMetadata(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true) + { + // Kick off a task to refresh the main item + var result = await base.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false); + + var additionalPartsChanged = await RefreshAdditionalParts(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false); + + return additionalPartsChanged || result; + } + + /// + /// Refreshes the additional parts. + /// + /// The cancellation token. + /// if set to true [force save]. + /// if set to true [force refresh]. + /// if set to true [allow slow providers]. + /// Task{System.Boolean}. + private async Task RefreshAdditionalParts(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true) + { + var newItems = LoadAdditionalParts().ToList(); + var newItemIds = newItems.Select(i => i.Id).ToList(); + + var itemsChanged = !AdditionalPartIds.SequenceEqual(newItemIds); + + var tasks = newItems.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders)); + + var results = await Task.WhenAll(tasks).ConfigureAwait(false); + + AdditionalPartIds = newItemIds; + + return itemsChanged || results.Contains(true); + } + + /// + /// Loads the additional parts. + /// + /// IEnumerable{Video}. + private IEnumerable