aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding/Subtitles
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.MediaEncoding/Subtitles')
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs18
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs4
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs48
3 files changed, 34 insertions, 36 deletions
diff --git a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs
index 3954897ca..2d29f29e3 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs
@@ -15,9 +15,9 @@ using MediaBrowser.Controller.Subtitles;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
+using Microsoft.Extensions.Logging;
using OpenSubtitlesHandler;
namespace MediaBrowser.MediaEncoding.Subtitles
@@ -34,9 +34,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles
private readonly IJsonSerializer _json;
private readonly IFileSystem _fileSystem;
- public OpenSubtitleDownloader(ILogManager logManager, IHttpClient httpClient, IServerConfigurationManager config, IEncryptionManager encryption, IJsonSerializer json, IFileSystem fileSystem)
+ public OpenSubtitleDownloader(ILoggerFactory loggerFactory, IHttpClient httpClient, IServerConfigurationManager config, IEncryptionManager encryption, IJsonSerializer json, IFileSystem fileSystem)
{
- _logger = logManager.GetLogger(GetType().Name);
+ _logger = loggerFactory.CreateLogger(GetType().Name);
_httpClient = httpClient;
_config = config;
_encryption = encryption;
@@ -208,7 +208,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var result = OpenSubtitles.GetSubLanguages("en");
if (!(result is MethodResponseGetSubLanguages))
{
- _logger.Error("Invalid response type");
+ _logger.LogError("Invalid response type");
return new List<NameIdPair>();
}
@@ -243,19 +243,19 @@ namespace MediaBrowser.MediaEncoding.Subtitles
case VideoContentType.Episode:
if (!request.IndexNumber.HasValue || !request.ParentIndexNumber.HasValue || string.IsNullOrEmpty(request.SeriesName))
{
- _logger.Debug("Episode information missing");
+ _logger.LogDebug("Episode information missing");
return new List<RemoteSubtitleInfo>();
}
break;
case VideoContentType.Movie:
if (string.IsNullOrEmpty(request.Name))
{
- _logger.Debug("Movie name missing");
+ _logger.LogDebug("Movie name missing");
return new List<RemoteSubtitleInfo>();
}
if (string.IsNullOrWhiteSpace(imdbIdText) || !long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId))
{
- _logger.Debug("Imdb id missing");
+ _logger.LogDebug("Imdb id missing");
return new List<RemoteSubtitleInfo>();
}
break;
@@ -263,7 +263,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
if (string.IsNullOrEmpty(request.MediaPath))
{
- _logger.Debug("Path Missing");
+ _logger.LogDebug("Path Missing");
return new List<RemoteSubtitleInfo>();
}
@@ -300,7 +300,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var result = await OpenSubtitles.SearchSubtitlesAsync(parms.ToArray(), cancellationToken).ConfigureAwait(false);
if (!(result is MethodResponseSubtitleSearch))
{
- _logger.Error("Invalid response type");
+ _logger.LogError("Invalid response type");
return new List<RemoteSubtitleInfo>();
}
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs
index de6d7bc72..7ca8aa1fd 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs
@@ -1,5 +1,5 @@
using MediaBrowser.Model.Extensions;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -50,7 +50,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
// This occurs when subtitle text has an empty line as part of the text.
// Need to adjust the break statement below to resolve this.
- _logger.Warn("Unrecognized line in srt: {0}", line);
+ _logger.LogWarning("Unrecognized line in srt: {0}", line);
continue;
}
subEvent.StartPositionTicks = GetTicks(time[0]);
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs
index d565ff3e2..43f775392 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs
@@ -5,7 +5,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
using System;
@@ -190,7 +190,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var bytes = await GetBytes(path, protocol, cancellationToken).ConfigureAwait(false);
var charset = _textEncoding.GetDetectedEncodingName(bytes, bytes.Length, language, true);
- _logger.Debug("charset {0} detected for {1}", charset ?? "null", path);
+ _logger.LogDebug("charset {0} detected for {1}", charset ?? "null", path);
if (!string.IsNullOrEmpty(charset))
{
@@ -423,7 +423,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
ErrorDialog = false
});
- _logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ _logger.LogInformation("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
try
{
@@ -431,7 +431,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
}
catch (Exception ex)
{
- _logger.ErrorException("Error starting ffmpeg", ex);
+ _logger.LogError(ex, "Error starting ffmpeg");
throw;
}
@@ -442,13 +442,13 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
try
{
- _logger.Info("Killing ffmpeg subtitle conversion process");
+ _logger.LogInformation("Killing ffmpeg subtitle conversion process");
process.Kill();
}
catch (Exception ex)
{
- _logger.ErrorException("Error killing subtitle conversion process", ex);
+ _logger.LogError(ex, "Error killing subtitle conversion process");
}
}
@@ -466,12 +466,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
try
{
- _logger.Info("Deleting converted subtitle due to failure: ", outputPath);
+ _logger.LogInformation("Deleting converted subtitle due to failure: ", outputPath);
_fileSystem.DeleteFile(outputPath);
}
catch (IOException ex)
{
- _logger.ErrorException("Error deleting converted subtitle {0}", ex, outputPath);
+ _logger.LogError(ex, "Error deleting converted subtitle {0}", outputPath);
}
}
}
@@ -484,13 +484,13 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
var msg = string.Format("ffmpeg subtitle conversion failed for {0}", inputPath);
- _logger.Error(msg);
+ _logger.LogError(msg);
throw new Exception(msg);
}
await SetAssFont(outputPath).ConfigureAwait(false);
- _logger.Info("ffmpeg subtitle conversion succeeded for {0}", inputPath);
+ _logger.LogInformation("ffmpeg subtitle conversion succeeded for {0}", inputPath);
}
/// <summary>
@@ -553,7 +553,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
ErrorDialog = false
});
- _logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ _logger.LogInformation("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
try
{
@@ -561,7 +561,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
}
catch (Exception ex)
{
- _logger.ErrorException("Error starting ffmpeg", ex);
+ _logger.LogError(ex, "Error starting ffmpeg");
throw;
}
@@ -572,13 +572,13 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
try
{
- _logger.Info("Killing ffmpeg subtitle extraction process");
+ _logger.LogInformation("Killing ffmpeg subtitle extraction process");
process.Kill();
}
catch (Exception ex)
{
- _logger.ErrorException("Error killing subtitle extraction process", ex);
+ _logger.LogError(ex, "Error killing subtitle extraction process");
}
}
@@ -594,7 +594,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
try
{
- _logger.Info("Deleting extracted subtitle due to failure: {0}", outputPath);
+ _logger.LogInformation("Deleting extracted subtitle due to failure: {0}", outputPath);
_fileSystem.DeleteFile(outputPath);
}
catch (FileNotFoundException)
@@ -603,7 +603,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
}
catch (IOException ex)
{
- _logger.ErrorException("Error deleting extracted subtitle {0}", ex, outputPath);
+ _logger.LogError(ex, "Error deleting extracted subtitle {0}", outputPath);
}
}
else if (!_fileSystem.FileExists(outputPath))
@@ -615,7 +615,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
var msg = string.Format("ffmpeg subtitle extraction failed for {0} to {1}", inputPath, outputPath);
- _logger.Error(msg);
+ _logger.LogError(msg);
throw new Exception(msg);
}
@@ -623,7 +623,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
var msg = string.Format("ffmpeg subtitle extraction completed for {0} to {1}", inputPath, outputPath);
- _logger.Info(msg);
+ _logger.LogInformation(msg);
}
if (string.Equals(outputCodec, "ass", StringComparison.OrdinalIgnoreCase))
@@ -639,7 +639,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
/// <returns>Task.</returns>
private async Task SetAssFont(string file)
{
- _logger.Info("Setting ass font within {0}", file);
+ _logger.LogInformation("Setting ass font within {0}", file);
string text;
Encoding encoding;
@@ -659,11 +659,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles
if (!string.Equals(text, newText))
{
using (var fileStream = _fileSystem.GetFileStream(file, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
+ using (var writer = new StreamWriter(fileStream, encoding))
{
- using (var writer = new StreamWriter(fileStream, encoding))
- {
- writer.Write(newText);
- }
+ writer.Write(newText);
}
}
}
@@ -698,7 +696,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var charset = _textEncoding.GetDetectedEncodingName(bytes, bytes.Length, language, true);
- _logger.Debug("charset {0} detected for {1}", charset ?? "null", path);
+ _logger.LogDebug("charset {0} detected for {1}", charset ?? "null", path);
return charset;
}
@@ -730,4 +728,4 @@ namespace MediaBrowser.MediaEncoding.Subtitles
}
}
-} \ No newline at end of file
+}