The Free Software Media System - Server Backend & API
Simplify/remove/clean code
Bond-009b44a70ff368f
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.csindex 484942946c..e15cb68e9e 100644--- a/Emby.Server.Implementations/ApplicationHost.cs+++ b/Emby.Server.Implementations/ApplicationHost.cs@@ -200,7 +200,7 @@ namespace Emby.Server.Implementations/// <summary>/// The disposable parts/// </summary>- protected readonly List<IDisposable> _disposableParts = new List<IDisposable>();+ private readonly List<IDisposable> _disposableParts = new List<IDisposable>();/// <summary>/// Gets the configuration manager.@@ -216,8 +216,9 @@ namespace Emby.Server.Implementations{#if BETAreturn PackageVersionClass.Beta;-#endif+#elsereturn PackageVersionClass.Release;+#endif}}@@ -340,7 +341,6 @@ namespace Emby.Server.Implementationsprotected IProcessFactory ProcessFactory { get; private set; }- protected ICryptoProvider CryptographyProvider = new CryptographyProvider();protected readonly IXmlSerializer XmlSerializer;protected ISocketFactory SocketFactory { get; private set; }@@ -369,9 +369,6 @@ namespace Emby.Server.Implementations{_configuration = configuration;- // hack alert, until common can target .net core- BaseExtensions.CryptographyProvider = CryptographyProvider;-XmlSerializer = new MyXmlSerializer(fileSystem, loggerFactory);NetworkManager = networkManager;@@ -735,13 +732,12 @@ namespace Emby.Server.ImplementationsApplicationHost.StreamHelper = new StreamHelper();serviceCollection.AddSingleton(StreamHelper);- serviceCollection.AddSingleton(CryptographyProvider);+ serviceCollection.AddSingleton(typeof(ICryptoProvider), typeof(CryptographyProvider));SocketFactory = new SocketFactory();serviceCollection.AddSingleton(SocketFactory);- InstallationManager = new InstallationManager(LoggerFactory, this, ApplicationPaths, HttpClient, JsonSerializer, ServerConfigurationManager, FileSystemManager, CryptographyProvider, ZipClient, PackageRuntime);- serviceCollection.AddSingleton(InstallationManager);+ serviceCollection.AddSingleton(typeof(IInstallationManager), typeof(InstallationManager));ZipClient = new ZipClient();serviceCollection.AddSingleton(ZipClient);@@ -908,8 +904,6 @@ namespace Emby.Server.Implementations_serviceProvider = serviceCollection.BuildServiceProvider();}- public virtual string PackageRuntime => "netcore";-public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths){// Distinct these to prevent users from reporting problems that aren't actually problems@@ -1049,6 +1043,8 @@ namespace Emby.Server.Implementations/// </summary>protected void FindParts(){+ InstallationManager = _serviceProvider.GetService<IInstallationManager>();+if (!ServerConfigurationManager.Configuration.IsPortAuthorized){ServerConfigurationManager.Configuration.IsPortAuthorized = true;diff --git a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs b/Emby.Server.Implementations/Cryptography/CryptographyProvider.csindex 982bba625d..6d7193ce20 100644--- a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs+++ b/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs@@ -4,7 +4,6 @@ using System.Globalization;using System.IO;using System.Security.Cryptography;using System.Text;-using System.Linq;using MediaBrowser.Model.Cryptography;namespace Emby.Server.Implementations.Cryptography@@ -136,7 +135,7 @@ namespace Emby.Server.Implementations.Cryptography{return PBKDF2(DefaultHashMethod, bytes, salt, _defaultIterations);}-+public byte[] ComputeHash(PasswordHash hash){int iterations = _defaultIterations;diff --git a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.csindex 3d60925da3..47552806d4 100644--- a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs+++ b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs@@ -90,9 +90,10 @@ namespace Emby.Server.Implementations.Data{throw new ArgumentNullException(nameof(displayPreferences));}+if (string.IsNullOrEmpty(displayPreferences.Id)){- throw new ArgumentNullException(nameof(displayPreferences.Id));+ throw new ArgumentException("Display preferences has an invalid Id", nameof(displayPreferences));}cancellationToken.ThrowIfCancellationRequested();diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.csindex 0389656477..8369f4f593 100644--- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs+++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs@@ -388,7 +388,7 @@ namespace Emby.Server.Implementations.EntryPointsFoldersRemovedFrom = foldersRemovedFrom.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToArray(),- CollectionFolders = GetTopParentIds(newAndRemoved, user, allUserRootChildren).ToArray()+ CollectionFolders = GetTopParentIds(newAndRemoved, allUserRootChildren).ToArray()};}@@ -407,7 +407,7 @@ namespace Emby.Server.Implementations.EntryPointsreturn item.SourceType == SourceType.Library;}- private IEnumerable<string> GetTopParentIds(List<BaseItem> items, User user, List<Folder> allUserRootChildren)+ private IEnumerable<string> GetTopParentIds(List<BaseItem> items, List<Folder> allUserRootChildren){var list = new List<string>();diff --git a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs b/Emby.Server.Implementations/HttpServer/Security/AuthService.csindex 499a334fc9..1027883ed9 100644--- a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs+++ b/Emby.Server.Implementations/HttpServer/Security/AuthService.cs@@ -45,7 +45,7 @@ namespace Emby.Server.Implementations.HttpServer.Security// This code is executed before the servicevar auth = AuthorizationContext.GetAuthorizationInfo(request);- if (!IsExemptFromAuthenticationToken(auth, authAttribtues, request))+ if (!IsExemptFromAuthenticationToken(authAttribtues, request)){ValidateSecurityToken(request, auth.Token);}@@ -122,7 +122,7 @@ namespace Emby.Server.Implementations.HttpServer.Security}}- private bool IsExemptFromAuthenticationToken(AuthorizationInfo auth, IAuthenticationAttributes authAttribtues, IRequest request)+ private bool IsExemptFromAuthenticationToken(IAuthenticationAttributes authAttribtues, IRequest request){if (!_config.Configuration.IsStartupWizardCompleted && authAttribtues.AllowBeforeStartupWizard){diff --git a/Emby.Server.Implementations/HttpServer/StreamWriter.cs b/Emby.Server.Implementations/HttpServer/StreamWriter.csindex cf30bbc326..324f9085e5 100644--- a/Emby.Server.Implementations/HttpServer/StreamWriter.cs+++ b/Emby.Server.Implementations/HttpServer/StreamWriter.cs@@ -1,6 +1,5 @@using System;using System.Collections.Generic;-using System.Globalization;using System.IO;using System.Threading;using System.Threading.Tasks;@@ -14,8 +13,6 @@ namespace Emby.Server.Implementations.HttpServer/// </summary>public class StreamWriter : IAsyncStreamWriter, IHasHeaders{- private static readonly CultureInfo UsCulture = new CultureInfo("en-US");-/// <summary>/// Gets or sets the source stream./// </summary>diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.csindex 58b3b6a69f..7b210d2313 100644--- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs+++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs@@ -261,7 +261,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTVpublic string HomePageUrl => "https://github.com/jellyfin/jellyfin";- public async Task RefreshSeriesTimers(CancellationToken cancellationToken, IProgress<double> progress)+ public async Task RefreshSeriesTimers(CancellationToken cancellationToken){var seriesTimers = await GetSeriesTimersAsync(cancellationToken).ConfigureAwait(false);@@ -271,7 +271,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV}}- public async Task RefreshTimers(CancellationToken cancellationToken, IProgress<double> progress)+ public async Task RefreshTimers(CancellationToken cancellationToken){var timers = await GetTimersAsync(cancellationToken).ConfigureAwait(false);diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.csindex f7ef16fb09..9093d9740f 100644--- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs+++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs@@ -1087,8 +1087,8 @@ namespace Emby.Server.Implementations.LiveTvif (coreService != null){- await coreService.RefreshSeriesTimers(cancellationToken, new SimpleProgress<double>()).ConfigureAwait(false);- await coreService.RefreshTimers(cancellationToken, new SimpleProgress<double>()).ConfigureAwait(false);+ await coreService.RefreshSeriesTimers(cancellationToken).ConfigureAwait(false);+ await coreService.RefreshTimers(cancellationToken).ConfigureAwait(false);}// Load these now which will prefetch metadatadiff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.csindex 588dcb843b..2d9bec53f0 100644--- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs@@ -10,14 +10,12 @@ using MediaBrowser.Controller;using MediaBrowser.Controller.Configuration;using MediaBrowser.Controller.Library;using MediaBrowser.Controller.LiveTv;-using MediaBrowser.Controller.MediaEncoding;using MediaBrowser.Model.Dto;using MediaBrowser.Model.Entities;using MediaBrowser.Model.IO;using MediaBrowser.Model.LiveTv;using MediaBrowser.Model.MediaInfo;using MediaBrowser.Model.Serialization;-using MediaBrowser.Model.System;using Microsoft.Extensions.Logging;using Microsoft.Net.Http.Headers;@@ -52,9 +50,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts{var channelIdPrefix = GetFullChannelIdPrefix(info);- var result = await new M3uParser(Logger, _httpClient, _appHost).Parse(info.Url, channelIdPrefix, info.Id, cancellationToken).ConfigureAwait(false);-- return result.Cast<ChannelInfo>().ToList();+ return await new M3uParser(Logger, _httpClient, _appHost).Parse(info.Url, channelIdPrefix, info.Id, cancellationToken).ConfigureAwait(false);}public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken)@@ -73,7 +69,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHostsreturn Task.FromResult(list);}- private string[] _disallowedSharedStreamExtensions = new string[]+ private static readonly string[] _disallowedSharedStreamExtensions = new string[]{".mkv",".mp4",@@ -88,9 +84,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHostsif (tunerCount > 0){var tunerHostId = info.Id;- var liveStreams = currentLiveStreams.Where(i => string.Equals(i.TunerHostId, tunerHostId, StringComparison.OrdinalIgnoreCase)).ToList();+ var liveStreams = currentLiveStreams.Where(i => string.Equals(i.TunerHostId, tunerHostId, StringComparison.OrdinalIgnoreCase));- if (liveStreams.Count >= tunerCount)+ if (liveStreams.Count() >= tunerCount){throw new LiveTvConflictException("M3U simultaneous stream limit has been reached.");}@@ -98,7 +94,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHostsvar sources = await GetChannelStreamMediaSources(info, channelInfo, cancellationToken).ConfigureAwait(false);- var mediaSource = sources.First();+ var mediaSource = sources[0];if (mediaSource.Protocol == MediaProtocol.Http && !mediaSource.RequiresLooping){diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.csindex ad124bb0ff..814031b126 100644--- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs@@ -11,7 +11,6 @@ using MediaBrowser.Common.Net;using MediaBrowser.Controller;using MediaBrowser.Controller.LiveTv;using MediaBrowser.Model.Extensions;-using MediaBrowser.Model.IO;using Microsoft.Extensions.Logging;namespace Emby.Server.Implementations.LiveTv.TunerHosts@@ -62,12 +61,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHostsreturn Task.FromResult((Stream)File.OpenRead(url));}- const string ExtInfPrefix = "#EXTINF:";+ private const string ExtInfPrefix = "#EXTINF:";+private List<ChannelInfo> GetChannels(TextReader reader, string channelIdPrefix, string tunerHostId){var channels = new List<ChannelInfo>();string line;- string extInf = "";+ string extInf = string.Empty;while ((line = reader.ReadLine()) != null){@@ -101,7 +101,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHostschannel.Path = line;channels.Add(channel);- extInf = "";+ extInf = string.Empty;}}@@ -110,8 +110,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHostsprivate ChannelInfo GetChannelnfo(string extInf, string tunerHostId, string mediaUrl){- var channel = new ChannelInfo();- channel.TunerHostId = tunerHostId;+ var channel = new ChannelInfo()+ {+ TunerHostId = tunerHostId+ };extInf = extInf.Trim();@@ -137,13 +139,15 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts{channelIdValues.Add(channelId);}+if (!string.IsNullOrWhiteSpace(tvgId)){channelIdValues.Add(tvgId);}+if (channelIdValues.Count > 0){- channel.Id = string.Join("_", channelIdValues.ToArray());+ channel.Id = string.Join("_", channelIdValues);}return channel;@@ -152,7 +156,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHostsprivate string GetChannelNumber(string extInf, Dictionary<string, string> attributes, string mediaUrl){var nameParts = extInf.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);- var nameInExtInf = nameParts.Length > 1 ? nameParts.Last().Trim() : null;+ var nameInExtInf = nameParts.Length > 1 ? nameParts[nameParts.Length - 1].Trim() : null;string numberString = null;string attributeValue;diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.csindex 301802b8a6..7310de55d4 100644--- a/Emby.Server.Implementations/Updates/InstallationManager.cs+++ b/Emby.Server.Implementations/Updates/InstallationManager.cs@@ -12,7 +12,6 @@ using MediaBrowser.Common.Plugins;using MediaBrowser.Common.Progress;using MediaBrowser.Common.Updates;using MediaBrowser.Controller.Configuration;-using MediaBrowser.Model.Cryptography;using MediaBrowser.Model.Events;using MediaBrowser.Model.IO;using MediaBrowser.Model.Serialization;@@ -39,11 +38,10 @@ namespace Emby.Server.Implementations.Updates/// <summary>/// The completed installations/// </summary>- private ConcurrentBag<InstallationInfo> CompletedInstallationsInternal { get; set; }+ private ConcurrentBag<InstallationInfo> _completedInstallationsInternal;- public IEnumerable<InstallationInfo> CompletedInstallations => CompletedInstallationsInternal;+ public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal;- #region PluginUninstalled Event/// <summary>/// Occurs when [plugin uninstalled]./// </summary>@@ -57,9 +55,7 @@ namespace Emby.Server.Implementations.Updates{PluginUninstalled?.Invoke(this, new GenericEventArgs<IPlugin> { Argument = plugin });}- #endregion- #region PluginUpdated Event/// <summary>/// Occurs when [plugin updated]./// </summary>@@ -77,9 +73,7 @@ namespace Emby.Server.Implementations.Updates_applicationHost.NotifyPendingRestart();}- #endregion- #region PluginInstalled Event/// <summary>/// Occurs when [plugin updated]./// </summary>@@ -96,7 +90,6 @@ namespace Emby.Server.Implementations.Updates_applicationHost.NotifyPendingRestart();}- #endregion/// <summary>/// The _logger@@ -115,12 +108,8 @@ namespace Emby.Server.Implementations.Updates/// <value>The application host.</value>private readonly IApplicationHost _applicationHost;- private readonly ICryptoProvider _cryptographyProvider;private readonly IZipClient _zipClient;- // netframework or netcore- private readonly string _packageRuntime;-public InstallationManager(ILoggerFactory loggerFactory,IApplicationHost appHost,@@ -129,9 +118,7 @@ namespace Emby.Server.Implementations.UpdatesIJsonSerializer jsonSerializer,IServerConfigurationManager config,IFileSystem fileSystem,- ICryptoProvider cryptographyProvider,- IZipClient zipClient,- string packageRuntime)+ IZipClient zipClient){if (loggerFactory == null){@@ -139,18 +126,16 @@ namespace Emby.Server.Implementations.Updates}CurrentInstallations = new List<Tuple<InstallationInfo, CancellationTokenSource>>();- CompletedInstallationsInternal = new ConcurrentBag<InstallationInfo>();+ _completedInstallationsInternal = new ConcurrentBag<InstallationInfo>();+ _logger = loggerFactory.CreateLogger(nameof(InstallationManager));_applicationHost = appHost;_appPaths = appPaths;_httpClient = httpClient;_jsonSerializer = jsonSerializer;_config = config;_fileSystem = fileSystem;- _cryptographyProvider = cryptographyProvider;_zipClient = zipClient;- _packageRuntime = packageRuntime;- _logger = loggerFactory.CreateLogger(nameof(InstallationManager));}private static Version GetPackageVersion(PackageVersionInfo version)@@ -222,11 +207,6 @@ namespace Emby.Server.Implementations.Updatescontinue;}- if (string.IsNullOrEmpty(version.runtimes) || version.runtimes.IndexOf(_packageRuntime, StringComparison.OrdinalIgnoreCase) == -1)- {- continue;- }-versions.Add(version);}@@ -448,7 +428,7 @@ namespace Emby.Server.Implementations.UpdatesCurrentInstallations.Remove(tuple);}- CompletedInstallationsInternal.Add(installationInfo);+ _completedInstallationsInternal.Add(installationInfo);PackageInstallationCompleted?.Invoke(this, installationEventArgs);}diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.csindex 82a76c6378..d4b10c8c84 100644--- a/Jellyfin.Server/Program.cs+++ b/Jellyfin.Server/Program.cs@@ -19,7 +19,6 @@ using MediaBrowser.Common.Configuration;using MediaBrowser.Controller.Drawing;using MediaBrowser.Model.Globalization;using MediaBrowser.Model.IO;-using Microsoft.AspNetCore.Hosting;using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Logging;diff --git a/MediaBrowser.Common/Extensions/BaseExtensions.cs b/MediaBrowser.Common/Extensions/BaseExtensions.csindex db0514bb18..40c16b9573 100644--- a/MediaBrowser.Common/Extensions/BaseExtensions.cs+++ b/MediaBrowser.Common/Extensions/BaseExtensions.cs@@ -1,6 +1,7 @@using System;+using System.Text;using System.Text.RegularExpressions;-using MediaBrowser.Model.Cryptography;+using System.Security.Cryptography;namespace MediaBrowser.Common.Extensions{@@ -9,8 +10,6 @@ namespace MediaBrowser.Common.Extensions/// </summary>public static class BaseExtensions{- public static ICryptoProvider CryptographyProvider { get; set; }-/// <summary>/// Strips the HTML./// </summary>@@ -31,7 +30,10 @@ namespace MediaBrowser.Common.Extensions/// <returns>Guid.</returns>public static Guid GetMD5(this string str){- return CryptographyProvider.GetMD5(str);+ using (var provider = MD5.Create())+ {+ return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str)));+ }}}}diff --git a/jellyfin.ruleset b/jellyfin.rulesetindex 0a04b4c557..262121a325 100644--- a/jellyfin.ruleset+++ b/jellyfin.ruleset@@ -20,6 +20,9 @@<Rule Id="SA1633" Action="None" /></Rules><Rules AnalyzerId="Microsoft.CodeAnalysis.FxCopAnalyzers" RuleNamespace="Microsoft.Design">+ <!-- disable warning CA1822: Member does not access instance data and can be marked as static -->+ <Rule Id="CA1822" Action="Info" />+<!-- disable warning CA1054: Change the type of parameter url from string to System.Uri --><Rule Id="CA1054" Action="None" /></Rules>