diff --git a/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs b/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs index 2984dfb..87c121d 100644 --- a/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs +++ b/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs @@ -9,7 +9,6 @@ using McMaster.Extensions.CommandLineUtils; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using NAudio.Wave; -using TagLib.Mpeg; using ZonyLrcTools.Cli.Config; using ZonyLrcTools.Cli.Infrastructure; using ZonyLrcTools.Cli.Infrastructure.Album; diff --git a/src/ZonyLrcTools.Cli/Config/LyricOption.cs b/src/ZonyLrcTools.Cli/Config/LyricOption.cs index 812b019..e474e4c 100644 --- a/src/ZonyLrcTools.Cli/Config/LyricOption.cs +++ b/src/ZonyLrcTools.Cli/Config/LyricOption.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using ZonyLrcTools.Cli.Infrastructure.Lyric; namespace ZonyLrcTools.Cli.Config; @@ -8,6 +9,11 @@ public class LyricOption public IEnumerable Plugin { get; set; } public LyricConfigOption Config { get; set; } + + public LyricProviderOption GetLyricProviderOption(string name) + { + return Plugin.FirstOrDefault(x => x.Name == name); + } } public class LyricConfigOption diff --git a/src/ZonyLrcTools.Cli/Config/LyricProviderOption.cs b/src/ZonyLrcTools.Cli/Config/LyricProviderOption.cs index 356c165..7d3be8b 100644 --- a/src/ZonyLrcTools.Cli/Config/LyricProviderOption.cs +++ b/src/ZonyLrcTools.Cli/Config/LyricProviderOption.cs @@ -11,5 +11,10 @@ /// 歌词下载时的优先级,当值为 -1 时是禁用。 /// public int Priority { get; set; } + + /// + /// 搜索深度,值越大搜索结果越多,但搜索时间越长。 + /// + public int Depth { get; set; } } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Config/ProviderOption.cs b/src/ZonyLrcTools.Cli/Config/ProviderOption.cs index 87ad51c..011cd94 100644 --- a/src/ZonyLrcTools.Cli/Config/ProviderOption.cs +++ b/src/ZonyLrcTools.Cli/Config/ProviderOption.cs @@ -1,5 +1,4 @@ -using ZonyLrcTools.Cli.Infrastructure.Lyric; -using ZonyLrcTools.Cli.Infrastructure.Tag; +using ZonyLrcTools.Cli.Infrastructure.Tag; namespace ZonyLrcTools.Cli.Config; diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchRequest.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchRequest.cs index c8981e9..b0c4ec4 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchRequest.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/JsonModel/SongSearchRequest.cs @@ -12,11 +12,17 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel [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; Platform = "WebFilter"; Keyword = HttpUtility.UrlEncode($"{musicName}+{artistName}", Encoding.UTF8); + PageSize = pageSize; + Page = 1; } } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/KuGourLyricDownloader.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/KuGourLyricDownloader.cs index 44bfdb2..f17856a 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/KuGourLyricDownloader.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/KuGou/KuGourLyricDownloader.cs @@ -1,7 +1,9 @@ using System; using System.Text; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Newtonsoft.Json.Linq; +using ZonyLrcTools.Cli.Config; using ZonyLrcTools.Cli.Infrastructure.Exceptions; using ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou.JsonModel; using ZonyLrcTools.Cli.Infrastructure.Network; @@ -14,22 +16,25 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou private readonly IWarpHttpClient _warpHttpClient; private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory; + private readonly ToolOptions _options; private const string KuGouSearchMusicUrl = @"https://songsearch.kugou.com/song_search_v2"; private const string KuGouGetLyricAccessKeyUrl = @"http://lyrics.kugou.com/search"; private const string KuGouGetLyricUrl = @"http://lyrics.kugou.com/download"; public KuGourLyricDownloader(IWarpHttpClient warpHttpClient, - ILyricItemCollectionFactory lyricItemCollectionFactory) + ILyricItemCollectionFactory lyricItemCollectionFactory, + IOptions options) { _warpHttpClient = warpHttpClient; _lyricItemCollectionFactory = lyricItemCollectionFactory; + _options = options.Value; } protected override async ValueTask DownloadDataAsync(LyricDownloaderArgs args) { var searchResult = await _warpHttpClient.GetAsync(KuGouSearchMusicUrl, - new SongSearchRequest(args.SongName, args.Artist)); + new SongSearchRequest(args.SongName, args.Artist, _options.Provider.Lyric.GetLyricProviderOption(DownloaderName).Depth)); ValidateSongSearchResponse(searchResult, args); diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/JsonModel/SongSearchRequest.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/JsonModel/SongSearchRequest.cs index df91141..88600d0 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/JsonModel/SongSearchRequest.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/JsonModel/SongSearchRequest.cs @@ -54,13 +54,14 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase.JsonModel 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. var regex = new Regex(@"\([^)]*\)"); musicName = regex.Replace(musicName, string.Empty); SearchKey = HttpUtility.UrlEncode($"{musicName}+{artistName}", Encoding.UTF8); + Limit = limit; } } } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/NetEaseLyricDownloader.cs b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/NetEaseLyricDownloader.cs index 3767997..ab9e14d 100644 --- a/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/NetEaseLyricDownloader.cs +++ b/src/ZonyLrcTools.Cli/Infrastructure/Lyric/NetEase/NetEaseLyricDownloader.cs @@ -2,7 +2,9 @@ using System; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Newtonsoft.Json; +using ZonyLrcTools.Cli.Config; using ZonyLrcTools.Cli.Infrastructure.Exceptions; using ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase.JsonModel; using ZonyLrcTools.Cli.Infrastructure.Network; @@ -15,6 +17,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase private readonly IWarpHttpClient _warpHttpClient; private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory; + private readonly ToolOptions _options; private const string NetEaseSearchMusicUrl = @"https://music.163.com/api/search/get/web"; 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"; public NetEaseLyricDownloader(IWarpHttpClient warpHttpClient, - ILyricItemCollectionFactory lyricItemCollectionFactory) + ILyricItemCollectionFactory lyricItemCollectionFactory, + IOptions options) { _warpHttpClient = warpHttpClient; _lyricItemCollectionFactory = lyricItemCollectionFactory; + _options = options.Value; } protected override async ValueTask DownloadDataAsync(LyricDownloaderArgs args) { var searchResult = await _warpHttpClient.PostAsync( NetEaseSearchMusicUrl, - new SongSearchRequest(args.SongName, args.Artist), + new SongSearchRequest(args.SongName, args.Artist, _options.Provider.Lyric.GetLyricProviderOption(DownloaderName).Depth), true, msg => { diff --git a/src/ZonyLrcTools.Cli/config.yaml b/src/ZonyLrcTools.Cli/config.yaml index 380d93c..af1f20f 100644 --- a/src/ZonyLrcTools.Cli/config.yaml +++ b/src/ZonyLrcTools.Cli/config.yaml @@ -35,10 +35,13 @@ globalOption: plugin: - name: NetEase # 基于网易云音乐的歌词下载器。 priority: 1 # 优先级,升序排列,改为 -1 时禁用。 + depth: 30 # 搜索深度,值越大搜索结果越多,但搜索时间越长。 - name: QQ # 基于 QQ 音乐的歌词下载器。 priority: 2 + # depth: 10 # 暂时不支持。 - name: KuGou # 基于酷狗音乐的歌词下载器。 priority: 3 + depth: 10 # 歌词下载的一些共有配置参数。 config: isOneLine: true # 双语歌词是否合并为一行展示。