mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 20:30:41 +00:00
test: Add QQ Music Lyric Downloader UnitTest Method.
This commit is contained in:
parent
abdb1dea23
commit
8f70e434f0
@ -9,12 +9,12 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric
|
||||
/// 网易云音乐歌词下载器。
|
||||
/// </summary>
|
||||
public const string NetEase = nameof(NetEase);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// QQ 音乐歌词下载器。
|
||||
/// </summary>
|
||||
public const string QQ = nameof(QQ);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 酷狗音乐歌词下载器。
|
||||
/// </summary>
|
||||
|
@ -9,11 +9,9 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase.JsonModel
|
||||
SongId = songId;
|
||||
SongIds = $"%5B{songId}%5D";
|
||||
}
|
||||
|
||||
[JsonProperty("id")]
|
||||
public int SongId { get; }
|
||||
|
||||
[JsonProperty("ids")]
|
||||
public string SongIds { get; }
|
||||
[JsonProperty("id")] public int SongId { get; }
|
||||
|
||||
[JsonProperty("ids")] public string SongIds { get; }
|
||||
}
|
||||
}
|
@ -48,7 +48,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic.JsonModel
|
||||
|
||||
[JsonProperty("needNewCode")] public int UnknownParameter11 { get; set; }
|
||||
|
||||
public SongSearchRequest()
|
||||
protected SongSearchRequest()
|
||||
{
|
||||
UnknownParameter1 = 24;
|
||||
ClientVersion = 1298;
|
||||
|
@ -5,34 +5,28 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic.JsonModel
|
||||
{
|
||||
public class SongSearchResponse
|
||||
{
|
||||
[JsonProperty("code")]
|
||||
public int StatusCode { get; set; }
|
||||
[JsonProperty("code")] public int StatusCode { get; set; }
|
||||
|
||||
[JsonProperty("data")]
|
||||
public QQMusicInnerDataModel Data { get; set; }
|
||||
[JsonProperty("data")] public QQMusicInnerDataModel Data { get; set; }
|
||||
}
|
||||
|
||||
public class QQMusicInnerDataModel
|
||||
{
|
||||
[JsonProperty("song")]
|
||||
public QQMusicInnerSongModel Song { get; set; }
|
||||
[JsonProperty("song")] public QQMusicInnerSongModel Song { get; set; }
|
||||
}
|
||||
|
||||
public class QQMusicInnerSongModel
|
||||
{
|
||||
[JsonProperty("list")]
|
||||
public List<QQMusicInnerSongItem> SongItems { get; set; }
|
||||
[JsonProperty("list")] public List<QQMusicInnerSongItem> SongItems { get; set; }
|
||||
}
|
||||
|
||||
public class QQMusicInnerSongItem
|
||||
{
|
||||
[JsonProperty("mid")]
|
||||
public string SongId { get; set; }
|
||||
[JsonProperty("mid")] public string SongId { get; set; }
|
||||
}
|
||||
|
||||
public class AlbumInfo
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public long Id { get; set; }
|
||||
[JsonProperty("id")] public long Id { get; set; }
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic.JsonModel;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Network;
|
||||
|
||||
namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
|
||||
@ -10,6 +11,8 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
|
||||
private readonly IWarpHttpClient _warpHttpClient;
|
||||
private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory;
|
||||
|
||||
private const string QQSearchMusicUrl = @"https://c.y.qq.com/soso/fcgi-bin/client_search_cp";
|
||||
|
||||
public QQLyricDownloader(IWarpHttpClient warpHttpClient,
|
||||
ILyricItemCollectionFactory lyricItemCollectionFactory)
|
||||
{
|
||||
@ -17,8 +20,11 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.QQMusic
|
||||
_lyricItemCollectionFactory = lyricItemCollectionFactory;
|
||||
}
|
||||
|
||||
protected override ValueTask<byte[]> DownloadDataAsync(LyricDownloaderArgs args)
|
||||
protected override async ValueTask<byte[]> DownloadDataAsync(LyricDownloaderArgs args)
|
||||
{
|
||||
var searchResult = await _warpHttpClient.PostAsync<SongSearchResponse>(
|
||||
QQSearchMusicUrl,
|
||||
new SongSearchRequest(args.SongName, args.Artist));
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Network
|
||||
/// 是否启用了网络代理功能。
|
||||
/// </summary>
|
||||
public bool Enable { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 代理服务器的 Ip。
|
||||
/// </summary>
|
||||
|
@ -20,11 +20,11 @@ namespace ZonyLrcTools.Tests.Infrastructure.Album
|
||||
downloader.ShouldNotBeNull();
|
||||
var albumBytes = await downloader.DownloadAsync("东方红", null);
|
||||
albumBytes.Length.ShouldBeGreaterThan(0);
|
||||
|
||||
|
||||
// 显示具体的图像。
|
||||
var tempAlbumPath = Path.Combine(Directory.GetCurrentDirectory(), "tempAlbum.png");
|
||||
File.Delete(tempAlbumPath);
|
||||
|
||||
|
||||
await using var file = File.Create(tempAlbumPath);
|
||||
await using var ws = new BinaryWriter(file);
|
||||
ws.Write(albumBytes);
|
||||
|
@ -10,7 +10,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Exceptions
|
||||
public void LoadMessage_Test()
|
||||
{
|
||||
ErrorCodeHelper.LoadErrorMessage();
|
||||
|
||||
|
||||
ErrorCodeHelper.ErrorMessages.ShouldNotBeNull();
|
||||
ErrorCodeHelper.ErrorMessages.Count.ShouldBe(11);
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Lyric;
|
||||
|
||||
namespace ZonyLrcTools.Tests.Infrastructure.Lyric
|
||||
{
|
||||
public class QQLyricDownloaderTests : TestBase
|
||||
{
|
||||
[Fact]
|
||||
public async Task DownloadAsync_Test()
|
||||
{
|
||||
var downloaderList = ServiceProvider.GetRequiredService<IEnumerable<ILyricDownloader>>();
|
||||
var qqDownloader = downloaderList.FirstOrDefault(t => t.DownloaderName == InternalLyricDownloaderNames.QQ);
|
||||
|
||||
qqDownloader.ShouldNotBeNull();
|
||||
var lyric = await qqDownloader.DownloadAsync("Hollow", "Janet Leon");
|
||||
lyric.ShouldNotBeNull();
|
||||
lyric.IsPruneMusic.ShouldBe(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Network
|
||||
var client = ServiceProvider.GetRequiredService<IWarpHttpClient>();
|
||||
|
||||
var response = await client.GetAsync(@"https://www.baidu.com");
|
||||
|
||||
|
||||
response.ShouldNotBeNull();
|
||||
response.ShouldContain("百度");
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ZonyLrcTools.Cli.Commands;
|
||||
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Extensions;
|
||||
|
||||
namespace ZonyLrcTools.Tests
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user