From 911e5cb490d410f551a08391433af806de4f449b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 10 Jan 2017 15:17:01 -0500 Subject: [PATCH 1/3] update nfo image saver --- .../Savers/BaseNfoSaver.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs index 18936df013..5e023c5db1 100644 --- a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs +++ b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs @@ -846,7 +846,7 @@ namespace MediaBrowser.XbmcMetadata.Savers AddUserData(item, writer, userManager, userDataRepo, options); - AddActors(people, writer, libraryManager, fileSystem, config); + AddActors(people, writer, libraryManager, fileSystem, config, options.SaveImagePathsInNfo); var folder = item as BoxSet; if (folder != null) @@ -974,7 +974,7 @@ namespace MediaBrowser.XbmcMetadata.Savers writer.WriteEndElement(); } - private static void AddActors(List people, XmlWriter writer, ILibraryManager libraryManager, IFileSystem fileSystem, IServerConfigurationManager config) + private static void AddActors(List people, XmlWriter writer, ILibraryManager libraryManager, IFileSystem fileSystem, IServerConfigurationManager config, bool saveImagePath) { var actors = people .Where(i => !IsPersonType(i, PersonType.Director) && !IsPersonType(i, PersonType.Writer)) @@ -1004,20 +1004,23 @@ namespace MediaBrowser.XbmcMetadata.Savers writer.WriteElementString("sortorder", person.SortOrder.Value.ToString(UsCulture)); } - try + if (saveImagePath) { - var personEntity = libraryManager.GetPerson(person.Name); - var image = personEntity.GetImageInfo(ImageType.Primary, 0); + try + { + var personEntity = libraryManager.GetPerson(person.Name); + var image = personEntity.GetImageInfo(ImageType.Primary, 0); - if (image != null) + if (image != null) + { + writer.WriteElementString("thumb", GetImagePathToSave(image, libraryManager, config)); + } + } + catch (Exception) { - writer.WriteElementString("thumb", GetImagePathToSave(image, libraryManager, config)); + // Already logged in core } } - catch (Exception) - { - // Already logged in core - } writer.WriteEndElement(); } From 12f20de68b3e988b27286a1f25175a2fe91db5a8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 10 Jan 2017 15:44:02 -0500 Subject: [PATCH 2/3] update offline detection --- .../Data/CleanDatabaseScheduledTask.cs | 8 +++- MediaBrowser.Controller/Entities/BaseItem.cs | 17 --------- MediaBrowser.Controller/Entities/Folder.cs | 38 +++++++++---------- 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs b/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs index 5bc3a625f1..2819a249fb 100644 --- a/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs +++ b/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs @@ -137,6 +137,11 @@ namespace Emby.Server.Implementations.Data var numComplete = 0; var numItems = result.Count; + var allLibraryPaths = _libraryManager + .GetVirtualFolders() + .SelectMany(i => i.Locations) + .ToList(); + foreach (var item in result) { cancellationToken.ThrowIfCancellationRequested(); @@ -170,9 +175,8 @@ namespace Emby.Server.Implementations.Data continue; } - if (Folder.IsPathOffline(path)) + if (Folder.IsPathOffline(path, allLibraryPaths)) { - await libraryItem.UpdateIsOffline(true).ConfigureAwait(false); continue; } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index c8f49820ff..3651ba3631 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -272,9 +272,6 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public virtual string Path { get; set; } - [IgnoreDataMember] - public bool IsOffline { get; set; } - [IgnoreDataMember] public virtual SourceType SourceType { get; set; } @@ -339,20 +336,6 @@ namespace MediaBrowser.Controller.Entities } } - public Task UpdateIsOffline(bool newValue) - { - var item = this; - - if (item.IsOffline != newValue) - { - item.IsOffline = newValue; - // this is creating too many repeated db updates - //return item.UpdateToRepository(ItemUpdateType.None, CancellationToken.None); - } - - return Task.FromResult(true); - } - /// /// Gets or sets the type of the location. /// diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 61747bd140..c8bdbd1942 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -369,6 +369,11 @@ namespace MediaBrowser.Controller.Entities var validChildren = new List(); + var allLibraryPaths = LibraryManager + .GetVirtualFolders() + .SelectMany(i => i.Locations) + .ToList(); + if (locationType != LocationType.Remote && locationType != LocationType.Virtual) { IEnumerable nonCachedChildren; @@ -402,7 +407,6 @@ namespace MediaBrowser.Controller.Entities if (currentChildren.TryGetValue(child.Id, out currentChild) && IsValidFromResolver(currentChild, child)) { - await currentChild.UpdateIsOffline(false).ConfigureAwait(false); validChildren.Add(currentChild); continue; @@ -429,9 +433,8 @@ namespace MediaBrowser.Controller.Entities { } - else if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path)) + else if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path, allLibraryPaths)) { - await item.UpdateIsOffline(true).ConfigureAwait(false); } else { @@ -446,7 +449,6 @@ namespace MediaBrowser.Controller.Entities Logger.Debug("Removed item: " + item.Path); item.SetParent(null); - item.IsOffline = false; await LibraryManager.DeleteItem(item, new DeleteOptions { DeleteFileLocation = false }).ConfigureAwait(false); LibraryManager.ReportItemRemoved(item); } @@ -611,6 +613,11 @@ namespace MediaBrowser.Controller.Entities /// The path. /// true if the specified path is offline; otherwise, false. public static bool IsPathOffline(string path) + { + return IsPathOffline(path, LibraryManager.GetVirtualFolders().SelectMany(i => i.Locations).ToList()); + } + + public static bool IsPathOffline(string path, List allLibraryPaths) { if (FileSystem.FileExists(path)) { @@ -627,26 +634,15 @@ namespace MediaBrowser.Controller.Entities return false; } - path = System.IO.Path.GetDirectoryName(path); - } + if (allLibraryPaths.Contains(path, StringComparer.OrdinalIgnoreCase)) + { + return true; + } - if (ContainsPath(LibraryManager.GetVirtualFolders(), originalPath)) - { - return true; + path = System.IO.Path.GetDirectoryName(path); } - return false; - } - - /// - /// Determines whether the specified folders contains path. - /// - /// The folders. - /// The path. - /// true if the specified folders contains path; otherwise, false. - private static bool ContainsPath(IEnumerable folders, string path) - { - return folders.SelectMany(i => i.Locations).Any(i => ContainsPath(i, path)); + return allLibraryPaths.Any(i => ContainsPath(i, originalPath)); } private static bool ContainsPath(string parent, string path) From 0b5d4ce3f839118a0a5903ec278321ecfecf1c32 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 11 Jan 2017 12:56:26 -0500 Subject: [PATCH 3/3] fix live tv folders being created in a loop --- .../IO/ManagedFileSystem.cs | 18 ++++++++++++++++++ Emby.Server.Core/IO/LibraryMonitor.cs | 2 +- .../Connect/ConnectManager.cs | 6 +++++- Emby.Server.Implementations/Dto/DtoService.cs | 5 +---- .../Library/LibraryManager.cs | 4 ++-- .../Library/UserViewManager.cs | 8 -------- .../LiveTv/EmbyTV/EmbyTV.cs | 2 +- .../UserViews/DynamicImageProvider.cs | 4 +++- MediaBrowser.Controller/Entities/Folder.cs | 2 +- .../Entities/ICollectionFolder.cs | 13 ------------- .../Configuration/UserConfiguration.cs | 3 --- MediaBrowser.Model/IO/IFileSystem.cs | 2 ++ 12 files changed, 34 insertions(+), 35 deletions(-) diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs index 78070a5d91..72b9d55eb1 100644 --- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs +++ b/Emby.Common.Implementations/IO/ManagedFileSystem.cs @@ -499,6 +499,24 @@ namespace Emby.Common.Implementations.IO CopyFile(temp1, file2, true); } + public bool AreEqual(string path1, string path2) + { + if (path1 == null && path2 == null) + { + return true; + } + + if (path1 == null || path2 == null) + { + return false; + } + + path1 = path1.TrimEnd(DirectorySeparatorChar); + path2 = path2.TrimEnd(DirectorySeparatorChar); + + return string.Equals(path1, path2, StringComparison.OrdinalIgnoreCase); + } + public bool ContainsSubPath(string parentPath, string path) { if (string.IsNullOrEmpty(parentPath)) diff --git a/Emby.Server.Core/IO/LibraryMonitor.cs b/Emby.Server.Core/IO/LibraryMonitor.cs index 87b70d0479..f0ecb9d892 100644 --- a/Emby.Server.Core/IO/LibraryMonitor.cs +++ b/Emby.Server.Core/IO/LibraryMonitor.cs @@ -87,7 +87,7 @@ namespace Emby.Server.Core.IO public bool IsPathLocked(string path) { var lockedPaths = _tempIgnoredPaths.Keys.ToList(); - return lockedPaths.Any(i => string.Equals(i, path, StringComparison.OrdinalIgnoreCase) || _fileSystem.ContainsSubPath(i, path)); + return lockedPaths.Any(i => _fileSystem.AreEqual(i, path) || _fileSystem.ContainsSubPath(i, path)); } public async void ReportFileSystemChangeComplete(string path, bool refreshPath) diff --git a/Emby.Server.Implementations/Connect/ConnectManager.cs b/Emby.Server.Implementations/Connect/ConnectManager.cs index 8c8b7b0268..23fafed158 100644 --- a/Emby.Server.Implementations/Connect/ConnectManager.cs +++ b/Emby.Server.Implementations/Connect/ConnectManager.cs @@ -925,7 +925,11 @@ namespace Emby.Server.Implementations.Connect } _data.PendingAuthorizations = newPendingList; - CacheData(); + + if (!newPendingList.Select(i => i.Id).SequenceEqual(currentPendingList.Select(i => i.Id), StringComparer.Ordinal)) + { + CacheData(); + } await RefreshGuestNames(list, refreshImages).ConfigureAwait(false); } diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index 8e6c1263d6..06ac7031a3 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -361,10 +361,7 @@ namespace Emby.Server.Implementations.Dto if (collectionFolder != null) { dto.OriginalCollectionType = collectionFolder.CollectionType; - - dto.CollectionType = user == null ? - collectionFolder.CollectionType : - collectionFolder.GetViewType(user); + dto.CollectionType = collectionFolder.CollectionType; } if (fields.Contains(ItemFields.CanDelete)) diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index db514af76f..71ba465df4 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -2010,7 +2010,7 @@ namespace Emby.Server.Implementations.Library private string GetContentTypeOverride(string path, bool inherit) { - var nameValuePair = ConfigurationManager.Configuration.ContentTypes.FirstOrDefault(i => string.Equals(i.Name, path, StringComparison.OrdinalIgnoreCase) || (inherit && !string.IsNullOrWhiteSpace(i.Name) && _fileSystem.ContainsSubPath(i.Name, path))); + var nameValuePair = ConfigurationManager.Configuration.ContentTypes.FirstOrDefault(i => _fileSystem.AreEqual(i.Name, path) || (inherit && !string.IsNullOrWhiteSpace(i.Name) && _fileSystem.ContainsSubPath(i.Name, path))); if (nameValuePair != null) { return nameValuePair.Value; @@ -3066,7 +3066,7 @@ namespace Emby.Server.Implementations.Library { removeList.Add(contentType); } - else if (string.Equals(path, contentType.Name, StringComparison.OrdinalIgnoreCase) + else if (_fileSystem.AreEqual(path, contentType.Name) || _fileSystem.ContainsSubPath(path, contentType.Name)) { removeList.Add(contentType); diff --git a/Emby.Server.Implementations/Library/UserViewManager.cs b/Emby.Server.Implementations/Library/UserViewManager.cs index 0a8b1c681c..f11cbd4987 100644 --- a/Emby.Server.Implementations/Library/UserViewManager.cs +++ b/Emby.Server.Implementations/Library/UserViewManager.cs @@ -55,8 +55,6 @@ namespace Emby.Server.Implementations.Library }).ToList(); } - var plainFolderIds = user.Configuration.PlainFolderViews.Select(i => new Guid(i)).ToList(); - var groupedFolders = new List(); var list = new List(); @@ -72,12 +70,6 @@ namespace Emby.Server.Implementations.Library continue; } - if (plainFolderIds.Contains(folder.Id) && UserView.IsEligibleForEnhancedView(folderViewType)) - { - list.Add(folder); - continue; - } - if (collectionFolder != null && UserView.IsEligibleForGrouping(folder) && user.IsFolderGrouped(folder.Id)) { groupedFolders.Add(collectionFolder); diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 2e591711bc..639621a98d 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -150,7 +150,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV foreach (var recordingFolder in recordingFolders) { var pathsToCreate = recordingFolder.Locations - .Where(i => !allExistingPaths.Contains(i, StringComparer.OrdinalIgnoreCase)) + .Where(i => !allExistingPaths.Any(p => _fileSystem.AreEqual(p, i))) .ToList(); if (pathsToCreate.Count == 0) diff --git a/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs b/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs index bef964c6fa..b8d03db3d3 100644 --- a/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs +++ b/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs @@ -151,7 +151,9 @@ namespace Emby.Server.Implementations.UserViews string[] collectionStripViewTypes = { CollectionType.Movies, - CollectionType.TvShows + CollectionType.TvShows, + CollectionType.Playlists, + CollectionType.Photos }; return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty); diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index c8bdbd1942..cdd503bba4 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -647,7 +647,7 @@ namespace MediaBrowser.Controller.Entities private static bool ContainsPath(string parent, string path) { - return string.Equals(parent, path, StringComparison.OrdinalIgnoreCase) || FileSystem.ContainsSubPath(parent, path); + return FileSystem.AreEqual(parent, path) || FileSystem.ContainsSubPath(parent, path); } /// diff --git a/MediaBrowser.Controller/Entities/ICollectionFolder.cs b/MediaBrowser.Controller/Entities/ICollectionFolder.cs index f4544f173e..d8b02034c7 100644 --- a/MediaBrowser.Controller/Entities/ICollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/ICollectionFolder.cs @@ -20,17 +20,4 @@ namespace MediaBrowser.Controller.Entities { bool EnableUserSpecificView { get; } } - - public static class CollectionFolderExtensions - { - public static string GetViewType(this ICollectionFolder folder, User user) - { - if (user.Configuration.PlainFolderViews.Contains(folder.Id.ToString("N"), StringComparer.OrdinalIgnoreCase)) - { - return null; - } - - return folder.CollectionType; - } - } } diff --git a/MediaBrowser.Model/Configuration/UserConfiguration.cs b/MediaBrowser.Model/Configuration/UserConfiguration.cs index efd3d6b671..5567063fe3 100644 --- a/MediaBrowser.Model/Configuration/UserConfiguration.cs +++ b/MediaBrowser.Model/Configuration/UserConfiguration.cs @@ -37,7 +37,6 @@ namespace MediaBrowser.Model.Configuration public string[] OrderedViews { get; set; } public string[] LatestItemsExcludes { get; set; } - public string[] PlainFolderViews { get; set; } public bool HidePlayedInLatest { get; set; } @@ -61,8 +60,6 @@ namespace MediaBrowser.Model.Configuration LatestItemsExcludes = new string[] { }; OrderedViews = new string[] { }; - PlainFolderViews = new string[] { }; - GroupedFolders = new string[] { }; } } diff --git a/MediaBrowser.Model/IO/IFileSystem.cs b/MediaBrowser.Model/IO/IFileSystem.cs index 62bb66ea85..f6d1bb3515 100644 --- a/MediaBrowser.Model/IO/IFileSystem.cs +++ b/MediaBrowser.Model/IO/IFileSystem.cs @@ -120,6 +120,8 @@ namespace MediaBrowser.Model.IO /// The file2. void SwapFiles(string file1, string file2); + bool AreEqual(string path1, string path2); + /// /// Determines whether [contains sub path] [the specified parent path]. ///