aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Library
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library')
-rw-r--r--MediaBrowser.Server.Implementations/Library/LibraryManager.cs83
-rw-r--r--MediaBrowser.Server.Implementations/Library/UserViewManager.cs12
2 files changed, 86 insertions, 9 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());
diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs
index 61b28a072..c32dc0d41 100644
--- a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs
@@ -167,8 +167,8 @@ namespace MediaBrowser.Server.Implementations.Library
if (_liveTvManager.GetEnabledUsers().Select(i => i.Id.ToString("N")).Contains(query.UserId))
{
- //list.Add(await _liveTvManager.GetInternalLiveTvFolder(query.UserId, cancellationToken).ConfigureAwait(false));
- list.Add(await GetUserView(new List<ICollectionFolder>(), list, CollectionType.LiveTv, string.Empty, user, cancellationToken).ConfigureAwait(false));
+ var name = _localizationManager.GetLocalizedString("ViewType" + CollectionType.LiveTv);
+ list.Add(await _libraryManager.GetNamedView(name, CollectionType.LiveTv, string.Empty, cancellationToken).ConfigureAwait(false));
}
}
@@ -187,18 +187,18 @@ namespace MediaBrowser.Server.Implementations.Library
.ThenBy(i => i.SortName);
}
- public Task<UserView> GetUserSubView(string name, string parentId, string type, User user, string sortName, CancellationToken cancellationToken)
+ public Task<UserView> GetUserSubView(string name, string parentId, string type, string sortName, CancellationToken cancellationToken)
{
var uniqueId = parentId + "subview" + type;
- return _libraryManager.GetNamedView(user, name, parentId, type, sortName, uniqueId, cancellationToken);
+ return _libraryManager.GetNamedView(name, parentId, type, sortName, uniqueId, cancellationToken);
}
- public Task<UserView> GetUserSubView(string parentId, string type, User user, string sortName, CancellationToken cancellationToken)
+ public Task<UserView> GetUserSubView(string parentId, string type, string sortName, CancellationToken cancellationToken)
{
var name = _localizationManager.GetLocalizedString("ViewType" + type);
- return GetUserSubView(name, parentId, type, user, sortName, cancellationToken);
+ return GetUserSubView(name, parentId, type, sortName, cancellationToken);
}
public async Task<UserView> GetUserView(List<ICollectionFolder> parents, List<Folder> currentViews, string viewType, string sortName, User user, CancellationToken cancellationToken)