From c1daea0ec7c07675b8a4c3f038be69d94a36a794 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Wed, 1 May 2019 07:47:22 +0200 Subject: [PATCH 1/3] Change owner and parent id of extras to the main media item --- MediaBrowser.Controller/Entities/BaseItem.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index e20641c99a..b05e97868f 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1481,7 +1481,10 @@ namespace MediaBrowser.Controller.Entities private async Task RefreshExtras(BaseItem item, MetadataRefreshOptions options, List fileSystemChildren, CancellationToken cancellationToken) { - var newExtras = LoadExtras(fileSystemChildren, options.DirectoryService).Concat(LoadThemeVideos(fileSystemChildren, options.DirectoryService)).Concat(LoadThemeSongs(fileSystemChildren, options.DirectoryService)); + var newExtras = LoadExtras(fileSystemChildren, options.DirectoryService) + .Concat(LoadThemeVideos(fileSystemChildren, options.DirectoryService)) + .Concat(LoadThemeSongs(fileSystemChildren, options.DirectoryService)) + .ToArray(); var newExtraIds = newExtras.Select(i => i.Id).ToArray(); @@ -1493,7 +1496,17 @@ namespace MediaBrowser.Controller.Entities var tasks = newExtras.Select(i => { - return RefreshMetadataForOwnedItem(i, true, new MetadataRefreshOptions(options), cancellationToken); + var subOptions = new MetadataRefreshOptions(options); + if (!i.ExtraType.HasValue || + i.OwnerId != ownerId || + !i.ParentId.Equals(Guid.Empty)) + { + i.OwnerId = ownerId; + i.ParentId = Guid.Empty; + subOptions.ForceSave = true; + } + + return RefreshMetadataForOwnedItem(i, true, subOptions, cancellationToken); }); await Task.WhenAll(tasks).ConfigureAwait(false); From b8a09339cd7c14ce4806463c4d62b80f760d93aa Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Thu, 2 May 2019 08:14:00 +0200 Subject: [PATCH 2/3] Enforce extras folder structure according to Emby's wiki --- MediaBrowser.Controller/Entities/BaseItem.cs | 67 ++++++++++++-------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index b05e97868f..1c6902b73f 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -82,6 +82,21 @@ namespace MediaBrowser.Controller.Entities public static string ThemeSongsFolderName = "theme-music"; public static string ThemeSongFilename = "theme"; public static string ThemeVideosFolderName = "backdrops"; + public static string ExtrasFolderName = "extras"; + public static string BehindTheScenesFolderName = "behind the scenes"; + public static string DeletedScenesFolderName = "deleted scenes"; + public static string InterviewFolderName = "interviews"; + public static string SceneFolderName = "scenes"; + public static string SampleFolderName = "samples"; + + public static string[] AllExtrasTypesFolderNames = { + ExtrasFolderName, + BehindTheScenesFolderName, + DeletedScenesFolderName, + InterviewFolderName, + SceneFolderName, + SampleFolderName + }; [IgnoreDataMember] public Guid[] ThemeSongIds { get; set; } @@ -1276,16 +1291,15 @@ namespace MediaBrowser.Controller.Entities .Select(item => { // Try to retrieve it from the db. If we don't find it, use the resolved version - var dbItem = LibraryManager.GetItemById(item.Id) as Video; - if (dbItem != null) + if (LibraryManager.GetItemById(item.Id) is Video dbItem) { item = dbItem; } else { // item is new - item.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeVideo; + item.ExtraType = Model.Entities.ExtraType.ThemeVideo; } return item; @@ -1296,32 +1310,36 @@ namespace MediaBrowser.Controller.Entities protected virtual BaseItem[] LoadExtras(List fileSystemChildren, IDirectoryService directoryService) { - var files = fileSystemChildren.Where(i => i.IsDirectory) - .SelectMany(i => FileSystem.GetFiles(i.FullName)); + var extras = new List