From 96efd27e2030703e7ab8b767c27c16f868c5ac22 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 11 Jul 2016 00:57:22 -0400 Subject: [PATCH 1/2] allow photos in home video libraries --- .../Library/Resolvers/PhotoResolver.cs | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs index 8beb03b71a..9dd30eddee 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/PhotoResolver.cs @@ -5,15 +5,19 @@ using MediaBrowser.Model.Entities; using System; using System.IO; using System.Linq; +using CommonIO; namespace MediaBrowser.Server.Implementations.Library.Resolvers { public class PhotoResolver : ItemResolver { private readonly IImageProcessor _imageProcessor; - public PhotoResolver(IImageProcessor imageProcessor) + private readonly ILibraryManager _libraryManager; + + public PhotoResolver(IImageProcessor imageProcessor, ILibraryManager libraryManager) { _imageProcessor = imageProcessor; + _libraryManager = libraryManager; } /// @@ -23,20 +27,45 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers /// Trailer. protected override Photo Resolve(ItemResolveArgs args) { - // Must be an image file within a photo collection - if (string.Equals(args.GetCollectionType(), CollectionType.Photos, StringComparison.OrdinalIgnoreCase) && - !args.IsDirectory && - IsImageFile(args.Path, _imageProcessor)) + if (!args.IsDirectory) { - return new Photo + // Must be an image file within a photo collection + var collectionType = args.GetCollectionType(); + + if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) || + string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) { - Path = args.Path - }; + if (IsImageFile(args.Path, _imageProcessor)) + { + var filename = Path.GetFileNameWithoutExtension(args.Path); + + // Make sure the image doesn't belong to a video file + if (args.DirectoryService.GetFiles(Path.GetDirectoryName(args.Path)).Any(i => IsOwnedByMedia(i, filename))) + { + return null; + } + + return new Photo + { + Path = args.Path + }; + } + } } return null; } + private bool IsOwnedByMedia(FileSystemMetadata file, string imageFilename) + { + if (_libraryManager.IsVideoFile(file.FullName) && imageFilename.StartsWith(Path.GetFileNameWithoutExtension(file.Name), StringComparison.OrdinalIgnoreCase)) + { + return true; + } + + return false; + } + private static readonly string[] IgnoreFiles = { "folder", @@ -44,7 +73,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers "landscape", "fanart", "backdrop", - "poster" + "poster", + "cover" }; internal static bool IsImageFile(string path, IImageProcessor imageProcessor) From 58d904a51a96bc15288b2ff0f99c87cdcb44728a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 11 Jul 2016 00:59:19 -0400 Subject: [PATCH 2/2] update next up --- MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs b/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs index 84d85d6675..c2a4339f0b 100644 --- a/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs +++ b/MediaBrowser.Server.Implementations/TV/TVSeriesManager.cs @@ -154,7 +154,6 @@ namespace MediaBrowser.Server.Implementations.TV SortOrder = SortOrder.Descending, IsPlayed = true, Limit = 1, - IsVirtualItem = false, ParentIndexNumberNotEquals = 0 }).FirstOrDefault();