音乐改成数据库形式(防止内存爆炸)
新增FFmpeg获取元数据方式(无法保证所有数据都能获取到) 预置音乐收藏夹功能 机器人登录后向群里通告 移除广告相关接口
This commit is contained in:
parent
68bf2d96fb
commit
fb9f02a751
7
pom.xml
7
pom.xml
@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>com.yutou</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
<version>1.0.10.4</version>
|
||||
<version>1.0</version>
|
||||
<name>tools</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
@ -121,6 +121,11 @@
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.28.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.bramp.ffmpeg</groupId>
|
||||
<artifactId>ffmpeg</artifactId>
|
||||
<version>0.6.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1,27 +1,21 @@
|
||||
package com.yutou.tools;
|
||||
|
||||
import com.yutou.tools.home.nas.MusicController;
|
||||
import com.yutou.tools.utils.*;
|
||||
import com.yutou.tools.utils.ConfigTools;
|
||||
import com.yutou.tools.utils.QQBotManager;
|
||||
import com.yutou.tools.utils.RedisTools;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ToolsApplication {
|
||||
public static final String version="1.0.11";
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("当前版本号:1.0.10.4");
|
||||
System.out.println("当前版本号:"+version);
|
||||
SpringApplication.run(ToolsApplication.class, args);
|
||||
MusicController.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
||||
RedisTools.initRedisPoolSub();
|
||||
if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("dev")) {
|
||||
MusicController.defaultMusicPath = "C:\\Users\\admin\\Music\\";
|
||||
MusicTools.getInstance().setMusicPath("C:\\Users\\admin\\Music\\");
|
||||
} else {
|
||||
MusicController.defaultMusicPath = "/media/yutou/4t/public/音乐";
|
||||
MusicTools.getInstance().setMusicPath("/media/yutou/4t/public/音乐");
|
||||
}
|
||||
QQBotManager.getInstance();
|
||||
}
|
||||
|
||||
|
@ -1,126 +0,0 @@
|
||||
package com.yutou.tools.ad;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.sqlite.ADSQLiteManager;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.text.ParsePosition;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("ad/")
|
||||
public class AdController {
|
||||
|
||||
@RequestMapping("addApp.do")
|
||||
@ResponseBody
|
||||
public String addApp(String packageName, String appName) {
|
||||
JSONObject json = new JSONObject();
|
||||
ADSQLiteManager manager = ADSQLiteManager.getInstance();
|
||||
json.put("code", 0);
|
||||
json.put("data", manager.addAppData(appName, packageName));
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@RequestMapping("addAppAd.do")
|
||||
@ResponseBody
|
||||
public String addAppAd(String appId, String adSrc, String adAppId, String adAppKey, String adOpenKey, String adInterKey,
|
||||
String adBannerKey, String adVideoKey, String adNativeKey) {
|
||||
JSONObject json = new JSONObject();
|
||||
ADSQLiteManager manager = ADSQLiteManager.getInstance();
|
||||
json.put("code", 0);
|
||||
json.put("data", manager.addAdData(appId, adSrc, adAppId, adAppKey, adOpenKey, adInterKey, adBannerKey, adVideoKey, adNativeKey));
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@RequestMapping("addAdLog.do")
|
||||
@ResponseBody
|
||||
public String addLog(String appId, String src, String type, String model) {
|
||||
JSONObject json = new JSONObject();
|
||||
ADSQLiteManager manager = ADSQLiteManager.getInstance();
|
||||
json.put("code", 0);
|
||||
json.put("data", manager.addLog(appId, src, type, model));
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@RequestMapping("getAppAd.do")
|
||||
@ResponseBody
|
||||
public String getAppAd(String appId, String packageName) {
|
||||
JSONObject json = new JSONObject();
|
||||
if (StringUtils.isEmpty(appId) && StringUtils.isEmpty(packageName)) {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "参数为空");
|
||||
json.put("data", "");
|
||||
return json.toJSONString();
|
||||
}
|
||||
ADSQLiteManager manager = ADSQLiteManager.getInstance();
|
||||
json.put("code", 0);
|
||||
if (StringUtils.isEmpty(appId)) {
|
||||
json.put("data", manager.getAdDataOfPackageName(packageName));
|
||||
} else {
|
||||
json.put("data", manager.getAdData(appId));
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@RequestMapping("getApp.do")
|
||||
@ResponseBody
|
||||
public String getApp(String appName, String packageName) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
ADSQLiteManager manager = ADSQLiteManager.getInstance();
|
||||
if (StringUtils.isEmpty(appName) && StringUtils.isEmpty(packageName)) {
|
||||
json.put("data", manager.getAllApp());
|
||||
return json.toJSONString();
|
||||
}
|
||||
if (StringUtils.isEmpty(appName)) {
|
||||
json.put("data", manager.getAppOfPackageName(packageName));
|
||||
} else {
|
||||
json.put("data", manager.getAppOfAppName(appName));
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
@RequestMapping("getAdLog.do")
|
||||
@ResponseBody
|
||||
public String getLog(String appId, String startTime, String endTime) {
|
||||
JSONObject json = new JSONObject();
|
||||
if (StringUtils.isEmpty(appId)) {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "AppId为空");
|
||||
return json.toJSONString();
|
||||
}
|
||||
String st = null;
|
||||
String et = null;
|
||||
//开始时间为空,则给当日开始时时间
|
||||
if (StringUtils.isEmpty(startTime) || (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime))) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
st = calendar.getTimeInMillis() + "";
|
||||
}
|
||||
//结束时间为空则取当前时间
|
||||
if (StringUtils.isEmpty(endTime)) {
|
||||
et = System.currentTimeMillis() + "";
|
||||
}
|
||||
try {
|
||||
if (st == null) {
|
||||
st = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).parse(startTime).getTime() + "";
|
||||
}
|
||||
if (et == null) {
|
||||
et = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).parse(endTime).getTime() + "";
|
||||
}
|
||||
ADSQLiteManager manager = ADSQLiteManager.getInstance();
|
||||
json.put("data", manager.getLog(appId, st, et));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return json.toJSONString();
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.yutou.tools.ad.Datas;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AppData {
|
||||
private String appName;
|
||||
private String packageName;
|
||||
private String appId;
|
||||
|
||||
private String adSrc;
|
||||
private String adAppId;
|
||||
private String adAppKey;
|
||||
private String adOpenKey;
|
||||
private String adInterKey;
|
||||
private String adBannerKey;
|
||||
private String adVideoKey;
|
||||
private String adNativeKey;
|
||||
}
|
||||
/*
|
||||
{"file":"ad.db","table":[{"name":"app","item":[{"name":"id","type":"int","isNull":false,"isKey":true},{"name":"appName","type":"String","isNull":false,"isKey":false},{"name":"packageName","type":"String","isNull":false,"isKey":false},{"name":"appId","type":"String","isNull":false,"isKey":false}]},{"name":"app_ad","item":[{"name":"id","type":"int","isNull":false,"isKey":true},{"name":"appId","type":"String","isNull":false,"isKey":false},{"name":"show","type":"int","isNull":false,"isKey":false},{"name":"adSrc","type":"String","isNull":false,"isKey":false},{"name":"adAppId","type":"String","isNull":false,"isKey":false},{"name":"adAppKey","type":"String","isNull":false,"isKey":false},{"name":"adOpenKey","type":"String","isNull":true,"isKey":false},{"name":"adInterKey","type":"String","isNull":true,"isKey":false},{"name":"adBannerKey","type":"String","isNull":true,"isKey":false},{"name":"adVideoKey","type":"String","isNull":true,"isKey":false},{"name":"adNativeKey","type":"String","isNull":true,"isKey":false}]},{"name":"ad_log","item":[{"name":"id","type":"int","isNull":false,"isKey":true},{"name":"appId","type":"String","isNull":false,"isKey":false},{"name":"adSrc","type":"String","isNull":false,"isKey":false},{"name":"adType","type":"String","isNull":false,"isKey":false},{"name":"model","type":"String","isNull":false,"isKey":false},{"name":"subtime","type":"String","isNull":false,"isKey":false}]}]}
|
||||
*/
|
@ -1,81 +0,0 @@
|
||||
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.springframework.util.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
|
||||
@Data
|
||||
public class MusicData {
|
||||
private String artist;//艺术家
|
||||
private String album;//专辑
|
||||
private String title;//标题
|
||||
private String comment;//评论
|
||||
private String year;//年份
|
||||
private String track;//音轨号
|
||||
private String disc_no;//碟片编号
|
||||
private String composer;//作曲
|
||||
private String artist_sort;//分类
|
||||
private File file;//音乐文件
|
||||
private String lastDir;//上一个文件夹
|
||||
private boolean isDir = false;
|
||||
|
||||
private int bitRate;//比特率
|
||||
private int sampleRate;//采样率
|
||||
private long noOfSamples;//采样数
|
||||
private int channelCount;//声道
|
||||
private String encodingType;//解码类型
|
||||
private double durationAsDouble;//持续时长
|
||||
private boolean lossless;//无损
|
||||
private boolean variableBitRate;//固定码率
|
||||
private String md5;//确保是同一个文件
|
||||
|
||||
|
||||
public void setFile(File file) {
|
||||
this.file = file;
|
||||
this.isDir = file.isDirectory();
|
||||
this.lastDir=file.getParentFile().getParent();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = file.getName();
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
public byte[] readImage() throws Exception {
|
||||
AudioFile audioFile = null;
|
||||
audioFile = AudioFileIO.read(file);
|
||||
Tag tag = audioFile.getTag().or(NullTag.INSTANCE);
|
||||
byte[] bytes = tag.getFirstArtwork().or(NullArtwork.INSTANCE).getBinaryData();
|
||||
if (bytes.length == 0) {
|
||||
return readImageFile();
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private byte[] readImageFile() throws Exception {
|
||||
String path = file.getAbsolutePath().replace(file.getName(), "");
|
||||
File img = new File(path, "cover.jpg");
|
||||
if (!img.exists()) {
|
||||
img = new File(path, "Cover.jpg");
|
||||
if (!img.exists()) {
|
||||
img = new File(path, "COVER.jpg");
|
||||
if (!img.exists()) {
|
||||
throw new NullPointerException("没有cover文件");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Files.readAllBytes(Paths.get(img.getAbsolutePath()));
|
||||
}
|
||||
}
|
@ -2,9 +2,8 @@ package com.yutou.tools.home.nas;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.home.nas.Data.MusicData;
|
||||
import com.yutou.tools.mybatis.model.MusicData;
|
||||
import com.yutou.tools.nas.UpdateIp;
|
||||
import com.yutou.tools.utils.APIFilter;
|
||||
import com.yutou.tools.utils.ConfigTools;
|
||||
import com.yutou.tools.utils.MusicTools;
|
||||
import com.yutou.tools.utils.Tools;
|
||||
@ -15,6 +14,7 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
@ -26,6 +26,8 @@ import java.util.List;
|
||||
public class MusicController {
|
||||
|
||||
public static String defaultMusicPath="/media/yutou/4t/public/音乐";
|
||||
@Resource
|
||||
MusicTools musicTools;
|
||||
|
||||
@RequestMapping("all.do")
|
||||
@ResponseBody
|
||||
@ -33,17 +35,16 @@ public class MusicController {
|
||||
JSONObject json = new JSONObject();
|
||||
JSONObject data = new JSONObject();
|
||||
json.put("code", 0);
|
||||
MusicTools tools = MusicTools.getInstance();
|
||||
json.put("scan", tools.isScan());
|
||||
json.put("size", tools.getLength());
|
||||
json.put("data", JSONArray.toJSON(tools.getMusicList()));
|
||||
json.put("scan", musicTools.isScan());
|
||||
json.put("size", musicTools.getLength());
|
||||
json.put("data", JSONArray.toJSON(musicTools.getMusicList()));
|
||||
return json.toJSONString();
|
||||
}
|
||||
@RequestMapping("list.do")
|
||||
@ResponseBody
|
||||
public String getMusicListOfPath(String path,String type){
|
||||
if(!StringUtils.isEmpty(path)&&!new File(path).exists()){
|
||||
path=base64ToString(path);
|
||||
path=Tools.base64ToString(path);
|
||||
}
|
||||
if(StringUtils.isEmpty(path)
|
||||
||path.equals("root")
|
||||
@ -53,21 +54,43 @@ public class MusicController {
|
||||
}
|
||||
|
||||
//path=path.replace(defaultMusicPath+File.separator,"");
|
||||
boolean isDir= !StringUtils.isEmpty(type) && (type.equals("true"));
|
||||
JSONObject json=new JSONObject();
|
||||
JSONObject data = new JSONObject();
|
||||
json.put("code", 0);
|
||||
MusicTools tools = MusicTools.getInstance();
|
||||
json.put("scan", tools.isScan());
|
||||
json.put("size", tools.getLength());
|
||||
json.put("data", JSONArray.toJSON(tools.getPath(path,!StringUtils.isEmpty(type))));
|
||||
json.put("scan", musicTools.isScan());
|
||||
json.put("size", musicTools.getLength());
|
||||
json.put("data", JSONArray.toJSON(musicTools.getPath(path,isDir)));
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("getAlbum.do")
|
||||
public String getAlbum(String album){
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("code",0);
|
||||
if(StringUtils.isEmpty(album)){
|
||||
json.put("data",JSONArray.toJSON(musicTools.getAllAlbum()));
|
||||
}else{
|
||||
json.put("data",JSONArray.toJSON(musicTools.selectAlbum(album)));
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("getArtist.do")
|
||||
public String getArtist(String artist){
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("code",0);
|
||||
if(StringUtils.isEmpty(artist)){
|
||||
json.put("data",JSONArray.toJSON(musicTools.getAllArtist()));
|
||||
}else{
|
||||
json.put("data",JSONArray.toJSON(musicTools.selectArtist(artist)));
|
||||
}
|
||||
return json.toJSONString();
|
||||
|
||||
}
|
||||
@RequestMapping("reload.do")
|
||||
@ResponseBody
|
||||
public String reload(){
|
||||
JSONObject json=new JSONObject();
|
||||
MusicTools.getInstance().scanMusic();
|
||||
musicTools.scanMusic();
|
||||
json.put("msg","ok");
|
||||
json.put("code",0);
|
||||
return json.toJSONString();
|
||||
@ -82,7 +105,7 @@ public class MusicController {
|
||||
return json.toJSONString();
|
||||
}
|
||||
json.put("code",0);
|
||||
json.put("data",MusicTools.getInstance().getMetadata(new File(base64ToString(path))));
|
||||
json.put("data",musicTools.getMusicData(path));
|
||||
return json.toJSONString();
|
||||
}
|
||||
@RequestMapping("getlocalhost.do")
|
||||
@ -109,12 +132,12 @@ public class MusicController {
|
||||
json.put("data", "");
|
||||
return json.toJSONString();
|
||||
}
|
||||
File file = new File(base64ToString(fileName));
|
||||
File file = new File(Tools.base64ToString(fileName));
|
||||
try {
|
||||
if (file.exists()) {
|
||||
json.put("msg", "ok");
|
||||
json.put("code", 0);
|
||||
json.put("data", MusicTools.getInstance().getMetadata(file).readImage());
|
||||
json.put("data", musicTools.readImage(file.getAbsolutePath()));
|
||||
} else {
|
||||
json.put("msg", "文件不存在");
|
||||
json.put("code", -1);
|
||||
@ -132,12 +155,12 @@ public class MusicController {
|
||||
@RequestMapping("random.do")
|
||||
@ResponseBody
|
||||
public String random(){
|
||||
List<MusicData> list=MusicTools.getInstance().getMusicList();
|
||||
List<MusicData> list=musicTools.getMusicList();
|
||||
MusicData data=list.get(Tools.randomCommon(0,list.size()-1,1)[0]);
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("code",0);
|
||||
try {
|
||||
json.put("data", URLEncoder.encode(getBase64(data.getFile().getAbsolutePath()),"UTF-8"));
|
||||
json.put("data", URLEncoder.encode(getBase64(data.getFile()),"UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -146,19 +169,16 @@ public class MusicController {
|
||||
private String getBase64(String str){
|
||||
return new String(Base64.getEncoder().encode(str.getBytes()));
|
||||
}
|
||||
private String base64ToString(String base){
|
||||
base=base.replace(" ","+");
|
||||
return new String(Base64.getDecoder().decode(base.replace("\r\n","").getBytes()));
|
||||
}
|
||||
|
||||
@RequestMapping("play.do")
|
||||
public ResponseEntity<FileSystemResource> play(String filePath,boolean random) {
|
||||
if(!StringUtils.isEmpty(filePath)){
|
||||
filePath=base64ToString(filePath);
|
||||
filePath=Tools.base64ToString(filePath);
|
||||
}
|
||||
if(random){
|
||||
List<MusicData> list=MusicTools.getInstance().getMusicList();
|
||||
List<MusicData> list=musicTools.getMusicList();
|
||||
MusicData data=list.get(Tools.randomCommon(0,list.size()-1,1)[0]);
|
||||
filePath=data.getFile().getAbsolutePath();
|
||||
filePath=data.getFile();
|
||||
}
|
||||
File file = new File(filePath);
|
||||
if (file.exists()) {
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.yutou.tools.home.nas;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
* 收藏夹相关
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/nas/music/")
|
||||
public class MusicFavoritesController{
|
||||
|
||||
}
|
41
src/main/java/com/yutou/tools/mybatis/dao/MusicDataDao.java
Normal file
41
src/main/java/com/yutou/tools/mybatis/dao/MusicDataDao.java
Normal file
@ -0,0 +1,41 @@
|
||||
package com.yutou.tools.mybatis.dao;
|
||||
|
||||
import com.yutou.tools.mybatis.model.MusicData;
|
||||
import com.yutou.tools.mybatis.model.MusicDataExample;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@Mapper
|
||||
public interface MusicDataDao {
|
||||
long countByExample(MusicDataExample example);
|
||||
|
||||
int deleteByExample(MusicDataExample example);
|
||||
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(MusicData record);
|
||||
|
||||
int insertSelective(MusicData record);
|
||||
|
||||
List<MusicData> selectByExample(MusicDataExample example);
|
||||
|
||||
MusicData selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByExampleSelective(@Param("record") MusicData record, @Param("example") MusicDataExample example);
|
||||
|
||||
int updateByExample(@Param("record") MusicData record, @Param("example") MusicDataExample example);
|
||||
|
||||
int updateByPrimaryKeySelective(MusicData record);
|
||||
|
||||
int updateByPrimaryKey(MusicData record);
|
||||
|
||||
void truncate();
|
||||
|
||||
List<MusicData> selectByRegexp(String regexp);
|
||||
|
||||
List<String> selectAllAlbum();
|
||||
List<String> selectAllArtist();
|
||||
List<MusicData> selectAlbum(String album);
|
||||
List<MusicData> selectArtist(String artist);
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.yutou.tools.mybatis.dao;
|
||||
|
||||
import com.yutou.tools.mybatis.model.MusicFavorites;
|
||||
import com.yutou.tools.mybatis.model.MusicFavoritesExample;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@Mapper
|
||||
public interface MusicFavoritesDao {
|
||||
long countByExample(MusicFavoritesExample example);
|
||||
|
||||
int deleteByExample(MusicFavoritesExample example);
|
||||
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(MusicFavorites record);
|
||||
|
||||
int insertSelective(MusicFavorites record);
|
||||
|
||||
List<MusicFavorites> selectByExample(MusicFavoritesExample example);
|
||||
|
||||
MusicFavorites selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByExampleSelective(@Param("record") MusicFavorites record, @Param("example") MusicFavoritesExample example);
|
||||
|
||||
int updateByExample(@Param("record") MusicFavorites record, @Param("example") MusicFavoritesExample example);
|
||||
|
||||
int updateByPrimaryKeySelective(MusicFavorites record);
|
||||
|
||||
int updateByPrimaryKey(MusicFavorites record);
|
||||
}
|
117
src/main/java/com/yutou/tools/mybatis/model/MusicData.java
Normal file
117
src/main/java/com/yutou/tools/mybatis/model/MusicData.java
Normal file
@ -0,0 +1,117 @@
|
||||
package com.yutou.tools.mybatis.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* music_data
|
||||
* @author
|
||||
*/
|
||||
@Data
|
||||
public class MusicData implements Serializable {
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 艺术家
|
||||
*/
|
||||
private String artist;
|
||||
|
||||
/**
|
||||
* 专辑
|
||||
*/
|
||||
private String album;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 评论
|
||||
*/
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* 年份
|
||||
*/
|
||||
private String year;
|
||||
|
||||
/**
|
||||
* 音轨号
|
||||
*/
|
||||
private String track;
|
||||
|
||||
/**
|
||||
* 碟片编号
|
||||
*/
|
||||
private String discNo;
|
||||
|
||||
/**
|
||||
* 作曲
|
||||
*/
|
||||
private String composer;
|
||||
|
||||
/**
|
||||
* 分类
|
||||
*/
|
||||
private String artistSort;
|
||||
|
||||
/**
|
||||
* 音乐文件路径
|
||||
*/
|
||||
private String file;
|
||||
|
||||
/**
|
||||
* 上一个文件夹
|
||||
*/
|
||||
private String lastdir;
|
||||
|
||||
private Integer isdir;
|
||||
|
||||
/**
|
||||
* 比特率
|
||||
*/
|
||||
private Integer bitrate;
|
||||
|
||||
/**
|
||||
* 采样率
|
||||
*/
|
||||
private Integer samplerate;
|
||||
|
||||
/**
|
||||
* 采样数
|
||||
*/
|
||||
private Long noofsamples;
|
||||
|
||||
/**
|
||||
* 声道
|
||||
*/
|
||||
private Integer channelcount;
|
||||
|
||||
/**
|
||||
* 解码类型
|
||||
*/
|
||||
private String encodingtype;
|
||||
|
||||
/**
|
||||
* 持续时长
|
||||
*/
|
||||
private Double durationasdouble;
|
||||
|
||||
/**
|
||||
* 无损
|
||||
*/
|
||||
private Integer lossless;
|
||||
|
||||
/**
|
||||
* 固定码率
|
||||
*/
|
||||
private Integer variablebitrate;
|
||||
|
||||
/**
|
||||
* md5
|
||||
*/
|
||||
private String md5;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
1651
src/main/java/com/yutou/tools/mybatis/model/MusicDataExample.java
Normal file
1651
src/main/java/com/yutou/tools/mybatis/model/MusicDataExample.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,19 @@
|
||||
package com.yutou.tools.mybatis.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* music_favorites
|
||||
* @author
|
||||
*/
|
||||
@Data
|
||||
public class MusicFavorites implements Serializable {
|
||||
private Integer id;
|
||||
|
||||
private String title;
|
||||
|
||||
private String musisMd5;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -0,0 +1,401 @@
|
||||
package com.yutou.tools.mybatis.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MusicFavoritesExample {
|
||||
protected String orderByClause;
|
||||
|
||||
protected boolean distinct;
|
||||
|
||||
protected List<Criteria> oredCriteria;
|
||||
|
||||
public MusicFavoritesExample() {
|
||||
oredCriteria = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setOrderByClause(String orderByClause) {
|
||||
this.orderByClause = orderByClause;
|
||||
}
|
||||
|
||||
public String getOrderByClause() {
|
||||
return orderByClause;
|
||||
}
|
||||
|
||||
public void setDistinct(boolean distinct) {
|
||||
this.distinct = distinct;
|
||||
}
|
||||
|
||||
public boolean isDistinct() {
|
||||
return distinct;
|
||||
}
|
||||
|
||||
public List<Criteria> getOredCriteria() {
|
||||
return oredCriteria;
|
||||
}
|
||||
|
||||
public void or(Criteria criteria) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
|
||||
public Criteria or() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
oredCriteria.add(criteria);
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public Criteria createCriteria() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
if (oredCriteria.size() == 0) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected Criteria createCriteriaInternal() {
|
||||
Criteria criteria = new Criteria();
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
oredCriteria.clear();
|
||||
orderByClause = null;
|
||||
distinct = false;
|
||||
}
|
||||
|
||||
protected abstract static class GeneratedCriteria {
|
||||
protected List<Criterion> criteria;
|
||||
|
||||
protected GeneratedCriteria() {
|
||||
super();
|
||||
criteria = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return criteria.size() > 0;
|
||||
}
|
||||
|
||||
public List<Criterion> getAllCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public List<Criterion> getCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition) {
|
||||
if (condition == null) {
|
||||
throw new RuntimeException("Value for condition cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value, String property) {
|
||||
if (value == null) {
|
||||
throw new RuntimeException("Value for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value1, Object value2, String property) {
|
||||
if (value1 == null || value2 == null) {
|
||||
throw new RuntimeException("Between values for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value1, value2));
|
||||
}
|
||||
|
||||
public Criteria andIdIsNull() {
|
||||
addCriterion("id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdIsNotNull() {
|
||||
addCriterion("id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdEqualTo(Integer value) {
|
||||
addCriterion("id =", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotEqualTo(Integer value) {
|
||||
addCriterion("id <>", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdGreaterThan(Integer value) {
|
||||
addCriterion("id >", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdGreaterThanOrEqualTo(Integer value) {
|
||||
addCriterion("id >=", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLessThan(Integer value) {
|
||||
addCriterion("id <", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLessThanOrEqualTo(Integer value) {
|
||||
addCriterion("id <=", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdIn(List<Integer> values) {
|
||||
addCriterion("id in", values, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotIn(List<Integer> values) {
|
||||
addCriterion("id not in", values, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdBetween(Integer value1, Integer value2) {
|
||||
addCriterion("id between", value1, value2, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotBetween(Integer value1, Integer value2) {
|
||||
addCriterion("id not between", value1, value2, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleIsNull() {
|
||||
addCriterion("title is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleIsNotNull() {
|
||||
addCriterion("title is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleEqualTo(String value) {
|
||||
addCriterion("title =", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleNotEqualTo(String value) {
|
||||
addCriterion("title <>", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleGreaterThan(String value) {
|
||||
addCriterion("title >", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("title >=", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleLessThan(String value) {
|
||||
addCriterion("title <", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleLessThanOrEqualTo(String value) {
|
||||
addCriterion("title <=", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleLike(String value) {
|
||||
addCriterion("title like", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleNotLike(String value) {
|
||||
addCriterion("title not like", value, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleIn(List<String> values) {
|
||||
addCriterion("title in", values, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleNotIn(List<String> values) {
|
||||
addCriterion("title not in", values, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleBetween(String value1, String value2) {
|
||||
addCriterion("title between", value1, value2, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTitleNotBetween(String value1, String value2) {
|
||||
addCriterion("title not between", value1, value2, "title");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5IsNull() {
|
||||
addCriterion("musis_md5 is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5IsNotNull() {
|
||||
addCriterion("musis_md5 is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5EqualTo(String value) {
|
||||
addCriterion("musis_md5 =", value, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5NotEqualTo(String value) {
|
||||
addCriterion("musis_md5 <>", value, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5GreaterThan(String value) {
|
||||
addCriterion("musis_md5 >", value, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5GreaterThanOrEqualTo(String value) {
|
||||
addCriterion("musis_md5 >=", value, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5LessThan(String value) {
|
||||
addCriterion("musis_md5 <", value, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5LessThanOrEqualTo(String value) {
|
||||
addCriterion("musis_md5 <=", value, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5Like(String value) {
|
||||
addCriterion("musis_md5 like", value, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5NotLike(String value) {
|
||||
addCriterion("musis_md5 not like", value, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5In(List<String> values) {
|
||||
addCriterion("musis_md5 in", values, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5NotIn(List<String> values) {
|
||||
addCriterion("musis_md5 not in", values, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5Between(String value1, String value2) {
|
||||
addCriterion("musis_md5 between", value1, value2, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMusisMd5NotBetween(String value1, String value2) {
|
||||
addCriterion("musis_md5 not between", value1, value2, "musisMd5");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
protected Criteria() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criterion {
|
||||
private String condition;
|
||||
|
||||
private Object value;
|
||||
|
||||
private Object secondValue;
|
||||
|
||||
private boolean noValue;
|
||||
|
||||
private boolean singleValue;
|
||||
|
||||
private boolean betweenValue;
|
||||
|
||||
private boolean listValue;
|
||||
|
||||
private String typeHandler;
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object getSecondValue() {
|
||||
return secondValue;
|
||||
}
|
||||
|
||||
public boolean isNoValue() {
|
||||
return noValue;
|
||||
}
|
||||
|
||||
public boolean isSingleValue() {
|
||||
return singleValue;
|
||||
}
|
||||
|
||||
public boolean isBetweenValue() {
|
||||
return betweenValue;
|
||||
}
|
||||
|
||||
public boolean isListValue() {
|
||||
return listValue;
|
||||
}
|
||||
|
||||
public String getTypeHandler() {
|
||||
return typeHandler;
|
||||
}
|
||||
|
||||
protected Criterion(String condition) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.typeHandler = null;
|
||||
this.noValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.typeHandler = typeHandler;
|
||||
if (value instanceof List<?>) {
|
||||
this.listValue = true;
|
||||
} else {
|
||||
this.singleValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value) {
|
||||
this(condition, value, null);
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.secondValue = secondValue;
|
||||
this.typeHandler = typeHandler;
|
||||
this.betweenValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue) {
|
||||
this(condition, value, secondValue, null);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package com.yutou.tools.other;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.ToolsApplication;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@ -61,4 +62,9 @@ public class tools {
|
||||
return str;
|
||||
//return "function test(){ return \"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1588139022200&di=8cc8405f7514dd54bd82fcd070349603&imgtype=0&src=http%3A%2F%2Fa2.att.hudong.com%2F36%2F48%2F19300001357258133412489354717.jpg\" }";
|
||||
}
|
||||
@RequestMapping("/public/version.do")
|
||||
@ResponseBody
|
||||
public String getVersion(){
|
||||
return ToolsApplication.version;
|
||||
}
|
||||
}
|
||||
|
20
src/main/java/com/yutou/tools/utils/ApplicationInit.java
Normal file
20
src/main/java/com/yutou/tools/utils/ApplicationInit.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.yutou.tools.utils;
|
||||
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 服务启动后执行
|
||||
*/
|
||||
@Component
|
||||
public class ApplicationInit implements ApplicationRunner {
|
||||
@Resource
|
||||
MusicTools musicTools;
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
musicTools.init();//初始化音乐库
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.yutou.tools.utils.Interfaces;
|
||||
|
||||
import com.yutou.tools.mybatis.model.MusicData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MusicToolsService {
|
||||
void init();
|
||||
|
||||
void scanMusic();
|
||||
|
||||
List<MusicData> getPath(String path, boolean isDir);
|
||||
|
||||
MusicData getMusicData(String md5);
|
||||
|
||||
List<MusicData> findOfTitle(String title);
|
||||
|
||||
List<MusicData> findOfArtist(String by);
|
||||
|
||||
List<MusicData> getMusicList();
|
||||
|
||||
int getLength();
|
||||
|
||||
boolean isScan();
|
||||
|
||||
String getMusicPath();
|
||||
|
||||
byte[] readImage(String path) throws Exception;
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
package com.yutou.tools.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.home.nas.Data.MusicData;
|
||||
import com.yutou.tools.home.nas.MusicController;
|
||||
import com.yutou.tools.mybatis.dao.MusicDataDao;
|
||||
import com.yutou.tools.mybatis.model.MusicData;
|
||||
import com.yutou.tools.mybatis.model.MusicDataExample;
|
||||
import com.yutou.tools.utils.Interfaces.MusicToolsService;
|
||||
import ealvatag.audio.AudioFile;
|
||||
import ealvatag.audio.AudioFileIO;
|
||||
import ealvatag.audio.AudioHeader;
|
||||
@ -11,31 +12,44 @@ import ealvatag.audio.exceptions.CannotReadException;
|
||||
import ealvatag.tag.FieldKey;
|
||||
import ealvatag.tag.NullTag;
|
||||
import ealvatag.tag.Tag;
|
||||
import ealvatag.tag.flac.FlacTag;
|
||||
import ealvatag.tag.images.NullArtwork;
|
||||
import net.bramp.ffmpeg.FFmpeg;
|
||||
import net.bramp.ffmpeg.FFprobe;
|
||||
import net.bramp.ffmpeg.probe.FFmpegFormat;
|
||||
import net.bramp.ffmpeg.probe.FFmpegProbeResult;
|
||||
import net.bramp.ffmpeg.probe.FFmpegStream;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class MusicTools {
|
||||
@Service("musicToolsService")
|
||||
public class MusicTools implements MusicToolsService {
|
||||
public static final int FIND_TITLE = 1;
|
||||
public static final int FIND_ARTIST = 2;
|
||||
|
||||
private static MusicTools tools;
|
||||
private String musicPath = "/media/yutou/4t/public/音乐";
|
||||
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() {
|
||||
if (tools == null) {
|
||||
tools = new MusicTools();
|
||||
}
|
||||
return tools;
|
||||
}
|
||||
@Resource
|
||||
MusicDataDao musicDataDao;
|
||||
|
||||
|
||||
private MusicTools() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
musicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
||||
scanMusic();
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
@ -49,36 +63,26 @@ public class MusicTools {
|
||||
}, 0, 10 * 1000);
|
||||
}
|
||||
|
||||
public synchronized void scanMusic() {
|
||||
if (isScan) {
|
||||
@Override
|
||||
public void scanMusic() {
|
||||
if (isScan || true) {
|
||||
return;
|
||||
}
|
||||
System.out.println("执行扫描");
|
||||
musicList.clear();
|
||||
musicMap.clear();
|
||||
musicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
||||
musicDataDao.truncate();
|
||||
System.out.println("执行扫描:" + musicPath);
|
||||
new Thread(() -> {
|
||||
long startTime = System.currentTimeMillis();
|
||||
QQBotManager.getInstance().sendMessage("开始扫描音乐夹");
|
||||
isScan = true;
|
||||
scan(new File(musicPath));
|
||||
isScan = false;
|
||||
System.out.println("扫描完成");
|
||||
QQBotManager.getInstance().sendMessage("音乐扫描完成,共" + getLength() + "首歌,耗时:"
|
||||
+ (System.currentTimeMillis() - startTime));
|
||||
}).start();
|
||||
}
|
||||
|
||||
public List<MusicData> scan(File path, boolean isScanDir) {
|
||||
if (isScanDir) {
|
||||
scan(path);
|
||||
return musicList;
|
||||
} else {
|
||||
if (path.exists() && path.isDirectory()) {
|
||||
List<MusicData> list = new ArrayList<>();
|
||||
for (File file : path.listFiles()) {
|
||||
list.add(getMetadata(file));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void scan(File path) {
|
||||
if (path.isFile()) {
|
||||
@ -105,6 +109,7 @@ public class MusicTools {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取指定目录下的音乐
|
||||
*
|
||||
@ -112,46 +117,48 @@ public class MusicTools {
|
||||
* @param isDir 是否扫描目录下的所有文件,false则仅为当前目录
|
||||
* @return 音乐列表
|
||||
*/
|
||||
@Override
|
||||
public List<MusicData> getPath(String path, boolean isDir) {
|
||||
List<MusicData> list = new ArrayList<>();
|
||||
List<MusicData> main;
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
String replacement = ConfigTools.load(ConfigTools.CONFIG, "os").equals("windows") ? "\\\\" : "/";
|
||||
if (isDir) {
|
||||
if (new File(path).isDirectory() && !path.equals(MusicController.defaultMusicPath)) {
|
||||
for (String key : musicMap.keySet()) {
|
||||
if (key.startsWith(path)) {
|
||||
list.addAll(musicMap.get(key));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
if (musicMap.containsKey(path)) {
|
||||
MusicData tmp = musicMap.get(path).isEmpty() ? null : musicMap.get(path).get(0);
|
||||
if (tmp != null) {
|
||||
if (!tmp.getFile().getParent().equals(MusicController.defaultMusicPath)) {
|
||||
MusicData t2 = new MusicData();
|
||||
t2.setTitle("返回");
|
||||
t2.setFile(new File(tmp.getLastDir()));
|
||||
list.add(t2);
|
||||
}
|
||||
|
||||
}
|
||||
getDirList(path, list);
|
||||
list.addAll(musicMap.get(path));
|
||||
return list;
|
||||
example.createCriteria().andFileLike(path.replace(File.separator, replacement) + "%");
|
||||
main = musicDataDao.selectByExample(example);
|
||||
} else {
|
||||
if (path.contains(MusicController.defaultMusicPath)) {
|
||||
MusicData t2 = new MusicData();
|
||||
t2.setTitle("返回");
|
||||
t2.setFile(new File(path).getParentFile());
|
||||
if (!path.equals(MusicController.defaultMusicPath)) {
|
||||
list.add(t2);
|
||||
}
|
||||
getDirList(path, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
main = musicDataDao.selectByRegexp(path.replace(File.separator, replacement) + replacement + "([^" + replacement + "]+)$");
|
||||
}
|
||||
return new ArrayList<>();
|
||||
System.out.println(path + " " + isDir);
|
||||
if (!path.equals(MusicController.defaultMusicPath) && !path.equals("root") && main.size() > 0) {
|
||||
MusicData tmp = main.get(0);
|
||||
System.out.println(tmp);
|
||||
MusicData t2 = new MusicData();
|
||||
t2.setTitle("返回");
|
||||
t2.setFile(new File(tmp.getLastdir()).getAbsolutePath());
|
||||
t2.setIsdir(1);
|
||||
list.add(t2);
|
||||
}
|
||||
getDirList(path, list);
|
||||
list.addAll(main);
|
||||
System.out.println(list.size());
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<String> getAllAlbum() {
|
||||
return musicDataDao.selectAllAlbum();
|
||||
}
|
||||
|
||||
public List<String> getAllArtist() {
|
||||
return musicDataDao.selectAllArtist();
|
||||
}
|
||||
|
||||
public List<MusicData> selectAlbum(String album) {
|
||||
return musicDataDao.selectAlbum(album);
|
||||
}
|
||||
|
||||
public List<MusicData> selectArtist(String artist) {
|
||||
return musicDataDao.selectArtist(artist);
|
||||
}
|
||||
|
||||
private void getDirList(String path, List<MusicData> list) {
|
||||
@ -160,7 +167,8 @@ public class MusicTools {
|
||||
if (listFile.isDirectory()) {
|
||||
MusicData data = new MusicData();
|
||||
data.setTitle(listFile.getName());
|
||||
data.setFile(listFile);
|
||||
data.setIsdir(1);
|
||||
data.setFile(listFile.getAbsolutePath());
|
||||
list.add(data);
|
||||
}
|
||||
}
|
||||
@ -169,19 +177,28 @@ public class MusicTools {
|
||||
private void add(File file) {
|
||||
MusicData data = getMetadata(file);
|
||||
if (data != null) {
|
||||
musicList.add(data);
|
||||
String path = file.getAbsolutePath().replace(File.separator + file.getName(), "");
|
||||
List<MusicData> list;
|
||||
if (musicMap.containsKey(path)) {
|
||||
list = musicMap.get(path);
|
||||
} else {
|
||||
list = new ArrayList<>();
|
||||
try {
|
||||
musicDataDao.insert(data);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
QQBotManager.getInstance().sendMessage("音乐文件添加失败:" + data.toString());
|
||||
}
|
||||
list.add(data);
|
||||
musicMap.put(path, list);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MusicData getMusicData(String path) {
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
example.createCriteria().andFileEqualTo(Tools.base64ToString(path));
|
||||
List<MusicData> list = musicDataDao.selectByExample(example);
|
||||
if (list != null && list.size() > 0) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public MusicData getMetadata(File file) {
|
||||
try {
|
||||
if (file.getName().endsWith(".lrc")
|
||||
@ -208,7 +225,7 @@ public class MusicTools {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
data.setArtist_sort(tag.getFirst(FieldKey.ARTIST_SORT));
|
||||
data.setArtistSort(tag.getFirst(FieldKey.ARTIST_SORT));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
@ -220,7 +237,7 @@ public class MusicTools {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
data.setDisc_no(tag.getFirst(FieldKey.DISC_NO));
|
||||
data.setDiscNo(tag.getFirst(FieldKey.DISC_NO));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
@ -240,30 +257,27 @@ public class MusicTools {
|
||||
data.setYear(tag.getFirst(FieldKey.YEAR));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
data.setFile(file);
|
||||
data.setFile(file.getAbsolutePath());
|
||||
data.setIsdir(file.isDirectory() ? 1 : 0);
|
||||
data.setLastdir(file.getParentFile().getParent());
|
||||
|
||||
AudioHeader header = audioFile.getAudioHeader();
|
||||
data.setBitRate(header.getBitRate());
|
||||
data.setSampleRate(header.getSampleRate());
|
||||
data.setNoOfSamples(header.getNoOfSamples());
|
||||
data.setChannelCount(header.getChannelCount());
|
||||
data.setEncodingType(header.getEncodingType());
|
||||
data.setDurationAsDouble(header.getDurationAsDouble());
|
||||
data.setLossless(header.isLossless());
|
||||
data.setVariableBitRate(header.isVariableBitRate());
|
||||
data.setBitrate(header.getBitRate());
|
||||
data.setSamplerate(header.getSampleRate());
|
||||
data.setNoofsamples(header.getNoOfSamples());
|
||||
data.setChannelcount(header.getChannelCount());
|
||||
data.setEncodingtype(header.getEncodingType());
|
||||
data.setDurationasdouble(header.getDurationAsDouble());
|
||||
data.setLossless(header.isLossless() ? 1 : 0);
|
||||
data.setVariablebitrate(header.isVariableBitRate() ? 1 : 0);
|
||||
try {
|
||||
data.setMd5(header.getClass().getMethod("getMd5").invoke(header).toString());
|
||||
} catch (Exception ignored) {
|
||||
data.setMd5(Base64.getEncoder().encodeToString(file.getAbsolutePath().getBytes()));
|
||||
data.setMd5(Tools.getFileMD5(file));
|
||||
}
|
||||
return data;
|
||||
} catch (CannotReadException e) {
|
||||
MusicData data = getMetadata_jthink(file);
|
||||
if (data == null)
|
||||
data = new MusicData();
|
||||
data.setTitle(file.getName());
|
||||
data.setFile(file);
|
||||
return data;
|
||||
return getMetadata_jthink(file);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -284,7 +298,7 @@ public class MusicTools {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
data.setArtist_sort(tag.getFirst(org.jaudiotagger.tag.FieldKey.ARTIST_SORT));
|
||||
data.setArtistSort(tag.getFirst(org.jaudiotagger.tag.FieldKey.ARTIST_SORT));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
@ -296,7 +310,7 @@ public class MusicTools {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
data.setDisc_no(tag.getFirst(org.jaudiotagger.tag.FieldKey.DISC_NO));
|
||||
data.setDiscNo(tag.getFirst(org.jaudiotagger.tag.FieldKey.DISC_NO));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
@ -316,60 +330,166 @@ public class MusicTools {
|
||||
data.setYear(tag.getFirst(org.jaudiotagger.tag.FieldKey.YEAR));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
data.setFile(file);
|
||||
data.setFile(file.getAbsolutePath());
|
||||
data.setIsdir(file.isDirectory() ? 1 : 0);
|
||||
data.setLastdir(file.getParentFile().getParent());
|
||||
|
||||
org.jaudiotagger.audio.AudioHeader header = audioFile.getAudioHeader();
|
||||
data.setBitRate(Integer.parseInt(header.getBitRate()));
|
||||
data.setSampleRate(Integer.parseInt(header.getSampleRate()));
|
||||
data.setNoOfSamples(header.getSampleRateAsNumber());
|
||||
data.setChannelCount(Integer.parseInt(header.getChannels()));
|
||||
data.setEncodingType(header.getEncodingType() + "");
|
||||
data.setDurationAsDouble(header.getTrackLength());
|
||||
data.setLossless(header.isLossless());
|
||||
data.setVariableBitRate(header.isVariableBitRate());
|
||||
data.setBitrate(Integer.parseInt(header.getBitRate()));
|
||||
data.setSamplerate(Integer.parseInt(header.getSampleRate()));
|
||||
data.setNoofsamples(Long.parseLong(header.getSampleRateAsNumber() + ""));
|
||||
data.setChannelcount(Integer.parseInt(header.getChannels()));
|
||||
data.setEncodingtype(header.getEncodingType() + "");
|
||||
data.setDurationasdouble(Double.parseDouble(header.getTrackLength() + ""));
|
||||
data.setLossless(header.isLossless() ? 1 : 0);
|
||||
data.setVariablebitrate(header.isVariableBitRate() ? 1 : 0);
|
||||
try {
|
||||
data.setMd5(header.getClass().getMethod("getMd5").invoke(header).toString());
|
||||
} catch (Exception ignored) {
|
||||
data.setMd5(Base64.getEncoder().encodeToString(file.getAbsolutePath().getBytes()));
|
||||
data.setMd5(Tools.getFileMD5(file));
|
||||
}
|
||||
return data;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return getMetadataOfFFmpeg(file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private MusicData getMetadataOfFFmpeg(File file) {
|
||||
MusicData data;
|
||||
try {
|
||||
data = new MusicData();
|
||||
FFprobe fFprobe = new FFprobe((String) ConfigTools.load(ConfigTools.CONFIG, "ffprobe"));
|
||||
FFmpegProbeResult result = fFprobe.probe(file.getAbsolutePath());
|
||||
FFmpegFormat format = result.getFormat();
|
||||
FFmpegStream stream = null;
|
||||
for (FFmpegStream tmp : result.getStreams()) {
|
||||
if (tmp.index == 0) {
|
||||
stream = tmp;
|
||||
}
|
||||
}
|
||||
Map<String, String> tag = format.tags;
|
||||
data.setTitle(getTitle(tag));
|
||||
data.setAlbum(getAlbum(tag));
|
||||
data.setArtist(getArtist(tag));
|
||||
data.setDiscNo(tag.get("disc") == null ? tag.get("disc".toUpperCase()) : tag.get("disc"));
|
||||
data.setTrack(tag.get("track") == null ? tag.get("track".toUpperCase()) : tag.get("track"));
|
||||
data.setYear(getYear(tag));
|
||||
data.setArtistSort(tag.get("album_artist") == null ? tag.get("album_artist".toUpperCase()) : tag.get("album_artist"));
|
||||
data.setDurationasdouble(format.duration);
|
||||
data.setBitrate((int) (format.bit_rate / 1000));
|
||||
if (stream != null) {
|
||||
if (data.getBitrate() == 0)
|
||||
data.setBitrate((int) (stream.bit_rate / 1000));
|
||||
data.setChannelcount(stream.channels);
|
||||
data.setLossless(0);
|
||||
data.setSamplerate(stream.sample_rate);
|
||||
data.setNoofsamples(stream.duration_ts);
|
||||
}
|
||||
data.setEncodingtype(format.format_long_name);
|
||||
data.setComment("");
|
||||
data.setComposer("");
|
||||
data.setVariablebitrate(0);
|
||||
data.setFile(file.getAbsolutePath());
|
||||
data.setLastdir(file.getParentFile().getParent());
|
||||
data.setIsdir(file.isDirectory() ? 1 : 0);
|
||||
if (data.getYear() == null) {
|
||||
data.setYear("0000");
|
||||
}
|
||||
data.setMd5(Tools.getFileMD5(file));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
data = new MusicData();
|
||||
data.setTitle(file.getName());
|
||||
data.setFile(file.getAbsolutePath());
|
||||
data.setIsdir(file.isDirectory() ? 1 : 0);
|
||||
data.setLastdir(file.getParentFile().getParent());
|
||||
data.setMd5(Tools.getFileMD5(file));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private String getTitle(Map<String, String> tag) {
|
||||
String title = tag.get("title");
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = tag.get("TITLE");
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = tag.get("Title");
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
private String getArtist(Map<String, String> tag) {
|
||||
String title = tag.get("artist");
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = tag.get("ARTIST");
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = tag.get("Artist");
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
private String getAlbum(Map<String, String> tag) {
|
||||
String title = tag.get("album");
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = tag.get("ALBUM");
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = tag.get("Album");
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
private String getYear(Map<String, String> tag) {
|
||||
String title = tag.get("year");
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = tag.get("YEAR");
|
||||
if (StringUtils.isEmpty(title)) {
|
||||
title = tag.get("Year");
|
||||
}
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MusicData> findOfTitle(String title) {
|
||||
return find(title, FIND_TITLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MusicData> findOfArtist(String by) {
|
||||
return find(by, FIND_ARTIST);
|
||||
}
|
||||
|
||||
public List<MusicData> getMusicList() {
|
||||
return musicList;
|
||||
return musicDataDao.selectByExample(new MusicDataExample());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return tools.musicList.size();
|
||||
return musicDataDao.selectByExample(new MusicDataExample()).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isScan() {
|
||||
return isScan;
|
||||
}
|
||||
|
||||
private List<MusicData> find(String title, int type) {
|
||||
List<MusicData> list = new ArrayList<>();
|
||||
for (MusicData data : musicList) {
|
||||
if (data.getTitle().contains(title)) {
|
||||
list.add(data);
|
||||
}
|
||||
List<MusicData> list;
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
if (type == FIND_TITLE) {
|
||||
example.createCriteria().andTitleEqualTo(title);
|
||||
} else if (type == FIND_ARTIST) {
|
||||
example.createCriteria().andArtistEqualTo(title);
|
||||
}
|
||||
list = musicDataDao.selectByExample(example);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getMusicPath() {
|
||||
return musicPath;
|
||||
}
|
||||
@ -378,26 +498,40 @@ public class MusicTools {
|
||||
this.musicPath = musicPath;
|
||||
}
|
||||
|
||||
private void saveImage(MusicData data) {
|
||||
try {
|
||||
File file = new File(data.getTitle() + ".jpg");
|
||||
if (!file.exists()) {
|
||||
if (!file.createNewFile()) {
|
||||
return;
|
||||
@Override
|
||||
public byte[] readImage(String path) throws Exception {
|
||||
File file = new File(path);
|
||||
AudioFile audioFile = null;
|
||||
audioFile = AudioFileIO.read(file);
|
||||
Tag tag = audioFile.getTag().or(NullTag.INSTANCE);
|
||||
byte[] bytes = tag.getFirstArtwork().or(NullArtwork.INSTANCE).getBinaryData();
|
||||
if (bytes.length == 0) {
|
||||
return readImageFile(file);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private byte[] readImageFile(File file) throws Exception {
|
||||
String path = file.getAbsolutePath().replace(file.getName(), "");
|
||||
File img = new File(path, "cover.jpg");
|
||||
if (!img.exists()) {
|
||||
img = new File(path, "Cover.jpg");
|
||||
if (!img.exists()) {
|
||||
img = new File(path, "COVER.jpg");
|
||||
if (!img.exists()) {
|
||||
throw new NullPointerException("没有cover文件");
|
||||
}
|
||||
}
|
||||
OutputStream outputStream = new FileOutputStream(file);
|
||||
outputStream.write(data.readImage());
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return Files.readAllBytes(Paths.get(img.getAbsolutePath()));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
File file = new File("Z:\\音乐\\总之就是非常酸\\ED\\カノエラナ - 月と星空\\カノエラナ.wav");
|
||||
System.out.println(new MusicTools().getMetadata(file));
|
||||
file = new File("Z:\\音乐\\终将成为你\\[OP]君にふれて\\rise.flac");
|
||||
// file = new File("Z:\\音乐\\周董\\2012 十二新作\\03 公公偏头痛.ape");
|
||||
System.out.println(new MusicTools().getMetadataOfFFmpeg(file));
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,8 +54,11 @@ public class QQBotManager {
|
||||
}
|
||||
});
|
||||
Events.registerEvents(bot, new MessageListener());
|
||||
|
||||
bot.login();
|
||||
sendMessage("姬妻酱上线拉~");
|
||||
bot.join();
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
@ -18,6 +18,8 @@ import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
@ -334,4 +336,44 @@ public class Tools {
|
||||
headers.add("ETag", String.valueOf(System.currentTimeMillis()));
|
||||
return ResponseEntity.ok().headers(headers).contentLength(file.length()).contentType(MediaType.parseMediaType("application/octet-stream")).body(new FileSystemResource(file));
|
||||
}
|
||||
public static String getFileMD5(File file) {
|
||||
if (!file.isFile()) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest digest = null;
|
||||
FileInputStream in = null;
|
||||
byte buffer[] = new byte[1024];
|
||||
int len;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
in = new FileInputStream(file);
|
||||
while ((len = in.read(buffer, 0, 1024)) != -1) {
|
||||
digest.update(buffer, 0, len);
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return bytesToHexString(digest.digest());
|
||||
}
|
||||
private static String bytesToHexString(byte[] src) {
|
||||
StringBuilder stringBuilder = new StringBuilder("");
|
||||
if (src == null || src.length <= 0) {
|
||||
return null;
|
||||
}
|
||||
for (byte aSrc : src) {
|
||||
int v = aSrc & 0xFF;
|
||||
String hv = Integer.toHexString(v);
|
||||
if (hv.length() < 2) {
|
||||
stringBuilder.append(0);
|
||||
}
|
||||
stringBuilder.append(hv);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
public static String base64ToString(String base){
|
||||
base=base.replace(" ","+");
|
||||
return new String(Base64.getDecoder().decode(base.replace("\r\n","").getBytes()));
|
||||
}
|
||||
}
|
||||
|
496
src/main/resources/mapper/MusicDataDao.xml
Normal file
496
src/main/resources/mapper/MusicDataDao.xml
Normal file
@ -0,0 +1,496 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yutou.tools.mybatis.dao.MusicDataDao">
|
||||
<resultMap id="BaseResultMap" type="com.yutou.tools.mybatis.model.MusicData">
|
||||
<id column="id" jdbcType="INTEGER" property="id" />
|
||||
<result column="artist" jdbcType="VARCHAR" property="artist" />
|
||||
<result column="album" jdbcType="VARCHAR" property="album" />
|
||||
<result column="title" jdbcType="VARCHAR" property="title" />
|
||||
<result column="comment" jdbcType="VARCHAR" property="comment" />
|
||||
<result column="year" jdbcType="VARCHAR" property="year" />
|
||||
<result column="track" jdbcType="VARCHAR" property="track" />
|
||||
<result column="disc_no" jdbcType="VARCHAR" property="discNo" />
|
||||
<result column="composer" jdbcType="VARCHAR" property="composer" />
|
||||
<result column="artist_sort" jdbcType="VARCHAR" property="artistSort" />
|
||||
<result column="file" jdbcType="VARCHAR" property="file" />
|
||||
<result column="lastDir" jdbcType="VARCHAR" property="lastdir" />
|
||||
<result column="isDir" jdbcType="INTEGER" property="isdir" />
|
||||
<result column="bitRate" jdbcType="INTEGER" property="bitrate" />
|
||||
<result column="sampleRate" jdbcType="INTEGER" property="samplerate" />
|
||||
<result column="noOfSamples" jdbcType="BIGINT" property="noofsamples" />
|
||||
<result column="channelCount" jdbcType="INTEGER" property="channelcount" />
|
||||
<result column="encodingType" jdbcType="VARCHAR" property="encodingtype" />
|
||||
<result column="durationAsDouble" jdbcType="DOUBLE" property="durationasdouble" />
|
||||
<result column="lossless" jdbcType="INTEGER" property="lossless" />
|
||||
<result column="variableBitRate" jdbcType="INTEGER" property="variablebitrate" />
|
||||
<result column="md5" jdbcType="VARCHAR" property="md5" />
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause">
|
||||
<where>
|
||||
<foreach collection="oredCriteria" item="criteria" separator="or">
|
||||
<if test="criteria.valid">
|
||||
<trim prefix="(" prefixOverrides="and" suffix=")">
|
||||
<foreach collection="criteria.criteria" item="criterion">
|
||||
<choose>
|
||||
<when test="criterion.noValue">
|
||||
and ${criterion.condition}
|
||||
</when>
|
||||
<when test="criterion.singleValue">
|
||||
and ${criterion.condition} #{criterion.value}
|
||||
</when>
|
||||
<when test="criterion.betweenValue">
|
||||
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
||||
</when>
|
||||
<when test="criterion.listValue">
|
||||
and ${criterion.condition}
|
||||
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
||||
#{listItem}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</if>
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Update_By_Example_Where_Clause">
|
||||
<where>
|
||||
<foreach collection="example.oredCriteria" item="criteria" separator="or">
|
||||
<if test="criteria.valid">
|
||||
<trim prefix="(" prefixOverrides="and" suffix=")">
|
||||
<foreach collection="criteria.criteria" item="criterion">
|
||||
<choose>
|
||||
<when test="criterion.noValue">
|
||||
and ${criterion.condition}
|
||||
</when>
|
||||
<when test="criterion.singleValue">
|
||||
and ${criterion.condition} #{criterion.value}
|
||||
</when>
|
||||
<when test="criterion.betweenValue">
|
||||
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
||||
</when>
|
||||
<when test="criterion.listValue">
|
||||
and ${criterion.condition}
|
||||
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
||||
#{listItem}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</if>
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, artist, album, title, `comment`, `year`, track, disc_no, composer, artist_sort,
|
||||
`file`, lastDir, isDir, bitRate, sampleRate, noOfSamples, channelCount, encodingType,
|
||||
durationAsDouble, lossless, variableBitRate, md5
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="com.yutou.tools.mybatis.model.MusicDataExample" resultMap="BaseResultMap">
|
||||
select
|
||||
<if test="distinct">
|
||||
distinct
|
||||
</if>
|
||||
<include refid="Base_Column_List" />
|
||||
from music_data
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from music_data
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
delete from music_data
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<delete id="deleteByExample" parameterType="com.yutou.tools.mybatis.model.MusicDataExample">
|
||||
delete from music_data
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
</delete>
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.MusicData" useGeneratedKeys="true">
|
||||
insert into music_data (artist, album, title,
|
||||
`comment`, `year`, track,
|
||||
disc_no, composer, artist_sort,
|
||||
`file`, lastDir, isDir,
|
||||
bitRate, sampleRate, noOfSamples,
|
||||
channelCount, encodingType, durationAsDouble,
|
||||
lossless, variableBitRate, md5
|
||||
)
|
||||
values (#{artist,jdbcType=VARCHAR}, #{album,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR},
|
||||
#{comment,jdbcType=VARCHAR}, #{year,jdbcType=VARCHAR}, #{track,jdbcType=VARCHAR},
|
||||
#{discNo,jdbcType=VARCHAR}, #{composer,jdbcType=VARCHAR}, #{artistSort,jdbcType=VARCHAR},
|
||||
#{file,jdbcType=VARCHAR}, #{lastdir,jdbcType=VARCHAR}, #{isdir,jdbcType=INTEGER},
|
||||
#{bitrate,jdbcType=INTEGER}, #{samplerate,jdbcType=INTEGER}, #{noofsamples,jdbcType=BIGINT},
|
||||
#{channelcount,jdbcType=INTEGER}, #{encodingtype,jdbcType=VARCHAR}, #{durationasdouble,jdbcType=DOUBLE},
|
||||
#{lossless,jdbcType=INTEGER}, #{variablebitrate,jdbcType=INTEGER}, #{md5,jdbcType=VARCHAR}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.MusicData" useGeneratedKeys="true">
|
||||
insert into music_data
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="artist != null">
|
||||
artist,
|
||||
</if>
|
||||
<if test="album != null">
|
||||
album,
|
||||
</if>
|
||||
<if test="title != null">
|
||||
title,
|
||||
</if>
|
||||
<if test="comment != null">
|
||||
`comment`,
|
||||
</if>
|
||||
<if test="year != null">
|
||||
`year`,
|
||||
</if>
|
||||
<if test="track != null">
|
||||
track,
|
||||
</if>
|
||||
<if test="discNo != null">
|
||||
disc_no,
|
||||
</if>
|
||||
<if test="composer != null">
|
||||
composer,
|
||||
</if>
|
||||
<if test="artistSort != null">
|
||||
artist_sort,
|
||||
</if>
|
||||
<if test="file != null">
|
||||
`file`,
|
||||
</if>
|
||||
<if test="lastdir != null">
|
||||
lastDir,
|
||||
</if>
|
||||
<if test="isdir != null">
|
||||
isDir,
|
||||
</if>
|
||||
<if test="bitrate != null">
|
||||
bitRate,
|
||||
</if>
|
||||
<if test="samplerate != null">
|
||||
sampleRate,
|
||||
</if>
|
||||
<if test="noofsamples != null">
|
||||
noOfSamples,
|
||||
</if>
|
||||
<if test="channelcount != null">
|
||||
channelCount,
|
||||
</if>
|
||||
<if test="encodingtype != null">
|
||||
encodingType,
|
||||
</if>
|
||||
<if test="durationasdouble != null">
|
||||
durationAsDouble,
|
||||
</if>
|
||||
<if test="lossless != null">
|
||||
lossless,
|
||||
</if>
|
||||
<if test="variablebitrate != null">
|
||||
variableBitRate,
|
||||
</if>
|
||||
<if test="md5 != null">
|
||||
md5,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="artist != null">
|
||||
#{artist,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="album != null">
|
||||
#{album,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="title != null">
|
||||
#{title,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="comment != null">
|
||||
#{comment,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="year != null">
|
||||
#{year,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="track != null">
|
||||
#{track,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="discNo != null">
|
||||
#{discNo,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="composer != null">
|
||||
#{composer,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="artistSort != null">
|
||||
#{artistSort,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="file != null">
|
||||
#{file,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="lastdir != null">
|
||||
#{lastdir,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="isdir != null">
|
||||
#{isdir,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="bitrate != null">
|
||||
#{bitrate,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="samplerate != null">
|
||||
#{samplerate,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="noofsamples != null">
|
||||
#{noofsamples,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="channelcount != null">
|
||||
#{channelcount,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="encodingtype != null">
|
||||
#{encodingtype,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="durationasdouble != null">
|
||||
#{durationasdouble,jdbcType=DOUBLE},
|
||||
</if>
|
||||
<if test="lossless != null">
|
||||
#{lossless,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="variablebitrate != null">
|
||||
#{variablebitrate,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="md5 != null">
|
||||
#{md5,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="com.yutou.tools.mybatis.model.MusicDataExample" resultType="java.lang.Long">
|
||||
select count(*) from music_data
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectByRegexp" resultType="com.yutou.tools.mybatis.model.MusicData">
|
||||
select * from web_tools.music_data where `file` REGEXP #{regexp,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="selectAllAlbum" resultType="java.lang.String">
|
||||
SELECT album FROM web_tools.music_data group by `album`;
|
||||
</select>
|
||||
<select id="selectAllArtist" resultType="java.lang.String">
|
||||
SELECT artist FROM web_tools.music_data group by `artist`;
|
||||
</select>
|
||||
<select id="selectAlbum" resultType="com.yutou.tools.mybatis.model.MusicData">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from web_tools.music_data where `album`= #{album,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="selectArtist" resultType="com.yutou.tools.mybatis.model.MusicData">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from web_tools.music_data where `artist`= #{artist,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<update id="updateByExampleSelective" parameterType="map">
|
||||
update music_data
|
||||
<set>
|
||||
<if test="record.id != null">
|
||||
id = #{record.id,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.artist != null">
|
||||
artist = #{record.artist,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.album != null">
|
||||
album = #{record.album,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.title != null">
|
||||
title = #{record.title,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.comment != null">
|
||||
`comment` = #{record.comment,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.year != null">
|
||||
`year` = #{record.year,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.track != null">
|
||||
track = #{record.track,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.discNo != null">
|
||||
disc_no = #{record.discNo,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.composer != null">
|
||||
composer = #{record.composer,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.artistSort != null">
|
||||
artist_sort = #{record.artistSort,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.file != null">
|
||||
`file` = #{record.file,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.lastdir != null">
|
||||
lastDir = #{record.lastdir,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.isdir != null">
|
||||
isDir = #{record.isdir,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.bitrate != null">
|
||||
bitRate = #{record.bitrate,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.samplerate != null">
|
||||
sampleRate = #{record.samplerate,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.noofsamples != null">
|
||||
noOfSamples = #{record.noofsamples,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="record.channelcount != null">
|
||||
channelCount = #{record.channelcount,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.encodingtype != null">
|
||||
encodingType = #{record.encodingtype,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.durationasdouble != null">
|
||||
durationAsDouble = #{record.durationasdouble,jdbcType=DOUBLE},
|
||||
</if>
|
||||
<if test="record.lossless != null">
|
||||
lossless = #{record.lossless,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.variablebitrate != null">
|
||||
variableBitRate = #{record.variablebitrate,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.md5 != null">
|
||||
md5 = #{record.md5,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByExample" parameterType="map">
|
||||
update music_data
|
||||
set id = #{record.id,jdbcType=INTEGER},
|
||||
artist = #{record.artist,jdbcType=VARCHAR},
|
||||
album = #{record.album,jdbcType=VARCHAR},
|
||||
title = #{record.title,jdbcType=VARCHAR},
|
||||
`comment` = #{record.comment,jdbcType=VARCHAR},
|
||||
`year` = #{record.year,jdbcType=VARCHAR},
|
||||
track = #{record.track,jdbcType=VARCHAR},
|
||||
disc_no = #{record.discNo,jdbcType=VARCHAR},
|
||||
composer = #{record.composer,jdbcType=VARCHAR},
|
||||
artist_sort = #{record.artistSort,jdbcType=VARCHAR},
|
||||
`file` = #{record.file,jdbcType=VARCHAR},
|
||||
lastDir = #{record.lastdir,jdbcType=VARCHAR},
|
||||
isDir = #{record.isdir,jdbcType=INTEGER},
|
||||
bitRate = #{record.bitrate,jdbcType=INTEGER},
|
||||
sampleRate = #{record.samplerate,jdbcType=INTEGER},
|
||||
noOfSamples = #{record.noofsamples,jdbcType=BIGINT},
|
||||
channelCount = #{record.channelcount,jdbcType=INTEGER},
|
||||
encodingType = #{record.encodingtype,jdbcType=VARCHAR},
|
||||
durationAsDouble = #{record.durationasdouble,jdbcType=DOUBLE},
|
||||
lossless = #{record.lossless,jdbcType=INTEGER},
|
||||
variableBitRate = #{record.variablebitrate,jdbcType=INTEGER},
|
||||
md5 = #{record.md5,jdbcType=VARCHAR}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.yutou.tools.mybatis.model.MusicData">
|
||||
update music_data
|
||||
<set>
|
||||
<if test="artist != null">
|
||||
artist = #{artist,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="album != null">
|
||||
album = #{album,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="title != null">
|
||||
title = #{title,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="comment != null">
|
||||
`comment` = #{comment,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="year != null">
|
||||
`year` = #{year,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="track != null">
|
||||
track = #{track,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="discNo != null">
|
||||
disc_no = #{discNo,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="composer != null">
|
||||
composer = #{composer,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="artistSort != null">
|
||||
artist_sort = #{artistSort,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="file != null">
|
||||
`file` = #{file,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="lastdir != null">
|
||||
lastDir = #{lastdir,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="isdir != null">
|
||||
isDir = #{isdir,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="bitrate != null">
|
||||
bitRate = #{bitrate,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="samplerate != null">
|
||||
sampleRate = #{samplerate,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="noofsamples != null">
|
||||
noOfSamples = #{noofsamples,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="channelcount != null">
|
||||
channelCount = #{channelcount,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="encodingtype != null">
|
||||
encodingType = #{encodingtype,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="durationasdouble != null">
|
||||
durationAsDouble = #{durationasdouble,jdbcType=DOUBLE},
|
||||
</if>
|
||||
<if test="lossless != null">
|
||||
lossless = #{lossless,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="variablebitrate != null">
|
||||
variableBitRate = #{variablebitrate,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="md5 != null">
|
||||
md5 = #{md5,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.yutou.tools.mybatis.model.MusicData">
|
||||
update music_data
|
||||
set artist = #{artist,jdbcType=VARCHAR},
|
||||
album = #{album,jdbcType=VARCHAR},
|
||||
title = #{title,jdbcType=VARCHAR},
|
||||
`comment` = #{comment,jdbcType=VARCHAR},
|
||||
`year` = #{year,jdbcType=VARCHAR},
|
||||
track = #{track,jdbcType=VARCHAR},
|
||||
disc_no = #{discNo,jdbcType=VARCHAR},
|
||||
composer = #{composer,jdbcType=VARCHAR},
|
||||
artist_sort = #{artistSort,jdbcType=VARCHAR},
|
||||
`file` = #{file,jdbcType=VARCHAR},
|
||||
lastDir = #{lastdir,jdbcType=VARCHAR},
|
||||
isDir = #{isdir,jdbcType=INTEGER},
|
||||
bitRate = #{bitrate,jdbcType=INTEGER},
|
||||
sampleRate = #{samplerate,jdbcType=INTEGER},
|
||||
noOfSamples = #{noofsamples,jdbcType=BIGINT},
|
||||
channelCount = #{channelcount,jdbcType=INTEGER},
|
||||
encodingType = #{encodingtype,jdbcType=VARCHAR},
|
||||
durationAsDouble = #{durationasdouble,jdbcType=DOUBLE},
|
||||
lossless = #{lossless,jdbcType=INTEGER},
|
||||
variableBitRate = #{variablebitrate,jdbcType=INTEGER},
|
||||
md5 = #{md5,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="truncate">
|
||||
TRUNCATE music_data;
|
||||
</update>
|
||||
</mapper>
|
173
src/main/resources/mapper/MusicFavoritesDao.xml
Normal file
173
src/main/resources/mapper/MusicFavoritesDao.xml
Normal file
@ -0,0 +1,173 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yutou.tools.mybatis.dao.MusicFavoritesDao">
|
||||
<resultMap id="BaseResultMap" type="com.yutou.tools.mybatis.model.MusicFavorites">
|
||||
<id column="id" jdbcType="INTEGER" property="id" />
|
||||
<result column="title" jdbcType="VARCHAR" property="title" />
|
||||
<result column="musis_md5" jdbcType="VARCHAR" property="musisMd5" />
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause">
|
||||
<where>
|
||||
<foreach collection="oredCriteria" item="criteria" separator="or">
|
||||
<if test="criteria.valid">
|
||||
<trim prefix="(" prefixOverrides="and" suffix=")">
|
||||
<foreach collection="criteria.criteria" item="criterion">
|
||||
<choose>
|
||||
<when test="criterion.noValue">
|
||||
and ${criterion.condition}
|
||||
</when>
|
||||
<when test="criterion.singleValue">
|
||||
and ${criterion.condition} #{criterion.value}
|
||||
</when>
|
||||
<when test="criterion.betweenValue">
|
||||
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
||||
</when>
|
||||
<when test="criterion.listValue">
|
||||
and ${criterion.condition}
|
||||
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
||||
#{listItem}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</if>
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Update_By_Example_Where_Clause">
|
||||
<where>
|
||||
<foreach collection="example.oredCriteria" item="criteria" separator="or">
|
||||
<if test="criteria.valid">
|
||||
<trim prefix="(" prefixOverrides="and" suffix=")">
|
||||
<foreach collection="criteria.criteria" item="criterion">
|
||||
<choose>
|
||||
<when test="criterion.noValue">
|
||||
and ${criterion.condition}
|
||||
</when>
|
||||
<when test="criterion.singleValue">
|
||||
and ${criterion.condition} #{criterion.value}
|
||||
</when>
|
||||
<when test="criterion.betweenValue">
|
||||
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
|
||||
</when>
|
||||
<when test="criterion.listValue">
|
||||
and ${criterion.condition}
|
||||
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
|
||||
#{listItem}
|
||||
</foreach>
|
||||
</when>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</if>
|
||||
</foreach>
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, title, musis_md5
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="com.yutou.tools.mybatis.model.MusicFavoritesExample" resultMap="BaseResultMap">
|
||||
select
|
||||
<if test="distinct">
|
||||
distinct
|
||||
</if>
|
||||
<include refid="Base_Column_List" />
|
||||
from music_favorites
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from music_favorites
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
delete from music_favorites
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<delete id="deleteByExample" parameterType="com.yutou.tools.mybatis.model.MusicFavoritesExample">
|
||||
delete from music_favorites
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
</delete>
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.MusicFavorites" useGeneratedKeys="true">
|
||||
insert into music_favorites (title, musis_md5)
|
||||
values (#{title,jdbcType=VARCHAR}, #{musisMd5,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.MusicFavorites" useGeneratedKeys="true">
|
||||
insert into music_favorites
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="title != null">
|
||||
title,
|
||||
</if>
|
||||
<if test="musisMd5 != null">
|
||||
musis_md5,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="title != null">
|
||||
#{title,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="musisMd5 != null">
|
||||
#{musisMd5,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="com.yutou.tools.mybatis.model.MusicFavoritesExample" resultType="java.lang.Long">
|
||||
select count(*) from music_favorites
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause" />
|
||||
</if>
|
||||
</select>
|
||||
<update id="updateByExampleSelective" parameterType="map">
|
||||
update music_favorites
|
||||
<set>
|
||||
<if test="record.id != null">
|
||||
id = #{record.id,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.title != null">
|
||||
title = #{record.title,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.musisMd5 != null">
|
||||
musis_md5 = #{record.musisMd5,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByExample" parameterType="map">
|
||||
update music_favorites
|
||||
set id = #{record.id,jdbcType=INTEGER},
|
||||
title = #{record.title,jdbcType=VARCHAR},
|
||||
musis_md5 = #{record.musisMd5,jdbcType=VARCHAR}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
</update>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.yutou.tools.mybatis.model.MusicFavorites">
|
||||
update music_favorites
|
||||
<set>
|
||||
<if test="title != null">
|
||||
title = #{title,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="musisMd5 != null">
|
||||
musis_md5 = #{musisMd5,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.yutou.tools.mybatis.model.MusicFavorites">
|
||||
update music_favorites
|
||||
set title = #{title,jdbcType=VARCHAR},
|
||||
musis_md5 = #{musisMd5,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
</mapper>
|
@ -46,7 +46,7 @@
|
||||
<link rel="stylesheet" href="/css/AudioPlayer.css">
|
||||
<script src="/js/AudioPlayer.js"></script>
|
||||
<script id="listTemplet">
|
||||
{{# if(d.dir){ }}
|
||||
{{# if(d.isdir===1){ }}
|
||||
<div><i class="layui-icon"> </i>{{d.title}}</div>
|
||||
{{# } else { }}
|
||||
<div><i class="layui-icon"> </i>{{d.title}}</div>
|
||||
@ -66,8 +66,9 @@
|
||||
try {
|
||||
let json = JSON.parse(obj);
|
||||
localhost = json.data+":8000";
|
||||
if(localhost==='http://null:8000'){
|
||||
localhost=""
|
||||
console.log("音频地址:"+localhost)
|
||||
if(localhost==='http://null:8000'||localhost===":8000"){
|
||||
localhost="http://127.0.0.1"
|
||||
}
|
||||
} catch (e) {
|
||||
localhost = ""
|
||||
@ -95,7 +96,7 @@
|
||||
})
|
||||
table.on('rowDouble(music)', function (obj) {
|
||||
//obj 同上
|
||||
if (obj.data.dir) {
|
||||
if (obj.data.isdir===1) {
|
||||
listTable.reload({
|
||||
where: {
|
||||
path: obj.data.file
|
||||
@ -115,7 +116,7 @@
|
||||
table.on('tool(music)', function (obj) {
|
||||
let data = obj.data;
|
||||
if (obj.event === 'download') {
|
||||
if (!data.dir) {
|
||||
if (data.isdir===0) {
|
||||
window.open(localhost + "/nas/music/play.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&random=false&filePath=" + new Base64().encode(data.file))
|
||||
}
|
||||
} else if (obj.event === 'play') {
|
||||
@ -185,7 +186,7 @@
|
||||
if (playIndex === musicLib.length) {
|
||||
playIndex = 0;
|
||||
}
|
||||
if (musicLib[playIndex].dir) {
|
||||
if (musicLib[playIndex].isdir===1) {
|
||||
playIndex++
|
||||
playNext()
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user