From 63f3cf97dada179fc6e9e3a177504d3e7b36321c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 26 Jan 2015 11:47:15 -0500 Subject: add option to merge metadata and IBN paths --- .../Configuration/ServerConfigurationManager.cs | 14 +- .../Devices/DeviceManager.cs | 25 +++- .../EntryPoints/Notifications/Notifications.cs | 22 +++- .../IO/LibraryMonitor.cs | 5 +- .../Library/LibraryManager.cs | 29 ++--- .../Library/MusicManager.cs | 35 +++++ .../Library/UserViewManager.cs | 141 ++++++++++++++++++++- .../Localization/Server/server.json | 6 +- .../Notifications/CoreNotificationTypes.cs | 14 +- .../Session/SessionManager.cs | 49 +++---- .../TV/TVSeriesManager.cs | 9 +- 11 files changed, 281 insertions(+), 68 deletions(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index 5f7ccec4b9..bb9e9057a3 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -88,9 +88,12 @@ namespace MediaBrowser.Server.Implementations.Configuration /// private void UpdateItemsByNamePath() { - ((ServerApplicationPaths)ApplicationPaths).ItemsByNamePath = string.IsNullOrEmpty(Configuration.ItemsByNamePath) ? - null : - Configuration.ItemsByNamePath; + if (!Configuration.MergeMetadataAndImagesByName) + { + ((ServerApplicationPaths)ApplicationPaths).ItemsByNamePath = string.IsNullOrEmpty(Configuration.ItemsByNamePath) ? + null : + Configuration.ItemsByNamePath; + } } /// @@ -101,6 +104,11 @@ namespace MediaBrowser.Server.Implementations.Configuration ((ServerApplicationPaths)ApplicationPaths).InternalMetadataPath = string.IsNullOrEmpty(Configuration.MetadataPath) ? GetInternalMetadataPath() : Configuration.MetadataPath; + + if (Configuration.MergeMetadataAndImagesByName) + { + ((ServerApplicationPaths)ApplicationPaths).ItemsByNamePath = ((ServerApplicationPaths)ApplicationPaths).InternalMetadataPath; + } } private string GetInternalMetadataPath() diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs index e057ec5cdd..3211f88d5f 100644 --- a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs +++ b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs @@ -27,6 +27,8 @@ namespace MediaBrowser.Server.Implementations.Devices private readonly IConfigurationManager _config; private readonly ILogger _logger; + public event EventHandler> CameraImageUploaded; + /// /// Occurs when [device options updated]. /// @@ -116,7 +118,7 @@ namespace MediaBrowser.Server.Implementations.Devices { devices = devices.Where(i => CanAccessDevice(query.UserId, i.Id)); } - + var array = devices.ToArray(); return new QueryResult { @@ -137,7 +139,8 @@ namespace MediaBrowser.Server.Implementations.Devices public async Task AcceptCameraUpload(string deviceId, Stream stream, LocalFileInfo file) { - var path = GetUploadPath(deviceId); + var device = GetDevice(deviceId); + var path = GetUploadPath(device); if (!string.IsNullOrWhiteSpace(file.Album)) { @@ -163,11 +166,27 @@ namespace MediaBrowser.Server.Implementations.Devices { _libraryMonitor.ReportFileSystemChangeComplete(path, true); } + + if (CameraImageUploaded != null) + { + EventHelper.FireEventIfNotNull(CameraImageUploaded, this, new GenericEventArgs + { + Argument = new CameraImageUploadInfo + { + Device = device, + FileInfo = file + } + }, _logger); + } } private string GetUploadPath(string deviceId) { - var device = GetDevice(deviceId); + return GetUploadPath(GetDevice(deviceId)); + } + + private string GetUploadPath(DeviceInfo device) + { if (!string.IsNullOrWhiteSpace(device.CameraUploadPath)) { return device.CameraUploadPath; diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs index 2d824f36ce..37bca4ddbc 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifications.cs @@ -3,6 +3,7 @@ using MediaBrowser.Common.Plugins; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Common.Updates; using MediaBrowser.Controller; +using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; @@ -44,8 +45,9 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications private readonly object _libraryChangedSyncLock = new object(); private readonly IConfigurationManager _config; + private readonly IDeviceManager _deviceManager; - public Notifications(IInstallationManager installationManager, IUserManager userManager, ILogger logger, ITaskManager taskManager, INotificationManager notificationManager, ILibraryManager libraryManager, ISessionManager sessionManager, IServerApplicationHost appHost, IConfigurationManager config) + public Notifications(IInstallationManager installationManager, IUserManager userManager, ILogger logger, ITaskManager taskManager, INotificationManager notificationManager, ILibraryManager libraryManager, ISessionManager sessionManager, IServerApplicationHost appHost, IConfigurationManager config, IDeviceManager deviceManager) { _installationManager = installationManager; _userManager = userManager; @@ -56,6 +58,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications _sessionManager = sessionManager; _appHost = appHost; _config = config; + _deviceManager = deviceManager; } public void Run() @@ -74,6 +77,21 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications _appHost.HasPendingRestartChanged += _appHost_HasPendingRestartChanged; _appHost.HasUpdateAvailableChanged += _appHost_HasUpdateAvailableChanged; _appHost.ApplicationUpdated += _appHost_ApplicationUpdated; + _deviceManager.CameraImageUploaded +=_deviceManager_CameraImageUploaded; + } + + async void _deviceManager_CameraImageUploaded(object sender, GenericEventArgs e) + { + var type = NotificationType.CameraImageUploaded.ToString(); + + var notification = new NotificationRequest + { + NotificationType = type + }; + + notification.Variables["DeviceName"] = e.Argument.Device.Name; + + await SendNotification(notification).ConfigureAwait(false); } async void _appHost_ApplicationUpdated(object sender, GenericEventArgs e) @@ -451,6 +469,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications _appHost.HasPendingRestartChanged -= _appHost_HasPendingRestartChanged; _appHost.HasUpdateAvailableChanged -= _appHost_HasUpdateAvailableChanged; _appHost.ApplicationUpdated -= _appHost_ApplicationUpdated; + + _deviceManager.CameraImageUploaded -= _deviceManager_CameraImageUploaded; } private void DisposeLibraryUpdateTimer() diff --git a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs index ce62242953..d501d1210b 100644 --- a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs +++ b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs @@ -566,7 +566,10 @@ namespace MediaBrowser.Server.Implementations.IO .Distinct() .ToList(); - foreach (var p in paths) Logger.Info(p + " reports change."); + foreach (var p in paths) + { + Logger.Info(p + " reports change."); + } // If the root folder changed, run the library task so the user can see it if (itemsToRefresh.Any(i => i is AggregateFolder)) diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 0ebd1aace6..124bb396ef 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -219,11 +219,7 @@ namespace MediaBrowser.Server.Implementations.Library /// /// The _root folder sync lock /// - private object _rootFolderSyncLock = new object(); - /// - /// The _root folder initialized - /// - private bool _rootFolderInitialized; + private readonly object _rootFolderSyncLock = new object(); /// /// Gets the root folder. /// @@ -232,17 +228,17 @@ namespace MediaBrowser.Server.Implementations.Library { get { - LazyInitializer.EnsureInitialized(ref _rootFolder, ref _rootFolderInitialized, ref _rootFolderSyncLock, CreateRootFolder); - return _rootFolder; - } - private set - { - _rootFolder = value; - - if (value == null) + if (_rootFolder == null) { - _rootFolderInitialized = false; + lock (_rootFolderSyncLock) + { + if (_rootFolder == null) + { + _rootFolder = CreateRootFolder(); + } + } } + return _rootFolder; } } @@ -849,11 +845,6 @@ namespace MediaBrowser.Server.Implementations.Library { get { - if (ConfigurationManager.Configuration.StoreArtistsInMetadata) - { - return Path.Combine(ConfigurationManager.ApplicationPaths.InternalMetadataPath, "artists"); - } - return Path.Combine(ConfigurationManager.ApplicationPaths.ItemsByNamePath, "artists"); } } diff --git a/MediaBrowser.Server.Implementations/Library/MusicManager.cs b/MediaBrowser.Server.Implementations/Library/MusicManager.cs index 5a7533ad21..7733e7d379 100644 --- a/MediaBrowser.Server.Implementations/Library/MusicManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MusicManager.cs @@ -83,5 +83,40 @@ namespace MediaBrowser.Server.Implementations.Library .Take(100) .OrderBy(i => Guid.NewGuid()); } + + public IEnumerable