mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 12:11:13 +00:00
chore: Move the related configuration items to the Common library.
This commit is contained in:
parent
9f96aa0186
commit
aa90e232f7
@ -8,7 +8,6 @@ using System.Threading.Tasks;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZonyLrcTools.Cli.Config;
|
||||
using ZonyLrcTools.Cli.Infrastructure;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Album;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Exceptions;
|
||||
@ -17,6 +16,7 @@ using ZonyLrcTools.Cli.Infrastructure.IO;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Lyric;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Tag;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Threading;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
using File = System.IO.File;
|
||||
|
||||
namespace ZonyLrcTools.Cli.Commands.SubCommand
|
||||
@ -30,11 +30,11 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
|
||||
private readonly IEnumerable<ILyricDownloader> _lyricDownloaderList;
|
||||
private readonly IEnumerable<IAlbumDownloader> _albumDownloaderList;
|
||||
|
||||
private readonly ToolOptions _options;
|
||||
private readonly GlobalOptions _options;
|
||||
|
||||
public DownloadCommand(ILogger<DownloadCommand> logger,
|
||||
IFileScanner fileScanner,
|
||||
IOptions<ToolOptions> options,
|
||||
IOptions<GlobalOptions> options,
|
||||
ITagLoader tagLoader,
|
||||
IEnumerable<ILyricDownloader> lyricDownloaderList,
|
||||
IEnumerable<IAlbumDownloader> albumDownloaderList)
|
||||
|
@ -4,8 +4,8 @@ using System.Net.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZonyLrcTools.Cli.Config;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Network;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
namespace ZonyLrcTools.Cli.Infrastructure.DependencyInject
|
||||
{
|
||||
@ -27,7 +27,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.DependencyInject
|
||||
services.AddHttpClient(DefaultWarpHttpClient.HttpClientNameConstant)
|
||||
.ConfigurePrimaryHttpMessageHandler(provider =>
|
||||
{
|
||||
var option = provider.GetRequiredService<IOptions<ToolOptions>>().Value;
|
||||
var option = provider.GetRequiredService<IOptions<GlobalOptions>>().Value;
|
||||
|
||||
return new HttpClientHandler
|
||||
{
|
||||
@ -49,7 +49,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.DependencyInject
|
||||
.AddYamlFile("config.yaml")
|
||||
.Build();
|
||||
|
||||
services.Configure<ToolOptions>(configuration.GetSection("globalOption"));
|
||||
services.Configure<GlobalOptions>(configuration.GetSection("globalOption"));
|
||||
|
||||
return services;
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ 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;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou
|
||||
{
|
||||
@ -16,7 +16,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou
|
||||
|
||||
private readonly IWarpHttpClient _warpHttpClient;
|
||||
private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory;
|
||||
private readonly ToolOptions _options;
|
||||
private readonly GlobalOptions _options;
|
||||
|
||||
private const string KuGouSearchMusicUrl = @"https://songsearch.kugou.com/song_search_v2";
|
||||
private const string KuGouGetLyricAccessKeyUrl = @"http://lyrics.kugou.com/search";
|
||||
@ -24,7 +24,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.KuGou
|
||||
|
||||
public KuGourLyricDownloader(IWarpHttpClient warpHttpClient,
|
||||
ILyricItemCollectionFactory lyricItemCollectionFactory,
|
||||
IOptions<ToolOptions> options)
|
||||
IOptions<GlobalOptions> options)
|
||||
{
|
||||
_warpHttpClient = warpHttpClient;
|
||||
_lyricItemCollectionFactory = lyricItemCollectionFactory;
|
||||
|
@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ZonyLrcTools.Cli.Config;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Extensions;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZonyLrcTools.Cli.Config;
|
||||
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
namespace ZonyLrcTools.Cli.Infrastructure.Lyric
|
||||
{
|
||||
@ -10,9 +10,9 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric
|
||||
/// </summary>
|
||||
public class LyricItemCollectionFactory : ILyricItemCollectionFactory, ITransientDependency
|
||||
{
|
||||
private readonly ToolOptions _options;
|
||||
private readonly GlobalOptions _options;
|
||||
|
||||
public LyricItemCollectionFactory(IOptions<ToolOptions> options)
|
||||
public LyricItemCollectionFactory(IOptions<GlobalOptions> options)
|
||||
{
|
||||
_options = options.Value;
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ 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;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase
|
||||
{
|
||||
@ -17,7 +17,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase
|
||||
|
||||
private readonly IWarpHttpClient _warpHttpClient;
|
||||
private readonly ILyricItemCollectionFactory _lyricItemCollectionFactory;
|
||||
private readonly ToolOptions _options;
|
||||
private readonly GlobalOptions _options;
|
||||
|
||||
private const string NetEaseSearchMusicUrl = @"https://music.163.com/api/search/get/web";
|
||||
private const string NetEaseGetLyricUrl = @"https://music.163.com/api/song/lyric";
|
||||
@ -27,7 +27,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase
|
||||
|
||||
public NetEaseLyricDownloader(IWarpHttpClient warpHttpClient,
|
||||
ILyricItemCollectionFactory lyricItemCollectionFactory,
|
||||
IOptions<ToolOptions> options)
|
||||
IOptions<GlobalOptions> options)
|
||||
{
|
||||
_warpHttpClient = warpHttpClient;
|
||||
_lyricItemCollectionFactory = lyricItemCollectionFactory;
|
||||
|
@ -3,19 +3,19 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
using ZonyLrcTools.Cli.Config;
|
||||
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
namespace ZonyLrcTools.Cli.Infrastructure.Tag
|
||||
{
|
||||
/// <inheritdoc cref="ZonyLrcTools.Cli.Infrastructure.Tag.IBlockWordDictionary" />
|
||||
public class BlockWordDictionary : IBlockWordDictionary, ISingletonDependency
|
||||
{
|
||||
private readonly ToolOptions _options;
|
||||
private readonly GlobalOptions _options;
|
||||
|
||||
private readonly Lazy<Dictionary<string, string>> _wordsDictionary;
|
||||
|
||||
public BlockWordDictionary(IOptions<ToolOptions> options)
|
||||
public BlockWordDictionary(IOptions<GlobalOptions> options)
|
||||
{
|
||||
_options = options.Value;
|
||||
|
||||
|
@ -4,9 +4,9 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZonyLrcTools.Cli.Config;
|
||||
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Exceptions;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
namespace ZonyLrcTools.Cli.Infrastructure.Tag
|
||||
{
|
||||
@ -19,13 +19,13 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
|
||||
protected readonly IBlockWordDictionary BlockWordDictionary;
|
||||
protected readonly ILogger<DefaultTagLoader> Logger;
|
||||
|
||||
protected ToolOptions Options;
|
||||
protected GlobalOptions Options;
|
||||
|
||||
private readonly IEnumerable<ITagInfoProvider> _sortedTagInfoProviders;
|
||||
|
||||
public DefaultTagLoader(IEnumerable<ITagInfoProvider> tagInfoProviders,
|
||||
IBlockWordDictionary blockWordDictionary,
|
||||
IOptions<ToolOptions> options,
|
||||
IOptions<GlobalOptions> options,
|
||||
ILogger<DefaultTagLoader> logger)
|
||||
{
|
||||
TagInfoProviders = tagInfoProviders;
|
||||
|
@ -3,8 +3,8 @@ using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZonyLrcTools.Cli.Config;
|
||||
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
namespace ZonyLrcTools.Cli.Infrastructure.Tag
|
||||
{
|
||||
@ -17,9 +17,9 @@ namespace ZonyLrcTools.Cli.Infrastructure.Tag
|
||||
public const string ConstantName = "FileName";
|
||||
public const string RegularExpressionsOption = "regularExpressions";
|
||||
|
||||
private readonly ToolOptions _options;
|
||||
private readonly GlobalOptions _options;
|
||||
|
||||
public FileNameTagInfoProvider(IOptions<ToolOptions> options)
|
||||
public FileNameTagInfoProvider(IOptions<GlobalOptions> options)
|
||||
{
|
||||
_options = options.Value;
|
||||
}
|
||||
|
@ -47,4 +47,8 @@
|
||||
<ProjectReference Include="..\ZonyLrcTools.Common\ZonyLrcTools.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Config" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,13 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using YamlDotNet.Serialization;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Lyric;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Network;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Tag;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
namespace ZonyLrcTools.Cli.Config
|
||||
namespace ZonyLrcTools.Common.Configuration
|
||||
{
|
||||
public class ToolOptions
|
||||
public class GlobalOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 支持的音乐文件后缀集合。
|
@ -1,4 +1,4 @@
|
||||
namespace ZonyLrcTools.Cli.Infrastructure.Network
|
||||
namespace ZonyLrcTools.Common.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// 工具网络相关的设定。
|
@ -1,6 +1,5 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZonyLrcTools.Cli.Config;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Lyric;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
using ZonyLrcTools.Common.Lyrics;
|
||||
|
@ -5,8 +5,8 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZonyLrcTools.Cli.Config;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Lyric;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
namespace ZonyLrcTools.Tests.Infrastructure.Lyric
|
||||
{
|
||||
@ -91,7 +91,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyric
|
||||
[Fact]
|
||||
public async Task DownloadAsync_Issue114_Test()
|
||||
{
|
||||
var options = ServiceProvider.GetRequiredService<IOptions<ToolOptions>>();
|
||||
var options = ServiceProvider.GetRequiredService<IOptions<GlobalOptions>>();
|
||||
options.Value.Provider.Lyric.Config.IsOnlyOutputTranslation = true;
|
||||
|
||||
var lyric = await _lyricDownloader.DownloadAsync("Bones", "Image Dragons");
|
||||
|
@ -3,8 +3,8 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZonyLrcTools.Cli.Config;
|
||||
using ZonyLrcTools.Cli.Infrastructure.Network;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
|
||||
namespace ZonyLrcTools.Tests.Infrastructure.Network
|
||||
{
|
||||
@ -33,7 +33,7 @@ namespace ZonyLrcTools.Tests.Infrastructure.Network
|
||||
[Fact]
|
||||
public async Task GetAsyncWithProxy_Test()
|
||||
{
|
||||
var option = ServiceProvider.GetRequiredService<IOptions<ToolOptions>>();
|
||||
var option = ServiceProvider.GetRequiredService<IOptions<GlobalOptions>>();
|
||||
option.Value.NetworkOptions.Ip = "127.0.0.1";
|
||||
option.Value.NetworkOptions.Port = 4780;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user