update:音乐列表输出排序

This commit is contained in:
Yutousama 2022-06-12 01:09:29 +08:00
parent 66c77b04b9
commit 81f91f756a

View File

@ -88,7 +88,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
public void getPathOrDir(String path, List<MusicData> list) {
File files = new File(path);
for (File file : files.listFiles()) {
for (File file : Objects.requireNonNull(files.listFiles())) {
if (file.isFile()) {
list.add(getMetadata(file));
} else {
@ -144,6 +144,9 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
list.addAll(main);
list.sort((o1, o2) -> {
if("返回".equals(o2.getTitle())){
return 1;
}
Comparator<Object> compare = Collator.getInstance(Locale.CHINA);
return compare.compare(o1.getTitle(),o2.getTitle());
});
@ -173,7 +176,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
File file = new File(path);
com.yutou.nas.utils.Log.i("扫描文件:" + path);
if (file.isDirectory()) {
for (File listFile : file.listFiles()) {
for (File listFile : Objects.requireNonNull(file.listFiles())) {
if (listFile.isDirectory()) {
MusicData data = new MusicData();
data.setTitle(listFile.getName());
@ -201,7 +204,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
}
} catch (Exception e) {
e.printStackTrace();
QQBotManager.getInstance().sendMessage("音乐文件添加失败:" + data.toString());
QQBotManager.getInstance().sendMessage("音乐文件添加失败:" + data);
}
}
@ -250,27 +253,27 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
MusicData data = new MusicData();
try {
data.setAlbum(tag.getFirst(FieldKey.ALBUM));
} catch (Exception e) {
} catch (Exception ignored) {
}
try {
data.setArtist(tag.getFirst(FieldKey.ARTIST));
} catch (Exception e) {
} catch (Exception ignored) {
}
try {
data.setArtistSort(tag.getFirst(FieldKey.ARTIST_SORT));
} catch (Exception e) {
} catch (Exception ignored) {
}
try {
data.setComment(tag.getFirst(FieldKey.COMMENT));
} catch (Exception e) {
} catch (Exception ignored) {
}
try {
data.setComposer(tag.getFirst(FieldKey.COMPOSER));
} catch (Exception e) {
} catch (Exception ignored) {
}
try {
data.setDiscNo(tag.getFirst(FieldKey.DISC_NO));
} catch (Exception e) {
} catch (Exception ignored) {
}
try {
if (StringUtils.isEmpty(tag.getFirst(FieldKey.TITLE))) {
@ -283,11 +286,11 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
}
try {
data.setTrack(tag.getFirst(FieldKey.TRACK));
} catch (Exception e) {
} catch (Exception ignored) {
}
try {
data.setYear(tag.getFirst(FieldKey.YEAR));
} catch (Exception e) {
} catch (Exception ignored) {
}
data.setFile(file.getAbsolutePath());
data.setIsdir(file.isDirectory() ? 1 : 0);
@ -437,7 +440,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
data.setIsdir(file.isDirectory() ? 1 : 0);
data.setLastdir(file.getParentFile().getParent());
data.setMd5(Tools.getFileMD5(file));
QQBotManager.getInstance().sendMessage("添加音乐文件失败:\n" + data.toString() + "\n" + Tools.getExceptionString(e));
QQBotManager.getInstance().sendMessage("添加音乐文件失败:\n" + data + "\n" + Tools.getExceptionString(e));
}
return data;
}
@ -536,7 +539,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
@Override
public byte[] readImage(String path) throws Exception {
File file = new File(path);
AudioFile audioFile = null;
AudioFile audioFile;
audioFile = AudioFileIO.read(file);
Tag tag = audioFile.getTag().or(NullTag.INSTANCE);
byte[] bytes = tag.getFirstArtwork().or(NullArtwork.INSTANCE).getBinaryData();
@ -552,7 +555,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
example.createCriteria().andMd5EqualTo(md5);
List<MusicData> list=musicDataDao.selectByExample(example,delFile);
Log.i("Music Size",list.size());
if(list!=null&&!list.isEmpty()){
if(!list.isEmpty()){
Log.i("Music File", list.get(0).toString());
return new File(list.get(0).getFile());
}