Compare commits

...

2 Commits

Author SHA1 Message Date
real-zony
e08d1c7f16 ci: Publish new version.(4.0.2)
Some checks failed
.NET / build (push) Has been cancelled
.NET / release (push) Has been cancelled
2024-12-15 15:29:32 +08:00
real-zony
c3d98d60b5 fix: Fixed the garbled text issue caused by the CSV file encoding. (#156) 2024-12-15 15:20:33 +08:00
7 changed files with 39 additions and 13 deletions

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<Version>4.0.1</Version>
<Version>4.0.2</Version>
<Authors>Zony(real-zony)</Authors>
<RepositoryUrl>https://github.com/real-zony/ZonyLrcToolsX</RepositoryUrl>
</PropertyGroup>

View File

@ -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>

View File

@ -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>

View File

@ -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;
}
}

View File

@ -15,6 +15,7 @@
<PackageReference Include="Polly"/>
<PackageReference Include="QRCoder"/>
<PackageReference Include="TagLibSharp"/>
<PackageReference Include="Ude.NetStandard" />
<PackageReference Include="YamlDotNet" />
</ItemGroup>

View File

@ -116,7 +116,8 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyrics
[Fact]
public async Task DownloadAsync_Source_Null_Test()
{
var lyric = await _lyricsProvider.DownloadAsync("Concerto for Piano and Orchestra No. 12 in A major, K414 - 1. Allegro",
var lyric = await _lyricsProvider.DownloadAsync(
"Concerto for Piano and Orchestra No. 12 in A major, K414 - 1. Allegro",
"Wolfgang Amadeus Mozart");
lyric.IsPruneMusic.ShouldBeTrue();
@ -143,5 +144,12 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyrics
var lyric = await _lyricsProvider.DownloadAsync("Your Heart Is A Muscle (2012)", "Carly Rae Jepsen");
lyric.IsPruneMusic.ShouldBeFalse();
}
[Fact]
public async Task DownloadAsync_Issue_156_Test()
{
var lyric = await _lyricsProvider.DownloadAsync("你说demo", "枯木逢春");
lyric.IsPruneMusic.ShouldBeFalse();
}
}
}

View File

@ -4,4 +4,4 @@ Enhancement: None
Fixed Bugs:
- 修复了 #159/#155 的问题。
- 修复了 #156 的问题。