4 Commits

Author SHA1 Message Date
real-zony
39dce9a7a0 feat: Add a basic API framework. 2025-07-25 23:01:53 +08:00
real-zony
c89b79fda6 build: Upgraded package version. 2025-07-25 22:27:24 +08:00
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
16 changed files with 196 additions and 28 deletions

View File

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

View File

@@ -3,23 +3,28 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageVersion Include="FastEndpoints" Version="7.0.1" />
<PackageVersion Include="FastEndpoints.Swagger" Version="7.0.1" />
<PackageVersion Include="FreeSql" Version="3.5.211" />
<PackageVersion Include="FreeSql.Provider.SqliteCore" Version="3.5.211" />
<PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" /> <PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
<PackageVersion Include="McMaster.Extensions.Hosting.CommandLine" Version="4.1.1" /> <PackageVersion Include="McMaster.Extensions.Hosting.CommandLine" Version="4.1.1" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="9.0.7" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> <PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> <PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.7" />
<PackageVersion Include="QRCoder" Version="1.6.0" /> <PackageVersion Include="QRCoder" Version="1.6.0" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="8.0.0" /> <PackageVersion Include="Serilog.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Serilog.Sinks.Async" Version="2.1.0" /> <PackageVersion Include="Serilog.Sinks.Async" Version="2.1.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" /> <PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" /> <PackageVersion Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0" /> <PackageVersion Include="System.Text.Encoding.CodePages" Version="9.0.7" />
<PackageVersion Include="Polly" Version="8.5.0" /> <PackageVersion Include="Polly" Version="8.6.2" />
<PackageVersion Include="TagLibSharp" Version="2.3.0" /> <PackageVersion Include="TagLibSharp" Version="2.3.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" /> <PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NetEscapades.Configuration.Yaml" Version="3.1.0" /> <PackageVersion Include="NetEscapades.Configuration.Yaml" Version="3.1.0" />
<PackageVersion Include="MusicDecrypto.Library" Version="2.4.1" /> <PackageVersion Include="MusicDecrypto.Library" Version="2.4.1" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" /> <PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.7" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" /> <PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.7" />
<PackageVersion Include="AutoMapper" Version="13.0.1" /> <PackageVersion Include="AutoMapper" Version="13.0.1" />
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" /> <PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.6" /> <PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.6" />
@@ -28,23 +33,18 @@
<PackageVersion Include="SuperSocket.WebSocket.Server" Version="2.0.0-beta.11" /> <PackageVersion Include="SuperSocket.WebSocket.Server" Version="2.0.0-beta.11" />
<!-- Testing Projects --> <!-- Testing Projects -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" /> <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Shouldly" Version="4.2.1" /> <PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="xunit" Version="2.8.1" /> <PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1"> <PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion> </PackageVersion>
<PackageVersion Include="coverlet.collector" Version="6.0.2"> <PackageVersion Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion> </PackageVersion>
<!-- Avalonia --> <!-- Avalonia -->
<PackageVersion Include="Avalonia" Version="11.0.11" /> <PackageVersion Include="Ude.NetStandard" Version="1.2.0" />
<PackageVersion Include="Avalonia.Desktop" Version="11.0.11" /> <PackageVersion Include="YamlDotNet" Version="16.3.0" />
<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="YamlDotNet" Version="16.2.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -13,6 +13,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.Tests", "tests
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.Common", "src\ZonyLrcTools.Common\ZonyLrcTools.Common.csproj", "{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.Common", "src\ZonyLrcTools.Common\ZonyLrcTools.Common.csproj", "{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "frontend", "frontend", "{07691E21-94C7-4C9F-970D-B0C77F02B878}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.Api", "src\ZonyLrcTools.Api\ZonyLrcTools.Api.csproj", "{698A1F4D-86F1-4251-B708-9B15648D7245}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -31,6 +35,10 @@ Global
{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Debug|Any CPU.Build.0 = Debug|Any CPU {9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Release|Any CPU.ActiveCfg = Release|Any CPU {9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Release|Any CPU.Build.0 = Release|Any CPU {9B42E4CA-61AA-4798-8D2B-2D8A7035EB67}.Release|Any CPU.Build.0 = Release|Any CPU
{698A1F4D-86F1-4251-B708-9B15648D7245}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{698A1F4D-86F1-4251-B708-9B15648D7245}.Debug|Any CPU.Build.0 = Debug|Any CPU
{698A1F4D-86F1-4251-B708-9B15648D7245}.Release|Any CPU.ActiveCfg = Release|Any CPU
{698A1F4D-86F1-4251-B708-9B15648D7245}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -42,5 +50,7 @@ Global
{55D74323-ABFA-4A73-A3BF-F3E8D5DE6DE8} = {C29FB05C-54B1-4020-94D2-87E192EB2F98} {55D74323-ABFA-4A73-A3BF-F3E8D5DE6DE8} = {C29FB05C-54B1-4020-94D2-87E192EB2F98}
{FFBD3200-568F-455B-8390-5E76C51D522C} = {AF8ADB2F-E46C-4DEE-8316-652D9FE1A69B} {FFBD3200-568F-455B-8390-5E76C51D522C} = {AF8ADB2F-E46C-4DEE-8316-652D9FE1A69B}
{9B42E4CA-61AA-4798-8D2B-2D8A7035EB67} = {C29FB05C-54B1-4020-94D2-87E192EB2F98} {9B42E4CA-61AA-4798-8D2B-2D8A7035EB67} = {C29FB05C-54B1-4020-94D2-87E192EB2F98}
{07691E21-94C7-4C9F-970D-B0C77F02B878} = {C29FB05C-54B1-4020-94D2-87E192EB2F98}
{698A1F4D-86F1-4251-B708-9B15648D7245} = {C29FB05C-54B1-4020-94D2-87E192EB2F98}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@@ -0,0 +1,19 @@
using FreeSql;
using Microsoft.Extensions.DependencyInjection;
namespace ZonyLrcTools.Api.Database;
public static class DatabaseServiceExtensions
{
public static IServiceCollection RegisterDatabaseServices(this IServiceCollection services)
{
var freeSqlBuilder = new FreeSqlBuilder()
.UseConnectionString(DataType.Sqlite, "Data Source=ZonyLrcTools.db;Pooling=true;Max Pool Size=10;")
.UseAutoSyncStructure(true);
var freeSql = freeSqlBuilder.Build();
services.AddSingleton(freeSql);
return services;
}
}

View File

@@ -0,0 +1,30 @@
using FreeSql.DataAnnotations;
namespace ZonyLrcTools.Api.Domain.Settings;
[Table(Name = "Settings")]
public class Setting
{
[Column(IsPrimary = true, IsIdentity = true)]
public Guid Id { get; set; }
public string Key { get; protected set; } = null!;
public string? Value { get; set; }
public SettingValueType ValueType { get; protected set; }
public Setting(string key, SettingValueType valueType)
{
Key = key;
ValueType = valueType;
}
}
public enum SettingValueType
{
String = 1,
Int = 2,
Bool = 3,
Double = 4
}

View File

@@ -0,0 +1,6 @@
namespace ZonyLrcTools.Api.Endpoints.Settings.DTOs;
public class GetAllSettingsResponse
{
public bool IsAutoCheckUpdate { get; set; }
}

View File

@@ -0,0 +1,31 @@
using FastEndpoints;
using ZonyLrcTools.Api.Domain.Settings;
using ZonyLrcTools.Api.Endpoints.Settings.DTOs;
namespace ZonyLrcTools.Api.Endpoints.Settings;
public class GetAllSettingsEndpoint(IFreeSql freeSql) : EndpointWithoutRequest<GetAllSettingsResponse>
{
public override void Configure()
{
Get("/api/settings");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
var setting = await freeSql.Select<Setting>()
.ToListAsync(ct);
if (setting.Count == 0)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(new GetAllSettingsResponse
{
IsAutoCheckUpdate = true
}, ct);
}
}

View File

@@ -0,0 +1,23 @@
using FastEndpoints;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using ZonyLrcTools.Api.Database;
namespace ZonyLrcTools.Api;
class Program
{
static async Task Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(k => k.ListenAnyIP(10086));
builder.Services.AddFastEndpoints();
builder.Services.RegisterDatabaseServices();
var app = builder.Build();
app.UseFastEndpoints();
await app.RunAsync();
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FastEndpoints" />
<PackageReference Include="FastEndpoints.Swagger" />
<PackageReference Include="FreeSql" />
<PackageReference Include="FreeSql.Provider.SqliteCore" />
<PackageReference Include="Microsoft.Data.Sqlite" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
</PropertyGroup> </PropertyGroup>
@@ -14,6 +14,7 @@
<PackageReference Include="Serilog.Sinks.Console"/> <PackageReference Include="Serilog.Sinks.Console"/>
<PackageReference Include="Serilog.Sinks.File"/> <PackageReference Include="Serilog.Sinks.File"/>
<PackageReference Include="System.Text.Encoding.CodePages"/> <PackageReference Include="System.Text.Encoding.CodePages"/>
<PackageReference Include="Ude.NetStandard"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,3 +1,5 @@
using System.Text;
using Ude;
using ZonyLrcTools.Common.Infrastructure.DependencyInject; using ZonyLrcTools.Common.Infrastructure.DependencyInject;
namespace ZonyLrcTools.Common.MusicScanner; namespace ZonyLrcTools.Common.MusicScanner;
@@ -13,11 +15,15 @@ public class CsvFileMusicScanner : ITransientDependency
/// <param name="csvFilePath">CSV 文件的路径。</param> /// <param name="csvFilePath">CSV 文件的路径。</param>
/// <param name="outputDirectory">歌词文件的输出目录。</param> /// <param name="outputDirectory">歌词文件的输出目录。</param>
/// <param name="pattern">输出的歌词文件格式,默认是 "{Artist} - {Title}.lrc" 的形式。</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 encoding = DetectFileEncoding(csvFilePath);
var csvFileLines = csvFileContent.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
return csvFileLines.Skip(1).Select(line => GetMusicInfoFromCsvFileLine(line, outputDirectory, pattern)).ToList(); 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) private MusicInfo GetMusicInfoFromCsvFileLine(string csvFileLine, string outputDirectory, string pattern)
@@ -29,4 +35,19 @@ public class CsvFileMusicScanner : ITransientDependency
var musicInfo = new MusicInfo(fakeFilePath, name, artist); var musicInfo = new MusicInfo(fakeFilePath, name, artist);
return musicInfo; 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

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
@@ -15,6 +15,7 @@
<PackageReference Include="Polly"/> <PackageReference Include="Polly"/>
<PackageReference Include="QRCoder"/> <PackageReference Include="QRCoder"/>
<PackageReference Include="TagLibSharp"/> <PackageReference Include="TagLibSharp"/>
<PackageReference Include="Ude.NetStandard" />
<PackageReference Include="YamlDotNet" /> <PackageReference Include="YamlDotNet" />
</ItemGroup> </ItemGroup>

View File

@@ -17,7 +17,7 @@ public class KuWoLyricsProviderTests : TestBase
.FirstOrDefault(t => t.DownloaderName == InternalLyricsProviderNames.KuWo); .FirstOrDefault(t => t.DownloaderName == InternalLyricsProviderNames.KuWo);
} }
[Fact] [Fact(Skip = "酷我音乐的 API 不稳定,可能导致测试失败,暂跳过")]
[Trait("LyricsProvider ", "KuGou")] [Trait("LyricsProvider ", "KuGou")]
public async Task DownloadAsync_Test() public async Task DownloadAsync_Test()
{ {

View File

@@ -116,7 +116,8 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyrics
[Fact] [Fact]
public async Task DownloadAsync_Source_Null_Test() 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"); "Wolfgang Amadeus Mozart");
lyric.IsPruneMusic.ShouldBeTrue(); 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"); var lyric = await _lyricsProvider.DownloadAsync("Your Heart Is A Muscle (2012)", "Carly Rae Jepsen");
lyric.IsPruneMusic.ShouldBeFalse(); lyric.IsPruneMusic.ShouldBeFalse();
} }
[Fact]
public async Task DownloadAsync_Issue_156_Test()
{
var lyric = await _lyricsProvider.DownloadAsync("你说demo", "枯木逢春");
lyric.IsPruneMusic.ShouldBeFalse();
}
} }
} }

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>

View File

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