Skip to content

Commit 39a44fe

Browse files
committed
Update to 1.1.6
1 parent 78c9804 commit 39a44fe

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
1. **[可跳过]** 使用 `mvn clean package` 命令进行编译。
3030

31-
2. 输入 `java -jar bili-download-1.1.5-jar-with-dependencies.jar`,进入程序。若您希望启用 debug 模式,请在参数中添加 `debug`,即输入 `java -jar bili-download-1.1.5-jar-with-dependencies.jar debug`,这将显示一些调试信息。
31+
2. 输入 `java -jar bili-download-1.1.6-jar-with-dependencies.jar`,进入程序。若您希望启用 debug 模式,请在参数中添加 `debug`,即输入 `java -jar bili-download-1.1.6-jar-with-dependencies.jar debug`,这将显示一些调试信息。
3232

3333
3. 输入一个 AV 号或 BV 号。
3434

@@ -81,6 +81,18 @@
8181
---
8282

8383
# ChangeLog
84+
## 1.1.6
85+
### 1. 添加了退出功能
86+
87+
在每次输入时,若输入 `*exit`,则程序会调用 `System.exit(0)` 中止进程。
88+
89+
### 2. 优化了代码结构
90+
91+
将主函数拆分成了多个函数,每一步为一个函数,增强了代码的可读性。
92+
93+
### 3. 优化了输出
94+
95+
若输入源为 `Input.txt` 文件,则程序在正常模式下将不再显示输入提示,在 `debug` 模式下会一并输出所读取的内容。
8496

8597
## 1.1.5
8698
### 1. 添加了 SESSDATA、保存路径、FFmpeg 路径的记忆功能

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.naptie</groupId>
88
<artifactId>bili-download</artifactId>
9-
<version>1.1.5</version>
9+
<version>1.1.6</version>
1010
<build>
1111
<plugins>
1212
<plugin>

src/main/java/me/naptie/bilidownload/Main.java

+26-20
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@SuppressWarnings("ResultOfMethodCallIgnored")
2424
public class Main {
2525

26-
private static boolean debug;
26+
private static boolean debug, hint, isFileInput;
2727
private static Scanner scanner;
2828
private static File config;
2929
private static long beginTime;
@@ -54,9 +54,13 @@ private static void setScanner() throws FileNotFoundException {
5454
File input = new File("Input.txt");
5555
if (input.exists() && input.length() > 0) {
5656
scanner = new Scanner(input);
57+
isFileInput = true;
58+
hint = debug;
5759
System.out.println("检测到 Input.txt,已切换输入源\n");
5860
} else {
5961
scanner = new Scanner(System.in);
62+
isFileInput = false;
63+
hint = true;
6064
}
6165
}
6266

@@ -66,19 +70,21 @@ private static String inputStr() {
6670
System.out.println("\n程序运行结束;总运行时间:" + getFormattedTime(System.currentTimeMillis() - beginTime));
6771
System.exit(0);
6872
}
73+
if (debug && hint && isFileInput) System.out.println(input);
6974
return input;
7075
}
7176

7277
private static int inputInt() {
7378
String input = scanner.next();
7479
if (input.equalsIgnoreCase("*exit")) {
75-
Thread.currentThread().interrupt();
80+
System.exit(0);
7681
}
82+
if (debug && hint && isFileInput) System.out.println(input);
7783
return Integer.parseInt(input);
7884
}
7985

8086
private static String getNumber() {
81-
System.out.println("请输入一个 AV 号或 BV 号:");
87+
if (hint) System.out.println("请输入一个 AV 号或 BV 号:");
8288
return inputStr();
8389
}
8490

