From e02fa70de1b4e28669b5cbf619841d511626da5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E7=85=8C?= Date: Sun, 17 Nov 2019 13:15:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NLyric/Arguments.cs | 54 +++++++++++++++++++++++++++++++++++++++++++- NLyric/NLyric.csproj | 4 ++-- NLyric/NLyricImpl.cs | 53 ++++++++++++++----------------------------- README.md | 4 +++- 4 files changed, 75 insertions(+), 40 deletions(-) diff --git a/NLyric/Arguments.cs b/NLyric/Arguments.cs index 4cb9ac1..5f82183 100644 --- a/NLyric/Arguments.cs +++ b/NLyric/Arguments.cs @@ -1,11 +1,43 @@ +using System; using System.Cli; using System.IO; namespace NLyric { internal sealed class Arguments { private string _directory; + private string _account; + private string _password; + + [Argument("-d", IsRequired = false, DefaultValue = "", Type = "DIR", Description = "存放音乐的文件夹,可以是相对路径或者绝对路径")] + public string DirectoryCliSetter { + set { + if (string.IsNullOrEmpty(value)) + return; + + Directory = value; + } + } + + [Argument("-a", IsRequired = false, DefaultValue = "", Type = "STR", Description = "网易云音乐账号(邮箱/手机号)")] + public string AccountCliSetter { + set { + if (string.IsNullOrEmpty(value)) + return; + + Account = value; + } + } + + [Argument("-p", IsRequired = false, DefaultValue = "", Type = "STR", Description = "网易云音乐密码")] + public string PasswordCliSetter { + set { + if (string.IsNullOrEmpty(value)) + return; + + Password = value; + } + } - [Argument("-d", IsRequired = true, Type = "DIR", Description = "存放音乐的文件夹,可以是相对路径或者绝对路径")] public string Directory { get => _directory; set { @@ -15,5 +47,25 @@ public string Directory { _directory = Path.GetFullPath(value); } } + + public string Account { + get => _account; + set { + if (string.IsNullOrEmpty(value)) + throw new ArgumentNullException(nameof(value)); + + _account = value; + } + } + + public string Password { + get => _password; + set { + if (string.IsNullOrEmpty(value)) + throw new ArgumentNullException(nameof(value)); + + _password = value; + } + } } } diff --git a/NLyric/NLyric.csproj b/NLyric/NLyric.csproj index 95bd78c..57f265b 100644 --- a/NLyric/NLyric.csproj +++ b/NLyric/NLyric.csproj @@ -4,8 +4,8 @@ NLyric NLyric Copyright © 2019 Wwh - 2.2.5.3 - 2.2.5.3 + 2.2.6.0 + 2.2.6.0 ..\bin\$(Configuration) Exe netcoreapp2.1;net472 diff --git a/NLyric/NLyricImpl.cs b/NLyric/NLyricImpl.cs index bac38dc..3bba7fc 100644 --- a/NLyric/NLyricImpl.cs +++ b/NLyric/NLyricImpl.cs @@ -27,14 +27,8 @@ internal static class NLyricImpl { private static AllCaches _allCaches; public static async Task ExecuteAsync(Arguments arguments) { - for (int i = 0; i < 3; i++) - Logger.Instance.LogInfo("登录可避免出现大部分API错误!!!软件出错请尝试登录!!!", ConsoleColor.Green); - Logger.Instance.LogInfo("重要的事情说3遍!!!", ConsoleColor.Green); - Logger.Instance.LogNewLine(); - Logger.Instance.LogInfo("程序会自动过滤相似度为0的结果与歌词未被收集的结果!!!", ConsoleColor.Green); - Logger.Instance.LogNewLine(); + await LoginIfNeedAsync(arguments); _allCachesPath = Path.Combine(arguments.Directory, ".nlyric"); - await LoginIfNeedAsync(); LoadLocalCaches(); foreach (string audioPath in Directory.EnumerateFiles(arguments.Directory, "*", SearchOption.AllDirectories)) { string lrcPath; @@ -56,34 +50,21 @@ public static async Task ExecuteAsync(Arguments arguments) { SaveLocalCaches(); } - private static async Task LoginIfNeedAsync() { - do { - string userInput; - - Logger.Instance.LogInfo("如果需要登录,请输入Y,反之输入N"); - userInput = Console.ReadLine().Trim().ToUpperInvariant(); - if (userInput == "Y") { - string account; - string password; - - Console.WriteLine("请输入账号"); - account = Console.ReadLine(); - Console.WriteLine("请输入密码"); - password = Console.ReadLine(); - if (await CloudMusic.LoginAsync(account, password)) { - Logger.Instance.LogInfo("登录成功", ConsoleColor.Green); - break; - } - else { - Logger.Instance.LogError("登录失败,请重试"); - Logger.Instance.LogNewLine(); - } + private static async Task LoginIfNeedAsync(Arguments arguments) { + if (string.IsNullOrEmpty(arguments.Account) || string.IsNullOrEmpty(arguments.Password)) { + for (int i = 0; i < 3; i++) + Logger.Instance.LogInfo("登录可避免出现大部分API错误!!!当前是免登录状态,若软件出错请尝试登录!!!", ConsoleColor.Green); + Logger.Instance.LogInfo("强烈建议登录使用软件:\"NLyric.exe -d C:\\Music -a example@example.com -p 123456\"", ConsoleColor.Green); + } + else { + Logger.Instance.LogInfo("登录中...", ConsoleColor.Green); + if (await CloudMusic.LoginAsync(arguments.Account, arguments.Password)) + Logger.Instance.LogInfo("登录成功!", ConsoleColor.Green); + else { + Logger.Instance.LogError("登录失败,输入任意键以免登录模式运行或重新运行尝试再次登录!"); + Console.ReadKey(); } - else if (userInput == "N") - break; - else - Logger.Instance.LogWarning("输入有误,请重新输入!"); - } while (true); + } Logger.Instance.LogNewLine(); } @@ -518,7 +499,7 @@ private static TSource Select(TSource[] sources, TTarget targe if (sources.Length == 0) return null; - Logger.Instance.LogInfo("请手动输入1,2,3...选择匹配的项,若不存在,请输入Pass。"); + Logger.Instance.LogInfo("请手动输入1,2,3...选择匹配的项,若不存在,请输入P。"); Logger.Instance.LogInfo("对比项:" + TrackOrAlbumToString(target)); for (int i = 0; i < sources.Length; i++) { double nameSimilarity; @@ -539,7 +520,7 @@ private static TSource Select(TSource[] sources, TTarget targe int index; userInput = Console.ReadLine().Trim(); - if (userInput.ToUpperInvariant() == "PASS") + if (userInput.ToUpperInvariant() == "P") break; if (int.TryParse(userInput, out index)) { index -= 1; diff --git a/README.md b/README.md index e4df223..53425bf 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ 可选择登录或免登陆下载,避免出现网易云音乐接口异常。 +网易云音乐已屏蔽部分关键字,导致搜索出现异常,属于正常现象(网易云音乐客户端内很多歌曲名已经打上\*号)。 + ![首次运行](./Images/首次运行.png) 首次运行,无需配置直接使用。 @@ -28,7 +30,7 @@ 2. 进入解压后的文件夹(内有NLyric.exe等文件),在文件夹内按住Shift,鼠标单击右键,选"在此处打开命令窗口" -3. 输入命令"NLyric.exe -d *音乐文件夹*" +3. 输入命令"NLyric.exe -d *音乐文件夹* -a *网易云音乐账号* -p *网易云音乐密码*"以登录模式启动,或输入命令"NLyric.exe -d *音乐文件夹*"以免登录模式启动(NLyric不会保存您的账号密码或将您的账号密码发送到第三方,NLyric仅会调用网易云音乐官方API) 4. 按照程序提示完成接下来的步骤