目录
小于 1 分钟
目录
介绍
fun rename(){
val path = "C:\\Users\\bll\\Downloads\\周借论钢琴曲"
// 获取所有文件
val files = FileUtil.getFiles(path)
for (file in files) {
// 修改文件名
val name = file.name
// 插入字符串
var newName = name.replace("-"," ")
println(newName)
file.renameTo(File(file.parentFile, newName))
}
}
fun downloadBB() {
val cmd = "C:\\Users\\bll\\Downloads\\周借论钢琴曲\\BBDown.exe"
val json = FileUtil.readFile("C:\\Users\\bll\\Downloads\\周借论钢琴曲\\json.txt")
val list = JsonUtil.toObject(json, ArrayList::class.java)
for (it in list) {
if (it is Map<*, *>) {
val id = it["bvid"]
exec(cmd, id.toString())
// 休眠3秒继续
Thread.sleep(3000)
}
}
}
// 执行命令
fun exec(cmd: String, bvId: String) {
val processBuilder = ProcessBuilder(cmd, bvId, "--audio-only")
println(processBuilder.command().toString())
processBuilder.redirectErrorStream(true)
val process = processBuilder.start()
val bufferedReader = process.inputStream.bufferedReader(charset = Charsets.US_ASCII)
var line: String?
while (bufferedReader.readLine().also { line = it } != null) {
println(line)
}
process.waitFor()
bufferedReader.close()
}