mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-03 14:28:46 +01:00
Add some analyzers to MediaBrowser.MediaEncoding
This commit is contained in:
@@ -25,7 +25,8 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
{
|
||||
string line;
|
||||
while (reader.ReadLine() != "[Events]")
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
var headers = ParseFieldHeaders(reader.ReadLine());
|
||||
|
||||
@@ -75,17 +76,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
{
|
||||
var fields = line.Substring(8).Split(',').Select(x => x.Trim()).ToList();
|
||||
|
||||
var result = new Dictionary<string, int> {
|
||||
{"Start", fields.IndexOf("Start")},
|
||||
{"End", fields.IndexOf("End")},
|
||||
{"Text", fields.IndexOf("Text")}
|
||||
};
|
||||
return result;
|
||||
return new Dictionary<string, int>
|
||||
{
|
||||
{ "Start", fields.IndexOf("Start") },
|
||||
{ "End", fields.IndexOf("End") },
|
||||
{ "Text", fields.IndexOf("Text") }
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Credit: https://github.com/SubtitleEdit/subtitleedit/blob/master/src/Logic/SubtitleFormats/AdvancedSubStationAlpha.cs
|
||||
/// </summary>
|
||||
private void RemoteNativeFormatting(SubtitleTrackEvent p)
|
||||
{
|
||||
int indexOfBegin = p.Text.IndexOf('{');
|
||||
|
||||
@@ -8,7 +8,7 @@ using MediaBrowser.Model.MediaInfo;
|
||||
namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
{
|
||||
/// <summary>
|
||||
/// Credit to https://github.com/SubtitleEdit/subtitleedit/blob/a299dc4407a31796364cc6ad83f0d3786194ba22/src/Logic/SubtitleFormats/SubStationAlpha.cs
|
||||
/// <see href="https://github.com/SubtitleEdit/subtitleedit/blob/a299dc4407a31796364cc6ad83f0d3786194ba22/src/Logic/SubtitleFormats/SubStationAlpha.cs">Credit</see>.
|
||||
/// </summary>
|
||||
public class SsaParser : ISubtitleParser
|
||||
{
|
||||
@@ -179,10 +179,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
{
|
||||
// h:mm:ss.cc
|
||||
string[] timeCode = time.Split(':', '.');
|
||||
return new TimeSpan(0, int.Parse(timeCode[0]),
|
||||
int.Parse(timeCode[1]),
|
||||
int.Parse(timeCode[2]),
|
||||
int.Parse(timeCode[3]) * 10).Ticks;
|
||||
return new TimeSpan(
|
||||
0,
|
||||
int.Parse(timeCode[0]),
|
||||
int.Parse(timeCode[1]),
|
||||
int.Parse(timeCode[2]),
|
||||
int.Parse(timeCode[3]) * 10).Ticks;
|
||||
}
|
||||
|
||||
private static string GetFormattedText(string text)
|
||||
@@ -282,6 +284,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
{
|
||||
text = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + ">");
|
||||
}
|
||||
|
||||
int indexOfEndTag = text.IndexOf("{\\c}", start);
|
||||
if (indexOfEndTag > 0)
|
||||
{
|
||||
@@ -320,6 +323,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
{
|
||||
text = text.Insert(start, "<font color=\"" + color + "\"" + extraTags + ">");
|
||||
}
|
||||
|
||||
text += "</font>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IMediaSourceManager _mediaSourceManager;
|
||||
|
||||
/// <summary>
|
||||
/// The _semaphoreLocks.
|
||||
/// </summary>
|
||||
private readonly ConcurrentDictionary<string, SemaphoreSlim> _semaphoreLocks =
|
||||
new ConcurrentDictionary<string, SemaphoreSlim>();
|
||||
|
||||
public SubtitleEncoder(
|
||||
ILibraryManager libraryManager,
|
||||
ILogger<SubtitleEncoder> logger,
|
||||
@@ -269,25 +275,6 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
return new SubtitleInfo(subtitleStream.Path, protocol, currentFormat, true);
|
||||
}
|
||||
|
||||
private struct SubtitleInfo
|
||||
{
|
||||
public SubtitleInfo(string path, MediaProtocol protocol, string format, bool isExternal)
|
||||
{
|
||||
Path = path;
|
||||
Protocol = protocol;
|
||||
Format = format;
|
||||
IsExternal = isExternal;
|
||||
}
|
||||
|
||||
public string Path { get; set; }
|
||||
|
||||
public MediaProtocol Protocol { get; set; }
|
||||
|
||||
public string Format { get; set; }
|
||||
|
||||
public bool IsExternal { get; set; }
|
||||
}
|
||||
|
||||
private ISubtitleParser GetReader(string format, bool throwIfMissing)
|
||||
{
|
||||
if (string.IsNullOrEmpty(format))
|
||||
@@ -360,12 +347,6 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
throw new ArgumentException("Unsupported format: " + format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The _semaphoreLocks.
|
||||
/// </summary>
|
||||
private readonly ConcurrentDictionary<string, SemaphoreSlim> _semaphoreLocks =
|
||||
new ConcurrentDictionary<string, SemaphoreSlim>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lock.
|
||||
/// </summary>
|
||||
@@ -414,7 +395,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// The <c>inputPath</c> or <c>outputPath</c> is <c>null</c>
|
||||
/// The <c>inputPath</c> or <c>outputPath</c> is <c>null</c>.
|
||||
/// </exception>
|
||||
private async Task ConvertTextSubtitleToSrtInternal(string inputPath, string language, MediaProtocol inputProtocol, string outputPath, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -438,7 +419,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
(encodingParam.Equals("UTF-16BE", StringComparison.OrdinalIgnoreCase) ||
|
||||
encodingParam.Equals("UTF-16LE", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
encodingParam = "";
|
||||
encodingParam = string.Empty;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(encodingParam))
|
||||
{
|
||||
@@ -540,7 +521,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
/// <param name="outputPath">The output path.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="ArgumentException">Must use inputPath list overload</exception>
|
||||
/// <exception cref="ArgumentException">Must use inputPath list overload.</exception>
|
||||
private async Task ExtractTextSubtitle(
|
||||
string[] inputFiles,
|
||||
MediaProtocol protocol,
|
||||
@@ -759,7 +740,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
&& (string.Equals(charset, "utf-16le", StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(charset, "utf-16be", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
charset = "";
|
||||
charset = string.Empty;
|
||||
}
|
||||
|
||||
_logger.LogDebug("charset {0} detected for {Path}", charset ?? "null", path);
|
||||
@@ -790,5 +771,24 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
throw new ArgumentOutOfRangeException(nameof(protocol));
|
||||
}
|
||||
}
|
||||
|
||||
private struct SubtitleInfo
|
||||
{
|
||||
public SubtitleInfo(string path, MediaProtocol protocol, string format, bool isExternal)
|
||||
{
|
||||
Path = path;
|
||||
Protocol = protocol;
|
||||
Format = format;
|
||||
IsExternal = isExternal;
|
||||
}
|
||||
|
||||
public string Path { get; set; }
|
||||
|
||||
public MediaProtocol Protocol { get; set; }
|
||||
|
||||
public string Format { get; set; }
|
||||
|
||||
public bool IsExternal { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user