From 0eaba37c1157df5e42a6025c404dce6b56b6562b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 13 May 2014 20:46:45 -0400 Subject: [PATCH] add library to front page --- .../ScheduledTasksWebSocketListener.cs | 8 +++ .../WebSocket/SessionInfoWebSocketListener.cs | 65 +++++++++++++++++++ .../BaseApplicationHost.cs | 2 +- .../ScheduledTasks/TaskManager.cs | 4 +- .../Updates/InstallationManager.cs | 14 ++-- MediaBrowser.Controller/Entities/BaseItem.cs | 26 ++++++-- .../Session/ISessionManager.cs | 7 ++ MediaBrowser.Model/Dlna/StreamBuilder.cs | 4 +- .../Manager/ItemImageProvider.cs | 47 +++++++++----- .../Library/UserManager.cs | 2 +- .../Session/SessionManager.cs | 19 +++++- 11 files changed, 159 insertions(+), 39 deletions(-) diff --git a/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs b/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs index 0d61c2ce1..f34c53b16 100644 --- a/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs +++ b/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs @@ -80,5 +80,13 @@ namespace MediaBrowser.Api.ScheduledTasks return false; } } + + protected override void Dispose(bool dispose) + { + TaskManager.TaskExecuting -= TaskManager_TaskExecuting; + TaskManager.TaskCompleted -= TaskManager_TaskCompleted; + + base.Dispose(dispose); + } } } diff --git a/MediaBrowser.Api/WebSocket/SessionInfoWebSocketListener.cs b/MediaBrowser.Api/WebSocket/SessionInfoWebSocketListener.cs index a16ea863f..600d9e405 100644 --- a/MediaBrowser.Api/WebSocket/SessionInfoWebSocketListener.cs +++ b/MediaBrowser.Api/WebSocket/SessionInfoWebSocketListener.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Session; @@ -36,6 +37,49 @@ namespace MediaBrowser.Api.WebSocket : base(logger) { _sessionManager = sessionManager; + + _sessionManager.SessionStarted += _sessionManager_SessionStarted; + _sessionManager.SessionEnded += _sessionManager_SessionEnded; + _sessionManager.PlaybackStart += _sessionManager_PlaybackStart; + _sessionManager.PlaybackStopped += _sessionManager_PlaybackStopped; + _sessionManager.PlaybackProgress += _sessionManager_PlaybackProgress; + _sessionManager.CapabilitiesChanged += _sessionManager_CapabilitiesChanged; + _sessionManager.SessionActivity += _sessionManager_SessionActivity; + } + + void _sessionManager_SessionActivity(object sender, SessionEventArgs e) + { + SendData(false); + } + + void _sessionManager_CapabilitiesChanged(object sender, SessionEventArgs e) + { + SendData(true); + } + + void _sessionManager_PlaybackProgress(object sender, PlaybackProgressEventArgs e) + { + SendData(false); + } + + void _sessionManager_PlaybackStopped(object sender, PlaybackStopEventArgs e) + { + SendData(true); + } + + void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e) + { + SendData(true); + } + + void _sessionManager_SessionEnded(object sender, SessionEventArgs e) + { + SendData(true); + } + + void _sessionManager_SessionStarted(object sender, SessionEventArgs e) + { + SendData(true); } /// @@ -47,5 +91,26 @@ namespace MediaBrowser.Api.WebSocket { return Task.FromResult(_sessionManager.Sessions.Where(i => i.IsActive).Select(_sessionManager.GetSessionInfoDto)); } + + protected override bool SendOnTimer + { + get + { + return false; + } + } + + protected override void Dispose(bool dispose) + { + _sessionManager.SessionStarted -= _sessionManager_SessionStarted; + _sessionManager.SessionEnded -= _sessionManager_SessionEnded; + _sessionManager.PlaybackStart -= _sessionManager_PlaybackStart; + _sessionManager.PlaybackStopped -= _sessionManager_PlaybackStopped; + _sessionManager.PlaybackProgress -= _sessionManager_PlaybackProgress; + _sessionManager.CapabilitiesChanged -= _sessionManager_CapabilitiesChanged; + _sessionManager.SessionActivity -= _sessionManager_SessionActivity; + + base.Dispose(dispose); + } } } diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index e488fd9bf..49bb49a76 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -765,7 +765,7 @@ namespace MediaBrowser.Common.Implementations { Logger.Info("Application has been updated to version {0}", package.versionStr); - EventHelper.QueueEventIfNotNull(ApplicationUpdated, this, new GenericEventArgs + EventHelper.FireEventIfNotNull(ApplicationUpdated, this, new GenericEventArgs { Argument = package diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs index 5aec39b89..5a3ac53dc 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs @@ -192,7 +192,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// The task. internal void OnTaskExecuting(IScheduledTaskWorker task) { - EventHelper.QueueEventIfNotNull(TaskExecuting, this, new GenericEventArgs + EventHelper.FireEventIfNotNull(TaskExecuting, this, new GenericEventArgs { Argument = task @@ -206,7 +206,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks /// The result. internal void OnTaskCompleted(IScheduledTaskWorker task, TaskResult result) { - EventHelper.QueueEventIfNotNull(TaskCompleted, task, new TaskCompletionEventArgs + EventHelper.FireEventIfNotNull(TaskCompleted, task, new TaskCompletionEventArgs { Result = result, Task = task diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs index fe484840a..ff32fc68e 100644 --- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs @@ -52,7 +52,7 @@ namespace MediaBrowser.Common.Implementations.Updates /// The plugin. private void OnPluginUninstalled(IPlugin plugin) { - EventHelper.QueueEventIfNotNull(PluginUninstalled, this, new GenericEventArgs { Argument = plugin }, _logger); + EventHelper.FireEventIfNotNull(PluginUninstalled, this, new GenericEventArgs { Argument = plugin }, _logger); } #endregion @@ -70,7 +70,7 @@ namespace MediaBrowser.Common.Implementations.Updates { _logger.Info("Plugin updated: {0} {1} {2}", newVersion.name, newVersion.version, newVersion.classification); - EventHelper.QueueEventIfNotNull(PluginUpdated, this, new GenericEventArgs> { Argument = new Tuple(plugin, newVersion) }, _logger); + EventHelper.FireEventIfNotNull(PluginUpdated, this, new GenericEventArgs> { Argument = new Tuple(plugin, newVersion) }, _logger); _applicationHost.NotifyPendingRestart(); } @@ -89,7 +89,7 @@ namespace MediaBrowser.Common.Implementations.Updates { _logger.Info("New plugin installed: {0} {1} {2}", package.name, package.version, package.classification); - EventHelper.QueueEventIfNotNull(PluginInstalled, this, new GenericEventArgs { Argument = package }, _logger); + EventHelper.FireEventIfNotNull(PluginInstalled, this, new GenericEventArgs { Argument = package }, _logger); _applicationHost.NotifyPendingRestart(); } @@ -403,7 +403,7 @@ namespace MediaBrowser.Common.Implementations.Updates PackageVersionInfo = package }; - EventHelper.QueueEventIfNotNull(PackageInstalling, this, installationEventArgs, _logger); + EventHelper.FireEventIfNotNull(PackageInstalling, this, installationEventArgs, _logger); try { @@ -418,7 +418,7 @@ namespace MediaBrowser.Common.Implementations.Updates CompletedInstallations.Add(installationInfo); - EventHelper.QueueEventIfNotNull(PackageInstallationCompleted, this, installationEventArgs, _logger); + EventHelper.FireEventIfNotNull(PackageInstallationCompleted, this, installationEventArgs, _logger); } catch (OperationCanceledException) { @@ -429,7 +429,7 @@ namespace MediaBrowser.Common.Implementations.Updates _logger.Info("Package installation cancelled: {0} {1}", package.name, package.versionStr); - EventHelper.QueueEventIfNotNull(PackageInstallationCancelled, this, installationEventArgs, _logger); + EventHelper.FireEventIfNotNull(PackageInstallationCancelled, this, installationEventArgs, _logger); throw; } @@ -442,7 +442,7 @@ namespace MediaBrowser.Common.Implementations.Updates CurrentInstallations.Remove(tuple); } - EventHelper.QueueEventIfNotNull(PackageInstallationFailed, this, new InstallationFailedEventArgs + EventHelper.FireEventIfNotNull(PackageInstallationFailed, this, new InstallationFailedEventArgs { InstallationInfo = installationInfo, Exception = ex diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index b8ea1bec4..3a0b251ee 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1422,22 +1422,34 @@ namespace MediaBrowser.Controller.Entities throw new ArgumentException("Cannot call AddImages with chapter images"); } - var existingImagePaths = GetImages(imageType) - .Select(i => i.Path) + var existingImages = GetImages(imageType) .ToList(); - var newImages = images - .Where(i => !existingImagePaths.Contains(i.FullName, StringComparer.OrdinalIgnoreCase)) - .ToList(); + var newImageList = new List(); - ImageInfos.AddRange(newImages.Select(i => new ItemImageInfo + foreach (var newImage in images) + { + var existing = existingImages + .FirstOrDefault(i => string.Equals(i.Path, newImage.FullName, StringComparison.OrdinalIgnoreCase)); + + if (existing == null) + { + newImageList.Add(newImage); + } + else + { + existing.DateModified = FileSystem.GetLastWriteTimeUtc(newImage); + } + } + + ImageInfos.AddRange(newImageList.Select(i => new ItemImageInfo { Path = i.FullName, Type = imageType, DateModified = FileSystem.GetLastWriteTimeUtc(i) })); - return newImages.Count > 0; + return newImageList.Count > 0; } /// diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index 33f3fbe82..f7d1ecd4a 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -38,6 +38,13 @@ namespace MediaBrowser.Controller.Session /// Occurs when [session ended]. /// event EventHandler SessionEnded; + + event EventHandler SessionActivity; + + /// + /// Occurs when [capabilities changed]. + /// + event EventHandler CapabilitiesChanged; /// /// Gets the sessions. diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 48356ef92..2e7ead823 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -269,8 +269,8 @@ namespace MediaBrowser.Model.Dlna playlistItem.AudioCodec = transcodingProfile.AudioCodec.Split(',')[0]; playlistItem.VideoCodec = transcodingProfile.VideoCodec; playlistItem.Protocol = transcodingProfile.Protocol; - playlistItem.AudioStreamIndex = options.AudioStreamIndex; - playlistItem.SubtitleStreamIndex = options.SubtitleStreamIndex; + playlistItem.AudioStreamIndex = options.AudioStreamIndex ?? item.DefaultAudioStreamIndex; + playlistItem.SubtitleStreamIndex = options.SubtitleStreamIndex ?? item.DefaultSubtitleStreamIndex; List videoTranscodingConditions = new List(); foreach (CodecProfile i in options.Profile.CodecProfiles) diff --git a/MediaBrowser.Providers/Manager/ItemImageProvider.cs b/MediaBrowser.Providers/Manager/ItemImageProvider.cs index a0ab069d3..ca02953ad 100644 --- a/MediaBrowser.Providers/Manager/ItemImageProvider.cs +++ b/MediaBrowser.Providers/Manager/ItemImageProvider.cs @@ -267,40 +267,55 @@ namespace MediaBrowser.Providers.Manager { var currentImage = item.GetImageInfo(type, 0); - if (currentImage == null || !string.Equals(currentImage.Path, image.FileInfo.FullName, StringComparison.OrdinalIgnoreCase)) + if (currentImage == null) { item.SetImagePath(type, image.FileInfo); changed = true; } + else if (!string.Equals(currentImage.Path, image.FileInfo.FullName, + StringComparison.OrdinalIgnoreCase)) + { + item.SetImagePath(type, image.FileInfo); + changed = true; + } + else + { + currentImage.DateModified = _fileSystem.GetLastWriteTimeUtc(image.FileInfo); + } } } - var backdrops = images.Where(i => i.Type == ImageType.Backdrop).ToList(); - if (backdrops.Count > 0) + if (UpdateMultiImages(item, images, ImageType.Backdrop)) { - var foundImages = images.Where(i => i.Type == ImageType.Backdrop) - .Select(i => i.FileInfo) - .ToList(); - - if (foundImages.Count > 0) - { - if (item.AddImages(ImageType.Backdrop, foundImages)) - { - changed = true; - } - } + changed = true; } var hasScreenshots = item as IHasScreenshots; if (hasScreenshots != null) { - var foundImages = images.Where(i => i.Type == ImageType.Screenshot) + if (UpdateMultiImages(item, images, ImageType.Screenshot)) + { + changed = true; + } + } + + return changed; + } + + private bool UpdateMultiImages(IHasImages item, List images, ImageType type) + { + var changed = false; + + var backdrops = images.Where(i => i.Type == type).ToList(); + if (backdrops.Count > 0) + { + var foundImages = images.Where(i => i.Type == type) .Select(i => i.FileInfo) .ToList(); if (foundImages.Count > 0) { - if (item.AddImages(ImageType.Screenshot, foundImages)) + if (item.AddImages(type, foundImages)) { changed = true; } diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 23303c41f..d81cd09a9 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -72,7 +72,7 @@ namespace MediaBrowser.Server.Implementations.Library /// The user. private void OnUserUpdated(User user) { - EventHelper.QueueEventIfNotNull(UserUpdated, this, new GenericEventArgs { Argument = user }, _logger); + EventHelper.FireEventIfNotNull(UserUpdated, this, new GenericEventArgs { Argument = user }, _logger); } #endregion diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index cf27df70d..26e451a81 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -77,8 +77,9 @@ namespace MediaBrowser.Server.Implementations.Session public event EventHandler PlaybackStopped; public event EventHandler SessionStarted; - + public event EventHandler CapabilitiesChanged; public event EventHandler SessionEnded; + public event EventHandler SessionActivity; private IEnumerable _sessionFactories = new List(); @@ -224,10 +225,16 @@ namespace MediaBrowser.Server.Implementations.Session { return session; } - + // Save this directly. No need to fire off all the events for this. await _userRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false); + EventHelper.FireEventIfNotNull(SessionActivity, this, new SessionEventArgs + { + SessionInfo = session + + }, _logger); + return session; } @@ -517,7 +524,7 @@ namespace MediaBrowser.Server.Implementations.Session } } - EventHelper.QueueEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs + EventHelper.FireEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs { Item = libraryItem, Users = users, @@ -1127,6 +1134,12 @@ namespace MediaBrowser.Server.Implementations.Session session.PlayableMediaTypes = capabilities.PlayableMediaTypes; session.SupportedCommands = capabilities.SupportedCommands; + + EventHelper.FireEventIfNotNull(CapabilitiesChanged, this, new SessionEventArgs + { + SessionInfo = session + + }, _logger); } public SessionInfoDto GetSessionInfoDto(SessionInfo session)