feat: Supports UTF-8 BOM encoding.

This commit is contained in:
real-zony
2023-02-22 21:45:27 +08:00
parent bfd89e9d82
commit 5dbabab5a6
3 changed files with 11 additions and 5 deletions

View File

@@ -118,6 +118,13 @@ public class LyricsDownloader : ILyricsDownloader, ISingletonDependency
private byte[] Utf8ToSelectedEncoding(LyricsItemCollection lyrics)
{
var supportEncodings = Encoding.GetEncodings();
// If the encoding is UTF-8 BOM, add the BOM to the front of the lyrics.
if (_options.Provider.Lyric.Config.FileEncoding == "utf-8-bom")
{
return Encoding.UTF8.GetPreamble().Concat(lyrics.GetUtf8Bytes()).ToArray();
}
if (supportEncodings.All(x => x.Name != _options.Provider.Lyric.Config.FileEncoding))
{
throw new ErrorCodeException(ErrorCodes.NotSupportedFileEncoding);