效果展示:
使用前:
使用后:
前置条件
:文件名按照【歌手】-【歌名】的形式命名
使用截图:
带swagger,在浏览器输入:http://localhost:8082/swagger-ui/index.html#
贴上部分代码:
private static void doFlac(File f, String encoding) throws Exception {
String fName = f.getName();
AudioFile audioFile;
if (fName.substring(fName.length() - 3).equalsIgnoreCase("mp3")) {
audioFile = MP_3_FILE_READER.read(f);
} else if (fName.substring(fName.length() - 4).equalsIgnoreCase("flac")) {
audioFile = FLAC_FILE_READER.read(f);
} else {
// 不支持的格式
return;
}
System.out.println("===============开始处理[" + fName + "]===============");
String musicInfo = fName.substring(0, fName.indexOf(".mp3"));
System.out.println("音乐信息:" + musicInfo);
String author = musicInfo;
String musicName = musicInfo;
if (fName.contains("-")) {
String[] split = musicInfo.split("-");
author = split[0];
musicName = split[1];
}
System.out.println("author====>" + author);
System.out.println("musicName====>" + musicName);
Tag tag = audioFile.getTag();
if (tag instanceof ID3v1Tag) {
ID3v1Tag id3v1Tag = (ID3v1Tag) tag;
Charset charset = id3v1Tag.getEncoding();
musicInfo = new String(musicInfo.getBytes(encoding), charset);
author = new String(author.getBytes(encoding), charset);
musicName = new String(musicName.getBytes(encoding), charset);
}
tag.deleteField(FieldKey.TITLE);
tag.addField(FieldKey.TITLE, musicName);
tag.deleteField(FieldKey.COMMENT);
tag.addField(FieldKey.COMMENT, musicInfo);
tag.deleteField(FieldKey.ARTIST);
tag.addField(FieldKey.ARTIST, author);
tag.deleteField(FieldKey.ALBUM);
tag.setField(FieldKey.ALBUM, author);
audioFile.setTag(tag);
audioFile.commit();
System.out.println("===================处理完毕===================");
}
项目资源:https://download.csdn.net/download/qq1170993239/87793099