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