From e934783b953ea68b5b5a48445958b0bbad9e4633 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 15 Aug 2013 12:00:39 -0400 Subject: [PATCH] initial support of multiple movies in folder --- .../Entities/Movies/Movie.cs | 2 +- MediaBrowser.Controller/Entities/Video.cs | 7 ++++ .../Savers/MovieXmlSaver.cs | 14 ++++--- .../Library/Resolvers/Movies/MovieResolver.cs | 37 ++++++++++++++++++- .../Providers/ImageSaver.cs | 26 +++++++++++-- 5 files changed, 76 insertions(+), 10 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Movies/Movie.cs b/MediaBrowser.Controller/Entities/Movies/Movie.cs index b787885c7..60e169936 100644 --- a/MediaBrowser.Controller/Entities/Movies/Movie.cs +++ b/MediaBrowser.Controller/Entities/Movies/Movie.cs @@ -47,7 +47,7 @@ namespace MediaBrowser.Controller.Entities.Movies // Must have a parent to have special features // In other words, it must be part of the Parent/Child tree - if (LocationType == LocationType.FileSystem && Parent != null) + if (LocationType == LocationType.FileSystem && Parent != null && !IsInMixedFolder) { specialFeaturesChanged = await RefreshSpecialFeatures(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false); } diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 67648ecc8..8bc519a43 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -65,6 +65,8 @@ namespace MediaBrowser.Controller.Entities return GetPlayableStreamFiles(Path); } + public bool IsInMixedFolder { get; set; } + /// /// Should be overridden to return the proper folder where metadata lives /// @@ -86,6 +88,11 @@ namespace MediaBrowser.Controller.Entities { get { + if (IsInMixedFolder) + { + return false; + } + return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso || IsMultiPart; } } diff --git a/MediaBrowser.Providers/Savers/MovieXmlSaver.cs b/MediaBrowser.Providers/Savers/MovieXmlSaver.cs index ef58bd740..9a4899cba 100644 --- a/MediaBrowser.Providers/Savers/MovieXmlSaver.cs +++ b/MediaBrowser.Providers/Savers/MovieXmlSaver.cs @@ -95,9 +95,11 @@ namespace MediaBrowser.Providers.Savers } } - XmlSaverHelpers.AddMediaInfo((Video)item, builder); + var video = (Video)item; - XmlSaverHelpers.AddChapters((Video)item, builder, _itemRepository); + XmlSaverHelpers.AddMediaInfo(video, builder); + + XmlSaverHelpers.AddChapters(video, builder, _itemRepository); builder.Append(""); @@ -117,9 +119,11 @@ namespace MediaBrowser.Providers.Savers public string GetSavePath(BaseItem item) { - return item.ResolveArgs.IsDirectory ? - Path.Combine(item.MetaLocation, "movie.xml") : - Path.ChangeExtension(item.Path, ".xml"); + var video = (Video)item; + + return video.IsInMixedFolder ? + Path.ChangeExtension(item.Path, ".xml") : + Path.Combine(item.MetaLocation, "movie.xml"); } } } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index c10db1bfa..94b79f0a1 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -85,6 +85,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies var collectionType = args.Parent == null ? null : _libraryManager.FindCollectionType(args.Parent); + // Find movies with their own folders if (isDirectory) { if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1 || @@ -115,7 +116,41 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies return FindMovie(args.Path, args.FileSystemChildren); } - return null; + // Find movies that are mixed in the same folder + if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1 || + string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase)) + { + return ResolveVideo(args); + } + + Video item = null; + + if (args.Path.IndexOf("[musicvideos]", StringComparison.OrdinalIgnoreCase) != -1 || + string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) + { + item = ResolveVideo(args); + } + + if (args.Path.IndexOf("[adultvideos]", StringComparison.OrdinalIgnoreCase) != -1 || + string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase)) + { + item = ResolveVideo(args); + } + + // To find a movie file, the collection type must be movies or boxsets + // Otherwise we'll consider it a plain video and let the video resolver handle it + if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || + string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) + { + item = ResolveVideo(args); + } + + if (item != null) + { + item.IsInMixedFolder = true; + } + + return item; } /// diff --git a/MediaBrowser.Server.Implementations/Providers/ImageSaver.cs b/MediaBrowser.Server.Implementations/Providers/ImageSaver.cs index 5da274ab9..615f9d8a0 100644 --- a/MediaBrowser.Server.Implementations/Providers/ImageSaver.cs +++ b/MediaBrowser.Server.Implementations/Providers/ImageSaver.cs @@ -238,9 +238,29 @@ namespace MediaBrowser.Server.Implementations.Providers filename += "." + extension.ToLower(); - var path = (saveLocally && !string.IsNullOrEmpty(item.MetaLocation)) ? - Path.Combine(item.MetaLocation, filename) : - _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Id, filename); + string path = null; + + if (saveLocally) + { + var video = item as Video; + + if (video != null && video.IsInMixedFolder) + { + var folder = Path.GetDirectoryName(video.Path); + + path = Path.Combine(folder, Path.GetFileNameWithoutExtension(video.Path) + "-" + filename); + } + + if (string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(item.MetaLocation)) + { + path = Path.Combine(item.MetaLocation, filename); + } + } + + if (string.IsNullOrEmpty(path)) + { + path = _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Id, filename); + } var parentPath = Path.GetDirectoryName(path);