From c99b45dbe0b6f0b02850eda5c9ece071c6c03e85 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Mon, 31 Dec 2018 00:28:23 +0100 Subject: Remove some warnings --- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs') diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index a661d7691..181fc0f65 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -6,7 +6,6 @@ using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Session; using MediaBrowser.MediaEncoding.Probing; using MediaBrowser.Model.Dlna; -using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; using MediaBrowser.Model.MediaInfo; @@ -550,7 +549,7 @@ namespace MediaBrowser.MediaEncoding.Encoder { //process.BeginErrorReadLine(); - var result = _jsonSerializer.DeserializeFromStream(process.StandardOutput.BaseStream); + var result = await _jsonSerializer.DeserializeFromStreamAsync(process.StandardOutput.BaseStream).ConfigureAwait(false); if (result == null || (result.streams == null && result.format == null)) { -- cgit v1.2.3 From 0042b96c806ce38b575b33246bdb56dfe73adace Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 2 Jan 2019 01:23:49 +0100 Subject: Use ValueTuple and Linq --- .../Encoder/EncoderValidator.cs | 43 +++++++--------------- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 8 ++-- 2 files changed, 17 insertions(+), 34 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs') diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs index 0f24a2370..400fa0b81 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; using MediaBrowser.Model.Diagnostics; using Microsoft.Extensions.Logging; @@ -17,21 +18,21 @@ namespace MediaBrowser.MediaEncoding.Encoder _processFactory = processFactory; } - public Tuple, List> Validate(string encoderPath) + public (IEnumerable decoders, IEnumerable encoders) Validate(string encoderPath) { - _logger.LogInformation("Validating media encoder at {0}", encoderPath); + _logger.LogInformation("Validating media encoder at {EncoderPath}", encoderPath); var decoders = GetDecoders(encoderPath); var encoders = GetEncoders(encoderPath); _logger.LogInformation("Encoder validation complete"); - return new Tuple, List>(decoders, encoders); + return (decoders, encoders); } public bool ValidateVersion(string encoderAppPath, bool logOutput) { - string output = string.Empty; + string output = null; try { output = GetProcessOutput(encoderAppPath, "-version"); @@ -70,7 +71,7 @@ namespace MediaBrowser.MediaEncoding.Encoder return true; } - private List GetDecoders(string encoderAppPath) + private IEnumerable GetDecoders(string encoderAppPath) { string output = null; try @@ -84,7 +85,7 @@ namespace MediaBrowser.MediaEncoding.Encoder if (string.IsNullOrWhiteSpace(output)) { - return new List(); + return Enumerable.Empty(); } var required = new[] @@ -104,23 +105,14 @@ namespace MediaBrowser.MediaEncoding.Encoder "hevc" }; - var found = new List(); - foreach (var codec in required) - { - var srch = " " + codec + " "; - - if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) != -1) - { - found.Add(codec); - } - } + var found = required.Where(x => output.IndexOf(x, StringComparison.OrdinalIgnoreCase) != -1); _logger.LogInformation("Available decoders: {Codecs}", found); return found; } - private List GetEncoders(string encoderAppPath) + private IEnumerable GetEncoders(string encoderAppPath) { string output = null; try @@ -134,7 +126,7 @@ namespace MediaBrowser.MediaEncoding.Encoder if (string.IsNullOrWhiteSpace(output)) { - return new List(); + return Enumerable.Empty(); } var required = new[] @@ -161,16 +153,7 @@ namespace MediaBrowser.MediaEncoding.Encoder "ac3" }; - var found = new List(); - foreach (var codec in required) - { - var srch = " " + codec + " "; - - if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) != -1) - { - found.Add(codec); - } - } + var found = required.Where(x => output.IndexOf(x, StringComparison.OrdinalIgnoreCase) != -1); _logger.LogInformation("Available encoders: {Codecs}", found); @@ -179,7 +162,7 @@ namespace MediaBrowser.MediaEncoding.Encoder private string GetProcessOutput(string path, string arguments) { - var process = _processFactory.Create(new ProcessOptions + IProcess process = _processFactory.Create(new ProcessOptions { CreateNoWindow = true, UseShellExecute = false, @@ -190,7 +173,7 @@ namespace MediaBrowser.MediaEncoding.Encoder RedirectStandardOutput = true }); - _logger.LogInformation("Running {path} {arguments}", path, arguments); + _logger.LogInformation("Running {Path} {Arguments}", path, arguments); using (process) { diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 181fc0f65..1d8cd6778 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -175,8 +175,8 @@ namespace MediaBrowser.MediaEncoding.Encoder { var result = new EncoderValidator(_logger, _processFactory).Validate(FFMpegPath); - SetAvailableDecoders(result.Item1); - SetAvailableEncoders(result.Item2); + SetAvailableDecoders(result.decoders); + SetAvailableEncoders(result.encoders); if (EnableEncoderFontFile) { @@ -401,14 +401,14 @@ namespace MediaBrowser.MediaEncoding.Encoder } private List _encoders = new List(); - public void SetAvailableEncoders(List list) + public void SetAvailableEncoders(IEnumerable list) { _encoders = list.ToList(); //_logger.Info("Supported encoders: {0}", string.Join(",", list.ToArray())); } private List _decoders = new List(); - public void SetAvailableDecoders(List list) + public void SetAvailableDecoders(IEnumerable list) { _decoders = list.ToList(); //_logger.Info("Supported decoders: {0}", string.Join(",", list.ToArray())); -- cgit v1.2.3 From ec47c5b0f7883cebc54a2d50cdb8e65d4e07084f Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 2 Jan 2019 15:12:52 +0100 Subject: Remove unused FontConfigLoader --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- .../Encoder/FontConfigLoader.cs | 179 --------------------- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 33 ++-- 3 files changed, 19 insertions(+), 195 deletions(-) delete mode 100644 MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs (limited to 'MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index f1e1b4b2d..07705e9e4 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1240,7 +1240,7 @@ namespace Emby.Server.Implementations HttpClient, ZipClient, ProcessFactory, - 5000, false, + 5000, EnvironmentInfo); MediaEncoder = mediaEncoder; diff --git a/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs b/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs deleted file mode 100644 index c62de0b11..000000000 --- a/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs +++ /dev/null @@ -1,179 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Net; -using MediaBrowser.Common.Progress; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Net; -using Microsoft.Extensions.Logging; - -namespace MediaBrowser.MediaEncoding.Encoder -{ - public class FontConfigLoader - { - private readonly IHttpClient _httpClient; - private readonly IApplicationPaths _appPaths; - private readonly ILogger _logger; - private readonly IZipClient _zipClient; - private readonly IFileSystem _fileSystem; - - private readonly string[] _fontUrls = - { - "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/ARIALUNI.7z" - }; - - public FontConfigLoader(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, IZipClient zipClient, IFileSystem fileSystem) - { - _httpClient = httpClient; - _appPaths = appPaths; - _logger = logger; - _zipClient = zipClient; - _fileSystem = fileSystem; - } - - /// - /// Extracts the fonts. - /// - /// The target path. - /// Task. - public async Task DownloadFonts(string targetPath) - { - try - { - var fontsDirectory = Path.Combine(targetPath, "fonts"); - - _fileSystem.CreateDirectory(fontsDirectory); - - const string fontFilename = "ARIALUNI.TTF"; - - var fontFile = Path.Combine(fontsDirectory, fontFilename); - - if (_fileSystem.FileExists(fontFile)) - { - await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false); - } - else - { - // Kick this off, but no need to wait on it - var task = Task.Run(async () => - { - await DownloadFontFile(fontsDirectory, fontFilename, new SimpleProgress()).ConfigureAwait(false); - - await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false); - }); - } - } - catch (HttpException ex) - { - // Don't let the server crash because of this - _logger.LogError(ex, "Error downloading ffmpeg font files"); - } - catch (Exception ex) - { - // Don't let the server crash because of this - _logger.LogError(ex, "Error writing ffmpeg font files"); - } - } - - /// - /// Downloads the font file. - /// - /// The fonts directory. - /// The font filename. - /// Task. - private async Task DownloadFontFile(string fontsDirectory, string fontFilename, IProgress progress) - { - var existingFile = _fileSystem - .GetFilePaths(_appPaths.ProgramDataPath, true) - .FirstOrDefault(i => string.Equals(fontFilename, Path.GetFileName(i), StringComparison.OrdinalIgnoreCase)); - - if (existingFile != null) - { - try - { - _fileSystem.CopyFile(existingFile, Path.Combine(fontsDirectory, fontFilename), true); - return; - } - catch (IOException ex) - { - // Log this, but don't let it fail the operation - _logger.LogError(ex, "Error copying file"); - } - } - - string tempFile = null; - - foreach (var url in _fontUrls) - { - progress.Report(0); - - try - { - tempFile = await _httpClient.GetTempFile(new HttpRequestOptions - { - Url = url, - Progress = progress - - }).ConfigureAwait(false); - - break; - } - catch (Exception ex) - { - // The core can function without the font file, so handle this - _logger.LogError(ex, "Failed to download ffmpeg font file from {url}", url); - } - } - - if (string.IsNullOrEmpty(tempFile)) - { - return; - } - - Extract7zArchive(tempFile, fontsDirectory); - - try - { - _fileSystem.DeleteFile(tempFile); - } - catch (IOException ex) - { - // Log this, but don't let it fail the operation - _logger.LogError(ex, "Error deleting temp file {path}", tempFile); - } - } - private void Extract7zArchive(string archivePath, string targetPath) - { - _logger.LogInformation("Extracting {ArchivePath} to {TargetPath}", archivePath, targetPath); - - _zipClient.ExtractAllFrom7z(archivePath, targetPath, true); - } - - /// - /// Writes the font config file. - /// - /// The fonts directory. - /// Task. - private async Task WriteFontConfigFile(string fontsDirectory) - { - const string fontConfigFilename = "fonts.conf"; - var fontConfigFile = Path.Combine(fontsDirectory, fontConfigFilename); - - if (!_fileSystem.FileExists(fontConfigFile)) - { - var contents = string.Format("{0}ArialArial Unicode MS", fontsDirectory); - - var bytes = Encoding.UTF8.GetBytes(contents); - - using (var fileStream = _fileSystem.GetFileStream(fontConfigFile, FileOpenMode.Create, FileAccessMode.Write, - FileShareMode.Read, true)) - { - await fileStream.WriteAsync(bytes, 0, bytes.Length); - } - } - } - } -} diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 1d8cd6778..a93dd9742 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -70,13 +70,27 @@ namespace MediaBrowser.MediaEncoding.Encoder private readonly string _originalFFMpegPath; private readonly string _originalFFProbePath; private readonly int DefaultImageExtractionTimeoutMs; - private readonly bool EnableEncoderFontFile; - private readonly IEnvironmentInfo _environmentInfo; - public MediaEncoder(ILogger logger, IJsonSerializer jsonSerializer, string ffMpegPath, string ffProbePath, bool hasExternalEncoder, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILiveTvManager liveTvManager, IIsoManager isoManager, ILibraryManager libraryManager, IChannelManager channelManager, ISessionManager sessionManager, Func subtitleEncoder, Func mediaSourceManager, IHttpClient httpClient, IZipClient zipClient, IProcessFactory processFactory, + public MediaEncoder(ILogger logger, + IJsonSerializer jsonSerializer, + string ffMpegPath, + string ffProbePath, + bool hasExternalEncoder, + IServerConfigurationManager configurationManager, + IFileSystem fileSystem, + ILiveTvManager liveTvManager, + IIsoManager isoManager, + ILibraryManager libraryManager, + IChannelManager channelManager, + ISessionManager sessionManager, + Func subtitleEncoder, + Func mediaSourceManager, + IHttpClient httpClient, + IZipClient zipClient, + IProcessFactory processFactory, int defaultImageExtractionTimeoutMs, - bool enableEncoderFontFile, IEnvironmentInfo environmentInfo) + IEnvironmentInfo environmentInfo) { _logger = logger; _jsonSerializer = jsonSerializer; @@ -93,7 +107,6 @@ namespace MediaBrowser.MediaEncoding.Encoder _zipClient = zipClient; _processFactory = processFactory; DefaultImageExtractionTimeoutMs = defaultImageExtractionTimeoutMs; - EnableEncoderFontFile = enableEncoderFontFile; _environmentInfo = environmentInfo; FFProbePath = ffProbePath; FFMpegPath = ffMpegPath; @@ -177,16 +190,6 @@ namespace MediaBrowser.MediaEncoding.Encoder SetAvailableDecoders(result.decoders); SetAvailableEncoders(result.encoders); - - if (EnableEncoderFontFile) - { - var directory = FileSystem.GetDirectoryName(FFMpegPath); - - if (!string.IsNullOrWhiteSpace(directory) && FileSystem.ContainsSubPath(ConfigurationManager.ApplicationPaths.ProgramDataPath, directory)) - { - new FontConfigLoader(_httpClient, ConfigurationManager.ApplicationPaths, _logger, _zipClient, FileSystem).DownloadFonts(directory).ConfigureAwait(false); - } - } } } -- cgit v1.2.3