From 81f91f756aab1a64322ee0cd4603950cb13e651a Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 12 Jun 2022 01:09:29 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=E9=9F=B3=E4=B9=90=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E8=BE=93=E5=87=BA=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/impl/MusicToolsServiceImpl.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/yutou/nas/Services/impl/MusicToolsServiceImpl.java b/src/main/java/com/yutou/nas/Services/impl/MusicToolsServiceImpl.java index 196589b..3cddfd2 100644 --- a/src/main/java/com/yutou/nas/Services/impl/MusicToolsServiceImpl.java +++ b/src/main/java/com/yutou/nas/Services/impl/MusicToolsServiceImpl.java @@ -88,7 +88,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService { public void getPathOrDir(String path, List 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 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 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()); }