@@ -102,7 +108,7 @@ private static String login() throws IOException {
102108
}
103109
}
104110
while (!loginSuccess) {
105-
System.out.println("\n请输入 Cookie 中 SESSDATA 的值(若无请填“#”):");
111+
if (hint) System.out.println("\n请输入 Cookie 中 SESSDATA 的值(若无请填“#”):");
106112
sessData = inputStr();
107113
if (sessData.equals("#")) {
108114
cookie = "#";
@@ -114,7 +120,7 @@ private static String login() throws IOException {
114120
if (login.getJSONObject("data").getBoolean("isLogin")) {
115121
loginSuccess = true;
116122
System.out.println("登录成功\nID:" + login.getJSONObject("data").getString("uname") + "\nUID:" + login.getJSONObject("data").getIntValue("mid"));
117-
System.out.println("请决定是否保存该 SESSDATA(输入“Y”或“N”):");
123+
if (hint) System.out.println("请决定是否保存该 SESSDATA(输入“Y”或“N”):");
118124
if (inputStr().equalsIgnoreCase("Y")) {
119125
if (!config.exists()) config.createNewFile();
120126
ConfigManager.init(config);
@@ -123,7 +129,7 @@ private static String login() throws IOException {
123129
map = new LinkedHashMap<>();
124130
map.put("sess-data", sessData);
125131
ConfigManager.dump(map);
126-
System.out.println("已保存 SESSDATA");
132+
if (hint) System.out.println("已保存 SESSDATA");
127133
}
128134
} else {
129135
System.out.println("登录失败");
@@ -137,11 +143,11 @@ private static String login() throws IOException {
137143
}
138144

139145
private static JSONObject getVideoInfo(String id, String cookie) throws IOException {
140-
System.out.println("\n正在获取稿件信息······");
146+
System.out.println((hint ? "\n" : "") + "正在获取稿件信息······");
141147
JSONObject info = readJsonFromUrl("http://api.bilibili.com/x/web-interface/view?" + (id.toLowerCase().startsWith("av") ? "aid=" + id.substring(2) : "bvid=" + id), cookie);
142148
if (info.getIntValue("code") != 0) {
143149
System.out.println(info.getString("message"));
144-
System.out.println("\n程序运行结束;总运行时间:" + getFormattedTime(System.currentTimeMillis() - beginTime));
150+
System.out.println("\n程序运行结束,错误代码:" + info.getIntValue("code") + ";总运行时间:" + getFormattedTime(System.currentTimeMillis() - beginTime));
145151
System.exit(info.getIntValue("code"));
146152
} else {
147153
info = info.getJSONObject("data");
@@ -166,7 +172,7 @@ private static Object[] specify(JSONObject info) {
166172
for (int i = 0; i < pages.size(); i++) {
167173
System.out.println(String.format("%3d", (i + 1)) + ". P" + String.format("%-5d", pages.getJSONObject(i).getIntValue("page")) + "CID:" + pages.getJSONObject(i).getIntValue("cid") + " 时长:" + getFormattedTime(pages.getJSONObject(i).getIntValue("duration"), pages.getJSONObject(i).getIntValue("duration") >= 3600) + " 标题:" + pages.getJSONObject(i).getString("part"));
168174
}
169-
System.out.println("请选择分P(输入 1~" + pages.size() + " 之间的整数):");
175+
if (hint) System.out.println("请选择分P(输入 1~" + pages.size() + " 之间的整数):");
170176
int part = inputInt();
171177
if (part > pages.size()) {
172178
System.out.println("输入的数字“" + part + "”太大,已为您选择末尾的分P " + pages.getJSONObject(pages.size() - 1).getString("part"));
@@ -197,7 +203,7 @@ private static Object[] getResolutions(JSONObject info, String cookie, int cid)
197203
for (int i = 1; i < qualities.size(); i++) {
198204
System.out.println(String.format("%3d", i) + ". " + qualities.getString(i));
199205
}
200-
System.out.println("请选择清晰度(输入 1~" + (qualities.size() - 1) + " 之间的整数):");
206+
if (hint) System.out.println("请选择清晰度(输入 1~" + (qualities.size() - 1) + " 之间的整数):");
201207
int quality = inputInt();
202208
String videoDownloadUrl;
203209
if (qualities.getIntValue(0) == 1) {
@@ -248,11 +254,11 @@ private static Path getPath(String name) throws IOException {
248254
}
249255
}
250256
while (!pathSuccess) {
251-
System.out.println("\n请输入保存路径:");
257+
if (hint) System.out.println("\n请输入保存路径:");
252258
savePath = inputStr();
253259
File file = new File(savePath);
254260
if (!file.exists()) {
255-
System.out.println("该目录不存在,请决定是否创建该目录(输入“Y”或“N”):");
261+
if (hint) System.out.println("该目录不存在,请决定是否创建该目录(输入“Y”或“N”):");
256262
if (inputStr().equalsIgnoreCase("Y")) {
257263
pathSuccess = file.mkdirs();
258264
if (!pathSuccess) System.out.println("创建目录失败");
@@ -261,7 +267,7 @@ private static Path getPath(String name) throws IOException {
261267
pathSuccess = true;
262268
}
263269
if (pathSuccess) {
264-
System.out.println("请决定是否保存该保存路径(输入“Y”或“N”):");
270+
if (hint) System.out.println("请决定是否保存该保存路径(输入“Y”或“N”):");
265271
if (inputStr().equalsIgnoreCase("Y")) {
266272
if (!config.exists()) config.createNewFile();
267273
ConfigManager.init(config);
@@ -270,7 +276,7 @@ private static Path getPath(String name) throws IOException {
270276
map = new LinkedHashMap<>();
271277
map.put("save-path", savePath);
272278
ConfigManager.dump(map);
273-
System.out.println("已保存该保存路径");
279+
if (hint) System.out.println("已保存该保存路径");
274280
}
275281
}
276282
}
@@ -282,7 +288,7 @@ private static void download(Object[] details, Path path) throws IOException, In
282288
JSONArray qualities = (JSONArray) details[1];
283289
int quality = (int) details[2];
284290
JSONObject videoWeb = (JSONObject) details[3];
285-
System.out.println("\n下载选项:\n 1. 视频+音频(合并需要 FFmpeg)\n 2. 仅视频\n 3. 仅音频\n请选择下载选项(输入 1~3 之间的整数):");
291+
if (hint) System.out.println("\n下载选项:\n 1. 视频+音频(合并需要 FFmpeg)\n 2. 仅视频\n 3. 仅音频\n请选择下载选项(输入 1~3 之间的整数):");
286292
int choice = inputInt();
287293
if (choice > 3) {
288294
System.out.println("输入的数字“" + choice + "”太大,已为您选择最后一个选项 仅音频");
@@ -309,7 +315,7 @@ private static void download(Object[] details, Path path) throws IOException, In
309315
}
310316
}
311317
while (ffmpegSuccess == 0) {
312-
System.out.println("\n请输入 ffmpeg.exe 目录(跳过合并请填“#”):");
318+
if (hint) System.out.println("\n请输入 ffmpeg.exe 目录(跳过合并请填“#”):");
313319
String ffmpegPath = inputStr();
314320
if (ffmpegPath.equals("#")) {
315321
ffmpegSuccess = -1;
@@ -318,7 +324,7 @@ private static void download(Object[] details, Path path) throws IOException, In
318324
ffmpeg = ffmpegPath.endsWith("ffmpeg.exe") ? new File(ffmpegPath) : new File(ffmpegPath, "ffmpeg.exe");
319325
ffmpegSuccess = ffmpeg.exists() ? 1 : 0;
320326
if (ffmpegSuccess == 1) {
321-
System.out.println("请决定是否保存 FFmpeg 路径(输入“Y”或“N”):");
327+
if (hint) System.out.println("请决定是否保存 FFmpeg 路径(输入“Y”或“N”):");
322328
if (inputStr().equalsIgnoreCase("Y")) {
323329
if (!config.exists()) config.createNewFile();
324330
ConfigManager.init(config);
@@ -327,7 +333,7 @@ private static void download(Object[] details, Path path) throws IOException, In
327333
map = new LinkedHashMap<>();
328334
map.put("ffmpeg-path", ffmpeg.getAbsolutePath());
329335
ConfigManager.dump(map);
330-
System.out.println("已保存 FFmpeg 路径");
336+
if (hint) System.out.println("已保存 FFmpeg 路径");
331337
}
332338
}
333339
}
@@ -452,14 +458,14 @@ private static JSONArray summarize(JSONArray qualitiesTV, JSONArray qualitiesWeb
452458
qualities.add(1);
453459
for (int i = 0; i < qualitiesTV.size(); i++)
454460
if (!videoTV.getJSONArray("accept_watermark").getBoolean(i))
455-
qualities.add(String.format("%-11s", "TV " + qualitiesTV.getString(i)) + watermark(videoTV.getJSONArray("accept_watermark").getBoolean(i)));
461+
qualities.add(String.format("%-11s", qualitiesTV.getString(i)) + watermark(videoTV.getJSONArray("accept_watermark").getBoolean(i)));
456462
else
457463
qualities.add(qualitiesTV.getString(i));
458464
} else {
459465
qualities.add(0);
460466
}
461467
for (int i = 0; i < qualitiesWeb.size(); i++)
462-
qualities.add("Web " + qualitiesWeb.getString(i));
468+
qualities.add(qualitiesWeb.getString(i));
463469
return qualities;
464470
}
465471

0 commit comments

Comments
 (0)