更换元数据读取库
This commit is contained in:
parent
b0460fbe14
commit
180346963c
5
pom.xml
5
pom.xml
@ -96,6 +96,11 @@
|
||||
<artifactId>jaudiotagger</artifactId>
|
||||
<version>2.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ealva</groupId>
|
||||
<artifactId>ealvatag</artifactId>
|
||||
<version>0.4.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -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\\");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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<MusicData> musicList = new ArrayList<>();
|
||||
private HashMap<String,List<MusicData>> musicMap=new HashMap<String,List<MusicData>>();
|
||||
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<MusicData> 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<MusicData> 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
<body>
|
||||
<div class="layui-layout layui-layout-admin">
|
||||
<div id="header"></div>
|
||||
|
||||
<div class="layui-body" style="left: 200px;">
|
||||
<div id="side"></div>
|
||||
|
||||
@ -19,20 +20,29 @@
|
||||
<img src="/assets/defaultPlayImg.jpg" id="img" style="height: 200px; width: 200px"/>
|
||||
|
||||
<div style="display:inline-block;">
|
||||
<div id="title">title</div>
|
||||
<div id="artist">by</div>
|
||||
<div id="album">album</div>
|
||||
<div id="composer">composer</div>
|
||||
<div id="title">标题:</div>
|
||||
<div id="artist">艺术家:</div>
|
||||
<div id="album">专辑:</div>
|
||||
<div id="composer">作曲家</div>
|
||||
</div>
|
||||
|
||||
<div id="audioWrap"></div>
|
||||
|
||||
</div>
|
||||
<ul class="layui-nav layui-bg-cyan" lay-filter="menus" style="margin-right: 10px;">
|
||||
<div style="margin-top: 10px;">
|
||||
<span id="menu" class="layui-breadcrumb" lay-separator="/"
|
||||
style="visibility: visible;">
|
||||
<a href="javascript:onMenuClick('root');">主目录</a>
|
||||
</span>
|
||||
</div>
|
||||
</ul>
|
||||
<table id="playlist" lay-filter="music"></table>
|
||||
</div>
|
||||
|
||||
<div id="footer"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script src="/layui/layui.js"></script>
|
||||
<script src="/js/jquery-3.2.1.js"></script>
|
||||
@ -43,8 +53,9 @@
|
||||
<script>
|
||||
//let localhost="http://192.168.31.88:8000";
|
||||
let localhost = "";
|
||||
layui.use('table', function () {
|
||||
layui.use(['table', 'element'], function () {
|
||||
let table = layui.table;
|
||||
let element = layui.element;
|
||||
table.render({
|
||||
elem: '#playlist'
|
||||
, height: 312
|
||||
@ -63,7 +74,11 @@
|
||||
console.log(obj.data.file) //得到当前行元素对象
|
||||
play(obj.data.file)
|
||||
});
|
||||
element.on('nav(menus)', function (elem) {
|
||||
console.log(elem); //得到当前点击的DOM对象
|
||||
});
|
||||
});
|
||||
|
||||
$.get("/login/check.do", function (data) {
|
||||
let json = JSON.parse(data);
|
||||
if (json.code !== 0) {
|
||||
@ -92,6 +107,10 @@
|
||||
random()
|
||||
});
|
||||
|
||||
function onMenuClick(that) {
|
||||
console.log(that)
|
||||
}
|
||||
|
||||
function random() {
|
||||
$.get(localhost + "/nas/music/random.do", function (data) {
|
||||
let json = JSON.parse(data)
|
||||
@ -107,6 +126,7 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function play(file) {
|
||||
let filePath = escape(new Base64().encode(file))
|
||||
player.updateSource({
|
||||
@ -115,6 +135,7 @@
|
||||
update(filePath)
|
||||
player.play()
|
||||
}
|
||||
|
||||
function update(fileName) {
|
||||
$.get(localhost + '/nas/music/find/file.do?path=' + fileName, function (data) {
|
||||
let json = JSON.parse(data);
|
||||
|
Loading…
Reference in New Issue
Block a user