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