Skip to content

Commit dc9523b

Browse files
committed
fix: try to catch non standard subtitle language fields
1 parent 2aaa11b commit dc9523b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

GelatoStremioProvider.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,33 @@ public struct StremioSubtitle
324324
public string? LangCode { get; set; }
325325
public string? Title { get; set; }
326326
public string? Moviehash { get; set; }
327+
328+
public string? TwoLetterISOLanguageName()
329+
{
330+
var lng = Lang ?? LangCode;
331+
if (!string.IsNullOrWhiteSpace(lng))
332+
{
333+
// If the input is 3 characters, try to convert it to a 2-letter ISO code
334+
if (lng.Length == 3)
335+
{
336+
try
337+
{
338+
CultureInfo culture = CultureInfo.GetCultureInfoByIetfLanguageTag(
339+
lng.ToLower()
340+
);
341+
lng = culture.TwoLetterISOLanguageName;
342+
}
343+
catch (CultureNotFoundException)
344+
{
345+
// If the 3-letter code is invalid, return null or handle as needed
346+
return null;
347+
}
348+
}
349+
return lng.ToLower();
350+
}
351+
352+
return null;
353+
}
327354
}
328355

329356
public struct StremioSubtitleResponse

Providers/SubtitleProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ CancellationToken cancellationToken
136136
? subs
137137
: subs.Where(s =>
138138
string.Equals(
139-
(s.LangCode ?? "").Trim().ToLower(),
139+
(s.TwoLetterISOLanguageName() ?? "").Trim().ToLower(),
140140
lang,
141141
StringComparison.OrdinalIgnoreCase
142142
)

0 commit comments

Comments
 (0)