diff options
46 files changed, 216 insertions, 581 deletions
diff --git a/Emby.Dlna/ContentDirectory/ContentDirectory.cs b/Emby.Dlna/ContentDirectory/ContentDirectory.cs index cd21599d0..b0fec90e6 100644 --- a/Emby.Dlna/ContentDirectory/ContentDirectory.cs +++ b/Emby.Dlna/ContentDirectory/ContentDirectory.cs @@ -76,7 +76,6 @@ namespace Emby.Dlna.ContentDirectory _dlna.GetDefaultProfile(); var serverAddress = request.RequestedUrl.Substring(0, request.RequestedUrl.IndexOf("/dlna", StringComparison.OrdinalIgnoreCase)); - string accessToken = null; var user = GetUser(profile); @@ -85,7 +84,7 @@ namespace Emby.Dlna.ContentDirectory _libraryManager, profile, serverAddress, - accessToken, + null, _imageProcessor, _userDataManager, user, diff --git a/Emby.Dlna/Didl/DidlBuilder.cs b/Emby.Dlna/Didl/DidlBuilder.cs index 81c4d3d16..440f96b3f 100644 --- a/Emby.Dlna/Didl/DidlBuilder.cs +++ b/Emby.Dlna/Didl/DidlBuilder.cs @@ -1088,8 +1088,8 @@ namespace Emby.Dlna.Didl //{ // var size = _imageProcessor.GetImageSize(imageInfo); - // width = Convert.ToInt32(size.Width); - // height = Convert.ToInt32(size.Height); + // width = size.Width; + // height = size.Height; //} //catch //{ @@ -1162,8 +1162,7 @@ namespace Emby.Dlna.Didl info.ImageTag, format, maxWidth.ToString(CultureInfo.InvariantCulture), - maxHeight.ToString(CultureInfo.InvariantCulture) - ); + maxHeight.ToString(CultureInfo.InvariantCulture)); var width = info.Width; var height = info.Height; @@ -1172,15 +1171,11 @@ namespace Emby.Dlna.Didl if (width.HasValue && height.HasValue) { - var newSize = DrawingUtils.Resize(new ImageSize - { - Height = height.Value, - Width = width.Value - - }, 0, 0, maxWidth, maxHeight); + var newSize = DrawingUtils.Resize( + new ImageDimensions(width.Value, height.Value), 0, 0, maxWidth, maxHeight); - width = Convert.ToInt32(newSize.Width); - height = Convert.ToInt32(newSize.Height); + width = newSize.Width; + height = newSize.Height; var normalizedFormat = format .Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase); diff --git a/Emby.Dlna/PlayTo/PlayToManager.cs b/Emby.Dlna/PlayTo/PlayToManager.cs index 8e82e6f69..790625705 100644 --- a/Emby.Dlna/PlayTo/PlayToManager.cs +++ b/Emby.Dlna/PlayTo/PlayToManager.cs @@ -162,9 +162,7 @@ namespace Emby.Dlna.PlayTo uuid = location.GetMD5().ToString("N"); } - string deviceName = null; - - var sessionInfo = _sessionManager.LogSessionActivity("DLNA", _appHost.ApplicationVersion, uuid, deviceName, uri.OriginalString, null); + var sessionInfo = _sessionManager.LogSessionActivity("DLNA", _appHost.ApplicationVersion, uuid, null, uri.OriginalString, null); var controller = sessionInfo.SessionControllers.OfType<PlayToController>().FirstOrDefault(); @@ -172,7 +170,7 @@ namespace Emby.Dlna.PlayTo { var device = await Device.CreateuPnpDeviceAsync(uri, _httpClient, _config, _logger, _timerFactory, cancellationToken).ConfigureAwait(false); - deviceName = device.Properties.Name; + string deviceName = device.Properties.Name; _sessionManager.UpdateDeviceName(sessionInfo.Id, deviceName); @@ -186,8 +184,6 @@ namespace Emby.Dlna.PlayTo serverAddress = _appHost.GetLocalApiUrl(info.LocalIpAddress); } - string accessToken = null; - controller = new PlayToController(sessionInfo, _sessionManager, _libraryManager, @@ -196,7 +192,7 @@ namespace Emby.Dlna.PlayTo _userManager, _imageProcessor, serverAddress, - accessToken, + null, _deviceDiscovery, _userDataManager, _localization, diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index c750b60e2..8ac2b9b27 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -18,7 +18,6 @@ using MediaBrowser.Model.Extensions; using MediaBrowser.Model.IO; using MediaBrowser.Model.Net; using Microsoft.Extensions.Logging; -using SkiaSharp; namespace Emby.Drawing { @@ -66,7 +65,7 @@ namespace Emby.Drawing _appPaths = appPaths; ImageEnhancers = Array.Empty<IImageEnhancer>(); - + ImageHelper.ImageProcessor = this; } @@ -168,10 +167,10 @@ namespace Emby.Drawing string originalImagePath = originalImage.Path; DateTime dateModified = originalImage.DateModified; - ImageSize? originalImageSize = null; + ImageDimensions? originalImageSize = null; if (originalImage.Width > 0 && originalImage.Height > 0) { - originalImageSize = new ImageSize(originalImage.Width, originalImage.Height); + originalImageSize = new ImageDimensions(originalImage.Width, originalImage.Height); } if (!_imageEncoder.SupportsImageEncoding) @@ -231,7 +230,7 @@ namespace Emby.Drawing return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); } - ImageSize newSize = ImageHelper.GetNewImageSize(options, null); + ImageDimensions newSize = ImageHelper.GetNewImageSize(options, null); int quality = options.Quality; ImageFormat outputFormat = GetOutputFormat(options.SupportedOutputFormats, requiresTransparency); @@ -334,7 +333,7 @@ namespace Emby.Drawing /// <summary> /// Gets the cache file path based on a set of parameters /// </summary> - private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageFormat format, bool addPlayedIndicator, double percentPlayed, int? unwatchedCount, int? blur, string backgroundColor, string foregroundLayer) + private string GetCacheFilePath(string originalPath, ImageDimensions outputSize, int quality, DateTime dateModified, ImageFormat format, bool addPlayedIndicator, double percentPlayed, int? unwatchedCount, int? blur, string backgroundColor, string foregroundLayer) { var filename = originalPath + "width=" + outputSize.Width @@ -378,26 +377,25 @@ namespace Emby.Drawing return GetCachePath(ResizedImageCachePath, filename, "." + format.ToString().ToLower()); } - public ImageSize GetImageSize(BaseItem item, ItemImageInfo info) + public ImageDimensions GetImageSize(BaseItem item, ItemImageInfo info) => GetImageSize(item, info, true); - public ImageSize GetImageSize(BaseItem item, ItemImageInfo info, bool updateItem) + public ImageDimensions GetImageSize(BaseItem item, ItemImageInfo info, bool updateItem) { int width = info.Width; int height = info.Height; if (height > 0 && width > 0) { - return new ImageSize(width, height); + return new ImageDimensions(width, height); } string path = info.Path; _logger.LogInformation("Getting image size for item {ItemType} {Path}", item.GetType().Name, path); - var size = GetImageSize(path); - - info.Height = Convert.ToInt32(size.Height); - info.Width = Convert.ToInt32(size.Width); + ImageDimensions size = GetImageSize(path); + info.Width = size.Width; + info.Height = size.Height; if (updateItem) { @@ -410,20 +408,8 @@ namespace Emby.Drawing /// <summary> /// Gets the size of the image. /// </summary> - public ImageSize GetImageSize(string path) - { - if (string.IsNullOrEmpty(path)) - { - throw new ArgumentNullException(nameof(path)); - } - - using (var s = new SKFileStream(path)) - using (var codec = SKCodec.Create(s)) - { - var info = codec.Info; - return new ImageSize(info.Width, info.Height); - } - } + public ImageDimensions GetImageSize(string path) + => _imageEncoder.GetImageSize(path); /// <summary> /// Gets the image cache tag. diff --git a/Emby.Drawing/NullImageEncoder.cs b/Emby.Drawing/NullImageEncoder.cs index e6f205a1f..14f0424ac 100644 --- a/Emby.Drawing/NullImageEncoder.cs +++ b/Emby.Drawing/NullImageEncoder.cs @@ -37,7 +37,7 @@ namespace Emby.Drawing public bool SupportsImageEncoding => false; - public ImageSize GetImageSize(string path) + public ImageDimensions GetImageSize(string path) { throw new NotImplementedException(); } diff --git a/Emby.Drawing/PercentPlayedDrawer.cs b/Emby.Drawing/PercentPlayedDrawer.cs index 52b4329e1..3ce46bc12 100644 --- a/Emby.Drawing/PercentPlayedDrawer.cs +++ b/Emby.Drawing/PercentPlayedDrawer.cs @@ -8,7 +8,7 @@ namespace Emby.Drawing { private const int IndicatorHeight = 8; - public static void Process(SKCanvas canvas, ImageSize imageSize, double percent) + public static void Process(SKCanvas canvas, ImageDimensions imageSize, double percent) { using (var paint = new SKPaint()) { @@ -24,7 +24,7 @@ namespace Emby.Drawing foregroundWidth /= 100; paint.Color = SKColor.Parse("#FF52B54B"); - canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, Convert.ToInt32(Math.Round(foregroundWidth)), (float)endY), paint); + canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, Convert.ToInt32(foregroundWidth), (float)endY), paint); } } } diff --git a/Emby.Drawing/PlayedIndicatorDrawer.cs b/Emby.Drawing/PlayedIndicatorDrawer.cs index a82398fa5..38b5edc92 100644 --- a/Emby.Drawing/PlayedIndicatorDrawer.cs +++ b/Emby.Drawing/PlayedIndicatorDrawer.cs @@ -7,7 +7,7 @@ namespace Emby.Drawing { private const int OffsetFromTopRightCorner = 38; - public static void DrawPlayedIndicator(SKCanvas canvas, ImageSize imageSize) + public static void DrawPlayedIndicator(SKCanvas canvas, ImageDimensions imageSize) { var x = imageSize.Width - OffsetFromTopRightCorner; diff --git a/Emby.Drawing/SkiaEncoder.cs b/Emby.Drawing/SkiaEncoder.cs index 9883b3cca..aae10f6cc 100644 --- a/Emby.Drawing/SkiaEncoder.cs +++ b/Emby.Drawing/SkiaEncoder.cs @@ -168,18 +168,14 @@ namespace Emby.Drawing } } - public ImageSize GetImageSize(string path) + public ImageDimensions GetImageSize(string path) { using (var s = new SKFileStream(path)) using (var codec = SKCodec.Create(s)) { var info = codec.Info; - return new ImageSize - { - Width = info.Width, - Height = info.Height - }; + return new ImageDimensions(info.Width, info.Height); } } @@ -513,7 +509,7 @@ namespace Emby.Drawing //_logger.LogInformation("Color type {0}", bitmap.Info.ColorType); - var originalImageSize = new ImageSize(bitmap.Width, bitmap.Height); + var originalImageSize = new ImageDimensions(bitmap.Width, bitmap.Height); if (!options.CropWhiteSpace && options.HasDefaultOptions(inputPath, originalImageSize) && !autoOrient) { @@ -523,8 +519,8 @@ namespace Emby.Drawing var newImageSize = ImageHelper.GetNewImageSize(options, originalImageSize); - var width = Convert.ToInt32(Math.Round(newImageSize.Width)); - var height = Convert.ToInt32(Math.Round(newImageSize.Height)); + var width = newImageSize.Width; + var height = newImageSize.Height; using (var resizedBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType)) { @@ -626,7 +622,7 @@ namespace Emby.Drawing { try { - var currentImageSize = new ImageSize(imageWidth, imageHeight); + var currentImageSize = new ImageDimensions(imageWidth, imageHeight); if (options.AddPlayedIndicator) { diff --git a/Emby.Drawing/UnplayedCountIndicator.cs b/Emby.Drawing/UnplayedCountIndicator.cs index 16c084a21..4d0cc9d40 100644 --- a/Emby.Drawing/UnplayedCountIndicator.cs +++ b/Emby.Drawing/UnplayedCountIndicator.cs @@ -8,7 +8,7 @@ namespace Emby.Drawing { private const int OffsetFromTopRightCorner = 38; - public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageSize imageSize, int count) + public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageDimensions imageSize, int count) { var x = imageSize.Width - OffsetFromTopRightCorner; var text = count.ToString(CultureInfo.InvariantCulture); diff --git a/Emby.Naming/AudioBook/AudioBookResolver.cs b/Emby.Naming/AudioBook/AudioBookResolver.cs index 67451a639..67ab62e80 100644 --- a/Emby.Naming/AudioBook/AudioBookResolver.cs +++ b/Emby.Naming/AudioBook/AudioBookResolver.cs @@ -36,7 +36,7 @@ namespace Emby.Naming.AudioBook return null; } - var extension = Path.GetExtension(path) ?? string.Empty; + var extension = Path.GetExtension(path); // Check supported extensions if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)) { diff --git a/Emby.Photos/PhotoProvider.cs b/Emby.Photos/PhotoProvider.cs index 4e483ad5b..aaebe1a21 100644 --- a/Emby.Photos/PhotoProvider.cs +++ b/Emby.Photos/PhotoProvider.cs @@ -185,8 +185,8 @@ namespace Emby.Photos if (size.Width > 0 && size.Height > 0) { - item.Width = Convert.ToInt32(size.Width); - item.Height = Convert.ToInt32(size.Height); + item.Width = size.Width; + item.Height = size.Height; } } catch (ArgumentException) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 72e0b7a13..f0a914922 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -244,8 +244,6 @@ namespace Emby.Server.Implementations /// </summary> protected readonly SimpleInjector.Container Container = new SimpleInjector.Container(); - protected ISystemEvents SystemEvents { get; set; } - /// <summary> /// Gets the server configuration manager. /// </summary> @@ -371,7 +369,6 @@ namespace Emby.Server.Implementations IFileSystem fileSystem, IEnvironmentInfo environmentInfo, IImageEncoder imageEncoder, - ISystemEvents systemEvents, INetworkManager networkManager) { @@ -383,7 +380,6 @@ namespace Emby.Server.Implementations NetworkManager = networkManager; networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets; EnvironmentInfo = environmentInfo; - SystemEvents = systemEvents; ApplicationPaths = applicationPaths; LoggerFactory = loggerFactory; @@ -466,9 +462,8 @@ namespace Emby.Server.Implementations private static Tuple<Assembly, string> GetAssembly(Type type) { var assembly = type.GetTypeInfo().Assembly; - string path = null; - return new Tuple<Assembly, string>(assembly, path); + return new Tuple<Assembly, string>(assembly, null); } public virtual IStreamHelper CreateStreamHelper() @@ -762,7 +757,6 @@ namespace Emby.Server.Implementations RegisterSingleInstance<IApplicationPaths>(ApplicationPaths); RegisterSingleInstance(JsonSerializer); - RegisterSingleInstance(SystemEvents); RegisterSingleInstance(LoggerFactory, false); RegisterSingleInstance(Logger); @@ -779,7 +773,7 @@ namespace Emby.Server.Implementations IsoManager = new IsoManager(); RegisterSingleInstance(IsoManager); - TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LoggerFactory, FileSystemManager, SystemEvents); + TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LoggerFactory, FileSystemManager); RegisterSingleInstance(TaskManager); RegisterSingleInstance(XmlSerializer); @@ -852,7 +846,7 @@ namespace Emby.Server.Implementations var musicManager = new MusicManager(LibraryManager); RegisterSingleInstance<IMusicManager>(new MusicManager(LibraryManager)); - LibraryMonitor = new LibraryMonitor(LoggerFactory, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, TimerFactory, SystemEvents, EnvironmentInfo); + LibraryMonitor = new LibraryMonitor(LoggerFactory, TaskManager, LibraryManager, ServerConfigurationManager, FileSystemManager, TimerFactory, EnvironmentInfo); RegisterSingleInstance(LibraryMonitor); RegisterSingleInstance<ISearchEngine>(() => new SearchEngine(LoggerFactory, LibraryManager, UserManager)); diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index 13febc214..d0a7de11d 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -1428,7 +1428,7 @@ namespace Emby.Server.Implementations.Dto var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary); - ImageSize size; + ImageDimensions size; var defaultAspectRatio = item.GetDefaultPrimaryImageAspectRatio(); @@ -1439,9 +1439,9 @@ namespace Emby.Server.Implementations.Dto return defaultAspectRatio; } - double dummyWidth = 200; - double dummyHeight = dummyWidth / defaultAspectRatio; - size = new ImageSize(dummyWidth, dummyHeight); + int dummyWidth = 200; + int dummyHeight = Convert.ToInt32(dummyWidth / defaultAspectRatio); + size = new ImageDimensions(dummyWidth, dummyHeight); } else { @@ -1481,7 +1481,7 @@ namespace Emby.Server.Implementations.Dto var width = size.Width; var height = size.Height; - if (width.Equals(0) || height.Equals(0)) + if (width <= 0 || height <= 0) { return null; } diff --git a/Emby.Server.Implementations/EntryPoints/SystemEvents.cs b/Emby.Server.Implementations/EntryPoints/SystemEvents.cs deleted file mode 100644 index 72c8acd9f..000000000 --- a/Emby.Server.Implementations/EntryPoints/SystemEvents.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using MediaBrowser.Controller; -using MediaBrowser.Controller.Plugins; -using MediaBrowser.Model.System; - -namespace Emby.Server.Implementations.EntryPoints -{ - public class SystemEvents : IServerEntryPoint - { - private readonly ISystemEvents _systemEvents; - private readonly IServerApplicationHost _appHost; - - public SystemEvents(ISystemEvents systemEvents, IServerApplicationHost appHost) - { - _systemEvents = systemEvents; - _appHost = appHost; - } - - public void Run() - { - _systemEvents.SystemShutdown += _systemEvents_SystemShutdown; - } - - private void _systemEvents_SystemShutdown(object sender, EventArgs e) - { - _appHost.Shutdown(); - } - - public void Dispose() - { - _systemEvents.SystemShutdown -= _systemEvents_SystemShutdown; - } - } -} diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index 6a3204011..204f9d949 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -140,7 +140,14 @@ namespace Emby.Server.Implementations.IO /// <summary> /// Initializes a new instance of the <see cref="LibraryMonitor" /> class. /// </summary> - public LibraryMonitor(ILoggerFactory loggerFactory, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ITimerFactory timerFactory, ISystemEvents systemEvents, IEnvironmentInfo environmentInfo) + public LibraryMonitor( + ILoggerFactory loggerFactory, + ITaskManager taskManager, + ILibraryManager libraryManager, + IServerConfigurationManager configurationManager, + IFileSystem fileSystem, + ITimerFactory timerFactory, + IEnvironmentInfo environmentInfo) { if (taskManager == null) { @@ -154,26 +161,9 @@ namespace Emby.Server.Implementations.IO _fileSystem = fileSystem; _timerFactory = timerFactory; _environmentInfo = environmentInfo; - - systemEvents.Resume += _systemEvents_Resume; - } - - private void _systemEvents_Resume(object sender, EventArgs e) - { - Restart(); - } - - private void Restart() - { - Stop(); - - if (!_disposed) - { - Start(); - } } - private bool IsLibraryMonitorEnabaled(BaseItem item) + private bool IsLibraryMonitorEnabled(BaseItem item) { if (item is BasePluginFolder) { @@ -200,7 +190,7 @@ namespace Emby.Server.Implementations.IO var paths = LibraryManager .RootFolder .Children - .Where(IsLibraryMonitorEnabaled) + .Where(IsLibraryMonitorEnabled) .OfType<Folder>() .SelectMany(f => f.PhysicalLocations) .Distinct(StringComparer.OrdinalIgnoreCase) @@ -223,7 +213,7 @@ namespace Emby.Server.Implementations.IO private void StartWatching(BaseItem item) { - if (IsLibraryMonitorEnabaled(item)) + if (IsLibraryMonitorEnabled(item)) { StartWatchingPath(item.Path); } diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 9e11494c9..4805e54dd 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -60,7 +60,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV private readonly IProviderManager _providerManager; private readonly IMediaEncoder _mediaEncoder; private readonly IProcessFactory _processFactory; - private readonly ISystemEvents _systemEvents; private readonly IAssemblyInfo _assemblyInfo; private IMediaSourceManager _mediaSourceManager; @@ -90,8 +89,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV IProviderManager providerManager, IMediaEncoder mediaEncoder, ITimerFactory timerFactory, - IProcessFactory processFactory, - ISystemEvents systemEvents) + IProcessFactory processFactory) { Current = this; @@ -105,7 +103,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV _providerManager = providerManager; _mediaEncoder = mediaEncoder; _processFactory = processFactory; - _systemEvents = systemEvents; _liveTvManager = (LiveTvManager)liveTvManager; _jsonSerializer = jsonSerializer; _assemblyInfo = assemblyInfo; @@ -131,15 +128,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV { _timerProvider.RestartTimers(); - _systemEvents.Resume += _systemEvents_Resume; await CreateRecordingFolders().ConfigureAwait(false); } - private void _systemEvents_Resume(object sender, EventArgs e) - { - _timerProvider.RestartTimers(); - } - private async void OnRecordingFoldersChanged() { await CreateRecordingFolders().ConfigureAwait(false); diff --git a/Emby.Server.Implementations/Localization/LocalizationManager.cs b/Emby.Server.Implementations/Localization/LocalizationManager.cs index af05cd7d7..c408a47f6 100644 --- a/Emby.Server.Implementations/Localization/LocalizationManager.cs +++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs @@ -502,58 +502,55 @@ namespace Emby.Server.Implementations.Localization return culture + ".json"; } - public LocalizatonOption[] GetLocalizationOptions() - { - return new LocalizatonOption[] + public LocalizationOption[] GetLocalizationOptions() + => new LocalizationOption[] { - new LocalizatonOption{ Name="Arabic", Value="ar"}, - new LocalizatonOption{ Name="Belarusian (Belarus)", Value="be-BY"}, - new LocalizatonOption{ Name="Bulgarian (Bulgaria)", Value="bg-BG"}, - new LocalizatonOption{ Name="Catalan", Value="ca"}, - new LocalizatonOption{ Name="Chinese Simplified", Value="zh-CN"}, - new LocalizatonOption{ Name="Chinese Traditional", Value="zh-TW"}, - new LocalizatonOption{ Name="Chinese Traditional (Hong Kong)", Value="zh-HK"}, - new LocalizatonOption{ Name="Croatian", Value="hr"}, - new LocalizatonOption{ Name="Czech", Value="cs"}, - new LocalizatonOption{ Name="Danish", Value="da"}, - new LocalizatonOption{ Name="Dutch", Value="nl"}, - new LocalizatonOption{ Name="English (United Kingdom)", Value="en-GB"}, - new LocalizatonOption{ Name="English (United States)", Value="en-US"}, - new LocalizatonOption{ Name="Finnish", Value="fi"}, - new LocalizatonOption{ Name="French", Value="fr"}, - new LocalizatonOption{ Name="French (Canada)", Value="fr-CA"}, - new LocalizatonOption{ Name="German", Value="de"}, - new LocalizatonOption{ Name="Greek", Value="el"}, - new LocalizatonOption{ Name="Hebrew", Value="he"}, - new LocalizatonOption{ Name="Hindi (India)", Value="hi-IN"}, - new LocalizatonOption{ Name="Hungarian", Value="hu"}, - new LocalizatonOption{ Name="Indonesian", Value="id"}, - new LocalizatonOption{ Name="Italian", Value="it"}, - new LocalizatonOption{ Name="Japanese", Value="ja"}, - new LocalizatonOption{ Name="Kazakh", Value="kk"}, - new LocalizatonOption{ Name="Korean", Value="ko"}, - new LocalizatonOption{ Name="Lithuanian", Value="lt-LT"}, - new LocalizatonOption{ Name="Malay", Value="ms"}, - new LocalizatonOption{ Name="Norwegian Bokmål", Value="nb"}, - new LocalizatonOption{ Name="Persian", Value="fa"}, - new LocalizatonOption{ Name="Polish", Value="pl"}, - new LocalizatonOption{ Name="Portuguese (Brazil)", Value="pt-BR"}, - new LocalizatonOption{ Name="Portuguese (Portugal)", Value="pt-PT"}, - new LocalizatonOption{ Name="Romanian", Value="ro"}, - new LocalizatonOption{ Name="Russian", Value="ru"}, - new LocalizatonOption{ Name="Slovak", Value="sk"}, - new LocalizatonOption{ Name="Slovenian (Slovenia)", Value="sl-SI"}, - new LocalizatonOption{ Name="Spanish", Value="es"}, - new LocalizatonOption{ Name="Spanish (Latin America)", Value="es-419"}, - new LocalizatonOption{ Name="Spanish (Mexico)", Value="es-MX"}, - new LocalizatonOption{ Name="Swedish", Value="sv"}, - new LocalizatonOption{ Name="Swiss German", Value="gsw"}, - new LocalizatonOption{ Name="Turkish", Value="tr"}, - new LocalizatonOption{ Name="Ukrainian", Value="uk"}, - new LocalizatonOption{ Name="Vietnamese", Value="vi"} - + new LocalizationOption("Arabic", "ar"), + new LocalizationOption("Belarusian (Belarus)", "be-BY"), + new LocalizationOption("Bulgarian (Bulgaria)", "bg-BG"), + new LocalizationOption("Catalan", "ca"), + new LocalizationOption("Chinese Simplified", "zh-CN"), + new LocalizationOption("Chinese Traditional", "zh-TW"), + new LocalizationOption("Chinese Traditional (Hong Kong)", "zh-HK"), + new LocalizationOption("Croatian", "hr"), + new LocalizationOption("Czech", "cs"), + new LocalizationOption("Danish", "da"), + new LocalizationOption("Dutch", "nl"), + new LocalizationOption("English (United Kingdom)", "en-GB"), + new LocalizationOption("English (United States)", "en-US"), + new LocalizationOption("Finnish", "fi"), + new LocalizationOption("French", "fr"), + new LocalizationOption("French (Canada)", "fr-CA"), + new LocalizationOption("German", "de"), + new LocalizationOption("Greek", "el"), + new LocalizationOption("Hebrew", "he"), + new LocalizationOption("Hindi (India)", "hi-IN"), + new LocalizationOption("Hungarian", "hu"), + new LocalizationOption("Indonesian", "id"), + new LocalizationOption("Italian", "it"), + new LocalizationOption("Japanese", "ja"), + new LocalizationOption("Kazakh", "kk"), + new LocalizationOption("Korean", "ko"), + new LocalizationOption("Lithuanian", "lt-LT"), + new LocalizationOption("Malay", "ms"), + new LocalizationOption("Norwegian Bokmål", "nb"), + new LocalizationOption("Persian", "fa"), + new LocalizationOption("Polish", "pl"), + new LocalizationOption("Portuguese (Brazil)", "pt-BR"), + new LocalizationOption("Portuguese (Portugal)", "pt-PT"), + new LocalizationOption("Romanian", "ro"), + new LocalizationOption("Russian", "ru"), + new LocalizationOption("Slovak", "sk"), + new LocalizationOption("Slovenian (Slovenia)", "sl-SI"), + new LocalizationOption("Spanish", "es"), + new LocalizationOption("Spanish (Latin America)", "es-419"), + new LocalizationOption("Spanish (Mexico)", "es-MX"), + new LocalizationOption("Swedish", "sv"), + new LocalizationOption("Swiss German", "gsw"), + new LocalizationOption("Turkish", "tr"), + new LocalizationOption("Ukrainian", "uk"), + new LocalizationOption("Vietnamese", "vi") }; - } } public interface ITextLocalizer diff --git a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index 44f6e2d7b..93a9a0d81 100644 --- a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -53,7 +53,6 @@ namespace Emby.Server.Implementations.ScheduledTasks /// <value>The task manager.</value> private ITaskManager TaskManager { get; set; } private readonly IFileSystem _fileSystem; - private readonly ISystemEvents _systemEvents; /// <summary> /// Initializes a new instance of the <see cref="ScheduledTaskWorker" /> class. @@ -74,7 +73,7 @@ namespace Emby.Server.Implementations.ScheduledTasks /// or /// logger /// </exception> - public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem, ISystemEvents systemEvents) + public ScheduledTaskWorker(IScheduledTask scheduledTask, IApplicationPaths applicationPaths, ITaskManager taskManager, IJsonSerializer jsonSerializer, ILogger logger, IFileSystem fileSystem) { if (scheduledTask == null) { @@ -103,7 +102,6 @@ namespace Emby.Server.Implementations.ScheduledTasks JsonSerializer = jsonSerializer; Logger = logger; _fileSystem = fileSystem; - _systemEvents = systemEvents; InitTriggerEvents(); } @@ -762,20 +760,6 @@ namespace Emby.Server.Implementations.ScheduledTasks }; } - if (info.Type.Equals(typeof(SystemEventTrigger).Name, StringComparison.OrdinalIgnoreCase)) - { - if (!info.SystemEvent.HasValue) - { - throw new ArgumentException("Info did not contain a SystemEvent.", nameof(info)); - } - - return new SystemEventTrigger(_systemEvents) - { - SystemEvent = info.SystemEvent.Value, - TaskOptions = options - }; - } - if (info.Type.Equals(typeof(StartupTrigger).Name, StringComparison.OrdinalIgnoreCase)) { return new StartupTrigger(); diff --git a/Emby.Server.Implementations/ScheduledTasks/SystemEventTrigger.cs b/Emby.Server.Implementations/ScheduledTasks/SystemEventTrigger.cs deleted file mode 100644 index 7a88fc2b0..000000000 --- a/Emby.Server.Implementations/ScheduledTasks/SystemEventTrigger.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Threading.Tasks; -using MediaBrowser.Model.System; -using MediaBrowser.Model.Tasks; -using Microsoft.Extensions.Logging; - -namespace Emby.Server.Implementations.ScheduledTasks -{ - /// <summary> - /// Class SystemEventTrigger - /// </summary> - public class SystemEventTrigger : ITaskTrigger - { - /// <summary> - /// Gets or sets the system event. - /// </summary> - /// <value>The system event.</value> - public SystemEvent SystemEvent { get; set; } - - /// <summary> - /// Gets or sets the options of this task. - /// </summary> - public TaskOptions TaskOptions { get; set; } - - private readonly ISystemEvents _systemEvents; - - public SystemEventTrigger(ISystemEvents systemEvents) - { - _systemEvents = systemEvents; - } - - /// <summary> - /// Stars waiting for the trigger action - /// </summary> - /// <param name="lastResult">The last result.</param> - /// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param> - public void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup) - { - switch (SystemEvent) - { - case SystemEvent.WakeFromSleep: - _systemEvents.Resume += _systemEvents_Resume; - break; - } - } - - private async void _systemEvents_Resume(object sender, EventArgs e) - { - if (SystemEvent == SystemEvent.WakeFromSleep) - { - // This value is a bit arbitrary, but add a delay to help ensure network connections have been restored before running the task - await Task.Delay(10000).ConfigureAwait(false); - - OnTriggered(); - } - } - - /// <summary> - /// Stops waiting for the trigger action - /// </summary> - public void Stop() - { - _systemEvents.Resume -= _systemEvents_Resume; - } - - /// <summary> - /// Occurs when [triggered]. - /// </summary> - public event EventHandler<EventArgs> Triggered; - - /// <summary> - /// Called when [triggered]. - /// </summary> - private void OnTriggered() - { - if (Triggered != null) - { - Triggered(this, EventArgs.Empty); - } - } - } -} diff --git a/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs b/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs index 02a082d3f..d74c8fe8c 100644 --- a/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs +++ b/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs @@ -46,8 +46,6 @@ namespace Emby.Server.Implementations.ScheduledTasks /// <value>The application paths.</value> private IApplicationPaths ApplicationPaths { get; set; } - private readonly ISystemEvents _systemEvents; - /// <summary> /// Gets the logger. /// </summary> @@ -66,54 +64,16 @@ namespace Emby.Server.Implementations.ScheduledTasks IApplicationPaths applicationPaths, IJsonSerializer jsonSerializer, ILoggerFactory loggerFactory, - IFileSystem fileSystem, - ISystemEvents systemEvents) + IFileSystem fileSystem) { ApplicationPaths = applicationPaths; JsonSerializer = jsonSerializer; Logger = loggerFactory.CreateLogger(nameof(TaskManager)); _fileSystem = fileSystem; - _systemEvents = systemEvents; ScheduledTasks = new IScheduledTaskWorker[] { }; } - private void BindToSystemEvent() - { - _systemEvents.Resume += _systemEvents_Resume; - } - - private void _systemEvents_Resume(object sender, EventArgs e) - { - foreach (var task in ScheduledTasks) - { - task.ReloadTriggerEvents(); - } - } - - public void RunTaskOnNextStartup(string key) - { - var path = Path.Combine(ApplicationPaths.CachePath, "startuptasks.txt"); - - List<string> lines; - - try - { - lines = _fileSystem.ReadAllLines(path).ToList(); - } - catch - { - lines = new List<string>(); - } - - if (!lines.Contains(key, StringComparer.OrdinalIgnoreCase)) - { - lines.Add(key); - _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path)); - _fileSystem.WriteAllLines(path, lines); - } - } - private void RunStartupTasks() { var path = Path.Combine(ApplicationPaths.CachePath, "startuptasks.txt"); @@ -290,12 +250,10 @@ namespace Emby.Server.Implementations.ScheduledTasks var myTasks = ScheduledTasks.ToList(); var list = tasks.ToList(); - myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger, _fileSystem, _systemEvents))); + myTasks.AddRange(list.Select(t => new ScheduledTaskWorker(t, ApplicationPaths, this, JsonSerializer, Logger, _fileSystem))); ScheduledTasks = myTasks.ToArray(); - BindToSystemEvent(); - RunStartupTasks(); } diff --git a/Emby.Server.Implementations/SystemEvents.cs b/Emby.Server.Implementations/SystemEvents.cs deleted file mode 100644 index e4c54c3c5..000000000 --- a/Emby.Server.Implementations/SystemEvents.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using MediaBrowser.Model.System; - -namespace Emby.Server.Implementations -{ - public class SystemEvents : ISystemEvents - { - public event EventHandler Resume; - public event EventHandler Suspend; - public event EventHandler SessionLogoff; - public event EventHandler SystemShutdown; - } -} diff --git a/Emby.XmlTv/Emby.XmlTv/Classes/XmlTvReader.cs b/Emby.XmlTv/Emby.XmlTv/Classes/XmlTvReader.cs index 52e58ed8d..52ec7a135 100644 --- a/Emby.XmlTv/Emby.XmlTv/Classes/XmlTvReader.cs +++ b/Emby.XmlTv/Emby.XmlTv/Classes/XmlTvReader.cs @@ -1005,7 +1005,7 @@ namespace Emby.XmlTv.Classes } } - public static Regex _regDateWithOffset = new Regex(@"^(?<dateDigits>[0-9]{4,14})(\s(?<dateOffset>[+-]*[0-9]{1,4}))?$"); + public const string _regDateWithOffset = @"^(?<dateDigits>[0-9]{4,14})(\s(?<dateOffset>[+-]*[0-9]{1,4}))?$"; public DateTimeOffset? ParseDate(string dateValue) { @@ -1018,50 +1018,47 @@ namespace Emby.XmlTv.Classes '200007281733 BST', '200209', '19880523083000 +0300'. (BST == +0100.) */ - DateTimeOffset? result = null; - - if (!string.IsNullOrEmpty(dateValue)) + if (string.IsNullOrEmpty(dateValue)) { - var completeDate = "20000101000000"; - var dateComponent = string.Empty; - var dateOffset = "+00:00"; + return null; + } - var match = _regDateWithOffset.Match(dateValue); - if (match.Success) + var completeDate = "20000101000000"; + var dateComponent = string.Empty; + var dateOffset = "+00:00"; + var match = Regex.Match(dateValue, _regDateWithOffset); + if (match.Success) + { + dateComponent = match.Groups["dateDigits"].Value; + if (!string.IsNullOrEmpty(match.Groups["dateOffset"].Value)) { - dateComponent = match.Groups["dateDigits"].Value; - if (!string.IsNullOrEmpty(match.Groups["dateOffset"].Value)) + dateOffset = match.Groups["dateOffset"].Value; // Add in the colon to ease parsing later + if (dateOffset.Length == 5) { - dateOffset = match.Groups["dateOffset"].Value; // Add in the colon to ease parsing later - if (dateOffset.Length == 5) - { - dateOffset = dateOffset.Insert(3, ":"); // Add in the colon to ease parsing later - } - else - { - dateOffset = "+00:00"; - } + dateOffset = dateOffset.Insert(3, ":"); // Add in the colon to ease parsing later + } + else + { + dateOffset = "+00:00"; } } + } - // Pad out the date component part to 14 characaters so 2016061509 becomes 20160615090000 - if (dateComponent.Length < 14) - { - dateComponent = dateComponent + completeDate.Substring(dateComponent.Length, completeDate.Length - dateComponent.Length); - } + // Pad out the date component part to 14 characaters so 2016061509 becomes 20160615090000 + if (dateComponent.Length < 14) + { + dateComponent = dateComponent + completeDate.Substring(dateComponent.Length, completeDate.Length - dateComponent.Length); + } - var standardDate = string.Format("{0} {1}", dateComponent, dateOffset); - if (DateTimeOffset.TryParseExact(standardDate, "yyyyMMddHHmmss zzz", CultureInfo.CurrentCulture, DateTimeStyles.None, out var parsedDateTime)) - { - return parsedDateTime.ToUniversalTime(); - } - else - { - //Logger.LogWarning("Unable to parse the date {0} from standardised form {1}", dateValue, standardDate); - } + var standardDate = string.Format("{0} {1}", dateComponent, dateOffset); + if (DateTimeOffset.TryParseExact(standardDate, "yyyyMMddHHmmss zzz", CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTimeOffset parsedDateTime)) + { + return parsedDateTime.ToUniversalTime(); } - return result; + // Logger.LogWarning("Unable to parse the date {0} from standardised form {1}", dateValue, standardDate); + + return null; } public string StandardiseDate(string value) @@ -1070,7 +1067,7 @@ namespace Emby.XmlTv.Classes var dateComponent = string.Empty; var dateOffset = "+0000"; - var match = _regDateWithOffset.Match(value); + var match = Regex.Match(value, _regDateWithOffset); if (match.Success) { dateComponent = match.Groups["dateDigits"].Value; diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs index 6832fe743..b580f45ca 100644 --- a/Jellyfin.Server/CoreAppHost.cs +++ b/Jellyfin.Server/CoreAppHost.cs @@ -11,8 +11,8 @@ namespace Jellyfin.Server { public class CoreAppHost : ApplicationHost { - public CoreAppHost(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory, StartupOptions options, IFileSystem fileSystem, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager) - : base(applicationPaths, loggerFactory, options, fileSystem, environmentInfo, imageEncoder, systemEvents, networkManager) + public CoreAppHost(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory, StartupOptions options, IFileSystem fileSystem, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, MediaBrowser.Common.Net.INetworkManager networkManager) + : base(applicationPaths, loggerFactory, options, fileSystem, environmentInfo, imageEncoder, networkManager) { } diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index c196a3f23..f64f50cd7 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -96,7 +96,6 @@ namespace Jellyfin.Server fileSystem, environmentInfo, new NullImageEncoder(), - new SystemEvents(), new NetworkManager(_loggerFactory, environmentInfo))) { appHost.Init(); diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index 26ac8d40e..149e54f01 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -328,10 +328,9 @@ namespace MediaBrowser.Api.Images var fileInfo = _fileSystem.GetFileInfo(info.Path); length = fileInfo.Length; - var size = _imageProcessor.GetImageSize(item, info, true); - - width = Convert.ToInt32(size.Width); - height = Convert.ToInt32(size.Height); + ImageDimensions size = _imageProcessor.GetImageSize(item, info, true); + width = size.Width; + height = size.Height; if (width <= 0 || height <= 0) { diff --git a/MediaBrowser.Api/LocalizationService.cs b/MediaBrowser.Api/LocalizationService.cs index 0694de782..3b2e18852 100644 --- a/MediaBrowser.Api/LocalizationService.cs +++ b/MediaBrowser.Api/LocalizationService.cs @@ -33,7 +33,7 @@ namespace MediaBrowser.Api /// Class ParentalRatings /// </summary> [Route("/Localization/Options", "GET", Summary = "Gets localization options")] - public class GetLocalizationOptions : IReturn<LocalizatonOption[]> + public class GetLocalizationOptions : IReturn<LocalizationOption[]> { } diff --git a/MediaBrowser.Controller/Drawing/IImageEncoder.cs b/MediaBrowser.Controller/Drawing/IImageEncoder.cs index 6e2d5781a..5b8c9da6f 100644 --- a/MediaBrowser.Controller/Drawing/IImageEncoder.cs +++ b/MediaBrowser.Controller/Drawing/IImageEncoder.cs @@ -44,6 +44,6 @@ namespace MediaBrowser.Controller.Drawing /// <value><c>true</c> if [supports image encoding]; otherwise, <c>false</c>.</value> bool SupportsImageEncoding { get; } - ImageSize GetImageSize(string path); + ImageDimensions GetImageSize(string path); } } diff --git a/MediaBrowser.Controller/Drawing/IImageProcessor.cs b/MediaBrowser.Controller/Drawing/IImageProcessor.cs index 7e6e0127f..783182730 100644 --- a/MediaBrowser.Controller/Drawing/IImageProcessor.cs +++ b/MediaBrowser.Controller/Drawing/IImageProcessor.cs @@ -26,16 +26,16 @@ namespace MediaBrowser.Controller.Drawing /// <value>The image enhancers.</value> IImageEnhancer[] ImageEnhancers { get; } - ImageSize GetImageSize(string path); + ImageDimensions GetImageSize(string path); /// <summary> /// Gets the size of the image. /// </summary> /// <param name="info">The information.</param> /// <returns>ImageSize.</returns> - ImageSize GetImageSize(BaseItem item, ItemImageInfo info); + ImageDimensions GetImageSize(BaseItem item, ItemImageInfo info); - ImageSize GetImageSize(BaseItem item, ItemImageInfo info, bool updateItem); + ImageDimensions GetImageSize(BaseItem item, ItemImageInfo info, bool updateItem); /// <summary> /// Adds the parts. diff --git a/MediaBrowser.Controller/Drawing/ImageHelper.cs b/MediaBrowser.Controller/Drawing/ImageHelper.cs index 2680c60bd..f88a63223 100644 --- a/MediaBrowser.Controller/Drawing/ImageHelper.cs +++ b/MediaBrowser.Controller/Drawing/ImageHelper.cs @@ -1,3 +1,4 @@ +using System; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Drawing; using MediaBrowser.Model.Entities; @@ -6,7 +7,7 @@ namespace MediaBrowser.Controller.Drawing { public static class ImageHelper { - public static ImageSize GetNewImageSize(ImageProcessingOptions options, ImageSize? originalImageSize) + public static ImageDimensions GetNewImageSize(ImageProcessingOptions options, ImageDimensions? originalImageSize) { if (originalImageSize.HasValue) { @@ -20,26 +21,26 @@ namespace MediaBrowser.Controller.Drawing public static IImageProcessor ImageProcessor { get; set; } - private static ImageSize GetSizeEstimate(ImageProcessingOptions options) + private static ImageDimensions GetSizeEstimate(ImageProcessingOptions options) { if (options.Width.HasValue && options.Height.HasValue) { - return new ImageSize(options.Width.Value, options.Height.Value); + return new ImageDimensions(options.Width.Value, options.Height.Value); } - var aspect = GetEstimatedAspectRatio(options.Image.Type, options.Item); + double aspect = GetEstimatedAspectRatio(options.Image.Type, options.Item); - var width = options.Width ?? options.MaxWidth; + int? width = options.Width ?? options.MaxWidth; if (width.HasValue) { - var heightValue = width.Value / aspect; - return new ImageSize(width.Value, heightValue); + int heightValue = Convert.ToInt32((double)width.Value / aspect); + return new ImageDimensions(width.Value, heightValue); } var height = options.Height ?? options.MaxHeight ?? 200; - var widthValue = aspect * height; - return new ImageSize(widthValue, height); + int widthValue = Convert.ToInt32(aspect * height); + return new ImageDimensions(widthValue, height); } private static double GetEstimatedAspectRatio(ImageType type, BaseItem item) diff --git a/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs b/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs index 00d93930f..db432f500 100644 --- a/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs +++ b/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs @@ -57,7 +57,7 @@ namespace MediaBrowser.Controller.Drawing !MaxHeight.HasValue; } - public bool HasDefaultOptions(string originalImagePath, ImageSize? size) + public bool HasDefaultOptions(string originalImagePath, ImageDimensions? size) { if (!size.HasValue) { diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 5534576f1..0d1a0ce86 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -2235,11 +2235,7 @@ namespace MediaBrowser.Controller.Entities /// </exception> /// <exception cref="ArgumentNullException">item</exception> public string GetImagePath(ImageType imageType, int imageIndex) - { - var info = GetImageInfo(imageType, imageIndex); - - return info == null ? null : info.Path; - } + => GetImageInfo(imageType, imageIndex)?.Path; /// <summary> /// Gets the image information. diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 6f98fcd8d..0b0134669 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -508,7 +508,7 @@ namespace MediaBrowser.Controller.Entities if (query.IsLiked.HasValue) { - userData = userData ?? userDataManager.GetUserData(user, item); + userData = userDataManager.GetUserData(user, item); if (!userData.Likes.HasValue || userData.Likes != query.IsLiked.Value) { diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index e086f9d33..d8d0a1aa3 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -424,11 +424,9 @@ namespace MediaBrowser.Controller.MediaEncoding if (state.VideoStream != null && state.VideoStream.Width.HasValue) { // This is hacky but not sure how to get the exact subtitle resolution - double height = state.VideoStream.Width.Value; - height /= 16; - height *= 9; + int height = Convert.ToInt32((double)state.VideoStream.Width.Value / 16.0 * 9.0); - arg += string.Format(" -canvas_size {0}:{1}", state.VideoStream.Width.Value.ToString(CultureInfo.InvariantCulture), Convert.ToInt32(height).ToString(CultureInfo.InvariantCulture)); + arg += string.Format(" -canvas_size {0}:{1}", state.VideoStream.Width.Value.ToString(CultureInfo.InvariantCulture), height.ToString(CultureInfo.InvariantCulture)); } var subtitlePath = state.SubtitleStream.Path; diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs b/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs index 6651a6d70..1fe8856cc 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingJobInfo.cs @@ -319,7 +319,7 @@ namespace MediaBrowser.Controller.MediaEncoding { if (VideoStream != null && VideoStream.Width.HasValue && VideoStream.Height.HasValue) { - var size = new ImageSize + var size = new ImageDimensions { Width = VideoStream.Width.Value, Height = VideoStream.Height.Value @@ -331,7 +331,7 @@ namespace MediaBrowser.Controller.MediaEncoding BaseRequest.MaxWidth ?? 0, BaseRequest.MaxHeight ?? 0); - return Convert.ToInt32(newSize.Width); + return newSize.Width; } if (!IsVideoRequest) @@ -349,7 +349,7 @@ namespace MediaBrowser.Controller.MediaEncoding { if (VideoStream != null && VideoStream.Width.HasValue && VideoStream.Height.HasValue) { - var size = new ImageSize + var size = new ImageDimensions { Width = VideoStream.Width.Value, Height = VideoStream.Height.Value @@ -361,7 +361,7 @@ namespace MediaBrowser.Controller.MediaEncoding BaseRequest.MaxWidth ?? 0, BaseRequest.MaxHeight ?? 0); - return Convert.ToInt32(newSize.Height); + return newSize.Height; } if (!IsVideoRequest) diff --git a/MediaBrowser.Controller/Providers/IImageEnhancer.cs b/MediaBrowser.Controller/Providers/IImageEnhancer.cs index 2de657854..c27c00ca2 100644 --- a/MediaBrowser.Controller/Providers/IImageEnhancer.cs +++ b/MediaBrowser.Controller/Providers/IImageEnhancer.cs @@ -37,7 +37,7 @@ namespace MediaBrowser.Controller.Providers /// <param name="imageIndex">Index of the image.</param> /// <param name="originalImageSize">Size of the original image.</param> /// <returns>ImageSize.</returns> - ImageSize GetEnhancedImageSize(BaseItem item, ImageType imageType, int imageIndex, ImageSize originalImageSize); + ImageDimensions GetEnhancedImageSize(BaseItem item, ImageType imageType, int imageIndex, ImageDimensions originalImageSize); EnhancedImageInfo GetEnhancedImageInfo(BaseItem item, string inputFile, ImageType imageType, int imageIndex); diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index 522c10980..6d03a03b0 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -953,22 +953,11 @@ namespace MediaBrowser.Model.Dlna if (videoStream != null && videoStream.Width.HasValue && videoStream.Height.HasValue) { - var size = new ImageSize - { - Width = videoStream.Width.Value, - Height = videoStream.Height.Value - }; - - double? maxWidth = MaxWidth.HasValue ? (double)MaxWidth.Value : (double?)null; - double? maxHeight = MaxHeight.HasValue ? (double)MaxHeight.Value : (double?)null; + ImageDimensions size = new ImageDimensions(videoStream.Width.Value, videoStream.Height.Value); - var newSize = DrawingUtils.Resize(size, - 0, - 0, - maxWidth ?? 0, - maxHeight ?? 0); + size = DrawingUtils.Resize(size, 0, 0, MaxWidth ?? 0, MaxHeight ?? 0); - return Convert.ToInt32(newSize.Width); + return size.Width; } return MaxWidth; @@ -983,22 +972,11 @@ namespace MediaBrowser.Model.Dlna if (videoStream != null && videoStream.Width.HasValue && videoStream.Height.HasValue) { - var size = new ImageSize - { - Width = videoStream.Width.Value, - Height = videoStream.Height.Value - }; - - double? maxWidth = MaxWidth.HasValue ? (double)MaxWidth.Value : (double?)null; - double? maxHeight = MaxHeight.HasValue ? (double)MaxHeight.Value : (double?)null; + ImageDimensions size = new ImageDimensions(videoStream.Width.Value, videoStream.Height.Value); - var newSize = DrawingUtils.Resize(size, - 0, - 0, - maxWidth ?? 0, - maxHeight ?? 0); + size = DrawingUtils.Resize(size, 0, 0, MaxWidth ?? 0, MaxHeight ?? 0); - return Convert.ToInt32(newSize.Height); + return size.Height; } return MaxHeight; diff --git a/MediaBrowser.Model/Drawing/DrawingUtils.cs b/MediaBrowser.Model/Drawing/DrawingUtils.cs index fbd074218..9fe85512f 100644 --- a/MediaBrowser.Model/Drawing/DrawingUtils.cs +++ b/MediaBrowser.Model/Drawing/DrawingUtils.cs @@ -1,3 +1,5 @@ +using System; + namespace MediaBrowser.Model.Drawing { /// <summary> @@ -14,27 +16,25 @@ namespace MediaBrowser.Model.Drawing /// <param name="maxWidth">A max fixed width, if desired</param> /// <param name="maxHeight">A max fixed height, if desired</param> /// <returns>A new size object</returns> - public static ImageSize Resize(ImageSize size, - double width, - double height, - double maxWidth, - double maxHeight) + public static ImageDimensions Resize(ImageDimensions size, + int width, + int height, + int maxWidth, + int maxHeight) { - double newWidth = size.Width; - double newHeight = size.Height; + int newWidth = size.Width; + int newHeight = size.Height; if (width > 0 && height > 0) { newWidth = width; newHeight = height; } - else if (height > 0) { newWidth = GetNewWidth(newHeight, newWidth, height); newHeight = height; } - else if (width > 0) { newHeight = GetNewHeight(newHeight, newWidth, width); @@ -53,7 +53,7 @@ namespace MediaBrowser.Model.Drawing newWidth = maxWidth; } - return new ImageSize { Width = newWidth, Height = newHeight }; + return new ImageDimensions(newWidth, newHeight); } /// <summary> @@ -62,15 +62,9 @@ namespace MediaBrowser.Model.Drawing /// <param name="currentHeight">Height of the current.</param> /// <param name="currentWidth">Width of the current.</param> /// <param name="newHeight">The new height.</param> - /// <returns>System.Double.</returns> - private static double GetNewWidth(double currentHeight, double currentWidth, double newHeight) - { - double scaleFactor = newHeight; - scaleFactor /= currentHeight; - scaleFactor *= currentWidth; - - return scaleFactor; - } + /// <returns>the new width</returns> + private static int GetNewWidth(int currentHeight, int currentWidth, int newHeight) + => Convert.ToInt32((double)newHeight / currentHeight * currentWidth); /// <summary> /// Gets the new height. @@ -79,13 +73,7 @@ namespace MediaBrowser.Model.Drawing /// <param name="currentWidth">Width of the current.</param> /// <param name="newWidth">The new width.</param> /// <returns>System.Double.</returns> - private static double GetNewHeight(double currentHeight, double currentWidth, double newWidth) - { - double scaleFactor = newWidth; - scaleFactor /= currentWidth; - scaleFactor *= currentHeight; - - return scaleFactor; - } + private static int GetNewHeight(int currentHeight, int currentWidth, int newWidth) + => Convert.ToInt32((double)newWidth / currentWidth * currentHeight); } } diff --git a/MediaBrowser.Model/Drawing/ImageSize.cs b/MediaBrowser.Model/Drawing/ImageSize.cs index 87764bbf4..75591d83d 100644 --- a/MediaBrowser.Model/Drawing/ImageSize.cs +++ b/MediaBrowser.Model/Drawing/ImageSize.cs @@ -1,36 +1,23 @@ -using System.Globalization; - namespace MediaBrowser.Model.Drawing { /// <summary> /// Struct ImageSize /// </summary> - public struct ImageSize + public struct ImageDimensions { - private double _height; - private double _width; - /// <summary> /// Gets or sets the height. /// </summary> /// <value>The height.</value> - public double Height - { - get => _height; - set => _height = value; - } + public int Height { get; set; } /// <summary> /// Gets or sets the width. /// </summary> /// <value>The width.</value> - public double Width - { - get => _width; - set => _width = value; - } + public int Width { get; set; } - public bool Equals(ImageSize size) + public bool Equals(ImageDimensions size) { return Width.Equals(size.Width) && Height.Equals(size.Height); } @@ -40,46 +27,10 @@ namespace MediaBrowser.Model.Drawing return string.Format("{0}-{1}", Width, Height); } - public ImageSize(string value) + public ImageDimensions(int width, int height) { - _width = 0; - - _height = 0; - - ParseValue(value); - } - - public ImageSize(int width, int height) - { - _width = width; - _height = height; - } - - public ImageSize(double width, double height) - { - _width = width; - _height = height; - } - - private void ParseValue(string value) - { - if (!string.IsNullOrEmpty(value)) - { - string[] parts = value.Split('-'); - - if (parts.Length == 2) - { - if (double.TryParse(parts[0], NumberStyles.Any, CultureInfo.InvariantCulture, out var val)) - { - _width = val; - } - - if (double.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture, out val)) - { - _height = val; - } - } - } + Width = width; + Height = height; } } } diff --git a/MediaBrowser.Model/Globalization/ILocalizationManager.cs b/MediaBrowser.Model/Globalization/ILocalizationManager.cs index a2531e504..05efb6681 100644 --- a/MediaBrowser.Model/Globalization/ILocalizationManager.cs +++ b/MediaBrowser.Model/Globalization/ILocalizationManager.cs @@ -49,7 +49,7 @@ namespace MediaBrowser.Model.Globalization /// Gets the localization options. /// </summary> /// <returns>IEnumerable{LocalizatonOption}.</returns> - LocalizatonOption[] GetLocalizationOptions(); + LocalizationOption[] GetLocalizationOptions(); string RemoveDiacritics(string text); diff --git a/MediaBrowser.Model/Globalization/LocalizationOption.cs b/MediaBrowser.Model/Globalization/LocalizationOption.cs new file mode 100644 index 000000000..c4c9a8919 --- /dev/null +++ b/MediaBrowser.Model/Globalization/LocalizationOption.cs @@ -0,0 +1,14 @@ +namespace MediaBrowser.Model.Globalization +{ + public class LocalizationOption + { + public LocalizationOption(string name, string value) + { + Name = name; + Value = value; + } + + public string Name { get; set; } + public string Value { get; set; } + } +} diff --git a/MediaBrowser.Model/Globalization/LocalizatonOption.cs b/MediaBrowser.Model/Globalization/LocalizatonOption.cs deleted file mode 100644 index 7fbc8135d..000000000 --- a/MediaBrowser.Model/Globalization/LocalizatonOption.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace MediaBrowser.Model.Globalization -{ - public class LocalizatonOption - { - public string Name { get; set; } - public string Value { get; set; } - } -} diff --git a/MediaBrowser.Model/System/ISystemEvents.cs b/MediaBrowser.Model/System/ISystemEvents.cs deleted file mode 100644 index 8c47d6fbf..000000000 --- a/MediaBrowser.Model/System/ISystemEvents.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace MediaBrowser.Model.System -{ - public interface ISystemEvents - { - event EventHandler Resume; - event EventHandler Suspend; - event EventHandler SessionLogoff; - event EventHandler SystemShutdown; - } -} diff --git a/MediaBrowser.Model/Tasks/ITaskManager.cs b/MediaBrowser.Model/Tasks/ITaskManager.cs index a7c2f6d86..57b8d1af8 100644 --- a/MediaBrowser.Model/Tasks/ITaskManager.cs +++ b/MediaBrowser.Model/Tasks/ITaskManager.cs @@ -72,7 +72,5 @@ namespace MediaBrowser.Model.Tasks event EventHandler<GenericEventArgs<IScheduledTaskWorker>> TaskExecuting; event EventHandler<TaskCompletionEventArgs> TaskCompleted; - - void RunTaskOnNextStartup(string key); } } diff --git a/MediaBrowser.Model/Tasks/SystemEvent.cs b/MediaBrowser.Model/Tasks/SystemEvent.cs deleted file mode 100644 index 5a3d8a8eb..000000000 --- a/MediaBrowser.Model/Tasks/SystemEvent.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace MediaBrowser.Model.Tasks -{ - /// <summary> - /// Enum SystemEvent - /// </summary> - public enum SystemEvent - { - /// <summary> - /// The wake from sleep - /// </summary> - WakeFromSleep = 0 - } -} diff --git a/MediaBrowser.Model/Tasks/TaskTriggerInfo.cs b/MediaBrowser.Model/Tasks/TaskTriggerInfo.cs index 80101ec48..714f11872 100644 --- a/MediaBrowser.Model/Tasks/TaskTriggerInfo.cs +++ b/MediaBrowser.Model/Tasks/TaskTriggerInfo.cs @@ -26,12 +26,6 @@ namespace MediaBrowser.Model.Tasks public long? IntervalTicks { get; set; } /// <summary> - /// Gets or sets the system event. - /// </summary> - /// <value>The system event.</value> - public SystemEvent? SystemEvent { get; set; } - - /// <summary> /// Gets or sets the day of week. /// </summary> /// <value>The day of week.</value> diff --git a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs index ecae0c39d..e4bb52217 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs @@ -510,13 +510,11 @@ namespace MediaBrowser.Providers.Music return new ValueTuple<string, string>(); } - private static ValueTuple<string, string> ParseArtistNameCredit(XmlReader reader) + private static (string, string) ParseArtistNameCredit(XmlReader reader) { reader.MoveToContent(); reader.Read(); - string name = null; - // http://stackoverflow.com/questions/2299632/why-does-xmlreader-skip-every-other-element-if-there-is-no-whitespace-separator // Loop through each element @@ -547,7 +545,7 @@ namespace MediaBrowser.Providers.Music } } - return new ValueTuple<string, string>(name, null); + return (null, null); } private static ValueTuple<string, string> ParseArtistArtistCredit(XmlReader reader, string artistId) |
