Skip to content

Commit

Permalink
Don't fail if can't extract three-letter language code on subs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Nov 23, 2023
1 parent 6e3e09b commit 85bbb40
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion YoutubeExplode.Converter/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private async ValueTask ProcessAsync(
{
arguments
.Add($"-metadata:s:s:{i}")
.Add($"language={subtitleInput.Info.Language.GetThreeLetterCode()}")
.Add($"language={subtitleInput.Info.Language.TryGetThreeLetterCode() ?? subtitleInput.Info.Language.GetTwoLetterCode()}")
.Add($"-metadata:s:s:{i}")
.Add($"title={subtitleInput.Info.Language.Name}");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using YoutubeExplode.Videos.ClosedCaptions;
using YoutubeExplode.Videos.ClosedCaptions;

namespace YoutubeExplode.Converter.Utils.Extensions;

Expand All @@ -11,7 +10,7 @@ public static string GetTwoLetterCode(this Language language)
return dashIndex >= 0 ? language.Code[..dashIndex] : language.Code;
}

public static string GetThreeLetterCode(this Language language) =>
public static string? TryGetThreeLetterCode(this Language language) =>
language.GetTwoLetterCode().ToLowerInvariant() switch
{
"aa" => "aar",
Expand Down Expand Up @@ -204,6 +203,6 @@ public static string GetThreeLetterCode(this Language language) =>
"za" => "zha",
"zh" => "zho",
"zu" => "zul",
var code => throw new InvalidOperationException($"Unrecognized language code '{code}'.")
_ => null
};
}

0 comments on commit 85bbb40

Please sign in to comment.