Skip to content

Commit

Permalink
修改登录方式
Browse files Browse the repository at this point in the history
  • Loading branch information
wwh1004 committed Nov 17, 2019
1 parent 9485d9b commit e02fa70
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 40 deletions.
54 changes: 53 additions & 1 deletion NLyric/Arguments.cs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
}
}
}
}
4 changes: 2 additions & 2 deletions NLyric/NLyric.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<Title>NLyric</Title>
<Product>NLyric</Product>
<Copyright>Copyright © 2019 Wwh</Copyright>
<AssemblyVersion>2.2.5.3</AssemblyVersion>
<FileVersion>2.2.5.3</FileVersion>
<AssemblyVersion>2.2.6.0</AssemblyVersion>
<FileVersion>2.2.6.0</FileVersion>
<OutputPath>..\bin\$(Configuration)</OutputPath>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>
Expand Down
53 changes: 17 additions & 36 deletions NLyric/NLyricImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 [email protected] -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();
}

Expand Down Expand Up @@ -518,7 +499,7 @@ private static TSource Select<TSource, TTarget>(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;
Expand All @@ -539,7 +520,7 @@ private static TSource Select<TSource, TTarget>(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;
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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

网易云音乐已屏蔽部分关键字,导致搜索出现异常,属于正常现象(网易云音乐客户端内很多歌曲名已经打上\*号)。

![首次运行](./Images/首次运行.png)
首次运行,无需配置直接使用。

Expand All @@ -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. 按照程序提示完成接下来的步骤

Expand Down

0 comments on commit e02fa70

Please sign in to comment.