diff options
| author | 7illusions <z@7illusions.com> | 2014-08-30 19:06:58 +0200 |
|---|---|---|
| committer | 7illusions <z@7illusions.com> | 2014-08-30 19:06:58 +0200 |
| commit | 66ad1699e22029b605e17735e8d9450285d8748a (patch) | |
| tree | ffc92c88d24850b2f82b6b3a8bdd904a2ccc77a5 /MediaBrowser.Server.Implementations/Library/UserViewManager.cs | |
| parent | 34bc54263e886aae777a3537dc50a6535b51330a (diff) | |
| parent | 9d36f518182bc075c19d78084870f5115fa62d1e (diff) | |
Merge pull request #1 from MediaBrowser/master
Update to latest
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/UserViewManager.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Library/UserViewManager.cs | 97 |
1 files changed, 84 insertions, 13 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs index fc4b9eb4c..63aa3764c 100644 --- a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs @@ -1,4 +1,6 @@ -using MediaBrowser.Common.IO; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; @@ -7,11 +9,14 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.Localization; +using MediaBrowser.Controller.Playlists; using MediaBrowser.Model.Channels; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Library; +using MediaBrowser.Model.Querying; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -27,8 +32,10 @@ namespace MediaBrowser.Server.Implementations.Library private readonly IChannelManager _channelManager; private readonly ILiveTvManager _liveTvManager; + private readonly IServerApplicationPaths _appPaths; + private readonly IPlaylistManager _playlists; - public UserViewManager(ILibraryManager libraryManager, ILocalizationManager localizationManager, IFileSystem fileSystem, IUserManager userManager, IChannelManager channelManager, ILiveTvManager liveTvManager) + public UserViewManager(ILibraryManager libraryManager, ILocalizationManager localizationManager, IFileSystem fileSystem, IUserManager userManager, IChannelManager channelManager, ILiveTvManager liveTvManager, IServerApplicationPaths appPaths, IPlaylistManager playlists) { _libraryManager = libraryManager; _localizationManager = localizationManager; @@ -36,6 +43,8 @@ namespace MediaBrowser.Server.Implementations.Library _userManager = userManager; _channelManager = channelManager; _liveTvManager = liveTvManager; + _appPaths = appPaths; + _playlists = playlists; } public async Task<IEnumerable<Folder>> GetUserViews(UserViewQuery query, CancellationToken cancellationToken) @@ -62,40 +71,58 @@ namespace MediaBrowser.Server.Implementations.Library if (recursiveChildren.OfType<Series>().Any()) { - list.Add(await GetUserView(CollectionType.TvShows, user, cancellationToken).ConfigureAwait(false)); + list.Add(await GetUserView(CollectionType.TvShows, user, string.Empty, cancellationToken).ConfigureAwait(false)); } if (recursiveChildren.OfType<MusicAlbum>().Any() || recursiveChildren.OfType<MusicVideo>().Any()) { - list.Add(await GetUserView(CollectionType.Music, user, cancellationToken).ConfigureAwait(false)); + list.Add(await GetUserView(CollectionType.Music, user, string.Empty, cancellationToken).ConfigureAwait(false)); } if (recursiveChildren.OfType<Movie>().Any()) { - list.Add(await GetUserView(CollectionType.Movies, user, cancellationToken).ConfigureAwait(false)); + list.Add(await GetUserView(CollectionType.Movies, user, string.Empty, cancellationToken).ConfigureAwait(false)); } if (recursiveChildren.OfType<Game>().Any()) { - list.Add(await GetUserView(CollectionType.Games, user, cancellationToken).ConfigureAwait(false)); + list.Add(await GetUserView(CollectionType.Games, user, string.Empty, cancellationToken).ConfigureAwait(false)); } - if (recursiveChildren.OfType<BoxSet>().Any()) + if (user.Configuration.DisplayCollectionsView && + recursiveChildren.OfType<BoxSet>().Any()) { - list.Add(await GetUserView(CollectionType.BoxSets, user, cancellationToken).ConfigureAwait(false)); + list.Add(await GetUserView(CollectionType.BoxSets, user, string.Empty, cancellationToken).ConfigureAwait(false)); + } + + if (recursiveChildren.OfType<Playlist>().Any()) + { + list.Add(_playlists.GetPlaylistsFolder(user.Id.ToString("N"))); + } + + if (user.Configuration.DisplayFoldersView) + { + list.Add(await GetUserView(CollectionType.Folders, user, "zz_" + CollectionType.Folders, cancellationToken).ConfigureAwait(false)); } if (query.IncludeExternalContent) { var channelResult = await _channelManager.GetChannels(new ChannelQuery { - Limit = 0, UserId = query.UserId }, cancellationToken).ConfigureAwait(false); - if (channelResult.TotalRecordCount > 0) + var channels = channelResult.Items; + + var embeddedChannels = channels + .Where(i => user.Configuration.DisplayChannelsWithinViews.Contains(i.Id)) + .ToList(); + + list.AddRange(embeddedChannels.Select(i => _channelManager.GetChannel(i.Id))); + + if (channels.Length > embeddedChannels.Count) { list.Add(await _channelManager.GetInternalChannelFolder(query.UserId, cancellationToken).ConfigureAwait(false)); } @@ -106,14 +133,58 @@ namespace MediaBrowser.Server.Implementations.Library } } - return list.OrderBy(i => i.SortName); + var sorted = _libraryManager.Sort(list, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending).ToList(); + + var orders = user.Configuration.OrderedViews.ToList(); + + return list + .OrderBy(i => + { + var index = orders.IndexOf(i.Id.ToString("N")); + + return index == -1 ? int.MaxValue : index; + }) + .ThenBy(sorted.IndexOf) + .ThenBy(i => i.SortName); } - private Task<UserView> GetUserView(string type, User user, CancellationToken cancellationToken) + public Task<UserView> GetUserView(string type, User user, string sortName, CancellationToken cancellationToken) { var name = _localizationManager.GetLocalizedString("ViewType" + type); - return _libraryManager.GetNamedView(name, type, string.Empty, cancellationToken); + return _libraryManager.GetNamedView(name, type, sortName, cancellationToken); + } + + public async Task<SpecialFolder> GetSpecialFolder(string name, SpecialFolderType type, string itemType, CancellationToken cancellationToken) + { + var path = Path.Combine(_appPaths.ItemsByNamePath, + "specialfolders", + _fileSystem.GetValidFilename(name)); + + var id = (path + "_specialfolder_" + name).GetMBId(typeof(SpecialFolder)); + + var item = _libraryManager.GetItemById(id) as SpecialFolder; + + if (item == null) + { + Directory.CreateDirectory(Path.GetDirectoryName(path)); + + item = new SpecialFolder + { + Path = path, + Id = id, + DateCreated = DateTime.UtcNow, + Name = name, + SpecialFolderType = type, + ItemTypeName = itemType + }; + + await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); + + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); + } + + return item; } } } |
