diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-08-14 14:00:26 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-08-14 14:00:26 -0400 |
| commit | 032891c9f3327ca626938ca175d7d4623e6a27d0 (patch) | |
| tree | d8d7f56ad3bae10c934e292a97e025b370a5d51a | |
| parent | ec5619e0f960a2abc2226f81fcfcb82ae9fc295a (diff) | |
update user views
7 files changed, 161 insertions, 63 deletions
diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index ba2820bc1..cee5dadd2 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -285,14 +285,14 @@ namespace MediaBrowser.Controller.Entities var list = new List<BaseItem>(); - list.Add(await GetUserView(SpecialFolder.MusicLatest, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicPlaylists, user, "1", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicAlbums, user, "2", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicAlbumArtists, user, "3", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicLatest, "0", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicPlaylists, "1", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicAlbums, "2", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicAlbumArtists, "3", parent).ConfigureAwait(false)); //list.Add(await GetUserView(SpecialFolder.MusicArtists, user, "4", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicSongs, user, "5", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicGenres, user, "6", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicFavorites, user, "7", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicSongs, "5", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicGenres, "6", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicFavorites, "7", parent).ConfigureAwait(false)); return GetResult(list, parent, query); } @@ -301,9 +301,9 @@ namespace MediaBrowser.Controller.Entities { var list = new List<BaseItem>(); - list.Add(await GetUserView(SpecialFolder.MusicFavoriteAlbums, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicFavoriteArtists, user, "1", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicFavoriteSongs, user, "2", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicFavoriteAlbums, "0", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicFavoriteArtists, "1", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicFavoriteSongs, "2", parent).ConfigureAwait(false)); return GetResult(list, parent, query); } @@ -329,7 +329,7 @@ namespace MediaBrowser.Controller.Entities }) .Where(i => i != null) - .Select(i => GetUserView(i.Name, SpecialFolder.MusicGenre, user, i.SortName, parent)); + .Select(i => GetUserView(i.Name, SpecialFolder.MusicGenre, i.SortName, parent)); var genres = await Task.WhenAll(tasks).ConfigureAwait(false); @@ -366,7 +366,7 @@ namespace MediaBrowser.Controller.Entities .OfType<IHasArtist>(); var artists = _libraryManager.GetArtists(items); - + return GetResult(artists, parent, query); } @@ -377,7 +377,7 @@ namespace MediaBrowser.Controller.Entities .OfType<IHasAlbumArtist>(); var artists = _libraryManager.GetAlbumArtists(items).Where(i => _userDataManager.GetUserData(user.Id, i.GetUserDataKey()).IsFavorite); - + return GetResult(artists, parent, query); } @@ -443,12 +443,12 @@ namespace MediaBrowser.Controller.Entities var list = new List<BaseItem>(); - list.Add(await GetUserView(SpecialFolder.MovieResume, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MovieLatest, user, "1", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MovieMovies, user, "2", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MovieCollections, user, "3", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MovieFavorites, user, "4", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MovieGenres, user, "5", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieResume, "0", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieLatest, "1", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieMovies, "2", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieCollections, "3", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieFavorites, "4", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieGenres, "5", parent).ConfigureAwait(false)); return GetResult(list, parent, query); } @@ -554,7 +554,7 @@ namespace MediaBrowser.Controller.Entities }) .Where(i => i != null) - .Select(i => GetUserView(i.Name, SpecialFolder.MovieGenre, user, i.SortName, parent)); + .Select(i => GetUserView(i.Name, SpecialFolder.MovieGenre, i.SortName, parent)); var genres = await Task.WhenAll(tasks).ConfigureAwait(false); @@ -616,13 +616,13 @@ namespace MediaBrowser.Controller.Entities var list = new List<BaseItem>(); - list.Add(await GetUserView(SpecialFolder.TvResume, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvNextUp, user, "1", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvLatest, user, "2", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvShowSeries, user, "3", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvFavoriteSeries, user, "4", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvFavoriteEpisodes, user, "5", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvGenres, user, "6", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvResume, "0", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvNextUp, "1", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvLatest, "2", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvShowSeries, "3", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvFavoriteSeries, "4", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvFavoriteEpisodes, "5", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvGenres, "6", parent).ConfigureAwait(false)); return GetResult(list, parent, query); } @@ -637,11 +637,11 @@ namespace MediaBrowser.Controller.Entities var list = new List<BaseItem>(); - list.Add(await GetUserView(SpecialFolder.LatestGames, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.RecentlyPlayedGames, user, "1", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.GameFavorites, user, "2", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.GameSystems, user, "3", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.GameGenres, user, "4", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.LatestGames, "0", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.RecentlyPlayedGames, "1", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.GameFavorites, "2", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.GameSystems, "3", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.GameGenres, "4", parent).ConfigureAwait(false)); return GetResult(list, parent, query); } @@ -739,7 +739,7 @@ namespace MediaBrowser.Controller.Entities }) .Where(i => i != null) - .Select(i => GetUserView(i.Name, SpecialFolder.TvGenre, user, i.SortName, parent)); + .Select(i => GetUserView(i.Name, SpecialFolder.TvGenre, i.SortName, parent)); var genres = await Task.WhenAll(tasks).ConfigureAwait(false); @@ -791,7 +791,7 @@ namespace MediaBrowser.Controller.Entities }) .Where(i => i != null) - .Select(i => GetUserView(i.Name, SpecialFolder.GameGenre, user, i.SortName, parent)); + .Select(i => GetUserView(i.Name, SpecialFolder.GameGenre, i.SortName, parent)); var genres = await Task.WhenAll(tasks).ConfigureAwait(false); @@ -1871,26 +1871,20 @@ namespace MediaBrowser.Controller.Entities var list = new List<BaseItem>(); //list.Add(await GetUserSubView(SpecialFolder.LiveTvNowPlaying, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.LiveTvChannels, user, string.Empty, user.RootFolder).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.LiveTvRecordingGroups, user, string.Empty, user.RootFolder).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.LiveTvChannels, string.Empty, user.RootFolder).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.LiveTvRecordingGroups, string.Empty, user.RootFolder).ConfigureAwait(false)); return GetResult(list, queryParent, query); } - private async Task<UserView> GetUserView(string name, string type, User user, string sortName, BaseItem parent) + private Task<UserView> GetUserView(string name, string type, string sortName, BaseItem parent) { - var view = await _userViewManager.GetUserSubView(name, parent.Id.ToString("N"), type, user, sortName, CancellationToken.None) - .ConfigureAwait(false); - - return view; + return _userViewManager.GetUserSubView(name, parent.Id.ToString("N"), type, sortName, CancellationToken.None); } - private async Task<UserView> GetUserView(string type, User user, string sortName, BaseItem parent) + private Task<UserView> GetUserView(string type, string sortName, BaseItem parent) { - var view = await _userViewManager.GetUserSubView(parent.Id.ToString("N"), type, user, sortName, CancellationToken.None) - .ConfigureAwait(false); - - return view; + return _userViewManager.GetUserSubView(parent.Id.ToString("N"), type, sortName, CancellationToken.None); } public static bool IsYearMismatched(BaseItem item, ILibraryManager libraryManager) diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 9c52fd2dc..6906a25fb 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -351,7 +351,37 @@ namespace MediaBrowser.Controller.Library Task<UserView> GetNamedView(User user, string name, string viewType, - string sortName, + string sortName, + CancellationToken cancellationToken); + + /// <summary> + /// Gets the named view. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="viewType">Type of the view.</param> + /// <param name="sortName">Name of the sort.</param> + /// <param name="cancellationToken">The cancellation token.</param> + /// <returns>Task<UserView>.</returns> + Task<UserView> GetNamedView(string name, + string viewType, + string sortName, + CancellationToken cancellationToken); + + /// <summary> + /// Gets the named view. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="parentId">The parent identifier.</param> + /// <param name="viewType">Type of the view.</param> + /// <param name="sortName">Name of the sort.</param> + /// <param name="uniqueId">The unique identifier.</param> + /// <param name="cancellationToken">The cancellation token.</param> + /// <returns>Task<UserView>.</returns> + Task<UserView> GetNamedView(string name, + string parentId, + string viewType, + string sortName, + string uniqueId, CancellationToken cancellationToken); /// <summary> diff --git a/MediaBrowser.Controller/Library/IUserViewManager.cs b/MediaBrowser.Controller/Library/IUserViewManager.cs index f0b862c2d..5391d113e 100644 --- a/MediaBrowser.Controller/Library/IUserViewManager.cs +++ b/MediaBrowser.Controller/Library/IUserViewManager.cs @@ -12,10 +12,9 @@ namespace MediaBrowser.Controller.Library { Task<IEnumerable<Folder>> GetUserViews(UserViewQuery query, CancellationToken cancellationToken); - Task<UserView> GetUserSubView(string name, string parentId, string type, User user, string sortName, - CancellationToken cancellationToken); + Task<UserView> GetUserSubView(string name, string parentId, string type, string sortName, CancellationToken cancellationToken); - Task<UserView> GetUserSubView(string category, string type, User user, string sortName, CancellationToken cancellationToken); + Task<UserView> GetUserSubView(string category, string type, string sortName, CancellationToken cancellationToken); List<Tuple<BaseItem, List<BaseItem>>> GetLatestItems(LatestItemsQuery request); } diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index fbecaa65d..cbbed856c 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -1407,9 +1407,8 @@ namespace MediaBrowser.Server.Implementations.Channels public async Task<Folder> GetInternalChannelFolder(string userId, CancellationToken cancellationToken) { var name = _localization.GetLocalizedString("ViewTypeChannels"); - var user = _userManager.GetUserById(userId); - return await _libraryManager.GetNamedView(user, name, "channels", "zz_" + name, cancellationToken).ConfigureAwait(false); + return await _libraryManager.GetNamedView(name, "channels", "zz_" + name, cancellationToken).ConfigureAwait(false); } public async Task DownloadChannelItem(IChannelMediaItem item, string destination, 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) diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 389eda904..cc3c06dd4 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -2204,8 +2204,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv public async Task<Folder> GetInternalLiveTvFolder(string userId, CancellationToken cancellationToken) { var name = _localization.GetLocalizedString("ViewTypeLiveTV"); - var user = _userManager.GetUserById(userId); - return await _libraryManager.GetNamedView(user, name, "livetv", "zz_" + name, cancellationToken).ConfigureAwait(false); + return await _libraryManager.GetNamedView(name, "livetv", "zz_" + name, cancellationToken).ConfigureAwait(false); } public async Task<TunerHostInfo> SaveTunerHost(TunerHostInfo info) |
