BiliBili下载视频重命名
介绍
该代码块用于将BiliBili UWP客户端下载的视频进行重命名。
使用
需要更改源代码,将代码中的文件路径改为自己的存储路径。
代码
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException;
@Slf4j public class FileRename {
public static void fileRename(File file) throws IOException { if (file.exists()) { if (file.isDirectory()) { File[] files = file.listFiles(); for (File f : files) { fileRename(f); } } if (file.isFile()) { String name = file.getName(); if (name.endsWith(".mp4")) { String parent = file.getParent(); System.out.println(parent); String[] s = name.split("_"); File titlefile = new File(parent + "/" + s[0] + ".info"); try { FileReader reader = new FileReader(titlefile); BufferedReader bufferedReader = new BufferedReader(reader); String s1 = bufferedReader.readLine(); JSONObject jsonObject = JSONObject.parseObject(s1); String title = (String) jsonObject.get("Title"); file.renameTo(new File(parent + File.separator + title.replaceAll("/", "-").replaceAll(" ", "") + ".mp4"));
} catch (Exception e) { log.error(e.getMessage(), e); } } } } }
public static void fileNameTrim(File file) throws IOException { if (file.exists()) { if (file.isDirectory()) { File[] files = file.listFiles(); for (File f : files) { fileNameTrim(f); } } if (file.isFile()) { String name = file.getName(); if (name.endsWith(".mp4")) { String fileName = file.getName(); String parent = file.getParent(); File newfile = new File(parent + File.separator + fileName.replaceAll("/", "-").replaceAll(" ", ""));
file.renameTo(newfile); } } } }
public static void main(String[] args) throws IOException { fileRename(new File("D:\\新建文件夹")); }
}
|