diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/LibraryManager.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Library/LibraryManager.cs | 83 |
1 files changed, 80 insertions, 3 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index dfcc1370e..1d2e5e322 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1651,7 +1651,7 @@ namespace MediaBrowser.Server.Implementations.Library private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromHours(24); - public async Task<UserView> GetNamedView(User user, + public Task<UserView> GetNamedView(User user, string name, string viewType, string sortName, @@ -1659,10 +1659,17 @@ namespace MediaBrowser.Server.Implementations.Library { if (ConfigurationManager.Configuration.EnableUserSpecificUserViews) { - return await GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken) - .ConfigureAwait(false); + return GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken); } + return GetNamedView(name, viewType, sortName, cancellationToken); + } + + public async Task<UserView> GetNamedView(string name, + string viewType, + string sortName, + CancellationToken cancellationToken) + { var path = Path.Combine(ConfigurationManager.ApplicationPaths.ItemsByNamePath, "views"); @@ -1806,6 +1813,76 @@ namespace MediaBrowser.Server.Implementations.Library return item; } + public async Task<UserView> GetNamedView(string name, + string parentId, + string viewType, + string sortName, + string uniqueId, + CancellationToken cancellationToken) + { + if (string.IsNullOrWhiteSpace(name)) + { + throw new ArgumentNullException("name"); + } + + var idValues = "37_namedview_" + name + (parentId ?? string.Empty); + if (!string.IsNullOrWhiteSpace(uniqueId)) + { + idValues += uniqueId; + } + + var id = GetNewItemId(idValues, typeof(UserView)); + + var path = Path.Combine(ConfigurationManager.ApplicationPaths.InternalMetadataPath, "views", id.ToString("N")); + + var item = GetItemById(id) as UserView; + + var isNew = false; + + if (item == null) + { + Directory.CreateDirectory(path); + + item = new UserView + { + Path = path, + Id = id, + DateCreated = DateTime.UtcNow, + Name = name, + ViewType = viewType, + ForcedSortName = sortName + }; + + if (!string.IsNullOrWhiteSpace(parentId)) + { + item.ParentId = new Guid(parentId); + } + + await CreateItem(item, cancellationToken).ConfigureAwait(false); + + isNew = true; + } + + if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase)) + { + item.ViewType = viewType; + await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); + } + + var refresh = isNew || (DateTime.UtcNow - item.DateLastSaved) >= _viewRefreshInterval; + + if (refresh) + { + _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions + { + // Need to force save to increment DateLastSaved + ForceSave = true + }); + } + + return item; + } + public bool IsVideoFile(string path) { var resolver = new VideoResolver(GetNamingOptions(), new PatternsLogger()); |
