diff --git a/pom.xml b/pom.xml index 8fe2612..0e8d7e4 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,11 @@ jaudiotagger 2.2.3 + + com.ealva + ealvatag + 0.4.3 + diff --git a/src/main/java/com/yutou/tools/ToolsApplication.java b/src/main/java/com/yutou/tools/ToolsApplication.java index 93aea68..58dbd82 100644 --- a/src/main/java/com/yutou/tools/ToolsApplication.java +++ b/src/main/java/com/yutou/tools/ToolsApplication.java @@ -11,8 +11,7 @@ public class ToolsApplication { public static void main(String[] args) { SpringApplication.run(ToolsApplication.class, args); RedisTools.initRedisPoolSub(); - MusicTools.getInstance().setMusicPath("Z:\\音乐\\Aimer - ARIA STRINGS"); - MusicTools.getInstance().scanMusic(); + MusicTools.getInstance().setMusicPath("C:\\Users\\admin\\Music\\"); } } diff --git a/src/main/java/com/yutou/tools/home/nas/Data/MusicData.java b/src/main/java/com/yutou/tools/home/nas/Data/MusicData.java index bc2ef53..7a640d2 100644 --- a/src/main/java/com/yutou/tools/home/nas/Data/MusicData.java +++ b/src/main/java/com/yutou/tools/home/nas/Data/MusicData.java @@ -1,13 +1,11 @@ package com.yutou.tools.home.nas.Data; +import ealvatag.audio.AudioFile; +import ealvatag.audio.AudioFileIO; +import ealvatag.tag.NullTag; +import ealvatag.tag.Tag; +import ealvatag.tag.images.NullArtwork; import lombok.Data; -import org.jaudiotagger.audio.AudioFile; -import org.jaudiotagger.audio.AudioFileIO; -import org.jaudiotagger.audio.exceptions.CannotReadException; -import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException; -import org.jaudiotagger.audio.exceptions.ReadOnlyFileException; -import org.jaudiotagger.tag.Tag; -import org.jaudiotagger.tag.TagException; import java.io.*; import java.nio.file.Files; @@ -29,11 +27,12 @@ public class MusicData { public byte[] readImage() throws Exception { AudioFile audioFile = null; audioFile = AudioFileIO.read(file); - Tag tag = audioFile.getTag(); - if (tag.getFirstArtwork() == null) { + Tag tag = audioFile.getTag().or(NullTag.INSTANCE); + byte[] bytes=tag.getFirstArtwork().or(NullArtwork.INSTANCE).getBinaryData(); + if (bytes.length==0) { return readImageFile(); } - return tag.getFirstArtwork().getBinaryData(); + return bytes; } private byte[] readImageFile() throws Exception { diff --git a/src/main/java/com/yutou/tools/home/nas/MusicController.java b/src/main/java/com/yutou/tools/home/nas/MusicController.java index 474ffda..7f81b2a 100644 --- a/src/main/java/com/yutou/tools/home/nas/MusicController.java +++ b/src/main/java/com/yutou/tools/home/nas/MusicController.java @@ -43,15 +43,17 @@ public class MusicController { if(StringUtils.isEmpty(path)){ return getAllMusicList(); } - path=path.replace(defaultMusicPath+File.separator,""); + if(path.equals("root")){ + return getAllMusicList(); + } + //path=path.replace(defaultMusicPath+File.separator,""); JSONObject json=new JSONObject(); JSONObject data = new JSONObject(); json.put("code", 1); MusicTools tools = MusicTools.getInstance(); - tools.setMusicPath(defaultMusicPath+File.separator+path); data.put("scan", tools.isScan()); data.put("size", tools.getLength()); - data.put("list", JSONArray.toJSON(tools.getMusicPath())); + data.put("list", JSONArray.toJSON(tools.getPath(path))); json.put("data", data); return json.toJSONString(); diff --git a/src/main/java/com/yutou/tools/utils/MusicTools.java b/src/main/java/com/yutou/tools/utils/MusicTools.java index fbe3fb6..835da82 100644 --- a/src/main/java/com/yutou/tools/utils/MusicTools.java +++ b/src/main/java/com/yutou/tools/utils/MusicTools.java @@ -1,18 +1,16 @@ package com.yutou.tools.utils; import com.yutou.tools.home.nas.Data.MusicData; -import org.jaudiotagger.audio.AudioFile; -import org.jaudiotagger.audio.AudioFileIO; -import org.jaudiotagger.audio.exceptions.CannotReadException; -import org.jaudiotagger.tag.FieldKey; -import org.jaudiotagger.tag.Tag; +import ealvatag.audio.AudioFile; +import ealvatag.audio.AudioFileIO; +import ealvatag.audio.exceptions.CannotReadException; +import ealvatag.tag.FieldKey; +import ealvatag.tag.NullTag; +import ealvatag.tag.Tag; import org.springframework.util.StringUtils; import java.io.*; -import java.util.ArrayList; -import java.util.Base64; -import java.util.List; -import java.util.Objects; +import java.util.*; public class MusicTools { public static final int FIND_TITLE = 1; @@ -21,6 +19,7 @@ public class MusicTools { private static MusicTools tools; private String musicPath = "C:\\Users\\admin\\Music"; private final List musicList = new ArrayList<>(); + private HashMap> musicMap=new HashMap>(); private boolean isScan = false; public static MusicTools getInstance() { @@ -29,8 +28,14 @@ public class MusicTools { } return tools; } + private MusicTools(){ + scanMusic(); + } public synchronized void scanMusic() { + if(isScan){ + return; + } System.out.println("执行扫描"); musicList.clear(); new Thread(() -> { @@ -70,11 +75,26 @@ public class MusicTools { } } } + public List getPath(String path){ + if(musicMap.containsKey(path)){ + return musicMap.get(path); + } + return new ArrayList<>(); + } private void add(File file) { MusicData data = getMetadata(file); if (data != null) { musicList.add(data); + String path=file.getAbsolutePath().replace(file.getName(),""); + List list; + if(musicMap.containsKey(path)){ + list=musicMap.get(path); + }else{ + list=new ArrayList<>(); + } + list.add(data); + musicMap.put(path,list); } } @@ -84,7 +104,7 @@ public class MusicTools { return null; } AudioFile audioFile = AudioFileIO.read(file); - Tag tag = audioFile.getTag(); + Tag tag = audioFile.getTag().or(NullTag.INSTANCE); MusicData data = new MusicData(); try { data.setAlbum(tag.getFirst(FieldKey.ALBUM)); @@ -197,9 +217,10 @@ public class MusicTools { } } - public static void main(String[] args) { - String base = "Wjpc6Z-z5LmQXOOAkOmbqOWuruWkqeOAkU1PUkEg5YWo5aWXMTHlvKBIaXJlc-S4k-i-kVxbMjAyMDA5MDJdIOmbqOWuruWkqSAzcmTjgqLjg6vjg5Djg6DjgIxQYWludCBpdCwgQkxVReOAjVs5NmtIejI0Yml0XVtGTEFDXVwwMDMtRGVmaWFuY2UuZmxhYw=="; - System.out.println(new String(Base64.getDecoder().decode(base))); + public static void main(String[] args) throws Exception{ + String base = "bXVzaWMuaHRtbDo2MyBaOlzpn7PkuZBc55m75bGx5bCR5aWzXFtzM11bRURd6Imy6YGV44GE44Gu57%2B8XDAyLiAwMiDoibLpgZXjgYTjga7nv7wgKOOBguOBiuOBhOODkOODvOOCuOODp%2BODsykud2F2Cg%3D%3D"; + byte[] bytes=getInstance().getMetadata(new File("Z:\\音乐\\BanG Dream!\\Poppin'on!\\B.O.F.flac")).readImage(); + System.out.println(bytes.length); } diff --git a/web/html/body/nas/music.html b/web/html/body/nas/music.html index d1b9c69..4ba2b58 100644 --- a/web/html/body/nas/music.html +++ b/web/html/body/nas/music.html @@ -11,6 +11,7 @@
+
@@ -19,20 +20,29 @@
-
title
-
by
-
album
-
composer
+
标题:
+
艺术家:
+
专辑:
+
作曲家
-
+ +
+ @@ -42,13 +52,14 @@