mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-09-03 11:36:53 +00:00
feat: Completed the NCM decryption tool class.
完成 NCM 解密工具类。
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
using ZonyLrcTools.Cli.Infrastructure.MusicDecryption;
|
||||
|
||||
namespace ZonyLrcTools.Tests.Infrastructure.MusicDecryption
|
||||
{
|
||||
public class NcmMusicDecryptorTests : TestBase
|
||||
{
|
||||
[Fact]
|
||||
public async Task ConvertMusic_Test()
|
||||
{
|
||||
var decryptor = ServiceProvider.GetRequiredService<IMusicDecryptor>();
|
||||
|
||||
await using var fs = File.Open(Path.Combine(Directory.GetCurrentDirectory(), "MusicFiles", "Loren Gray - Queen.ncm"), FileMode.Open);
|
||||
using var reader = new BinaryReader(fs);
|
||||
var response = await decryptor.ConvertMusic(reader.ReadBytes((int) fs.Length));
|
||||
|
||||
var musicFilePath = Path.Combine(Directory.GetCurrentDirectory(),
|
||||
"MusicFiles",
|
||||
$"Loren Gray - Queen.{((JObject) response.ExtensionObjects["JSON"]).SelectToken("$.format").Value<string>()}");
|
||||
|
||||
if (File.Exists(musicFilePath))
|
||||
{
|
||||
File.Delete(musicFilePath);
|
||||
}
|
||||
|
||||
await using var musicFileStream = File.Create(musicFilePath);
|
||||
await musicFileStream.WriteAsync(response.Data);
|
||||
await musicFileStream.FlushAsync();
|
||||
}
|
||||
}
|
||||
}
|
BIN
tests/ZonyLrcTools.Tests/MusicFiles/Loren Gray - Queen.ncm
Normal file
BIN
tests/ZonyLrcTools.Tests/MusicFiles/Loren Gray - Queen.ncm
Normal file
Binary file not shown.
@@ -29,6 +29,10 @@
|
||||
<Content Include="MusicFiles\曾经艺也 - 荀彧(纯音乐版).mp3">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Remove="MusicFiles\Loren Gray - Queen.ncm" />
|
||||
<Content Include="MusicFiles\Loren Gray - Queen.ncm">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user