From 5dbabab5a63dd17f479801ab05f79c9f8eac1a5a Mon Sep 17 00:00:00 2001 From: real-zony Date: Wed, 22 Feb 2023 21:45:27 +0800 Subject: [PATCH] feat: Supports UTF-8 BOM encoding. --- README.md | 2 ++ src/ZonyLrcTools.Common/Lyrics/LyricsDownloader.cs | 7 +++++++ versions/release.bak.md | 7 ++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 741df94..721601d 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,8 @@ globalOption: 详细信息请参考: [MSDN Encoding 列表](https://learn.microsoft.com/en-us/dotnet/api/System.Text.Encoding.GetEncodings?view=net-6.0#examples),使用 `identifier and name` 作为参数值填入 `config.yaml` 文件当中的 `fileEncoding`。 +> 针对 UTF-8 BOM 格式,程序进行了特殊处理,请在 `fileEncoding` 里面填写 "utf-8-bom" 以支持。 + #### 支持的歌词源 | 歌词源 | 默认优先级 | diff --git a/src/ZonyLrcTools.Common/Lyrics/LyricsDownloader.cs b/src/ZonyLrcTools.Common/Lyrics/LyricsDownloader.cs index b4b8ea5..032edd5 100644 --- a/src/ZonyLrcTools.Common/Lyrics/LyricsDownloader.cs +++ b/src/ZonyLrcTools.Common/Lyrics/LyricsDownloader.cs @@ -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); diff --git a/versions/release.bak.md b/versions/release.bak.md index c57de16..2b8a8cc 100644 --- a/versions/release.bak.md +++ b/versions/release.bak.md @@ -1,11 +1,8 @@ -New Features: - -- CLI 提供了一个更新检查功能,在程序启动的时候会检测最新的版本。 -- 支持从酷我音乐搜索歌词。 +New Features: NONE Breaking Changes: None Enhancement: -- 基于 MusicDecrypto 提供歌曲解密功能,支持 40 种格式的文件,具体支持格式请自己尝试。 +- 支持 UTF-8 BOM 编码,以解决部分设备乱码的问题。 Fixed Bugs: - None \ No newline at end of file