Add subtitle parser errors to log if available (#12479)

This commit is contained in:
Łukasz 2024-09-06 15:47:06 +02:00 committed by GitHub
parent cd95eabcc6
commit 1451cbc39e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 6 deletions

View file

@ -187,6 +187,7 @@
- [HonestlyWhoKnows](https://github.com/honestlywhoknows)
- [TheMelmacian](https://github.com/TheMelmacian)
- [ItsAllAboutTheCode](https://github.com/ItsAllAboutTheCode)
- [pret0rian8](https://github.com/pret0rian)
# Emby Contributors

View file

@ -54,12 +54,23 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
break;
}
_logger.LogError(
"{ErrorCount} errors encountered while parsing '{FileExtension}' subtitle using the {SubtitleFormatParser} format parser",
subtitleFormat.ErrorCount,
fileExtension,
subtitleFormat.Name);
else if (subtitleFormat.TryGetErrors(out var errors))
{
_logger.LogError(
"{ErrorCount} errors encountered while parsing '{FileExtension}' subtitle using the {SubtitleFormatParser} format parser, errors: {Errors}",
subtitleFormat.ErrorCount,
fileExtension,
subtitleFormat.Name,
errors);
}
else
{
_logger.LogError(
"{ErrorCount} errors encountered while parsing '{FileExtension}' subtitle using the {SubtitleFormatParser} format parser",
subtitleFormat.ErrorCount,
fileExtension,
subtitleFormat.Name);
}
}
if (subtitle.Paragraphs.Count == 0)

View file

@ -0,0 +1,29 @@
using System.Diagnostics.CodeAnalysis;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
namespace MediaBrowser.MediaEncoding.Subtitles;
internal static class SubtitleFormatExtensions
{
/// <summary>
/// Will try to find errors if supported by provider.
/// </summary>
/// <param name="format">The subtitle format.</param>
/// <param name="errors">The out errors value.</param>
/// <returns>True if errors are available for given format.</returns>
public static bool TryGetErrors(this SubtitleFormat format, [NotNullWhen(true)] out string? errors)
{
errors = format switch
{
SubStationAlpha ssa => ssa.Errors,
AdvancedSubStationAlpha assa => assa.Errors,
SubRip subRip => subRip.Errors,
MicroDvd microDvd => microDvd.Errors,
DCinemaSmpte2007 smpte2007 => smpte2007.Errors,
DCinemaSmpte2010 smpte2010 => smpte2010.Errors,
_ => null,
};
return !string.IsNullOrWhiteSpace(errors);
}
}