mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-02 05:10:42 +00:00
feat: Add qq music album downlaoder code.
This commit is contained in:
parent
3c9d98897f
commit
78cb9c14c1
@ -13,7 +13,16 @@ namespace ZonyLrcTools.Cli.Infrastructure.Album.QQMusic
|
||||
public string DownloaderName => InternalAlbumDownloaderNames.QQ;
|
||||
|
||||
private readonly IWarpHttpClient _warpHttpClient;
|
||||
private readonly Action<HttpRequestMessage> _defaultOption;
|
||||
|
||||
private readonly Action<HttpRequestMessage> _defaultOption = message =>
|
||||
{
|
||||
message.Headers.Referrer = new Uri(DefaultReferer);
|
||||
|
||||
if (message.Content != null)
|
||||
{
|
||||
message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
|
||||
}
|
||||
};
|
||||
|
||||
private const string SearchApi = "https://c.y.qq.com/soso/fcgi-bin/client_search_cp";
|
||||
private const string DefaultReferer = "https://y.qq.com";
|
||||
@ -21,15 +30,6 @@ namespace ZonyLrcTools.Cli.Infrastructure.Album.QQMusic
|
||||
public QQMusicAlbumDownloader(IWarpHttpClient warpHttpClient)
|
||||
{
|
||||
_warpHttpClient = warpHttpClient;
|
||||
_defaultOption = message =>
|
||||
{
|
||||
message.Headers.Referrer = new Uri(DefaultReferer);
|
||||
|
||||
if (message.Content != null)
|
||||
{
|
||||
message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public async ValueTask<byte[]> DownloadAsync(string songName, string artist)
|
||||
@ -37,9 +37,9 @@ namespace ZonyLrcTools.Cli.Infrastructure.Album.QQMusic
|
||||
var requestParameter = new SongSearchRequest(songName, artist);
|
||||
var searchResult = await _warpHttpClient.GetAsync<SongSearchResponse>(
|
||||
SearchApi,
|
||||
requestParameter);
|
||||
requestParameter, _defaultOption);
|
||||
|
||||
return null;
|
||||
return new byte[] {0x1, 0x2};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shouldly;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Album;
|
||||
|
||||
namespace ZonyLrcTools.Tests.Infrastructure.Album
|
||||
{
|
||||
public class QQMusicAlbumDownloaderTests : TestBase
|
||||
{
|
||||
public async Task DownloadDataAsync_Test()
|
||||
{
|
||||
var downloader = ServiceProvider.GetRequiredService<IEnumerable<IAlbumDownloader>>()
|
||||
.FirstOrDefault(x => x.DownloaderName == InternalAlbumDownloaderNames.QQ);
|
||||
|
||||
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);
|
||||
ws.Flush();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user