diff options
Diffstat (limited to 'MediaBrowser.MediaEncoding')
30 files changed, 210 insertions, 351 deletions
diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs index 557f4d637..3b6b91684 100644 --- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs +++ b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs @@ -1,11 +1,10 @@ -using BDInfo; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.MediaInfo; -using System; +using System; using System.Collections.Generic; using System.Linq; +using BDInfo; +using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; -using MediaBrowser.Model.Text; +using MediaBrowser.Model.MediaInfo; namespace MediaBrowser.MediaEncoding.BdInfo { @@ -15,12 +14,10 @@ namespace MediaBrowser.MediaEncoding.BdInfo public class BdInfoExaminer : IBlurayExaminer { private readonly IFileSystem _fileSystem; - private readonly ITextEncoding _textEncoding; - public BdInfoExaminer(IFileSystem fileSystem, ITextEncoding textEncoding) + public BdInfoExaminer(IFileSystem fileSystem) { _fileSystem = fileSystem; - _textEncoding = textEncoding; } /// <summary> @@ -32,10 +29,10 @@ namespace MediaBrowser.MediaEncoding.BdInfo { if (string.IsNullOrWhiteSpace(path)) { - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); } - var bdrom = new BDROM(path, _fileSystem, _textEncoding); + var bdrom = new BDROM(path, _fileSystem); bdrom.Scan(); @@ -44,7 +41,7 @@ namespace MediaBrowser.MediaEncoding.BdInfo var outputStream = new BlurayDiscInfo { - MediaStreams = new MediaStream[] {} + MediaStreams = new MediaStream[] { } }; if (playlist == null) @@ -190,12 +187,12 @@ namespace MediaBrowser.MediaEncoding.BdInfo private void AddSubtitleStream(List<MediaStream> streams, TSGraphicsStream textStream) { streams.Add(new MediaStream - { - Language = textStream.LanguageCode, - Codec = textStream.CodecShortName, - Type = MediaStreamType.Subtitle, - Index = streams.Count - }); + { + Language = textStream.LanguageCode, + Codec = textStream.CodecShortName, + Type = MediaStreamType.Subtitle, + Index = streams.Count + }); } } } diff --git a/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs b/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs index 16c67655a..1af4146bc 100644 --- a/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs +++ b/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs @@ -1,9 +1,7 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.Configuration; using System.Collections.Generic; using System.IO; - -using MediaBrowser.Controller.IO; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.IO; namespace MediaBrowser.MediaEncoding.Configuration diff --git a/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs index 2a874eba1..d5773fe31 100644 --- a/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs @@ -1,11 +1,11 @@ -using MediaBrowser.Controller.Configuration; +using System; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Session; +using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.IO; using Microsoft.Extensions.Logging; -using System; -using MediaBrowser.Model.Diagnostics; namespace MediaBrowser.MediaEncoding.Encoder { @@ -53,10 +53,6 @@ namespace MediaBrowser.MediaEncoding.Encoder return null; } - protected override bool IsVideoEncoder - { - get { return false; } - } - + protected override bool IsVideoEncoder => false; } } diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs index 187f350b8..ed4c445cd 100644 --- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs @@ -1,23 +1,20 @@ -using MediaBrowser.Common.Configuration; +using System; +using System.Globalization; +using System.IO; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; -using Microsoft.Extensions.Logging; using MediaBrowser.Model.MediaInfo; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Model.Diagnostics; -using MediaBrowser.Model.Dlna; +using Microsoft.Extensions.Logging; namespace MediaBrowser.MediaEncoding.Encoder { diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs index 578e9f264..262772959 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs index 9761de98f..d4040cd31 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Threading.Tasks; using MediaBrowser.Controller.Library; @@ -15,43 +15,30 @@ namespace MediaBrowser.MediaEncoding.Encoder public bool IsCancelled { get; internal set; } public Stream LogFileStream { get; set; } - public IProgress<double> Progress { get; set; } public TaskCompletionSource<bool> TaskCompletionSource; public EncodingJobOptions Options { - get { return (EncodingJobOptions) BaseRequest; } - set { BaseRequest = value; } + get => (EncodingJobOptions)BaseRequest; + set => BaseRequest = value; } - public string Id { get; set; } + public Guid Id { get; set; } - public string MimeType { get; set; } public bool EstimateContentLength { get; set; } public TranscodeSeekInfo TranscodeSeekInfo { get; set; } - public long? EncodingDurationTicks { get; set; } public string ItemType { get; set; } - public string GetMimeType(string outputPath) - { - if (!string.IsNullOrEmpty(MimeType)) - { - return MimeType; - } - - return MimeTypes.GetMimeType(outputPath); - } - private readonly ILogger _logger; private readonly IMediaSourceManager _mediaSourceManager; - public EncodingJob(ILogger logger, IMediaSourceManager mediaSourceManager) : - base(logger, mediaSourceManager, TranscodingJobType.Progressive) + public EncodingJob(ILogger logger, IMediaSourceManager mediaSourceManager) : + base(TranscodingJobType.Progressive) { _logger = logger; _mediaSourceManager = mediaSourceManager; - Id = Guid.NewGuid().ToString("N"); + Id = Guid.NewGuid(); _logger = logger; TaskCompletionSource = new TaskCompletionSource<bool>(); @@ -61,6 +48,7 @@ namespace MediaBrowser.MediaEncoding.Encoder { DisposeLiveStream(); DisposeLogStream(); + DisposeIsoMount(); } private void DisposeLogStream() @@ -95,49 +83,21 @@ namespace MediaBrowser.MediaEncoding.Encoder } } - public string OutputFilePath { get; set; } - public string ActualOutputVideoCodec + private void DisposeIsoMount() { - get + if (IsoMount != null) { - var codec = OutputVideoCodec; - - if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase)) + try { - var stream = VideoStream; - - if (stream != null) - { - return stream.Codec; - } - - return null; + IsoMount.Dispose(); } - - return codec; - } - } - - public string ActualOutputAudioCodec - { - get - { - var codec = OutputAudioCodec; - - if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase)) + catch (Exception ex) { - var stream = AudioStream; - - if (stream != null) - { - return stream.Codec; - } - - return null; + _logger.LogError("Error disposing iso mount", ex); } - return codec; + IsoMount = null; } } diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs index 4e6ee89e1..95454c447 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs @@ -1,18 +1,16 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.MediaEncoding; -using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Dlna; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; -using Microsoft.Extensions.Logging; -using MediaBrowser.Model.MediaInfo; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.MediaEncoding; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Dlna; +using MediaBrowser.Model.Entities; +using Microsoft.Extensions.Logging; namespace MediaBrowser.MediaEncoding.Encoder { @@ -25,7 +23,7 @@ namespace MediaBrowser.MediaEncoding.Encoder private readonly IMediaEncoder _mediaEncoder; protected static readonly CultureInfo UsCulture = new CultureInfo("en-US"); - + public EncodingJobFactory(ILogger logger, ILibraryManager libraryManager, IMediaSourceManager mediaSourceManager, IConfigurationManager config, IMediaEncoder mediaEncoder) { _logger = logger; @@ -255,7 +253,7 @@ namespace MediaBrowser.MediaEncoding.Encoder if (profile == null) { - // Don't use settings from the default profile. + // Don't use settings from the default profile. // Only use a specific profile if it was requested. return; } diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs index dc3cb5f5e..44e62446b 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs @@ -1,6 +1,6 @@ -using MediaBrowser.Model.MediaInfo; using System.Collections.Generic; using System.Linq; +using MediaBrowser.Model.MediaInfo; namespace MediaBrowser.MediaEncoding.Encoder { diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index a93dd9742..d9c178431 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -1,3 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Net; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Library; @@ -5,24 +15,13 @@ using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Session; using MediaBrowser.MediaEncoding.Probing; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Serialization; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Model.Configuration; -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.Net; -using MediaBrowser.Model.Diagnostics; -using MediaBrowser.Model.System; using Microsoft.Extensions.Logging; namespace MediaBrowser.MediaEncoding.Encoder @@ -70,9 +69,9 @@ namespace MediaBrowser.MediaEncoding.Encoder private readonly string _originalFFMpegPath; private readonly string _originalFFProbePath; private readonly int DefaultImageExtractionTimeoutMs; - private readonly IEnvironmentInfo _environmentInfo; - public MediaEncoder(ILogger logger, + public MediaEncoder( + ILoggerFactory loggerFactory, IJsonSerializer jsonSerializer, string ffMpegPath, string ffProbePath, @@ -89,10 +88,9 @@ namespace MediaBrowser.MediaEncoding.Encoder IHttpClient httpClient, IZipClient zipClient, IProcessFactory processFactory, - int defaultImageExtractionTimeoutMs, - IEnvironmentInfo environmentInfo) + int defaultImageExtractionTimeoutMs) { - _logger = logger; + _logger = loggerFactory.CreateLogger(nameof(MediaEncoder)); _jsonSerializer = jsonSerializer; ConfigurationManager = configurationManager; FileSystem = fileSystem; @@ -107,46 +105,13 @@ namespace MediaBrowser.MediaEncoding.Encoder _zipClient = zipClient; _processFactory = processFactory; DefaultImageExtractionTimeoutMs = defaultImageExtractionTimeoutMs; - _environmentInfo = environmentInfo; FFProbePath = ffProbePath; FFMpegPath = ffMpegPath; _originalFFProbePath = ffProbePath; _originalFFMpegPath = ffMpegPath; - _hasExternalEncoder = hasExternalEncoder; } - private readonly object _logLock = new object(); - public void SetLogFilename(string name) - { - lock (_logLock) - { - try - { - _environmentInfo.SetProcessEnvironmentVariable("FFREPORT", "file=" + name + ":level=32"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error setting FFREPORT environment variable"); - } - } - } - - public void ClearLogFilename() - { - lock (_logLock) - { - try - { - _environmentInfo.SetProcessEnvironmentVariable("FFREPORT", null); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error setting FFREPORT environment variable"); - } - } - } - public string EncoderLocationType { get @@ -246,7 +211,7 @@ namespace MediaBrowser.MediaEncoding.Encoder { if (string.IsNullOrWhiteSpace(path)) { - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); } if (!FileSystem.FileExists(path) && !FileSystem.DirectoryExists(path)) @@ -362,7 +327,7 @@ namespace MediaBrowser.MediaEncoding.Encoder private Tuple<string, string> GetPathsFromDirectory(string path) { - // Since we can't predict the file extension, first try directly within the folder + // Since we can't predict the file extension, first try directly within the folder // If that doesn't pan out, then do a recursive search var files = FileSystem.GetFilePaths(path); @@ -451,10 +416,7 @@ namespace MediaBrowser.MediaEncoding.Encoder /// Gets the encoder path. /// </summary> /// <value>The encoder path.</value> - public string EncoderPath - { - get { return FFMpegPath; } - } + public string EncoderPath => FFMpegPath; /// <summary> /// Gets the media info. @@ -496,7 +458,7 @@ namespace MediaBrowser.MediaEncoding.Encoder /// <param name="inputFiles">The input files.</param> /// <param name="protocol">The protocol.</param> /// <returns>System.String.</returns> - /// <exception cref="System.ArgumentException">Unrecognized InputType</exception> + /// <exception cref="ArgumentException">Unrecognized InputType</exception> public string GetInputArgument(string[] inputFiles, MediaProtocol protocol) { return EncodingUtils.GetInputArgument(inputFiles.ToList(), protocol); @@ -525,7 +487,7 @@ namespace MediaBrowser.MediaEncoding.Encoder CreateNoWindow = true, UseShellExecute = false, - // Must consume both or ffmpeg may hang due to deadlocks. See comments below. + // Must consume both or ffmpeg may hang due to deadlocks. See comments below. RedirectStandardOutput = true, FileName = FFProbePath, Arguments = string.Format(args, probeSizeArgument, inputPath).Trim(), @@ -642,13 +604,13 @@ namespace MediaBrowser.MediaEncoding.Encoder { if (string.IsNullOrEmpty(inputPath)) { - throw new ArgumentNullException("inputPath"); + throw new ArgumentNullException(nameof(inputPath)); } var tempExtractPath = Path.Combine(ConfigurationManager.ApplicationPaths.TempDirectory, Guid.NewGuid() + ".jpg"); FileSystem.CreateDirectory(FileSystem.GetDirectoryName(tempExtractPath)); - // apply some filters to thumbnail extracted below (below) crop any black lines that we made and get the correct ar then scale to width 600. + // apply some filters to thumbnail extracted below (below) crop any black lines that we made and get the correct ar then scale to width 600. // This filter chain may have adverse effects on recorded tv thumbnails if ar changes during presentation ex. commercials @ diff ar var vf = "scale=600:trunc(600/dar/2)*2"; @@ -676,7 +638,7 @@ namespace MediaBrowser.MediaEncoding.Encoder break; } } - + var mapArg = imageStreamIndex.HasValue ? (" -map 0:v:" + imageStreamIndex.Value.ToString(CultureInfo.InvariantCulture)) : string.Empty; var enableThumbnail = !new List<string> { "wtv" }.Contains(container ?? string.Empty, StringComparer.OrdinalIgnoreCase); @@ -1057,7 +1019,8 @@ namespace MediaBrowser.MediaEncoding.Encoder public bool CanExtractSubtitles(string codec) { - return false; + // TODO is there ever a case when a subtitle can't be extracted?? + return true; } private class ProcessWrapper : IDisposable diff --git a/MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs index 732b5bf84..bf23a73bd 100644 --- a/MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs @@ -1,14 +1,11 @@ -using MediaBrowser.Controller.Configuration; +using System; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Session; -using MediaBrowser.Model.Dlna; +using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.IO; using Microsoft.Extensions.Logging; -using System; -using System.IO; -using System.Threading.Tasks; -using MediaBrowser.Model.Diagnostics; namespace MediaBrowser.MediaEncoding.Encoder { @@ -57,10 +54,6 @@ namespace MediaBrowser.MediaEncoding.Encoder return null; } - protected override bool IsVideoEncoder - { - get { return true; } - } - + protected override bool IsVideoEncoder => true; } } diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj index d93394957..68b8bd4fa 100644 --- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj +++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj @@ -17,4 +17,9 @@ <ProjectReference Include="..\OpenSubtitlesHandler\OpenSubtitlesHandler.csproj" /> </ItemGroup> + <ItemGroup> + <PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" /> + <PackageReference Include="UTF.Unknown" Version="1.0.0-beta1" /> + </ItemGroup> + </Project> diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.nuget.targets b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.nuget.targets index e69ce0e64..f793e09bc 100644 --- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.nuget.targets +++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.nuget.targets @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8" standalone="no"?> +<?xml version="1.0" encoding="utf-8" standalone="no"?> <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Target Name="EmitMSBuildWarning" BeforeTargets="Build"> <Warning Text="Packages containing MSBuild targets and props files cannot be fully installed in projects targeting multiple frameworks. The MSBuild targets and props files have been ignored." /> diff --git a/MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs b/MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs index 396c85e21..e4eabaf38 100644 --- a/MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs +++ b/MediaBrowser.MediaEncoding/Probing/FFProbeHelpers.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; namespace MediaBrowser.MediaEncoding.Probing @@ -13,7 +13,7 @@ namespace MediaBrowser.MediaEncoding.Probing { if (result == null) { - throw new ArgumentNullException("result"); + throw new ArgumentNullException(nameof(result)); } if (result.format != null && result.format.tags != null) @@ -52,9 +52,7 @@ namespace MediaBrowser.MediaEncoding.Probing return null; } - string val; - - tags.TryGetValue(key, out val); + tags.TryGetValue(key, out var val); return val; } @@ -70,9 +68,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrEmpty(val)) { - int i; - - if (int.TryParse(val, out i)) + if (int.TryParse(val, out var i)) { return i; } @@ -93,9 +89,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrEmpty(val)) { - DateTime i; - - if (DateTime.TryParse(val, out i)) + if (DateTime.TryParse(val, out var i)) { return i.ToUniversalTime(); } diff --git a/MediaBrowser.MediaEncoding/Probing/InternalMediaInfoResult.cs b/MediaBrowser.MediaEncoding/Probing/InternalMediaInfoResult.cs index eef273250..cc9d27608 100644 --- a/MediaBrowser.MediaEncoding/Probing/InternalMediaInfoResult.cs +++ b/MediaBrowser.MediaEncoding/Probing/InternalMediaInfoResult.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; namespace MediaBrowser.MediaEncoding.Probing { @@ -149,7 +149,7 @@ namespace MediaBrowser.MediaEncoding.Probing /// </summary> /// <value>The bits_per_raw_sample.</value> public int bits_per_raw_sample { get; set; } - + /// <summary> /// Gets or sets the r_frame_rate. /// </summary> diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 5367a87f7..5099ccb2a 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -52,8 +52,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrEmpty(data.format.bit_rate)) { - int value; - if (int.TryParse(data.format.bit_rate, NumberStyles.Any, _usCulture, out value)) + if (int.TryParse(data.format.bit_rate, NumberStyles.Any, _usCulture, out var value)) { info.Bitrate = value; } @@ -132,7 +131,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrWhiteSpace(iTunEXTC)) { var parts = iTunEXTC.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); - // Example + // Example // mpaa|G|100|For crude humor if (parts.Length > 1) { @@ -300,7 +299,7 @@ namespace MediaBrowser.MediaEncoding.Probing private void ReadFromDictNode(XmlReader reader, MediaInfo info) { string currentKey = null; - List<NameValuePair> pairs = new List<NameValuePair>(); + var pairs = new List<NameValuePair>(); reader.MoveToContent(); reader.Read(); @@ -360,7 +359,7 @@ namespace MediaBrowser.MediaEncoding.Probing private List<NameValuePair> ReadValueArray(XmlReader reader) { - List<NameValuePair> pairs = new List<NameValuePair>(); + var pairs = new List<NameValuePair>(); reader.MoveToContent(); reader.Read(); @@ -423,7 +422,7 @@ namespace MediaBrowser.MediaEncoding.Probing Type = PersonType.Writer }); } - + } else if (string.Equals(key, "producers", StringComparison.OrdinalIgnoreCase)) { @@ -579,8 +578,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrEmpty(streamInfo.sample_rate)) { - int value; - if (int.TryParse(streamInfo.sample_rate, NumberStyles.Any, _usCulture, out value)) + if (int.TryParse(streamInfo.sample_rate, NumberStyles.Any, _usCulture, out var value)) { stream.SampleRate = value; } @@ -619,7 +617,7 @@ namespace MediaBrowser.MediaEncoding.Probing else if (string.Equals(stream.Codec, "mjpeg", StringComparison.OrdinalIgnoreCase)) { // How to differentiate between video and embedded image? - // The only difference I've seen thus far is presence of codec tag, also embedded images have high (unusual) framerates + // The only difference I've seen thus far is presence of codec tag, also embedded images have high (unusual) framerates if (!string.IsNullOrWhiteSpace(stream.CodecTag)) { stream.Type = MediaStreamType.Video; @@ -669,8 +667,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrEmpty(streamInfo.bit_rate)) { - int value; - if (int.TryParse(streamInfo.bit_rate, NumberStyles.Any, _usCulture, out value)) + if (int.TryParse(streamInfo.bit_rate, NumberStyles.Any, _usCulture, out var value)) { bitrate = value; } @@ -679,8 +676,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (bitrate == 0 && formatInfo != null && !string.IsNullOrEmpty(formatInfo.bit_rate) && stream.Type == MediaStreamType.Video) { // If the stream info doesn't have a bitrate get the value from the media format info - int value; - if (int.TryParse(formatInfo.bit_rate, NumberStyles.Any, _usCulture, out value)) + if (int.TryParse(formatInfo.bit_rate, NumberStyles.Any, _usCulture, out var value)) { bitrate = value; } @@ -732,9 +728,7 @@ namespace MediaBrowser.MediaEncoding.Probing return null; } - string val; - - tags.TryGetValue(key, out val); + tags.TryGetValue(key, out var val); return val; } @@ -752,13 +746,10 @@ namespace MediaBrowser.MediaEncoding.Probing { var original = info.display_aspect_ratio; - int height; - int width; - var parts = (original ?? string.Empty).Split(':'); if (!(parts.Length == 2 && - int.TryParse(parts[0], NumberStyles.Any, _usCulture, out width) && - int.TryParse(parts[1], NumberStyles.Any, _usCulture, out height) && + int.TryParse(parts[0], NumberStyles.Any, _usCulture, out var width) && + int.TryParse(parts[1], NumberStyles.Any, _usCulture, out var height) && width > 0 && height > 0)) { @@ -881,7 +872,7 @@ namespace MediaBrowser.MediaEncoding.Probing } } - private void SetSize(InternalMediaInfoResult data, Model.MediaInfo.MediaInfo info) + private void SetSize(InternalMediaInfoResult data, MediaInfo info) { if (data.format != null) { @@ -901,7 +892,7 @@ namespace MediaBrowser.MediaEncoding.Probing var composer = FFProbeHelpers.GetDictionaryValue(tags, "composer"); if (!string.IsNullOrWhiteSpace(composer)) { - List<BaseItemPerson> peoples = new List<BaseItemPerson>(); + var peoples = new List<BaseItemPerson>(); foreach (var person in Split(composer, false)) { peoples.Add(new BaseItemPerson { Name = person, Type = PersonType.Composer }); @@ -932,7 +923,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrWhiteSpace(writer)) { - List<BaseItemPerson> peoples = new List<BaseItemPerson>(); + var peoples = new List<BaseItemPerson>(); foreach (var person in Split(writer, false)) { peoples.Add(new BaseItemPerson { Name = person, Type = PersonType.Writer }); @@ -955,7 +946,7 @@ namespace MediaBrowser.MediaEncoding.Probing var artist = FFProbeHelpers.GetDictionaryValue(tags, "artist"); if (string.IsNullOrWhiteSpace(artist)) { - audio.Artists = new string[] {}; + audio.Artists = new string[] { }; } else { @@ -977,7 +968,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (string.IsNullOrWhiteSpace(albumArtist)) { - audio.AlbumArtists = new string[] {}; + audio.AlbumArtists = new string[] { }; } else { @@ -1054,7 +1045,7 @@ namespace MediaBrowser.MediaEncoding.Probing /// <returns>System.String[][].</returns> private IEnumerable<string> Split(string val, bool allowCommaDelimiter) { - // Only use the comma as a delimeter if there are no slashes or pipes. + // Only use the comma as a delimeter if there are no slashes or pipes. // We want to be careful not to split names that have commas in them var delimeter = !allowCommaDelimiter || _nameDelimiters.Any(i => val.IndexOf(i) != -1) ? _nameDelimiters : @@ -1125,7 +1116,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrEmpty(val)) { var studios = Split(val, true); - List<string> studioList = new List<string>(); + var studioList = new List<string>(); foreach (var studio in studios) { @@ -1160,7 +1151,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrEmpty(val)) { - List<string> genres = new List<string>(info.Genres); + var genres = new List<string>(info.Genres); foreach (var genre in Split(val, true)) { genres.Add(genre); @@ -1187,9 +1178,7 @@ namespace MediaBrowser.MediaEncoding.Probing { disc = disc.Split('/')[0]; - int num; - - if (int.TryParse(disc, out num)) + if (int.TryParse(disc, out var num)) { return num; } @@ -1204,8 +1193,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (chapter.tags != null) { - string name; - if (chapter.tags.TryGetValue("title", out name)) + if (chapter.tags.TryGetValue("title", out string name)) { info.Name = name; } @@ -1213,9 +1201,8 @@ namespace MediaBrowser.MediaEncoding.Probing // Limit accuracy to milliseconds to match xml saving var secondsString = chapter.start_time; - double seconds; - if (double.TryParse(secondsString, NumberStyles.Any, CultureInfo.InvariantCulture, out seconds)) + if (double.TryParse(secondsString, NumberStyles.Any, CultureInfo.InvariantCulture, out var seconds)) { var ms = Math.Round(TimeSpan.FromSeconds(seconds).TotalMilliseconds); info.StartPositionTicks = TimeSpan.FromMilliseconds(ms).Ticks; @@ -1269,9 +1256,7 @@ namespace MediaBrowser.MediaEncoding.Probing var year = FFProbeHelpers.GetDictionaryValue(data.format.tags, "WM/OriginalReleaseTime"); if (!string.IsNullOrWhiteSpace(year)) { - int val; - - if (int.TryParse(year, NumberStyles.Integer, _usCulture, out val)) + if (int.TryParse(year, NumberStyles.Integer, _usCulture, out var val)) { video.ProductionYear = val; } @@ -1280,11 +1265,9 @@ namespace MediaBrowser.MediaEncoding.Probing var premiereDateString = FFProbeHelpers.GetDictionaryValue(data.format.tags, "WM/MediaOriginalBroadcastDateTime"); if (!string.IsNullOrWhiteSpace(premiereDateString)) { - DateTime val; - // Credit to MCEBuddy: https://mcebuddy2x.codeplex.com/ // DateTime is reported along with timezone info (typically Z i.e. UTC hence assume None) - if (DateTime.TryParse(year, null, DateTimeStyles.None, out val)) + if (DateTime.TryParse(year, null, DateTimeStyles.None, out var val)) { video.PremiereDate = val.ToUniversalTime(); } @@ -1301,7 +1284,7 @@ namespace MediaBrowser.MediaEncoding.Probing // OR -> COMMENT. SUBTITLE: DESCRIPTION // e.g. -> 4/13. The Doctor's Wife: Science fiction drama. When he follows a Time Lord distress signal, the Doctor puts Amy, Rory and his beloved TARDIS in grave danger. Also in HD. [AD,S] // e.g. -> CBeebies Bedtime Hour. The Mystery: Animated adventures of two friends who live on an island in the middle of the big city. Some of Abney and Teal's favourite objects are missing. [S] - if (String.IsNullOrWhiteSpace(subTitle) && !String.IsNullOrWhiteSpace(description) && description.Substring(0, Math.Min(description.Length, MaxSubtitleDescriptionExtractionLength)).Contains(":")) // Check within the Subtitle size limit, otherwise from description it can get too long creating an invalid filename + if (string.IsNullOrWhiteSpace(subTitle) && !string.IsNullOrWhiteSpace(description) && description.Substring(0, Math.Min(description.Length, MaxSubtitleDescriptionExtractionLength)).Contains(":")) // Check within the Subtitle size limit, otherwise from description it can get too long creating an invalid filename { string[] parts = description.Split(':'); if (parts.Length > 0) @@ -1315,7 +1298,7 @@ namespace MediaBrowser.MediaEncoding.Probing video.IndexNumber = int.Parse(numbers[0].Replace(".", "").Split('/')[0]); int totalEpisodesInSeason = int.Parse(numbers[0].Replace(".", "").Split('/')[1]); - description = String.Join(" ", numbers, 1, numbers.Length - 1).Trim(); // Skip the first, concatenate the rest, clean up spaces and save it + description = string.Join(" ", numbers, 1, numbers.Length - 1).Trim(); // Skip the first, concatenate the rest, clean up spaces and save it } else throw new Exception(); // Switch to default parsing @@ -1323,7 +1306,7 @@ namespace MediaBrowser.MediaEncoding.Probing catch // Default parsing { if (subtitle.Contains(".")) // skip the comment, keep the subtitle - description = String.Join(".", subtitle.Split('.'), 1, subtitle.Split('.').Length - 1).Trim(); // skip the first + description = string.Join(".", subtitle.Split('.'), 1, subtitle.Split('.').Length - 1).Trim(); // skip the first else description = subtitle.Trim(); // Clean up whitespaces and save it } diff --git a/MediaBrowser.MediaEncoding/Properties/AssemblyInfo.cs b/MediaBrowser.MediaEncoding/Properties/AssemblyInfo.cs index 53f4eb403..6ecdf89bc 100644 --- a/MediaBrowser.MediaEncoding/Properties/AssemblyInfo.cs +++ b/MediaBrowser.MediaEncoding/Properties/AssemblyInfo.cs @@ -1,33 +1,21 @@ -using System.Reflection; +using System.Reflection; +using System.Resources; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("MediaBrowser.MediaEncoding")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MediaBrowser.MediaEncoding")] -[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyCompany("Jellyfin Project")] +[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")] +[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] +[assembly: NeutralResourcesLanguage("en")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("05f49ab9-2a90-4332-9d41-7817a9cccd90")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")]
\ No newline at end of file diff --git a/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs b/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs index 71fefba44..605504418 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/AssParser.cs @@ -1,4 +1,3 @@ -using MediaBrowser.Model.Extensions; using System; using System.Collections.Generic; using System.Globalization; @@ -6,6 +5,7 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Threading; +using MediaBrowser.Model.Extensions; using MediaBrowser.Model.MediaInfo; namespace MediaBrowser.MediaEncoding.Subtitles @@ -17,26 +17,26 @@ namespace MediaBrowser.MediaEncoding.Subtitles public SubtitleTrackInfo Parse(Stream stream, CancellationToken cancellationToken) { var trackInfo = new SubtitleTrackInfo(); - List<SubtitleTrackEvent> trackEvents = new List<SubtitleTrackEvent>(); + var trackEvents = new List<SubtitleTrackEvent>(); var eventIndex = 1; using (var reader = new StreamReader(stream)) { string line; while (reader.ReadLine() != "[Events]") - {} + { } var headers = ParseFieldHeaders(reader.ReadLine()); while ((line = reader.ReadLine()) != null) { cancellationToken.ThrowIfCancellationRequested(); - + if (string.IsNullOrWhiteSpace(line)) { continue; } - if(line.StartsWith("[")) + if (line.StartsWith("[")) break; - if(string.IsNullOrEmpty(line)) + if (string.IsNullOrEmpty(line)) continue; var subEvent = new SubtitleTrackEvent { Id = eventIndex.ToString(_usCulture) }; eventIndex++; @@ -49,7 +49,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles RemoteNativeFormatting(subEvent); subEvent.Text = subEvent.Text.Replace("\\n", ParserValues.NewLine, StringComparison.OrdinalIgnoreCase); - + subEvent.Text = Regex.Replace(subEvent.Text, @"\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}", string.Empty, RegexOptions.IgnoreCase); trackEvents.Add(subEvent); @@ -61,13 +61,13 @@ namespace MediaBrowser.MediaEncoding.Subtitles long GetTicks(string time) { - TimeSpan span; - return TimeSpan.TryParseExact(time, @"h\:mm\:ss\.ff", _usCulture, out span) - ? span.Ticks: 0; + return TimeSpan.TryParseExact(time, @"h\:mm\:ss\.ff", _usCulture, out var span) + ? span.Ticks : 0; } - private Dictionary<string,int> ParseFieldHeaders(string line) { - var fields = line.Substring(8).Split(',').Select(x=>x.Trim()).ToList(); + private Dictionary<string, int> ParseFieldHeaders(string line) + { + var fields = line.Substring(8).Split(',').Select(x => x.Trim()).ToList(); var result = new Dictionary<string, int> { {"Start", fields.IndexOf("Start")}, diff --git a/MediaBrowser.MediaEncoding/Subtitles/ConfigurationExtension.cs b/MediaBrowser.MediaEncoding/Subtitles/ConfigurationExtension.cs index 973c653a4..92544f4f6 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/ConfigurationExtension.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/ConfigurationExtension.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using MediaBrowser.Common.Configuration; using MediaBrowser.Model.Providers; diff --git a/MediaBrowser.MediaEncoding/Subtitles/ISubtitleParser.cs b/MediaBrowser.MediaEncoding/Subtitles/ISubtitleParser.cs index 75de81f46..f0d107196 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/ISubtitleParser.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/ISubtitleParser.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using System.Threading; using MediaBrowser.Model.MediaInfo; diff --git a/MediaBrowser.MediaEncoding/Subtitles/ISubtitleWriter.cs b/MediaBrowser.MediaEncoding/Subtitles/ISubtitleWriter.cs index e28da9185..3401c2d67 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/ISubtitleWriter.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/ISubtitleWriter.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using System.Threading; using MediaBrowser.Model.MediaInfo; diff --git a/MediaBrowser.MediaEncoding/Subtitles/JsonWriter.cs b/MediaBrowser.MediaEncoding/Subtitles/JsonWriter.cs index 474f712f9..8995fcfe1 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/JsonWriter.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/JsonWriter.cs @@ -1,8 +1,8 @@ -using MediaBrowser.Model.MediaInfo; -using MediaBrowser.Model.Serialization; using System.IO; using System.Text; using System.Threading; +using MediaBrowser.Model.MediaInfo; +using MediaBrowser.Model.Serialization; namespace MediaBrowser.MediaEncoding.Subtitles { diff --git a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs index b62fa8398..a1d925881 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -83,10 +83,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles return _encryption.DecryptString(password.Substring(2)); } - public string Name - { - get { return "Open Subtitles"; } - } + public string Name => "Open Subtitles"; private SubtitleOptions GetOptions() { @@ -121,7 +118,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles { if (string.IsNullOrWhiteSpace(id)) { - throw new ArgumentNullException("id"); + throw new ArgumentNullException(nameof(id)); } var idParts = id.Split(new[] { '-' }, 3); diff --git a/MediaBrowser.MediaEncoding/Subtitles/ParserValues.cs b/MediaBrowser.MediaEncoding/Subtitles/ParserValues.cs index b8c2fef1e..bf8808eb8 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/ParserValues.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/ParserValues.cs @@ -1,4 +1,4 @@ -namespace MediaBrowser.MediaEncoding.Subtitles +namespace MediaBrowser.MediaEncoding.Subtitles { public class ParserValues { diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs index 7ca8aa1fd..0606dbdb2 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs @@ -1,12 +1,12 @@ -using MediaBrowser.Model.Extensions; -using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text.RegularExpressions; using System.Threading; +using MediaBrowser.Model.Extensions; using MediaBrowser.Model.MediaInfo; +using Microsoft.Extensions.Logging; namespace MediaBrowser.MediaEncoding.Subtitles { @@ -24,8 +24,8 @@ namespace MediaBrowser.MediaEncoding.Subtitles public SubtitleTrackInfo Parse(Stream stream, CancellationToken cancellationToken) { var trackInfo = new SubtitleTrackInfo(); - List<SubtitleTrackEvent> trackEvents = new List<SubtitleTrackEvent>(); - using ( var reader = new StreamReader(stream)) + var trackEvents = new List<SubtitleTrackEvent>(); + using (var reader = new StreamReader(stream)) { string line; while ((line = reader.ReadLine()) != null) @@ -36,14 +36,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles { continue; } - var subEvent = new SubtitleTrackEvent {Id = line}; + var subEvent = new SubtitleTrackEvent { Id = line }; line = reader.ReadLine(); if (string.IsNullOrWhiteSpace(line)) { continue; } - + var time = Regex.Split(line, @"[\t ]*-->[\t ]*"); if (time.Length < 2) @@ -81,11 +81,11 @@ namespace MediaBrowser.MediaEncoding.Subtitles return trackInfo; } - long GetTicks(string time) { - TimeSpan span; - return TimeSpan.TryParseExact(time, @"hh\:mm\:ss\.fff", _usCulture, out span) + long GetTicks(string time) + { + return TimeSpan.TryParseExact(time, @"hh\:mm\:ss\.fff", _usCulture, out var span) ? span.Ticks - : (TimeSpan.TryParseExact(time, @"hh\:mm\:ss\,fff", _usCulture, out span) + : (TimeSpan.TryParseExact(time, @"hh\:mm\:ss\,fff", _usCulture, out span) ? span.Ticks : 0); } } diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs index c05929fde..6f96a641e 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SrtWriter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.IO; using System.Text; diff --git a/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs index a2cee7793..2c18a02ef 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs @@ -1,10 +1,10 @@ -using MediaBrowser.Model.Extensions; using System; +using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; +using MediaBrowser.Model.Extensions; using MediaBrowser.Model.MediaInfo; -using System.Collections.Generic; namespace MediaBrowser.MediaEncoding.Subtitles { @@ -16,7 +16,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles public SubtitleTrackInfo Parse(Stream stream, CancellationToken cancellationToken) { var trackInfo = new SubtitleTrackInfo(); - List<SubtitleTrackEvent> trackEvents = new List<SubtitleTrackEvent>(); + var trackEvents = new List<SubtitleTrackEvent>(); using (var reader = new StreamReader(stream)) { @@ -129,10 +129,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles } } } - } - + } + //if (header.Length > 0) - //subtitle.Header = header.ToString(); + //subtitle.Header = header.ToString(); //subtitle.Renumber(1); } @@ -288,8 +288,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles private static bool IsInteger(string s) { - int i; - if (int.TryParse(s, out i)) + if (int.TryParse(s, out var i)) return true; return false; } diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index 68faffa91..59a624433 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Concurrent; using System.Globalization; using System.IO; @@ -12,14 +12,14 @@ using MediaBrowser.Common.Net; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; -using MediaBrowser.Model.IO; using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.IO; using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.Text; using Microsoft.Extensions.Logging; +using UtfUnknown; namespace MediaBrowser.MediaEncoding.Subtitles { @@ -34,22 +34,20 @@ namespace MediaBrowser.MediaEncoding.Subtitles private readonly IHttpClient _httpClient; private readonly IMediaSourceManager _mediaSourceManager; private readonly IProcessFactory _processFactory; - private readonly ITextEncoding _textEncoding; public SubtitleEncoder( ILibraryManager libraryManager, - ILogger logger, + ILoggerFactory loggerFactory, IApplicationPaths appPaths, IFileSystem fileSystem, IMediaEncoder mediaEncoder, IJsonSerializer json, IHttpClient httpClient, IMediaSourceManager mediaSourceManager, - IProcessFactory processFactory, - ITextEncoding textEncoding) + IProcessFactory processFactory) { _libraryManager = libraryManager; - _logger = logger; + _logger = loggerFactory.CreateLogger(nameof(SubtitleEncoder)); _appPaths = appPaths; _fileSystem = fileSystem; _mediaEncoder = mediaEncoder; @@ -57,22 +55,15 @@ namespace MediaBrowser.MediaEncoding.Subtitles _httpClient = httpClient; _mediaSourceManager = mediaSourceManager; _processFactory = processFactory; - _textEncoding = textEncoding; } - private string SubtitleCachePath - { - get - { - return Path.Combine(_appPaths.DataPath, "subtitles"); - } - } + private string SubtitleCachePath => Path.Combine(_appPaths.DataPath, "subtitles"); private Stream ConvertSubtitles(Stream stream, string inputFormat, string outputFormat, long startTimeTicks, - long? endTimeTicks, + long endTimeTicks, bool preserveOriginalTimestamps, CancellationToken cancellationToken) { @@ -100,19 +91,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles return ms; } - private void FilterEvents(SubtitleTrackInfo track, long startPositionTicks, long? endTimeTicks, bool preserveTimestamps) + private void FilterEvents(SubtitleTrackInfo track, long startPositionTicks, long endTimeTicks, bool preserveTimestamps) { // Drop subs that are earlier than what we're looking for track.TrackEvents = track.TrackEvents .SkipWhile(i => (i.StartPositionTicks - startPositionTicks) < 0 || (i.EndPositionTicks - startPositionTicks) < 0) .ToArray(); - if (endTimeTicks.HasValue) + if (endTimeTicks > 0) { - long endTime = endTimeTicks.Value; - track.TrackEvents = track.TrackEvents - .TakeWhile(i => i.StartPositionTicks <= endTime) + .TakeWhile(i => i.StartPositionTicks <= endTimeTicks) .ToArray(); } @@ -130,11 +119,11 @@ namespace MediaBrowser.MediaEncoding.Subtitles { if (item == null) { - throw new ArgumentNullException("item"); + throw new ArgumentNullException(nameof(item)); } if (string.IsNullOrWhiteSpace(mediaSourceId)) { - throw new ArgumentNullException("mediaSourceId"); + throw new ArgumentNullException(nameof(mediaSourceId)); } // TODO network path substition useful ? @@ -202,13 +191,15 @@ namespace MediaBrowser.MediaEncoding.Subtitles { var bytes = await GetBytes(path, protocol, cancellationToken).ConfigureAwait(false); - var charset = _textEncoding.GetDetectedEncodingName(bytes, bytes.Length, language, true); - _logger.LogDebug("charset {0} detected for {1}", charset ?? "null", path); + var charset = CharsetDetector.DetectFromBytes(bytes).Detected?.EncodingName; + _logger.LogDebug("charset {CharSet} detected for {Path}", charset ?? "null", path); if (!string.IsNullOrEmpty(charset)) { + // Make sure we have all the code pages we can get + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); using (var inputStream = new MemoryStream(bytes)) - using (var reader = new StreamReader(inputStream, _textEncoding.GetEncodingFromCharset(charset))) + using (var reader = new StreamReader(inputStream, Encoding.GetEncoding(charset))) { var text = await reader.ReadToEndAsync().ConfigureAwait(false); @@ -300,7 +291,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles { if (string.IsNullOrEmpty(format)) { - throw new ArgumentNullException("format"); + throw new ArgumentNullException(nameof(format)); } if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase)) @@ -328,7 +319,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles { if (string.IsNullOrEmpty(format)) { - throw new ArgumentNullException("format"); + throw new ArgumentNullException(nameof(format)); } if (string.Equals(format, "json", StringComparison.OrdinalIgnoreCase)) @@ -414,7 +405,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles /// <param name="outputPath">The output path.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> - /// <exception cref="System.ArgumentNullException"> + /// <exception cref="ArgumentNullException"> /// inputPath /// or /// outputPath @@ -423,12 +414,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles { if (string.IsNullOrEmpty(inputPath)) { - throw new ArgumentNullException("inputPath"); + throw new ArgumentNullException(nameof(inputPath)); } if (string.IsNullOrEmpty(outputPath)) { - throw new ArgumentNullException("outputPath"); + throw new ArgumentNullException(nameof(outputPath)); } _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(outputPath)); @@ -531,7 +522,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles /// <param name="outputPath">The output path.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> - /// <exception cref="System.ArgumentException">Must use inputPath list overload</exception> + /// <exception cref="ArgumentException">Must use inputPath list overload</exception> private async Task ExtractTextSubtitle( string[] inputFiles, MediaProtocol protocol, @@ -566,12 +557,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles { if (string.IsNullOrEmpty(inputPath)) { - throw new ArgumentNullException("inputPath"); + throw new ArgumentNullException(nameof(inputPath)); } if (string.IsNullOrEmpty(outputPath)) { - throw new ArgumentNullException("outputPath"); + throw new ArgumentNullException(nameof(outputPath)); } _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(outputPath)); @@ -729,7 +720,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles { var bytes = await GetBytes(path, protocol, cancellationToken).ConfigureAwait(false); - var charset = _textEncoding.GetDetectedEncodingName(bytes, bytes.Length, language, true); + var charset = CharsetDetector.DetectFromBytes(bytes).Detected?.EncodingName; _logger.LogDebug("charset {0} detected for {Path}", charset ?? "null", path); @@ -740,7 +731,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles { if (protocol == MediaProtocol.Http) { - HttpRequestOptions opts = new HttpRequestOptions() + var opts = new HttpRequestOptions() { Url = path, CancellationToken = cancellationToken @@ -759,7 +750,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles return _fileSystem.ReadAllBytes(path); } - throw new ArgumentOutOfRangeException("protocol"); + throw new ArgumentOutOfRangeException(nameof(protocol)); } } } diff --git a/MediaBrowser.MediaEncoding/Subtitles/TtmlWriter.cs b/MediaBrowser.MediaEncoding/Subtitles/TtmlWriter.cs index c32005f89..cdaf94964 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/TtmlWriter.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/TtmlWriter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text; using System.Text.RegularExpressions; @@ -45,7 +45,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles writer.WriteLine("</div>"); writer.WriteLine("</body>"); - + writer.WriteLine("</tt>"); } } diff --git a/MediaBrowser.MediaEncoding/Subtitles/VttWriter.cs b/MediaBrowser.MediaEncoding/Subtitles/VttWriter.cs index 092add992..2e328ba63 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/VttWriter.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/VttWriter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text; using System.Text.RegularExpressions; @@ -19,8 +19,8 @@ namespace MediaBrowser.MediaEncoding.Subtitles { cancellationToken.ThrowIfCancellationRequested(); - TimeSpan startTime = TimeSpan.FromTicks(trackEvent.StartPositionTicks); - TimeSpan endTime = TimeSpan.FromTicks(trackEvent.EndPositionTicks); + var startTime = TimeSpan.FromTicks(trackEvent.StartPositionTicks); + var endTime = TimeSpan.FromTicks(trackEvent.EndPositionTicks); // make sure the start and end times are different and seqential if (endTime.TotalMilliseconds <= startTime.TotalMilliseconds) diff --git a/MediaBrowser.MediaEncoding/packages.config b/MediaBrowser.MediaEncoding/packages.config index 6b8deb9c9..bbeaf5f00 100644 --- a/MediaBrowser.MediaEncoding/packages.config +++ b/MediaBrowser.MediaEncoding/packages.config @@ -1,3 +1,3 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <packages> </packages>
\ No newline at end of file |
