mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 20:30:41 +00:00
feat: Support song depth search.
This commit is contained in:
parent
f519eb1251
commit
6d7ee04b74
@ -9,7 +9,6 @@ using McMaster.Extensions.CommandLineUtils;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using NAudio.Wave;
|
using NAudio.Wave;
|
||||||
using TagLib.Mpeg;
|
|
||||||
using ZonyLrcTools.Cli.Config;
|
using ZonyLrcTools.Cli.Config;
|
||||||
using ZonyLrcTools.Cli.Infrastructure;
|
using ZonyLrcTools.Cli.Infrastructure;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Album;
|
using ZonyLrcTools.Cli.Infrastructure.Album;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Lyric;
|
using ZonyLrcTools.Cli.Infrastructure.Lyric;
|
||||||
|
|
||||||
namespace ZonyLrcTools.Cli.Config;
|
namespace ZonyLrcTools.Cli.Config;
|
||||||
@ -8,6 +9,11 @@ public class LyricOption
|
|||||||
public IEnumerable<LyricProviderOption> Plugin { get; set; }
|
public IEnumerable<LyricProviderOption> Plugin { get; set; }
|
||||||
|
|
||||||
public LyricConfigOption Config { get; set; }
|
public LyricConfigOption Config { get; set; }
|
||||||
|
|
||||||
|
public LyricProviderOption GetLyricProviderOption(string name)
|
||||||
|
{
|
||||||
|
return Plugin.FirstOrDefault(x => x.Name == name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LyricConfigOption
|
public class LyricConfigOption
|
||||||
|
@ -11,5 +11,10 @@
|
|||||||
/// 歌词下载时的优先级,当值为 -1 时是禁用。
|
/// 歌词下载时的优先级,当值为 -1 时是禁用。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Priority { get; set; }
|
public int Priority { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 搜索深度,值越大搜索结果越多,但搜索时间越长。
|
||||||
|
/// </summary>
|
||||||
|
public int Depth { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using ZonyLrcTools.Cli.Infrastructure.Lyric;
|
using ZonyLrcTools.Cli.Infrastructure.Tag;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Tag;
|
|
||||||
|
|
||||||
namespace ZonyLrcTools.Cli.Config;
|
namespace ZonyLrcTools.Cli.Config;
|
||||||
|
|
||||||
|
@ -12,11 +12,17 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel
|
|||||||
|
|
||||||
[JsonProperty("keyword")] public string Keyword { get; }
|
[JsonProperty("keyword")] public string Keyword { get; }
|
||||||
|
|
||||||
public SongSearchRequest(string musicName, string artistName)
|
[JsonProperty("pagesize")] public int PageSize { get; }
|
||||||
|
|
||||||
|
[JsonProperty("page")] public int Page { get; }
|
||||||
|
|
||||||
|
public SongSearchRequest(string musicName, string artistName, int pageSize = 30)
|
||||||
{
|
{
|
||||||
Filter = 2;
|
Filter = 2;
|
||||||
Platform = "WebFilter";
|
Platform = "WebFilter";
|
||||||
Keyword = HttpUtility.UrlEncode($"{musicName}+{artistName}", Encoding.UTF8);
|
Keyword = HttpUtility.UrlEncode($"{musicName}+{artistName}", Encoding.UTF8);
|
||||||
|
PageSize = pageSize;
|
||||||
|
Page = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using ZonyLrcTools.Cli.Config;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Exceptions;
|
using ZonyLrcTools.Cli.Infrastructure.Exceptions;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel;
|
using ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Network;
|
using ZonyLrcTools.Cli.Infrastructure.Network;
|
||||||
@ -14,22 +16,25 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou
|
|||||||
|
|
||||||
private readonly IWarpHttpClient _warpHttpClient;
|
private readonly IWarpHttpClient _warpHttpClient;
|
||||||
private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory;
|
private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory;
|
||||||
|
private readonly ToolOptions _options;
|
||||||
|
|
||||||
private const string KuGouSearchMusicUrl = @"https://songsearch.kugou.com/song_search_v2";
|
private const string KuGouSearchMusicUrl = @"https://songsearch.kugou.com/song_search_v2";
|
||||||
private const string KuGouGetLyricAccessKeyUrl = @"http://lyrics.kugou.com/search";
|
private const string KuGouGetLyricAccessKeyUrl = @"http://lyrics.kugou.com/search";
|
||||||
private const string KuGouGetLyricUrl = @"http://lyrics.kugou.com/download";
|
private const string KuGouGetLyricUrl = @"http://lyrics.kugou.com/download";
|
||||||
|
|
||||||
public KuGourLyricDownloader(IWarpHttpClient warpHttpClient,
|
public KuGourLyricDownloader(IWarpHttpClient warpHttpClient,
|
||||||
ILyricItemCollectionFactory lyricItemCollectionFactory)
|
ILyricItemCollectionFactory lyricItemCollectionFactory,
|
||||||
|
IOptions<ToolOptions> options)
|
||||||
{
|
{
|
||||||
_warpHttpClient = warpHttpClient;
|
_warpHttpClient = warpHttpClient;
|
||||||
_lyricItemCollectionFactory = lyricItemCollectionFactory;
|
_lyricItemCollectionFactory = lyricItemCollectionFactory;
|
||||||
|
_options = options.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async ValueTask<byte[]> DownloadDataAsync(LyricDownloaderArgs args)
|
protected override async ValueTask<byte[]> DownloadDataAsync(LyricDownloaderArgs args)
|
||||||
{
|
{
|
||||||
var searchResult = await _warpHttpClient.GetAsync<SongSearchResponse>(KuGouSearchMusicUrl,
|
var searchResult = await _warpHttpClient.GetAsync<SongSearchResponse>(KuGouSearchMusicUrl,
|
||||||
new SongSearchRequest(args.SongName, args.Artist));
|
new SongSearchRequest(args.SongName, args.Artist, _options.Provider.Lyric.GetLyricProviderOption(DownloaderName).Depth));
|
||||||
|
|
||||||
ValidateSongSearchResponse(searchResult, args);
|
ValidateSongSearchResponse(searchResult, args);
|
||||||
|
|
||||||
|
@ -54,13 +54,14 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase.JsonModel
|
|||||||
Limit = 10;
|
Limit = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SongSearchRequest(string musicName, string artistName) : this()
|
public SongSearchRequest(string musicName, string artistName, int limit = 10) : this()
|
||||||
{
|
{
|
||||||
// Remove all the brackets and the content inside them.
|
// Remove all the brackets and the content inside them.
|
||||||
var regex = new Regex(@"\([^)]*\)");
|
var regex = new Regex(@"\([^)]*\)");
|
||||||
musicName = regex.Replace(musicName, string.Empty);
|
musicName = regex.Replace(musicName, string.Empty);
|
||||||
|
|
||||||
SearchKey = HttpUtility.UrlEncode($"{musicName}+{artistName}", Encoding.UTF8);
|
SearchKey = HttpUtility.UrlEncode($"{musicName}+{artistName}", Encoding.UTF8);
|
||||||
|
Limit = limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,9 @@ using System;
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using ZonyLrcTools.Cli.Config;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Exceptions;
|
using ZonyLrcTools.Cli.Infrastructure.Exceptions;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase.JsonModel;
|
using ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase.JsonModel;
|
||||||
using ZonyLrcTools.Cli.Infrastructure.Network;
|
using ZonyLrcTools.Cli.Infrastructure.Network;
|
||||||
@ -15,6 +17,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase
|
|||||||
|
|
||||||
private readonly IWarpHttpClient _warpHttpClient;
|
private readonly IWarpHttpClient _warpHttpClient;
|
||||||
private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory;
|
private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory;
|
||||||
|
private readonly ToolOptions _options;
|
||||||
|
|
||||||
private const string NetEaseSearchMusicUrl = @"https://music.163.com/api/search/get/web";
|
private const string NetEaseSearchMusicUrl = @"https://music.163.com/api/search/get/web";
|
||||||
private const string NetEaseGetLyricUrl = @"https://music.163.com/api/song/lyric";
|
private const string NetEaseGetLyricUrl = @"https://music.163.com/api/song/lyric";
|
||||||
@ -23,17 +26,19 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase
|
|||||||
private const string NetEaseRequestContentType = @"application/x-www-form-urlencoded";
|
private const string NetEaseRequestContentType = @"application/x-www-form-urlencoded";
|
||||||
|
|
||||||
public NetEaseLyricDownloader(IWarpHttpClient warpHttpClient,
|
public NetEaseLyricDownloader(IWarpHttpClient warpHttpClient,
|
||||||
ILyricItemCollectionFactory lyricItemCollectionFactory)
|
ILyricItemCollectionFactory lyricItemCollectionFactory,
|
||||||
|
IOptions<ToolOptions> options)
|
||||||
{
|
{
|
||||||
_warpHttpClient = warpHttpClient;
|
_warpHttpClient = warpHttpClient;
|
||||||
_lyricItemCollectionFactory = lyricItemCollectionFactory;
|
_lyricItemCollectionFactory = lyricItemCollectionFactory;
|
||||||
|
_options = options.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async ValueTask<byte[]> DownloadDataAsync(LyricDownloaderArgs args)
|
protected override async ValueTask<byte[]> DownloadDataAsync(LyricDownloaderArgs args)
|
||||||
{
|
{
|
||||||
var searchResult = await _warpHttpClient.PostAsync<SongSearchResponse>(
|
var searchResult = await _warpHttpClient.PostAsync<SongSearchResponse>(
|
||||||
NetEaseSearchMusicUrl,
|
NetEaseSearchMusicUrl,
|
||||||
new SongSearchRequest(args.SongName, args.Artist),
|
new SongSearchRequest(args.SongName, args.Artist, _options.Provider.Lyric.GetLyricProviderOption(DownloaderName).Depth),
|
||||||
true,
|
true,
|
||||||
msg =>
|
msg =>
|
||||||
{
|
{
|
||||||
|
@ -35,10 +35,13 @@ globalOption:
|
|||||||
plugin:
|
plugin:
|
||||||
- name: NetEase # 基于网易云音乐的歌词下载器。
|
- name: NetEase # 基于网易云音乐的歌词下载器。
|
||||||
priority: 1 # 优先级,升序排列,改为 -1 时禁用。
|
priority: 1 # 优先级,升序排列,改为 -1 时禁用。
|
||||||
|
depth: 30 # 搜索深度,值越大搜索结果越多,但搜索时间越长。
|
||||||
- name: QQ # 基于 QQ 音乐的歌词下载器。
|
- name: QQ # 基于 QQ 音乐的歌词下载器。
|
||||||
priority: 2
|
priority: 2
|
||||||
|
# depth: 10 # 暂时不支持。
|
||||||
- name: KuGou # 基于酷狗音乐的歌词下载器。
|
- name: KuGou # 基于酷狗音乐的歌词下载器。
|
||||||
priority: 3
|
priority: 3
|
||||||
|
depth: 10
|
||||||
# 歌词下载的一些共有配置参数。
|
# 歌词下载的一些共有配置参数。
|
||||||
config:
|
config:
|
||||||
isOneLine: true # 双语歌词是否合并为一行展示。
|
isOneLine: true # 双语歌词是否合并为一行展示。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user