-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
63 lines (59 loc) · 2.35 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Objects;
public class Main {
final static File ROOT = new File("music");
final static String URL = "";
final static String FILENAME = "music.js";
public static void main(String[] args) throws IOException {
StringBuilder musicList = getMusicList(ROOT);
FileWriter fileWriter = new FileWriter(FILENAME);
PrintWriter printWriter = new PrintWriter(fileWriter);
printWriter.print("let json = [");
printWriter.print(musicList.substring(0, musicList.length() - 2));
printWriter.print("]");
printWriter.flush();
}
static StringBuilder getMusicList(File file) {
StringBuilder str = new StringBuilder();
if (file.isDirectory() && Objects.requireNonNull(file.list()).length > 0) {
File[] files = file.listFiles();
assert files != null;
if (files[0].isFile()) {
return printList(file);
} else {
for (File file1 : files) {
str.append(getMusicList(file1));
}
}
}
if (file.isDirectory() && Objects.requireNonNull(file.list()).length == 0) {
return str;
}
return str;
}
static StringBuilder printList(File file) {
StringBuilder str = new StringBuilder();
File[] files = file.listFiles();
String coverName = "";
assert files != null;
for (File file1 : files) {
if (file1.getName().endsWith(".jpg") || file1.getName().endsWith(".png")) {
coverName = file1.getName();
}
}
for (File file1 : files)
if (!file1.getName().endsWith(".jpg") && !file1.getName().endsWith(".png")) {
str.append(String.format("""
{
"name": "%s",
"url": "%s",
"image": "%s"
},
""", file1.getName().substring(0, file1.getName().lastIndexOf('.')).replaceAll("F_I_R_", "F.I.R."), URL + file.getPath().replace('\\', '/') + "/" + file1.getName().replaceAll("#", "%23"), URL + file.getPath().replace('\\', '/') + "/" + coverName));
}
return str;
}
}