Skip to content

Commit e02fa70

Browse files
committed
修改登录方式
1 parent 9485d9b commit e02fa70

File tree

4 files changed

+75
-40
lines changed

4 files changed

+75
-40
lines changed

NLyric/Arguments.cs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
1+
using System;
12
using System.Cli;
23
using System.IO;
34

45
namespace NLyric {
56
internal sealed class Arguments {
67
private string _directory;
8+
private string _account;
9+
private string _password;
10+
11+
[Argument("-d", IsRequired = false, DefaultValue = "", Type = "DIR", Description = "存放音乐的文件夹,可以是相对路径或者绝对路径")]
12+
public string DirectoryCliSetter {
13+
set {
14+
if (string.IsNullOrEmpty(value))
15+
return;
16+
17+
Directory = value;
18+
}
19+
}
20+
21+
[Argument("-a", IsRequired = false, DefaultValue = "", Type = "STR", Description = "网易云音乐账号(邮箱/手机号)")]
22+
public string AccountCliSetter {
23+
set {
24+
if (string.IsNullOrEmpty(value))
25+
return;
26+
27+
Account = value;
28+
}
29+
}
30+
31+
[Argument("-p", IsRequired = false, DefaultValue = "", Type = "STR", Description = "网易云音乐密码")]
32+
public string PasswordCliSetter {
33+
set {
34+
if (string.IsNullOrEmpty(value))
35+
return;
36+
37+
Password = value;
38+
}
39+
}
740

8-
[Argument("-d", IsRequired = true, Type = "DIR", Description = "存放音乐的文件夹,可以是相对路径或者绝对路径")]
941
public string Directory {
1042
get => _directory;
1143
set {
@@ -15,5 +47,25 @@ public string Directory {
1547
_directory = Path.GetFullPath(value);
1648
}
1749
}
50+
51+
public string Account {
52+
get => _account;
53+
set {
54+
if (string.IsNullOrEmpty(value))
55+
throw new ArgumentNullException(nameof(value));
56+
57+
_account = value;
58+
}
59+
}
60+
61+
public string Password {
62+
get => _password;
63+
set {
64+
if (string.IsNullOrEmpty(value))
65+
throw new ArgumentNullException(nameof(value));
66+
67+
_password = value;
68+
}
69+
}
1870
}
1971
}

NLyric/NLyric.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<Title>NLyric</Title>
55
<Product>NLyric</Product>
66
<Copyright>Copyright © 2019 Wwh</Copyright>
7-
<AssemblyVersion>2.2.5.3</AssemblyVersion>
8-
<FileVersion>2.2.5.3</FileVersion>
7+
<AssemblyVersion>2.2.6.0</AssemblyVersion>
8+
<FileVersion>2.2.6.0</FileVersion>
99
<OutputPath>..\bin\$(Configuration)</OutputPath>
1010
<OutputType>Exe</OutputType>
1111
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>

NLyric/NLyricImpl.cs

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,8 @@ internal static class NLyricImpl {
2727
private static AllCaches _allCaches;
2828

2929
public static async Task ExecuteAsync(Arguments arguments) {
30-
for (int i = 0; i < 3; i++)
31-
Logger.Instance.LogInfo("登录可避免出现大部分API错误!!!软件出错请尝试登录!!!", ConsoleColor.Green);
32-
Logger.Instance.LogInfo("重要的事情说3遍!!!", ConsoleColor.Green);
33-
Logger.Instance.LogNewLine();
34-
Logger.Instance.LogInfo("程序会自动过滤相似度为0的结果与歌词未被收集的结果!!!", ConsoleColor.Green);
35-
Logger.Instance.LogNewLine();
30+
await LoginIfNeedAsync(arguments);
3631
_allCachesPath = Path.Combine(arguments.Directory, ".nlyric");
37-
await LoginIfNeedAsync();
3832
LoadLocalCaches();
3933
foreach (string audioPath in Directory.EnumerateFiles(arguments.Directory, "*", SearchOption.AllDirectories)) {
4034
string lrcPath;
@@ -56,34 +50,21 @@ public static async Task ExecuteAsync(Arguments arguments) {
5650
SaveLocalCaches();
5751
}
5852

59-
private static async Task LoginIfNeedAsync() {
60-
do {
61-
string userInput;
62-
63-
Logger.Instance.LogInfo("如果需要登录,请输入Y,反之输入N");
64-
userInput = Console.ReadLine().Trim().ToUpperInvariant();
65-
if (userInput == "Y") {
66-
string account;
67-
string password;
68-
69-
Console.WriteLine("请输入账号");
70-
account = Console.ReadLine();
71-
Console.WriteLine("请输入密码");
72-
password = Console.ReadLine();
73-
if (await CloudMusic.LoginAsync(account, password)) {
74-
Logger.Instance.LogInfo("登录成功", ConsoleColor.Green);
75-
break;
76-
}
77-
else {
78-
Logger.Instance.LogError("登录失败,请重试");
79-
Logger.Instance.LogNewLine();
80-
}
53+
private static async Task LoginIfNeedAsync(Arguments arguments) {
54+
if (string.IsNullOrEmpty(arguments.Account) || string.IsNullOrEmpty(arguments.Password)) {
55+
for (int i = 0; i < 3; i++)
56+
Logger.Instance.LogInfo("登录可避免出现大部分API错误!!!当前是免登录状态,若软件出错请尝试登录!!!", ConsoleColor.Green);
57+
Logger.Instance.LogInfo("强烈建议登录使用软件:\"NLyric.exe -d C:\\Music -a example@example.com -p 123456\"", ConsoleColor.Green);
58+
}
59+
else {
60+
Logger.Instance.LogInfo("登录中...", ConsoleColor.Green);
61+
if (await CloudMusic.LoginAsync(arguments.Account, arguments.Password))
62+
Logger.Instance.LogInfo("登录成功!", ConsoleColor.Green);
63+
else {
64+
Logger.Instance.LogError("登录失败,输入任意键以免登录模式运行或重新运行尝试再次登录!");
65+
Console.ReadKey();
8166
}
82-
else if (userInput == "N")
83-
break;
84-
else
85-
Logger.Instance.LogWarning("输入有误,请重新输入!");
86-
} while (true);
67+
}
8768
Logger.Instance.LogNewLine();
8869
}
8970

@@ -518,7 +499,7 @@ private static TSource Select<TSource, TTarget>(TSource[] sources, TTarget targe
518499

519500
if (sources.Length == 0)
520501
return null;
521-
Logger.Instance.LogInfo("请手动输入1,2,3...选择匹配的项,若不存在,请输入Pass。");
502+
Logger.Instance.LogInfo("请手动输入1,2,3...选择匹配的项,若不存在,请输入P。");
522503
Logger.Instance.LogInfo("对比项:" + TrackOrAlbumToString(target));
523504
for (int i = 0; i < sources.Length; i++) {
524505
double nameSimilarity;
@@ -539,7 +520,7 @@ private static TSource Select<TSource, TTarget>(TSource[] sources, TTarget targe
539520
int index;
540521

541522
userInput = Console.ReadLine().Trim();
542-
if (userInput.ToUpperInvariant() == "PASS")
523+
if (userInput.ToUpperInvariant() == "P")
543524
break;
544525
if (int.TryParse(userInput, out index)) {
545526
index -= 1;

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
可选择登录或免登陆下载,避免出现网易云音乐接口异常。
66

7+
网易云音乐已屏蔽部分关键字,导致搜索出现异常,属于正常现象(网易云音乐客户端内很多歌曲名已经打上\*号)。
8+
79
![首次运行](./Images/首次运行.png)
810
首次运行,无需配置直接使用。
911

@@ -28,7 +30,7 @@
2830

2931
2. 进入解压后的文件夹(内有NLyric.exe等文件),在文件夹内按住Shift,鼠标单击右键,选"在此处打开命令窗口"
3032

31-
3. 输入命令"NLyric.exe -d *音乐文件夹*"
33+
3. 输入命令"NLyric.exe -d *音乐文件夹* -a *网易云音乐账号* -p *网易云音乐密码*"以登录模式启动,或输入命令"NLyric.exe -d *音乐文件夹*"以免登录模式启动(NLyric不会保存您的账号密码或将您的账号密码发送到第三方,NLyric仅会调用网易云音乐官方API)
3234

3335
4. 按照程序提示完成接下来的步骤
3436

0 commit comments

Comments
 (0)