mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-08-31 09:36:53 +00:00
fix: Fixed the garbled text issue caused by the CSV file encoding. (#156)
This commit is contained in:
@@ -39,12 +39,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageVersion>
|
||||
<!-- Avalonia -->
|
||||
<PackageVersion Include="Avalonia" Version="11.0.11" />
|
||||
<PackageVersion Include="Avalonia.Desktop" Version="11.0.11" />
|
||||
<PackageVersion Include="Avalonia.Themes.Fluent" Version="11.0.11" />
|
||||
<PackageVersion Include="Avalonia.Fonts.Inter" Version="11.0.11" />
|
||||
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.0.11" />
|
||||
<PackageVersion Include="Avalonia.Diagnostics" Version="11.0.11" />
|
||||
<PackageVersion Include="Ude.NetStandard" Version="1.2.0" />
|
||||
<PackageVersion Include="YamlDotNet" Version="16.2.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@@ -14,6 +14,7 @@
|
||||
<PackageReference Include="Serilog.Sinks.Console"/>
|
||||
<PackageReference Include="Serilog.Sinks.File"/>
|
||||
<PackageReference Include="System.Text.Encoding.CodePages"/>
|
||||
<PackageReference Include="Ude.NetStandard"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -1,3 +1,5 @@
|
||||
using System.Text;
|
||||
using Ude;
|
||||
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
|
||||
|
||||
namespace ZonyLrcTools.Common.MusicScanner;
|
||||
@@ -13,11 +15,15 @@ public class CsvFileMusicScanner : ITransientDependency
|
||||
/// <param name="csvFilePath">CSV 文件的路径。</param>
|
||||
/// <param name="outputDirectory">歌词文件的输出目录。</param>
|
||||
/// <param name="pattern">输出的歌词文件格式,默认是 "{Artist} - {Title}.lrc" 的形式。</param>
|
||||
public async Task<List<MusicInfo>> GetMusicInfoFromCsvFileAsync(string csvFilePath, string outputDirectory, string pattern)
|
||||
public async Task<List<MusicInfo>> GetMusicInfoFromCsvFileAsync(string csvFilePath, string outputDirectory,
|
||||
string pattern)
|
||||
{
|
||||
var csvFileContent = await File.ReadAllTextAsync(csvFilePath);
|
||||
var csvFileLines = csvFileContent.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
||||
return csvFileLines.Skip(1).Select(line => GetMusicInfoFromCsvFileLine(line, outputDirectory, pattern)).ToList();
|
||||
var encoding = DetectFileEncoding(csvFilePath);
|
||||
|
||||
var csvFileContent = await File.ReadAllTextAsync(csvFilePath, encoding);
|
||||
var csvFileLines = csvFileContent.Split([Environment.NewLine], StringSplitOptions.RemoveEmptyEntries);
|
||||
return csvFileLines.Skip(1).Select(line => GetMusicInfoFromCsvFileLine(line, outputDirectory, pattern))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private MusicInfo GetMusicInfoFromCsvFileLine(string csvFileLine, string outputDirectory, string pattern)
|
||||
@@ -29,4 +35,19 @@ public class CsvFileMusicScanner : ITransientDependency
|
||||
var musicInfo = new MusicInfo(fakeFilePath, name, artist);
|
||||
return musicInfo;
|
||||
}
|
||||
|
||||
private Encoding DetectFileEncoding(string filePath)
|
||||
{
|
||||
using var fileStream = File.OpenRead(filePath);
|
||||
var detector = new CharsetDetector();
|
||||
detector.Feed(fileStream);
|
||||
detector.DataEnd();
|
||||
|
||||
if (detector.Charset != null)
|
||||
{
|
||||
return Encoding.GetEncoding(detector.Charset);
|
||||
}
|
||||
|
||||
return Encoding.Default;
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@
|
||||
<PackageReference Include="Polly"/>
|
||||
<PackageReference Include="QRCoder"/>
|
||||
<PackageReference Include="TagLibSharp"/>
|
||||
<PackageReference Include="Ude.NetStandard" />
|
||||
<PackageReference Include="YamlDotNet" />
|
||||
</ItemGroup>
|
||||
|
||||
|
Reference in New Issue
Block a user