mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
using ErsatzTV.Core.Interfaces.Metadata; |
|
|
|
namespace ErsatzTV.Core.Metadata; |
|
|
|
public class LanguageCodeService(ILanguageCodeCache languageCodeCache) : ILanguageCodeService |
|
{ |
|
public List<string> GetAllLanguageCodes(string mediaCode) |
|
{ |
|
if (string.IsNullOrWhiteSpace(mediaCode)) |
|
{ |
|
return []; |
|
} |
|
|
|
string code = mediaCode.ToLowerInvariant(); |
|
|
|
if (languageCodeCache.CodeToGroupLookup.TryGetValue(code, out string[] group)) |
|
{ |
|
return group.ToList(); |
|
} |
|
|
|
return []; |
|
} |
|
|
|
public List<string> GetAllLanguageCodes(List<string> mediaCodes) |
|
{ |
|
var validCodes = mediaCodes |
|
.Where(c => !string.IsNullOrWhiteSpace(c)) |
|
.Select(c => c.ToLowerInvariant()) |
|
.ToHashSet(); |
|
|
|
if (validCodes.Count == 0) |
|
{ |
|
return []; |
|
} |
|
|
|
var result = new System.Collections.Generic.HashSet<string>(validCodes); |
|
|
|
foreach (string code in validCodes) |
|
{ |
|
if (languageCodeCache.CodeToGroupLookup.TryGetValue(code, out string[] group)) |
|
{ |
|
result.UnionWith(group); |
|
} |
|
} |
|
|
|
return result.ToList(); |
|
} |
|
}
|
|
|