File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff 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
329356public struct StremioSubtitleResponse
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments