From b4016ae07efabce5909fe9202e8f860c654afe37 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 27 May 2014 17:17:48 -0400 Subject: [PATCH] update notification styles --- MediaBrowser.Model/ApiClient/IApiClient.cs | 7 ++ .../Channels/ChannelFeatures.cs | 8 +-- .../Channels/ChannelManager.cs | 66 ++++++++++++++++--- .../LiveTv/LiveTvManager.cs | 12 +++- .../ApplicationHost.cs | 2 +- Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 8 files changed, 86 insertions(+), 19 deletions(-) diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs index 02dce0f6b7..f30bb5dafb 100644 --- a/MediaBrowser.Model/ApiClient/IApiClient.cs +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -212,6 +212,13 @@ namespace MediaBrowser.Model.ApiClient /// userId Task GetRootFolderAsync(string userId); + /// + /// Gets the additional parts. + /// + /// The item identifier. + /// Task{BaseItemDto[]}. + Task GetAdditionalParts(string itemId); + /// /// Gets the users async. /// diff --git a/MediaBrowser.Model/Channels/ChannelFeatures.cs b/MediaBrowser.Model/Channels/ChannelFeatures.cs index cec40d7f25..494ebe3a3c 100644 --- a/MediaBrowser.Model/Channels/ChannelFeatures.cs +++ b/MediaBrowser.Model/Channels/ChannelFeatures.cs @@ -57,10 +57,10 @@ namespace MediaBrowser.Model.Channels { Name = 0, CommunityRating = 1, - ContentReleaseDate = 2, - DateAdded = 3, + PremiereDate = 2, + DateCreated = 3, Runtime = 4, - CommunityMostWatched = 5, - UserPlayCount = 6 + PlayCount = 5, + CommunityPlayCount = 6 } } diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index acfc5228e8..335366077c 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Extensions; +using System.Globalization; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Configuration; @@ -299,8 +300,25 @@ namespace MediaBrowser.Server.Implementations.Channels ? null : _userManager.GetUserById(new Guid(query.UserId)); - var itemsResult = await GetChannelItems(channelProvider, user, query.FolderId, providerStartIndex, providerLimit, cancellationToken) - .ConfigureAwait(false); + ChannelItemSortField? sortField = null; + ChannelItemSortField parsedField; + if (query.SortBy.Length == 1 && + Enum.TryParse(query.SortBy[0], true, out parsedField)) + { + sortField = parsedField; + } + + var sortDescending = query.SortOrder.HasValue && query.SortOrder.Value == SortOrder.Descending; + + var itemsResult = await GetChannelItems(channelProvider, + user, + query.FolderId, + providerStartIndex, + providerLimit, + sortField, + sortDescending, + cancellationToken) + .ConfigureAwait(false); var providerTotalRecordCount = providerLimit.HasValue ? itemsResult.TotalRecordCount : null; @@ -322,9 +340,16 @@ namespace MediaBrowser.Server.Implementations.Channels } private readonly SemaphoreSlim _resourcePool = new SemaphoreSlim(1, 1); - private async Task GetChannelItems(IChannel channel, User user, string folderId, int? startIndex, int? limit, CancellationToken cancellationToken) + private async Task GetChannelItems(IChannel channel, + User user, + string folderId, + int? startIndex, + int? limit, + ChannelItemSortField? sortField, + bool sortDescending, + CancellationToken cancellationToken) { - var cachePath = GetChannelDataCachePath(channel, user, folderId); + var cachePath = GetChannelDataCachePath(channel, user, folderId, sortField, sortDescending); try { @@ -376,7 +401,9 @@ namespace MediaBrowser.Server.Implementations.Channels { User = user, StartIndex = startIndex, - Limit = limit + Limit = limit, + SortBy = sortField, + SortDescending = sortDescending }; if (!string.IsNullOrWhiteSpace(folderId)) @@ -415,7 +442,11 @@ namespace MediaBrowser.Server.Implementations.Channels } } - private string GetChannelDataCachePath(IChannel channel, User user, string folderId) + private string GetChannelDataCachePath(IChannel channel, + User user, + string folderId, + ChannelItemSortField? sortField, + bool sortDescending) { var channelId = GetInternalChannelId(channel.Name).ToString("N"); @@ -423,7 +454,26 @@ namespace MediaBrowser.Server.Implementations.Channels var version = string.IsNullOrWhiteSpace(channel.DataVersion) ? "0" : channel.DataVersion; - return Path.Combine(_config.ApplicationPaths.CachePath, "channels", channelId, version, folderKey, user.Id.ToString("N") + ".json"); + var filename = user.Id.ToString("N"); + var hashfilename = false; + + if (sortField.HasValue) + { + filename += "-sortField-" + sortField.Value; + hashfilename = true; + } + if (sortDescending) + { + filename += "-sortDescending"; + hashfilename = true; + } + + if (hashfilename) + { + filename = filename.GetMD5().ToString("N"); + } + + return Path.Combine(_config.ApplicationPaths.CachePath, "channels", channelId, version, folderKey, filename + ".json"); } private async Task> GetReturnItems(IEnumerable items, int? totalCountFromProvider, User user, ChannelItemQuery query, CancellationToken cancellationToken) diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index caa058b96e..bc22c531c5 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -21,6 +21,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Model.Serialization; namespace MediaBrowser.Server.Implementations.LiveTv { @@ -37,6 +38,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv private readonly IUserDataManager _userDataManager; private readonly ILibraryManager _libraryManager; private readonly ITaskManager _taskManager; + private readonly IJsonSerializer _json; private readonly LiveTvDtoService _tvDtoService; @@ -51,7 +53,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv private readonly SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(1, 1); - public LiveTvManager(IServerConfigurationManager config, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, ITaskManager taskManager) + public LiveTvManager(IServerConfigurationManager config, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, ITaskManager taskManager, IJsonSerializer json) { _config = config; _fileSystem = fileSystem; @@ -60,6 +62,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv _userManager = userManager; _libraryManager = libraryManager; _taskManager = taskManager; + _json = json; _userDataManager = userDataManager; _tvDtoService = new LiveTvDtoService(dtoService, userDataManager, imageProcessor, logger, _itemRepo); @@ -294,6 +297,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv var result = await service.GetRecordingStream(recording.Id, cancellationToken).ConfigureAwait(false); + _logger.Debug("Live stream info: " + _json.SerializeToString(result)); + if (!string.IsNullOrEmpty(result.Id)) { _openStreams.AddOrUpdate(result.Id, result, (key, info) => result); @@ -327,6 +332,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv var result = await service.GetChannelStream(channel.ExternalId, cancellationToken).ConfigureAwait(false); + _logger.Debug("Live stream info: " + _json.SerializeToString(result)); + if (!string.IsNullOrEmpty(result.Id)) { _openStreams.AddOrUpdate(result.Id, result, (key, info) => result); @@ -1525,6 +1532,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv try { await service.CloseLiveStream(id, cancellationToken).ConfigureAwait(false); + + LiveStreamInfo removed; + _openStreams.TryRemove(id, out removed); } catch (Exception ex) { diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index d6c3a7e9f9..5797ecc977 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -531,7 +531,7 @@ namespace MediaBrowser.ServerApplication var collectionManager = new CollectionManager(LibraryManager, FileSystemManager, LibraryMonitor); RegisterSingleInstance(collectionManager); - LiveTvManager = new LiveTvManager(ServerConfigurationManager, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager); + LiveTvManager = new LiveTvManager(ServerConfigurationManager, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, JsonSerializer); RegisterSingleInstance(LiveTvManager); NotificationManager = new NotificationManager(LogManager, UserManager, ServerConfigurationManager); diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index e401d699d0..b4d2dbdc53 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.384 + 3.0.386 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 4ea543d85c..fa5c667514 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.384 + 3.0.386 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 60ed34067b..3c025207a2 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.384 + 3.0.386 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +