新增定时刷新及手动刷新曲库的方法

过滤png和torrent文件
This commit is contained in:
Yutousama 2020-10-26 23:43:20 +08:00
parent dbe2b3fe1c
commit ec31aa01b9
3 changed files with 29 additions and 3 deletions

View File

@ -62,12 +62,21 @@ public class MusicController {
return json.toJSONString();
}
@RequestMapping("reload.do")
@ResponseBody
public String reload(){
JSONObject json=new JSONObject();
MusicTools.getInstance().scanMusic();
json.put("msg","ok");
json.put("code",0);
return json.toJSONString();
}
@RequestMapping("find/file.do")
@ResponseBody
public String findFile(String path){
JSONObject json=new JSONObject();
if(StringUtils.isEmpty(path)){
json.put("code",0);
json.put("code",-1);
json.put("msg","地址为空");
return json.toJSONString();
}

View File

@ -11,6 +11,7 @@ import ealvatag.tag.Tag;
import org.springframework.util.StringUtils;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
public class MusicTools {
@ -32,6 +33,16 @@ public class MusicTools {
private MusicTools() {
scanMusic();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
String time=new SimpleDateFormat("HH:mm").format(new Date());
if(time.equals("00:00")){
System.out.println("零点刷新列表");
scanMusic();
}
}
},0,10*1000);
}
public synchronized void scanMusic() {
@ -170,6 +181,8 @@ public class MusicTools {
if (file.getName().endsWith(".lrc")
|| file.getName().endsWith(".jpg")
|| file.getName().endsWith(".ini")
|| file.getName().endsWith(".png")
|| file.getName().endsWith(".torrent")
) {
return null;
}

View File

@ -32,6 +32,7 @@
</div>
<table id="playlist" lay-filter="music"></table>
<a class="layui-btn layui-btn-normal" id="reload">刷新曲库</a>
</div>
<div id="footer"></div>
@ -168,10 +169,13 @@
});
$('#download').click(function () {
window.open(localhost + "/nas/music/play.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&random=false&filePath=" + playNow)
})
});
$('#next').click(function (){
playNext()
})
});
$('#reload').click(function (){
$.get(localhost+"/nas/music/reload.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk")
});
function playNext() {