add新增过滤纯音乐
This commit is contained in:
parent
a39d99eeb6
commit
3509de8cef
@ -47,20 +47,21 @@ public class MusicController {
|
|||||||
public String getMusicListOfPath(@RequestBody JSONObject body) {
|
public String getMusicListOfPath(@RequestBody JSONObject body) {
|
||||||
String path = body.getString("path");
|
String path = body.getString("path");
|
||||||
boolean type = body.containsKey("type") ? body.getBoolean("type") : false;
|
boolean type = body.containsKey("type") ? body.getBoolean("type") : false;
|
||||||
|
boolean filter = body.containsKey("filter") ? body.getBoolean("filter") : false;
|
||||||
if (StringUtils.isEmpty(path)
|
if (StringUtils.isEmpty(path)
|
||||||
|| "root".equals(path)
|
|| "root".equals(path)
|
||||||
|| !path.contains(defaultMusicPath)
|
|| !path.contains(defaultMusicPath)
|
||||||
) {
|
) {
|
||||||
path = defaultMusicPath;
|
path = defaultMusicPath;
|
||||||
}
|
}
|
||||||
com.yutou.nas.utils.Log.i("接收到地址:" + path);
|
com.yutou.nas.utils.Log.i("接收到地址:" + body);
|
||||||
|
|
||||||
//path=path.replace(defaultMusicPath+File.separator,"");
|
//path=path.replace(defaultMusicPath+File.separator,"");
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("code", 0);
|
json.put("code", 0);
|
||||||
json.put("scan", musicTools.isScan());
|
json.put("scan", musicTools.isScan());
|
||||||
json.put("size", musicTools.getLength());
|
json.put("size", musicTools.getLength());
|
||||||
json.put("data", JSON.toJSON(musicTools.getPath(path, type, true)));
|
json.put("data", JSON.toJSON(musicTools.getPath(path, type, true, filter)));
|
||||||
return json.toJSONString();
|
return json.toJSONString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,8 +190,9 @@ public class MusicController {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/nas/music/lrc.do")
|
@RequestMapping("/nas/music/lrc.do")
|
||||||
public ResponseEntity<FileSystemResource> lrc(String filePath){
|
public ResponseEntity<FileSystemResource> lrc(String filePath) {
|
||||||
return Tools.getFile(musicTools.getMusicLrcMd5(filePath));
|
return Tools.getFile(musicTools.getMusicLrcMd5(filePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,8 +237,8 @@ public class MusicController {
|
|||||||
array.add(musicTools.getMusicData(file.getAbsolutePath(), true));
|
array.add(musicTools.getMusicData(file.getAbsolutePath(), true));
|
||||||
} else {
|
} else {
|
||||||
for (File listFile : Objects.requireNonNull(file.listFiles())) {
|
for (File listFile : Objects.requireNonNull(file.listFiles())) {
|
||||||
MusicData data=musicTools.getMusicData(listFile.getAbsolutePath(), true);
|
MusicData data = musicTools.getMusicData(listFile.getAbsolutePath(), true);
|
||||||
if(data!=null) {
|
if (data != null) {
|
||||||
array.add(data);
|
array.add(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ public interface IMusicToolsService {
|
|||||||
void scanMusic();
|
void scanMusic();
|
||||||
|
|
||||||
List<MusicData> getPath(String path, boolean isDir,boolean delPath);
|
List<MusicData> getPath(String path, boolean isDir,boolean delPath);
|
||||||
|
List<MusicData> getPath(String path, boolean isDir,boolean delPath,boolean filter);
|
||||||
|
|
||||||
MusicData getMusicDataOfMd5(String md5,boolean isDelFile);
|
MusicData getMusicDataOfMd5(String md5,boolean isDelFile);
|
||||||
MusicData getMusicData(String path,boolean isDelFile);
|
MusicData getMusicData(String path,boolean isDelFile);
|
||||||
|
@ -69,8 +69,8 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
|
|
||||||
|
|
||||||
private void scan(File path) {
|
private void scan(File path) {
|
||||||
if(!path.exists()){
|
if (!path.exists()) {
|
||||||
Log.i("MusicScan","文件夹不存在,取消扫描");
|
Log.i("MusicScan", "文件夹不存在,取消扫描");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (path.isFile()) {
|
if (path.isFile()) {
|
||||||
@ -97,6 +97,10 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MusicData> getPath(String path, boolean isDir, boolean delPath) {
|
||||||
|
return getPath(path, isDir, delPath, false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定目录下的音乐
|
* 获取指定目录下的音乐
|
||||||
@ -106,18 +110,22 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
* @return 音乐列表
|
* @return 音乐列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<MusicData> getPath(String path, boolean isDir,boolean delPath) {
|
public List<MusicData> getPath(String path, boolean isDir, boolean delPath, boolean filter) {
|
||||||
List<MusicData> list = new ArrayList<>();
|
List<MusicData> list = new ArrayList<>();
|
||||||
List<MusicData> main = new ArrayList<>();
|
List<MusicData> main = new ArrayList<>();
|
||||||
MusicDataExample example = new MusicDataExample();
|
MusicDataExample example = new MusicDataExample();
|
||||||
String replacement = "windows".equals(ConfigTools.load(ConfigTools.CONFIG, "os")) ? "\\\\" : "/";
|
String replacement = "windows".equals(ConfigTools.load(ConfigTools.CONFIG, "os")) ? "\\\\" : "/";
|
||||||
String tmpPath = path;
|
String tmpPath = path;
|
||||||
if(StringUtils.isEmpty(path)){
|
if (StringUtils.isEmpty(path)) {
|
||||||
tmpPath=AppData.defaultMusicPath;
|
tmpPath = AppData.defaultMusicPath;
|
||||||
}
|
}
|
||||||
if (isDir) {
|
if (isDir) {
|
||||||
example.createCriteria().andFileLike(tmpPath.replace(File.separator, replacement) + "%");
|
if (filter) {
|
||||||
main = musicDataDao.selectByExample(example,delPath);
|
example.createCriteria().andFileLike(tmpPath.replace(File.separator, replacement) + "%").andTitleNotLike("instrumental");
|
||||||
|
} else {
|
||||||
|
example.createCriteria().andFileLike(tmpPath.replace(File.separator, replacement) + "%");
|
||||||
|
}
|
||||||
|
main = musicDataDao.selectByExample(example, delPath);
|
||||||
}
|
}
|
||||||
tmpPath = tmpPath.replace(File.separator, replacement)
|
tmpPath = tmpPath.replace(File.separator, replacement)
|
||||||
.replace("+", "\\+")
|
.replace("+", "\\+")
|
||||||
@ -125,7 +133,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
.replace("(", "\\(")
|
.replace("(", "\\(")
|
||||||
.replace(")", "\\)")
|
.replace(")", "\\)")
|
||||||
.replace("]", "\\]");
|
.replace("]", "\\]");
|
||||||
main.addAll(musicDataDao.selectByRegexp(tmpPath + replacement + "([^" + replacement + "]+)$",delPath));
|
main.addAll(musicDataDao.selectByRegexp(tmpPath + replacement + "([^" + replacement + "]+)$", delPath));
|
||||||
|
|
||||||
if (!path.equals(AppData.defaultMusicPath) && !"root".equals(path)) {
|
if (!path.equals(AppData.defaultMusicPath) && !"root".equals(path)) {
|
||||||
MusicData t2 = new MusicData();
|
MusicData t2 = new MusicData();
|
||||||
@ -144,18 +152,17 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
list.addAll(main);
|
list.addAll(main);
|
||||||
|
|
||||||
list.sort((o1, o2) -> {
|
list.sort((o1, o2) -> {
|
||||||
if("返回".equals(o2.getTitle())){
|
if ("返回".equals(o2.getTitle())) {
|
||||||
return 1;
|
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());
|
||||||
});
|
});
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<MusicData> getAllAlbum() {
|
public List<MusicData> getAllAlbum() {
|
||||||
return musicDataDao.selectAllAlbum();
|
return musicDataDao.selectAllAlbum();
|
||||||
}
|
}
|
||||||
@ -164,12 +171,12 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
return musicDataDao.selectAllArtist();
|
return musicDataDao.selectAllArtist();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MusicData> selectAlbum(String album,boolean isDelFile) {
|
public List<MusicData> selectAlbum(String album, boolean isDelFile) {
|
||||||
return musicDataDao.selectAlbum(album,isDelFile);
|
return musicDataDao.selectAlbum(album, isDelFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MusicData> selectArtist(String artist,boolean isDelFile) {
|
public List<MusicData> selectArtist(String artist, boolean isDelFile) {
|
||||||
return musicDataDao.selectArtist(artist,isDelFile);
|
return musicDataDao.selectArtist(artist, isDelFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDirList(String path, List<MusicData> list) {
|
private void getDirList(String path, List<MusicData> list) {
|
||||||
@ -198,7 +205,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
MusicData data = getMetadata(file);
|
MusicData data = getMetadata(file);
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
try {
|
try {
|
||||||
if (getMusicData(file.getAbsolutePath(),false) == null) {
|
if (getMusicData(file.getAbsolutePath(), false) == null) {
|
||||||
// System.out.println(data);
|
// System.out.println(data);
|
||||||
musicDataDao.insert(data);
|
musicDataDao.insert(data);
|
||||||
}
|
}
|
||||||
@ -211,20 +218,21 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicData getMusicData(String path,boolean delFile) {
|
public MusicData getMusicData(String path, boolean delFile) {
|
||||||
MusicDataExample example = new MusicDataExample();
|
MusicDataExample example = new MusicDataExample();
|
||||||
example.createCriteria().andFileEqualTo(path);
|
example.createCriteria().andFileEqualTo(path);
|
||||||
List<MusicData> list = musicDataDao.selectByExample(example,delFile);
|
List<MusicData> list = musicDataDao.selectByExample(example, delFile);
|
||||||
if (list != null && list.size() > 0) {
|
if (list != null && list.size() > 0) {
|
||||||
return list.get(0);
|
return list.get(0);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicData getMusicDataOfMd5(String md5, boolean isDelFile) {
|
public MusicData getMusicDataOfMd5(String md5, boolean isDelFile) {
|
||||||
MusicDataExample example = new MusicDataExample();
|
MusicDataExample example = new MusicDataExample();
|
||||||
example.createCriteria().andMd5EqualTo(md5);
|
example.createCriteria().andMd5EqualTo(md5);
|
||||||
List<MusicData> list = musicDataDao.selectByExample(example,isDelFile);
|
List<MusicData> list = musicDataDao.selectByExample(example, isDelFile);
|
||||||
if (list != null && list.size() > 0) {
|
if (list != null && list.size() > 0) {
|
||||||
return list.get(0);
|
return list.get(0);
|
||||||
}
|
}
|
||||||
@ -490,23 +498,23 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MusicData> findOfTitle(String title,boolean delFile) {
|
public List<MusicData> findOfTitle(String title, boolean delFile) {
|
||||||
return find(title, FIND_TITLE,delFile);
|
return find(title, FIND_TITLE, delFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MusicData> findOfArtist(String by,boolean delFile) {
|
public List<MusicData> findOfArtist(String by, boolean delFile) {
|
||||||
return find(by, FIND_ARTIST,delFile);
|
return find(by, FIND_ARTIST, delFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MusicData> getMusicList(boolean delFile) {
|
public List<MusicData> getMusicList(boolean delFile) {
|
||||||
return musicDataDao.selectByExample(new MusicDataExample(),delFile);
|
return musicDataDao.selectByExample(new MusicDataExample(), delFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLength() {
|
public int getLength() {
|
||||||
return musicDataDao.selectByExample(new MusicDataExample(),true).size();
|
return musicDataDao.selectByExample(new MusicDataExample(), true).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -514,7 +522,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
return isScan;
|
return isScan;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MusicData> find(String title, int type,boolean delFile) {
|
private List<MusicData> find(String title, int type, boolean delFile) {
|
||||||
List<MusicData> list;
|
List<MusicData> list;
|
||||||
MusicDataExample example = new MusicDataExample();
|
MusicDataExample example = new MusicDataExample();
|
||||||
if (type == FIND_TITLE) {
|
if (type == FIND_TITLE) {
|
||||||
@ -522,7 +530,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
} else if (type == FIND_ARTIST) {
|
} else if (type == FIND_ARTIST) {
|
||||||
example.createCriteria().andArtistEqualTo(title);
|
example.createCriteria().andArtistEqualTo(title);
|
||||||
}
|
}
|
||||||
list = musicDataDao.selectByExample(example,delFile);
|
list = musicDataDao.selectByExample(example, delFile);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -550,12 +558,12 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getMusicOfMd5(String md5,boolean delFile) {
|
public File getMusicOfMd5(String md5, boolean delFile) {
|
||||||
MusicDataExample example=new MusicDataExample();
|
MusicDataExample example = new MusicDataExample();
|
||||||
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.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());
|
||||||
}
|
}
|
||||||
@ -564,15 +572,15 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getMusicLrcMd5(String md5) {
|
public File getMusicLrcMd5(String md5) {
|
||||||
MusicDataExample example=new MusicDataExample();
|
MusicDataExample example = new MusicDataExample();
|
||||||
example.createCriteria().andMd5EqualTo(md5);
|
example.createCriteria().andMd5EqualTo(md5);
|
||||||
List<MusicData> list=musicDataDao.selectByExample(example,false);
|
List<MusicData> list = musicDataDao.selectByExample(example, false);
|
||||||
if(!list.isEmpty()){
|
if (!list.isEmpty()) {
|
||||||
String fileName=list.get(0).getFile();
|
String fileName = list.get(0).getFile();
|
||||||
fileName=fileName.replace(fileName.substring(fileName.lastIndexOf(".")),".lrc");
|
fileName = fileName.replace(fileName.substring(fileName.lastIndexOf(".")), ".lrc");
|
||||||
System.out.println("fileName = " + fileName);
|
System.out.println("fileName = " + fileName);
|
||||||
File file=new File(fileName);
|
File file = new File(fileName);
|
||||||
if(file.exists()){
|
if (file.exists()) {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user