mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 05:57:20 -04:00
loop over all compatible SubtitleFormats
This commit is contained in:
parent
1db748399c
commit
78f437401b
1 changed files with 15 additions and 9 deletions
|
@ -30,17 +30,23 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|||
/// <inheritdoc />
|
||||
public SubtitleTrackInfo Parse(Stream stream, string fileExtension)
|
||||
{
|
||||
var subtitleFormat = SubtitleFormat.AllSubtitleFormats.FirstOrDefault(asf => asf.Extension.Equals(fileExtension, StringComparison.OrdinalIgnoreCase));
|
||||
if (subtitleFormat == null)
|
||||
{
|
||||
throw new ArgumentException("Unsupported format: " + fileExtension);
|
||||
}
|
||||
|
||||
var lines = stream.ReadAllLines().ToList();
|
||||
var subtitle = new Subtitle();
|
||||
subtitleFormat.LoadSubtitle(subtitle, lines, fileExtension);
|
||||
if (subtitleFormat.ErrorCount > 0)
|
||||
var lines = stream.ReadAllLines().ToList();
|
||||
|
||||
var subtitleFormats = SubtitleFormat.AllSubtitleFormats.Where(asf => asf.Extension.Equals(fileExtension, StringComparison.OrdinalIgnoreCase));
|
||||
foreach (var subtitleFormat in subtitleFormats)
|
||||
{
|
||||
if (subtitleFormat == null)
|
||||
{
|
||||
throw new ArgumentException("Unsupported format: " + fileExtension);
|
||||
}
|
||||
|
||||
subtitleFormat.LoadSubtitle(subtitle, lines, fileExtension);
|
||||
if (subtitleFormat.ErrorCount == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
_logger.LogError("{ErrorCount} errors encountered while parsing subtitle", subtitleFormat.ErrorCount);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue