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,13 +54,24 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
break;
}
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);
}
}