mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-17 15:53:42 +01:00
Merge pull request #9799 from Bond-009/genregex
This commit is contained in:
@@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MediaBrowser.MediaEncoding.Encoder
|
||||
{
|
||||
public class EncoderValidator
|
||||
public partial class EncoderValidator
|
||||
{
|
||||
private static readonly string[] _requiredDecoders = new[]
|
||||
{
|
||||
@@ -165,6 +165,12 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
|
||||
public static Version? MaxVersion { get; } = null;
|
||||
|
||||
[GeneratedRegex(@"^ffmpeg version n?((?:[0-9]+\.?)+)")]
|
||||
private static partial Regex FfmpegVersionRegex();
|
||||
|
||||
[GeneratedRegex(@"((?<name>lib\w+)\s+(?<major>[0-9]+)\.\s*(?<minor>[0-9]+))", RegexOptions.Multiline)]
|
||||
private static partial Regex LibraryRegex();
|
||||
|
||||
public bool ValidateVersion()
|
||||
{
|
||||
string output;
|
||||
@@ -283,7 +289,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
internal Version? GetFFmpegVersionInternal(string output)
|
||||
{
|
||||
// For pre-built binaries the FFmpeg version should be mentioned at the very start of the output
|
||||
var match = Regex.Match(output, @"^ffmpeg version n?((?:[0-9]+\.?)+)");
|
||||
var match = FfmpegVersionRegex().Match(output);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
@@ -331,10 +337,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
{
|
||||
var map = new Dictionary<string, Version>();
|
||||
|
||||
foreach (Match match in Regex.Matches(
|
||||
output,
|
||||
@"((?<name>lib\w+)\s+(?<major>[0-9]+)\.\s*(?<minor>[0-9]+))",
|
||||
RegexOptions.Multiline))
|
||||
foreach (Match match in LibraryRegex().Matches(output))
|
||||
{
|
||||
var version = new Version(
|
||||
int.Parse(match.Groups["major"].ValueSpan, CultureInfo.InvariantCulture),
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
/// <summary>
|
||||
/// Class MediaEncoder.
|
||||
/// </summary>
|
||||
public class MediaEncoder : IMediaEncoder, IDisposable
|
||||
public partial class MediaEncoder : IMediaEncoder, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The default SDR image extraction timeout in milliseconds.
|
||||
@@ -142,6 +142,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
/// <inheritdoc />
|
||||
public bool IsVaapiDeviceSupportVulkanFmtModifier => _isVaapiDeviceSupportVulkanFmtModifier;
|
||||
|
||||
[GeneratedRegex(@"[^\/\\]+?(\.[^\/\\\n.]+)?$")]
|
||||
private static partial Regex FfprobePathRegex();
|
||||
|
||||
/// <summary>
|
||||
/// Run at startup or if the user removes a Custom path from transcode page.
|
||||
/// Sets global variables FFmpegPath.
|
||||
@@ -176,7 +179,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
if (_ffmpegPath is not null)
|
||||
{
|
||||
// Determine a probe path from the mpeg path
|
||||
_ffprobePath = Regex.Replace(_ffmpegPath, @"[^\/\\]+?(\.[^\/\\\n.]+)?$", @"ffprobe$1");
|
||||
_ffprobePath = FfprobePathRegex().Replace(_ffmpegPath, @"ffprobe$1");
|
||||
|
||||
// Interrogate to understand what coders are supported
|
||||
var validator = new EncoderValidator(_logger, _ffmpegPath);
|
||||
@@ -416,8 +419,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
public Task<MediaInfo> GetMediaInfo(MediaInfoRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var extractChapters = request.MediaType == DlnaProfileType.Video && request.ExtractChapters;
|
||||
string analyzeDuration = string.Empty;
|
||||
string ffmpegAnalyzeDuration = _config.GetFFmpegAnalyzeDuration() ?? string.Empty;
|
||||
var analyzeDuration = string.Empty;
|
||||
var ffmpegAnalyzeDuration = _config.GetFFmpegAnalyzeDuration() ?? string.Empty;
|
||||
|
||||
if (request.MediaSource.AnalyzeDurationMs > 0)
|
||||
{
|
||||
|
||||
@@ -11,8 +11,11 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
/// <summary>
|
||||
/// ASS subtitle writer.
|
||||
/// </summary>
|
||||
public class AssWriter : ISubtitleWriter
|
||||
public partial class AssWriter : ISubtitleWriter
|
||||
{
|
||||
[GeneratedRegex(@"\n", RegexOptions.IgnoreCase)]
|
||||
private static partial Regex NewLineRegex();
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -40,7 +43,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
var trackEvent = trackEvents[i];
|
||||
var startTime = TimeSpan.FromTicks(trackEvent.StartPositionTicks).ToString(timeFormat, CultureInfo.InvariantCulture);
|
||||
var endTime = TimeSpan.FromTicks(trackEvent.EndPositionTicks).ToString(timeFormat, CultureInfo.InvariantCulture);
|
||||
var text = Regex.Replace(trackEvent.Text, @"\n", "\\n", RegexOptions.IgnoreCase);
|
||||
var text = NewLineRegex().Replace(trackEvent.Text, "\\n");
|
||||
|
||||
writer.WriteLine(
|
||||
"Dialogue: 0,{0},{1},Default,{2}",
|
||||
|
||||
@@ -11,8 +11,11 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
/// <summary>
|
||||
/// SRT subtitle writer.
|
||||
/// </summary>
|
||||
public class SrtWriter : ISubtitleWriter
|
||||
public partial class SrtWriter : ISubtitleWriter
|
||||
{
|
||||
[GeneratedRegex(@"\\n", RegexOptions.IgnoreCase)]
|
||||
private static partial Regex NewLineEscapedRegex();
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -35,7 +38,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
var text = trackEvent.Text;
|
||||
|
||||
// TODO: Not sure how to handle these
|
||||
text = Regex.Replace(text, @"\\n", " ", RegexOptions.IgnoreCase);
|
||||
text = NewLineEscapedRegex().Replace(text, " ");
|
||||
|
||||
writer.WriteLine(text);
|
||||
writer.WriteLine();
|
||||
|
||||
@@ -11,8 +11,11 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
/// <summary>
|
||||
/// SSA subtitle writer.
|
||||
/// </summary>
|
||||
public class SsaWriter : ISubtitleWriter
|
||||
public partial class SsaWriter : ISubtitleWriter
|
||||
{
|
||||
[GeneratedRegex(@"\n", RegexOptions.IgnoreCase)]
|
||||
private static partial Regex NewLineRegex();
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -40,7 +43,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
var trackEvent = trackEvents[i];
|
||||
var startTime = TimeSpan.FromTicks(trackEvent.StartPositionTicks).ToString(timeFormat, CultureInfo.InvariantCulture);
|
||||
var endTime = TimeSpan.FromTicks(trackEvent.EndPositionTicks).ToString(timeFormat, CultureInfo.InvariantCulture);
|
||||
var text = Regex.Replace(trackEvent.Text, @"\n", "\\n", RegexOptions.IgnoreCase);
|
||||
var text = NewLineRegex().Replace(trackEvent.Text, "\\n");
|
||||
|
||||
writer.WriteLine(
|
||||
"Dialogue: 0,{0},{1},Default,{2}",
|
||||
|
||||
@@ -9,8 +9,11 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
/// <summary>
|
||||
/// TTML subtitle writer.
|
||||
/// </summary>
|
||||
public class TtmlWriter : ISubtitleWriter
|
||||
public partial class TtmlWriter : ISubtitleWriter
|
||||
{
|
||||
[GeneratedRegex(@"\\n", RegexOptions.IgnoreCase)]
|
||||
private static partial Regex NewLineEscapeRegex();
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -38,7 +41,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
{
|
||||
var text = trackEvent.Text;
|
||||
|
||||
text = Regex.Replace(text, @"\\n", "<br/>", RegexOptions.IgnoreCase);
|
||||
text = NewLineEscapeRegex().Replace(text, "<br/>");
|
||||
|
||||
writer.WriteLine(
|
||||
"<p begin=\"{0}\" dur=\"{1}\">{2}</p>",
|
||||
|
||||
@@ -10,8 +10,11 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
/// <summary>
|
||||
/// Subtitle writer for the WebVTT format.
|
||||
/// </summary>
|
||||
public class VttWriter : ISubtitleWriter
|
||||
public partial class VttWriter : ISubtitleWriter
|
||||
{
|
||||
[GeneratedRegex(@"\\n", RegexOptions.IgnoreCase)]
|
||||
private static partial Regex NewlineEscapeRegex();
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -39,7 +42,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
var text = trackEvent.Text;
|
||||
|
||||
// TODO: Not sure how to handle these
|
||||
text = Regex.Replace(text, @"\\n", " ", RegexOptions.IgnoreCase);
|
||||
text = NewlineEscapeRegex().Replace(text, " ");
|
||||
|
||||
writer.WriteLine(text);
|
||||
writer.WriteLine();
|
||||
|
||||
Reference in New Issue
Block a user