@@ -75,7 +75,7 @@ private static String getNumber() {
75
75
}
76
76
77
77
private static String [] login () throws IOException {
78
- boolean loginSuccess = false ;
78
+ boolean webSuccess = false , tvSuccess = false ;
79
79
String sessData = "#" , accessToken = "" , cookie = "#" ;
80
80
if (config .exists ()) {
81
81
ConfigManager .init (config );
@@ -88,23 +88,22 @@ private static String[] login() throws IOException {
88
88
JSONObject login = HttpManager .readJsonFromUrl ("https://api.bilibili.com/x/web-interface/nav" , cookie , false );
89
89
if (login .getIntValue ("code" ) == 0 )
90
90
if (login .getJSONObject ("data" ).getBoolean ("isLogin" )) {
91
- if (debug )
92
- System .out .println ("检测到配置文件,已自动填充 SESSDATA\n ID:" + login .getJSONObject ("data" ).getString ("uname" ) + "\n UID:" + login .getJSONObject ("data" ).getIntValue ("mid" ));
93
- loginSuccess = true ;
91
+ System .out .println ("成功使用保存的 SESSDATA 登录\n ID:" + login .getJSONObject ("data" ).getString ("uname" ) + "\n UID:" + login .getJSONObject ("data" ).getIntValue ("mid" ));
92
+ webSuccess = true ;
94
93
}
95
94
}
96
95
if (map .containsKey ("access-token" )) {
97
96
accessToken = (String ) map .get ("access-token" );
98
97
String params = "access_key=" + accessToken + "&appkey=4409e2ce8ffd12b8&ts=" + System .currentTimeMillis ();
99
98
JSONObject login = HttpManager .readJsonFromUrl ("https://app.bilibili.com/x/v2/account/myinfo?" + params + "&sign=" + SignUtil .generate (params ), "#" , true );
100
99
if (login .getIntValue ("code" ) == 0 ) {
101
- if (debug )
102
- System .out .println ("检测到配置文件,已自动填充 token\n ID:" + login .getJSONObject ("data" ).getString ("name" ) + "\n UID:" + login .getJSONObject ("data" ).getIntValue ("mid" ));
103
- loginSuccess = true ;
100
+ System .out .println ("成功使用保存的 TOKEN 登录\n ID:" + login .getJSONObject ("data" ).getString ("name" ) + "\n UID:" + login .getJSONObject ("data" ).getIntValue ("mid" ));
101
+ tvSuccess = true ;
104
102
}
105
103
}
106
104
}
107
- do {
105
+ boolean loginSuccess = webSuccess && tvSuccess ;
106
+ while (!loginSuccess ) {
108
107
System .out .println ("\n 登录方式:\n 1. WEB 端二维码登录\n 2. TV 端二维码登录\n 3. 输入 SESSDATA 登录\n 4. 跳过登录\n 请选择登录方式(输入 1~4 之间的整数):" );
109
108
int method = inputInt ();
110
109
if (method < 1 ) {
@@ -117,45 +116,34 @@ private static String[] login() throws IOException {
117
116
}
118
117
if (method == 1 ) {
119
118
LoginManager .showQRCodeFromWeb ();
120
- while (true )
121
- if (!LoginManager .sessData .equalsIgnoreCase ("*Not_Yet_Prepared*" ))
122
- break ;
123
119
sessData = LoginManager .sessData ;
124
120
if (sessData .isEmpty ()) {
125
121
System .out .println ("登录失败" );
126
- if (hint ) System .out .println ("请决定是否继续登录(输入“Y”或“N”):" );
127
- if (input ().equalsIgnoreCase ("Y" ))
128
- continue ;
129
122
}
130
123
} else if (method == 2 ) {
131
124
LoginManager .showQRCodeFromTV ();
132
- while (true )
133
- if (!LoginManager .accessToken .equalsIgnoreCase ("*Not_Yet_Prepared*" ))
134
- break ;
135
125
accessToken = LoginManager .accessToken ;
136
126
if (accessToken .isEmpty ()) {
137
127
System .out .println ("登录失败" );
138
- if (hint ) System .out .println ("请决定是否继续登录(输入“Y”或“N”):" );
139
- if (input ().equalsIgnoreCase ("Y" ))
140
- continue ;
141
128
}
142
129
} else if (method == 3 ) {
143
130
if (hint ) System .out .println ("\n 请输入 Cookie 中 SESSDATA 的值:" );
144
131
sessData = input ();
145
132
} else {
146
133
break ;
147
134
}
148
- if (sessData .equals ("#" )) {
149
- cookie = "#" ;
150
- break ;
151
- } else if (method != 2 ) {
135
+ if (method != 2 ) {
136
+ if (sessData .equals ("#" )) {
137
+ cookie = "#" ;
138
+ break ;
139
+ }
152
140
cookie = "SESSDATA=" + sessData + "; Path=/; Domain=bilibili.com;" ;
153
141
JSONObject login = HttpManager .readJsonFromUrl ("https://api.bilibili.com/x/web-interface/nav" , cookie , false );
154
142
if (login .getIntValue ("code" ) == 0 )
155
143
if (login .getJSONObject ("data" ).getBoolean ("isLogin" )) {
156
144
loginSuccess = true ;
157
145
System .out .println ("登录成功" + (debug ? "\n ID:" + login .getJSONObject ("data" ).getString ("uname" ) + "\n UID:" + login .getJSONObject ("data" ).getIntValue ("mid" ) : "" ));
158
- if (hint ) System .out .println ("请决定是否保存该 SESSDATA(输入“Y”或 “N”):" );
146
+ if (hint ) System .out .println ("请决定是否保存该 SESSDATA(输入“Y”代表是,输入 “N”代表否 ):" );
159
147
if (input ().equalsIgnoreCase ("Y" )) {
160
148
if (!config .exists ()) config .createNewFile ();
161
149
ConfigManager .init (config );
@@ -166,55 +154,40 @@ private static String[] login() throws IOException {
166
154
ConfigManager .dump (map );
167
155
if (hint ) System .out .println ("已保存 SESSDATA" );
168
156
}
169
- if (hint ) System .out .println ("请决定是否继续登录(输入“Y”或 “N”):" );
157
+ if (hint ) System .out .println ("请决定是否继续登录(输入“Y”代表是,输入 “N”代表否 ):" );
170
158
if (input ().equalsIgnoreCase ("Y" ))
171
159
loginSuccess = false ;
172
160
} else {
173
161
System .out .println ("登录失败" );
174
- if (loginSuccess ) {
175
- if (hint ) System .out .println ("请决定是否继续登录(输入“Y”或“N”):" );
176
- if (input ().equalsIgnoreCase ("Y" ))
177
- loginSuccess = false ;
178
- }
179
162
}
180
163
else {
181
164
System .out .println ("登录失败" );
182
- if (loginSuccess ) {
183
- if (hint ) System .out .println ("请决定是否继续登录(输入“Y”或“N”):" );
184
- if (input ().equalsIgnoreCase ("Y" ))
185
- loginSuccess = false ;
186
- }
187
165
}
188
166
} else {
189
167
String params = "access_key=" + accessToken + "&appkey=4409e2ce8ffd12b8&ts=" + System .currentTimeMillis ();
190
168
JSONObject login = HttpManager .readJsonFromUrl ("https://app.bilibili.com/x/v2/account/myinfo?" + params + "&sign=" + SignUtil .generate (params ), "#" , true );
191
169
if (login .getIntValue ("code" ) == 0 ) {
192
170
loginSuccess = true ;
193
171
System .out .println ("登录成功" + (debug ? "\n ID:" + login .getJSONObject ("data" ).getString ("name" ) + "\n UID:" + login .getJSONObject ("data" ).getIntValue ("mid" ) : "" ));
194
- if (hint ) System .out .println ("请决定是否保存该 token (输入“Y”或 “N”):" );
172
+ if (hint ) System .out .println ("请决定是否保存该 TOKEN (输入“Y”代表是,输入 “N”代表否 ):" );
195
173
if (input ().equalsIgnoreCase ("Y" )) {
196
174
if (!config .exists ()) config .createNewFile ();
197
175
ConfigManager .init (config );
198
176
Map <String , Object > map = ConfigManager .get ();
199
177
if (map == null )
200
178
map = new LinkedHashMap <>();
201
- map .put ("access-token" , sessData );
179
+ map .put ("access-token" , accessToken );
202
180
ConfigManager .dump (map );
203
- if (hint ) System .out .println ("已保存 token " );
181
+ if (hint ) System .out .println ("已保存 TOKEN " );
204
182
}
205
- if (hint ) System .out .println ("请决定是否继续登录(输入“Y”或 “N”):" );
183
+ if (hint ) System .out .println ("请决定是否继续登录(输入“Y”代表是,输入 “N”代表否 ):" );
206
184
if (input ().equalsIgnoreCase ("Y" ))
207
185
loginSuccess = false ;
208
186
} else {
209
187
System .out .println ("登录失败" );
210
- if (loginSuccess ) {
211
- if (hint ) System .out .println ("请决定是否继续登录(输入“Y”或“N”):" );
212
- if (input ().equalsIgnoreCase ("Y" ))
213
- loginSuccess = false ;
214
- }
215
188
}
216
189
}
217
- } while (! loginSuccess );
190
+ }
218
191
return new String []{cookie , accessToken };
219
192
}
220
193
@@ -334,7 +307,7 @@ private static String[] getPath(String name) throws IOException {
334
307
savePath = input ();
335
308
File file = new File (savePath );
336
309
if (!file .exists ()) {
337
- if (hint ) System .out .println ("该目录不存在,请决定是否创建该目录(输入“Y”或 “N”):" );
310
+ if (hint ) System .out .println ("该目录不存在,请决定是否创建该目录(输入“Y”代表是,输入 “N”代表否 ):" );
338
311
if (input ().equalsIgnoreCase ("Y" )) {
339
312
pathSuccess = file .mkdirs ();
340
313
if (!pathSuccess ) System .out .println ("创建目录失败" );
@@ -343,7 +316,7 @@ private static String[] getPath(String name) throws IOException {
343
316
pathSuccess = true ;
344
317
}
345
318
if (pathSuccess ) {
346
- if (hint ) System .out .println ("请决定是否保存该保存路径(输入“Y”或 “N”):" );
319
+ if (hint ) System .out .println ("请决定是否保存该保存路径(输入“Y”代表是,输入 “N”代表否 ):" );
347
320
if (input ().equalsIgnoreCase ("Y" )) {
348
321
if (!config .exists ()) config .createNewFile ();
349
322
ConfigManager .init (config );
@@ -401,7 +374,7 @@ private static void download(Object[] details, String[] path) throws IOException
401
374
ffmpeg = ffmpegPath .endsWith ("ffmpeg.exe" ) ? new File (ffmpegPath ) : new File (ffmpegPath , "ffmpeg.exe" );
402
375
ffmpegSuccess = ffmpeg .exists () ? 1 : 0 ;
403
376
if (ffmpegSuccess == 1 ) {
404
- if (hint ) System .out .println ("请决定是否保存 FFmpeg 路径(输入“Y”或 “N”):" );
377
+ if (hint ) System .out .println ("请决定是否保存 FFmpeg 路径(输入“Y”代表是,输入 “N”代表否 ):" );
405
378
if (input ().equalsIgnoreCase ("Y" )) {
406
379
if (!config .exists ()) config .createNewFile ();
407
380
ConfigManager .init (config );
0 commit comments