Compare commits
90 Commits
Dev_
...
c1468cf094
| Author | SHA1 | Date | |
|---|---|---|---|
| c1468cf094 | |||
| 558ad1bdaf | |||
| 6ffbe7f2f5 | |||
| ec5dbeda2b | |||
| 59f82aef19 | |||
| db2bc033be | |||
| be98dc533e | |||
| e27c22640c | |||
| 55870fbc05 | |||
| 05823742e3 | |||
| ad40de7815 | |||
| 1029dbee9c | |||
| 2c8c3e8685 | |||
| 36f93eb06f | |||
| d46c7411bf | |||
| e2d3a8e270 | |||
| 25bc6e22f4 | |||
| c9ac6b2e7b | |||
| 8e06346be0 | |||
| dd1fcb8145 | |||
| f50dcb2244 | |||
| f94b4f130c | |||
| f3e9feb8fd | |||
| 4bf62c1a1f | |||
| 0be4bef30e | |||
| 007184031b | |||
| 3cf9b7da7e | |||
| eab928a111 | |||
| e58cb29656 | |||
| face663b6e | |||
| 3509de8cef | |||
| a39d99eeb6 | |||
| 8fa1f81ff9 | |||
| ee089312f2 | |||
| 56e55bab44 | |||
| 7ccb852223 | |||
| bfbe81aa11 | |||
| c771f17140 | |||
| ed70cea2a6 | |||
| 0a15594184 | |||
| 32b53a6a16 | |||
| c3ce37e1b4 | |||
| 780e86c7af | |||
| ca06eed516 | |||
| 1045e761c9 | |||
| 584779cc13 | |||
| 15e32c9b00 | |||
| 7b2bdca2e6 | |||
| ebe876fcfa | |||
| 238efb7a40 | |||
| e8fe762c53 | |||
| 56ff209497 | |||
| f379a31cd9 | |||
| 1b1c249e0f | |||
| b783224077 | |||
| cf30e6db7c | |||
| e090e6375e | |||
| 3997ee91ac | |||
| 72c2752128 | |||
| 81f91f756a | |||
| 66c77b04b9 | |||
| 25e1ddca64 | |||
| ed659dfa65 | |||
| 7b533bb0df | |||
| a21a875261 | |||
| b63d05a89c | |||
| 893afd295c | |||
| 2f1ba2acb9 | |||
| 51c15f4a34 | |||
| 74f7b9cd21 | |||
| 9bfe05b119 | |||
| 4bcf56207d | |||
| fe10c4b686 | |||
| ed97daa089 | |||
| 9dc132bcae | |||
| c7f42e87e0 | |||
| 0a0d62ce11 | |||
| 7ce3e76268 | |||
| 805fa61f19 | |||
| 890b7b20ad | |||
| afce2ac901 | |||
| ee6317a984 | |||
| e8cb0ef814 | |||
| 0da3b9f0d0 | |||
| d01cda4d50 | |||
| 71e18e03b9 | |||
| 301dc63624 | |||
| 6d9ba12cf1 | |||
| 11534b04f7 | |||
| 006fb8c836 |
13
.gitea/workflows/build.yaml
Normal file
13
.gitea/workflows/build.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
name: buildDemo
|
||||
run-name: ${{ github.actor }} is testing out Gitea Actions 🚀
|
||||
on:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
Explore-Gitea-Actions:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '11'
|
||||
run: | java1 -version
|
||||
103
pom.xml
103
pom.xml
@@ -41,7 +41,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
<version>1.18.24</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -60,23 +60,22 @@
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>3.6.0-RC1</version>
|
||||
<version>4.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
<version>2.4.7</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.67</version>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.17</version>
|
||||
</dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/libs/fastjson2-2.0.3.jar</systemPath>
|
||||
</dependency>-->
|
||||
<!-- https://mvnrepository.com/artifact/com.jcraft/jsch -->
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
@@ -86,33 +85,18 @@
|
||||
<dependency>
|
||||
<groupId>net.jthink</groupId>
|
||||
<artifactId>jaudiotagger</artifactId>
|
||||
<version>2.2.3</version>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ealva</groupId>
|
||||
<artifactId>ealvatag</artifactId>
|
||||
<version>0.4.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.mamoe</groupId>
|
||||
<artifactId>mirai-core-jvm</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-jdk8</artifactId>
|
||||
<version>1.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>0.4.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.bramp.ffmpeg</groupId>
|
||||
<artifactId>ffmpeg</artifactId>
|
||||
<version>0.6.2</version>
|
||||
<version>0.7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.iflytek</groupId>
|
||||
@@ -131,22 +115,29 @@
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<version>2.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.10.2</version>
|
||||
<version>3.15.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.drewnoakes</groupId>
|
||||
<artifactId>metadata-extractor</artifactId>
|
||||
<version>2.18.0</version>
|
||||
</dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>20030203.000550</version>
|
||||
<groupId>com.acgist</groupId>
|
||||
<artifactId>snail</artifactId>
|
||||
<version>1.17.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -172,27 +163,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
@@ -210,21 +180,24 @@
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<outputDirectory>
|
||||
X:\servier\tools\
|
||||
</outputDirectory>
|
||||
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<compilerArguments>
|
||||
<extdirs>${basedir}/libs</extdirs>
|
||||
</compilerArguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>libs</directory>
|
||||
<targetPath>/BOOT-INF/lib/</targetPath>
|
||||
<targetPath>BOOT-INF/lib/</targetPath>
|
||||
<includes>
|
||||
<include>**/*.jar</include>
|
||||
</includes>
|
||||
|
||||
@@ -1,17 +1,41 @@
|
||||
package com.yutou.nas.Controllers;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.Services.IBangumiService;
|
||||
import com.yutou.nas.utils.AnimRssManager;
|
||||
import com.yutou.nas.utils.BTDownloadManager;
|
||||
import com.yutou.nas.utils.DmhyRssDownloadManager;
|
||||
import com.yutou.nas.utils.Log;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Controller
|
||||
public class BTDownloadController {
|
||||
@Resource
|
||||
IBangumiService bangumiService;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/bt/down.do")
|
||||
public String bt(){
|
||||
BTDownloadManager.getInstance().start();
|
||||
DmhyRssDownloadManager.getInstance().start();
|
||||
AnimRssManager.scan();
|
||||
return "ok";
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/bt/done.do")
|
||||
public String done(String path,String filename,String hash1,String hash2,String tid){
|
||||
Log.i("BTDownloadController.done","path = " + path + ", filename = " + filename + ", hash1 = " + hash1 + ", hash2 = " + hash2 + ", tid = " + tid);
|
||||
BTDownloadManager.done(path, filename, hash1, hash2, tid);
|
||||
return "ok";
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/bt/download.do")
|
||||
public String download(int id,boolean isDownloadNext,String url){
|
||||
Log.i("跳过下载","手动下载 id = " + id + ", isDownloadNext = " + isDownloadNext + ", url = " + url);
|
||||
bangumiService.download(id,isDownloadNext,url);
|
||||
return "1";
|
||||
}
|
||||
}
|
||||
|
||||
85
src/main/java/com/yutou/nas/Controllers/DoorController.java
Normal file
85
src/main/java/com/yutou/nas/Controllers/DoorController.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.yutou.nas.Controllers;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.utils.ConfigTools;
|
||||
import com.yutou.nas.utils.RedisTools;
|
||||
import com.yutou.nas.utils.StringUtils;
|
||||
import com.yutou.nas.utils.Tools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
@Controller
|
||||
public class DoorController {
|
||||
@RequestMapping("/door/data.do")
|
||||
@ResponseBody
|
||||
public JSONObject getData(){
|
||||
JSONObject json=new JSONObject();
|
||||
String zoom=RedisTools.get("door_zoom");
|
||||
if(StringUtils.isEmpty(zoom)){
|
||||
zoom="0";
|
||||
}
|
||||
json.put("zoom", Float.parseFloat(zoom));
|
||||
json.put("audio",RedisTools.get("door_audio"));
|
||||
json.put("restart",RedisTools.get("door_reboot"));
|
||||
json.put("af",RedisTools.get("door_af"));
|
||||
File file=new File("web"+File.separator+"apk"+File.separator+"door");
|
||||
if(file.exists()&& Objects.requireNonNull(file.listFiles()).length!=0){
|
||||
JSONObject update=new JSONObject();
|
||||
update.put("versionName", Objects.requireNonNull(file.listFiles())[0].getName().replace("app-release-","").replace(".apk",""));
|
||||
update.put("url","http://"+ ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":803/apk/door/"+ Objects.requireNonNull(file.listFiles())[0].getName());
|
||||
json.put("update",update);
|
||||
}
|
||||
RedisTools.remove("door_audio");
|
||||
RedisTools.remove("door_reboot");
|
||||
RedisTools.remove("door_af");
|
||||
return json;
|
||||
}
|
||||
@RequestMapping("/door/zoom.do")
|
||||
@ResponseBody
|
||||
public String setZoom(float zoom){
|
||||
if(zoom>1){
|
||||
zoom=1;
|
||||
}
|
||||
if(zoom<0){
|
||||
zoom=0;
|
||||
}
|
||||
RedisTools.set("door_zoom",zoom+"");
|
||||
return "1";
|
||||
}
|
||||
@RequestMapping(value="/door/audio.do")
|
||||
@ResponseBody
|
||||
public String setAudio(@RequestParam("audio") MultipartFile audio){
|
||||
System.out.println("收到音频");
|
||||
try {
|
||||
String path=Tools.createFile("audio",audio,System.currentTimeMillis()+".mp3");
|
||||
RedisTools.set("door_audio","http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":801/"+path);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "1";
|
||||
}
|
||||
@RequestMapping(value="/door/audio_url.do")
|
||||
@ResponseBody
|
||||
public String setAudioUrl(String url){
|
||||
RedisTools.set("door_audio",url);
|
||||
return "1";
|
||||
}
|
||||
@RequestMapping("/door/reboot.do")
|
||||
@ResponseBody
|
||||
public String reboot(){
|
||||
RedisTools.set("door_reboot","1");
|
||||
return "1";
|
||||
}
|
||||
@RequestMapping("/door/af.do")
|
||||
@ResponseBody
|
||||
public String af(){
|
||||
RedisTools.set("door_af","1");
|
||||
return "1";
|
||||
}
|
||||
}
|
||||
30
src/main/java/com/yutou/nas/Controllers/HHDController.java
Normal file
30
src/main/java/com/yutou/nas/Controllers/HHDController.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.yutou.nas.Controllers;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.utils.QQBotManager;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Controller
|
||||
public class HHDController {
|
||||
@ResponseBody
|
||||
@RequestMapping("/nas/hhd.do")
|
||||
public String hddSMART(@RequestBody JSONObject json){
|
||||
Pattern pattern=Pattern.compile(".(?<=(result: )).*");
|
||||
for (String key : json.keySet()) {
|
||||
Matcher matcher=pattern.matcher(json.getString(key));
|
||||
if(matcher.find()){
|
||||
String result=matcher.group(0).trim();
|
||||
if(!"PASSED".equals(result)){
|
||||
QQBotManager.getInstance().sendMessage("硬盘异常警告:"+key+":"+result);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "服务已接收";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.yutou.nas.Controllers;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.utils.*;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Controller
|
||||
public class JellyfinController {
|
||||
@RequestMapping("/jellyfin/addItem")
|
||||
@ResponseBody
|
||||
public String addItem(String Name, String Date) {
|
||||
if (!StringUtils.isEmpty(Name) && !StringUtils.isEmpty(Date)) {
|
||||
QQBotManager.getInstance().sendMessage(734332887L, " 新增:" + Name);
|
||||
AppTools.exec("/home/yutou/public/servier/tinyMediaManager/tinyMediaManager tvshow -u --scrapeUnscraped", null, false, true);
|
||||
new JellyfinAPIManager().refresh();
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/jellyfin/updateMeta")
|
||||
public String updateMeta() {
|
||||
AppTools.exec("/home/yutou/public/servier/tinyMediaManager/tinyMediaManager tvshow -u --scrapeUnscraped", null, false, true);
|
||||
new JellyfinAPIManager().refresh();
|
||||
return "ok";
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/jellyfin/setAppVersion")
|
||||
public String setAppVersion(String version){
|
||||
RedisTools.set("jellyfin_app_version",version);
|
||||
return "";
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/jellyfin/setTvAppVersion")
|
||||
public String setTvAppVersion(String version){
|
||||
RedisTools.set("jellyfin_tv_version",version);
|
||||
return "";
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/jellyfin/updateApp.do")
|
||||
public JSONObject updateApp(String version){
|
||||
JSONObject json=new JSONObject();
|
||||
String appVersion=RedisTools.get("jellyfin_app_version");
|
||||
if(appVersion==null){
|
||||
json.put("code",0);
|
||||
}else{
|
||||
File dir=new File("web"+File.separator+"apk"+File.separator+"jellyfin"+File.separator);
|
||||
buildDownloadJson(json, appVersion, dir);
|
||||
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
private void buildDownloadJson(JSONObject json, String appVersion, File dir) {
|
||||
json.put("code",0);
|
||||
if(dir.exists()){
|
||||
for (File file : dir.listFiles()) {
|
||||
if(file.getName().endsWith(".apk")){
|
||||
json.put("code",1);
|
||||
JSONObject data=new JSONObject();
|
||||
data.put("version",appVersion);
|
||||
data.put("url","http://nas.cnmglz.com:9999/apk"+file.getAbsolutePath().replace(new File("web"+File.separator+"apk"+File.separator).getAbsolutePath(),""));
|
||||
json.put("data",data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/jellyfin/updateTvApp.do")
|
||||
public JSONObject updateTvApp(String version){
|
||||
JSONObject json=new JSONObject();
|
||||
String appVersion=RedisTools.get("jellyfin_tv_version");
|
||||
if(appVersion==null){
|
||||
json.put("code",0);
|
||||
}else{
|
||||
File dir=new File("web"+File.separator+"apk"+File.separator+"jellyfinTv"+File.separator);
|
||||
buildDownloadJson(json, appVersion, dir);
|
||||
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.yutou.nas.Controllers;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.nas.mybatis.model.MusicData;
|
||||
import com.yutou.nas.utils.*;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.Services.impl.MusicToolsServiceImpl;
|
||||
import com.yutou.nas.mybatis.model.MusicData;
|
||||
import com.yutou.nas.utils.ConfigTools;
|
||||
import com.yutou.nas.utils.RedisTools;
|
||||
import com.yutou.nas.utils.StringUtils;
|
||||
import com.yutou.nas.utils.Tools;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -15,10 +19,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.yutou.nas.Datas.AppData.defaultMusicPath;
|
||||
@@ -36,7 +38,7 @@ public class MusicController {
|
||||
json.put("code", 0);
|
||||
json.put("scan", musicTools.isScan());
|
||||
json.put("size", musicTools.getLength());
|
||||
json.put("data", JSONArray.toJSON(musicTools.getMusicList()));
|
||||
json.put("data", JSON.toJSON(musicTools.getMusicList(true)));
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@@ -45,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", JSONArray.toJSON(musicTools.getPath(path, type)));
|
||||
json.put("data", JSON.toJSON(musicTools.getPath(path, type, true, filter)));
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@@ -69,9 +72,9 @@ public class MusicController {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
if (StringUtils.isEmpty(album)) {
|
||||
json.put("data", JSONArray.toJSON(musicTools.getAllAlbum()));
|
||||
json.put("data", JSON.toJSON(musicTools.getAllAlbum()));
|
||||
} else {
|
||||
json.put("data", JSONArray.toJSON(musicTools.selectAlbum(album)));
|
||||
json.put("data", JSON.toJSON(musicTools.selectAlbum(album, true)));
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
@@ -83,9 +86,9 @@ public class MusicController {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
if (StringUtils.isEmpty(artist)) {
|
||||
json.put("data", JSONArray.toJSON(musicTools.getAllArtist()));
|
||||
json.put("data", JSON.toJSON(musicTools.getAllArtist()));
|
||||
} else {
|
||||
json.put("data", JSONArray.toJSON(musicTools.selectArtist(artist)));
|
||||
json.put("data", JSON.toJSON(musicTools.selectArtist(artist, true)));
|
||||
}
|
||||
return json.toJSONString();
|
||||
}
|
||||
@@ -104,9 +107,7 @@ public class MusicController {
|
||||
@ResponseBody
|
||||
public String findFile(@RequestBody JSONObject body) {
|
||||
String path = body.getString("path");
|
||||
if (!path.startsWith(defaultMusicPath)) {
|
||||
path = Tools.base64ToString(path);
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
if (StringUtils.isEmpty(path)) {
|
||||
json.put("code", -1);
|
||||
@@ -114,7 +115,7 @@ public class MusicController {
|
||||
return json.toJSONString();
|
||||
}
|
||||
json.put("code", 0);
|
||||
json.put("data", musicTools.getMusicData(path));
|
||||
json.put("data", musicTools.getMusicDataOfMd5(path, true));
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@@ -147,24 +148,9 @@ public class MusicController {
|
||||
@RequestMapping(value = "/nas/music/image.do", produces = MediaType.IMAGE_JPEG_VALUE)
|
||||
@ResponseBody
|
||||
public byte[] getImage(@RequestBody JSONObject body) {
|
||||
String fileName = body.getString("fileName");
|
||||
if (!fileName.startsWith(defaultMusicPath)) {
|
||||
fileName = Tools.base64ToString(fileName);
|
||||
}
|
||||
List<MusicData> list = null;
|
||||
if ("album".equals(body.getString("type"))) {
|
||||
list = musicTools.selectAlbum(fileName);
|
||||
}
|
||||
File file;
|
||||
if (list != null && !list.isEmpty()) {
|
||||
fileName = list.get(0).getFile();
|
||||
}
|
||||
if(!fileName.startsWith("/media/yutou/disk_lvm/public/音乐/")
|
||||
||fileName.endsWith("..")
|
||||
||fileName.endsWith("../")){
|
||||
return null;
|
||||
}
|
||||
file = new File(fileName);
|
||||
String md5 = body.getString("fileName");
|
||||
|
||||
File file = musicTools.getMusicOfMd5(md5, false);
|
||||
if (file.exists()) {
|
||||
try {
|
||||
return musicTools.readImage(file.getAbsolutePath());
|
||||
@@ -177,84 +163,100 @@ public class MusicController {
|
||||
|
||||
@RequestMapping("/nas/music/random.do")
|
||||
@ResponseBody
|
||||
public String random() {
|
||||
List<MusicData> list = musicTools.getMusicList();
|
||||
public String random(String filter) {
|
||||
boolean _fieldName = false;
|
||||
if(!StringUtils.isEmpty(filter)){
|
||||
_fieldName="true".equals(filter);
|
||||
}
|
||||
List<MusicData> list = musicTools.getMusicList(true);
|
||||
if(_fieldName) {
|
||||
list.removeIf(data -> data.getTitle().toLowerCase().contains("instrumental"));
|
||||
}
|
||||
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()), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
json.put("data", data.getMd5());
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
private String getBase64(String str) {
|
||||
return new String(Base64.getEncoder().encode(str.getBytes()));
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/nas/music/play.do")
|
||||
public ResponseEntity<FileSystemResource> play(String filePath, String random) {
|
||||
String _filePath;
|
||||
boolean _random;
|
||||
_random = !StringUtils.isEmpty(random) && "true".equals(random);
|
||||
_filePath = Tools.base64ToString(filePath);
|
||||
if (_random) {
|
||||
List<MusicData> list = musicTools.getMusicList();
|
||||
List<MusicData> list = musicTools.getMusicList(true);
|
||||
MusicData data = list.get(Tools.randomCommon(0, list.size() - 1, 1)[0]);
|
||||
_filePath = data.getFile();
|
||||
filePath = data.getMd5();
|
||||
}
|
||||
if(!_filePath.startsWith("/media/yutou/disk_lvm/public/音乐/")
|
||||
||_filePath.endsWith("..")
|
||||
||_filePath.endsWith("../")){
|
||||
return null;
|
||||
}
|
||||
File file = new File(_filePath);
|
||||
|
||||
File file = musicTools.getMusicOfMd5(filePath, false);
|
||||
if (file.exists()) {
|
||||
return Tools.getFile(file);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/nas/music/lrc.do")
|
||||
public ResponseEntity<FileSystemResource> lrc(String filePath) {
|
||||
return Tools.getFile(musicTools.getMusicLrcMd5(filePath));
|
||||
}
|
||||
|
||||
@RequestMapping("/nas/music/share.do")
|
||||
@ResponseBody
|
||||
public JSONObject share(@RequestBody JSONObject data){
|
||||
public JSONObject share(@RequestBody JSONObject data) {
|
||||
System.out.println(data);
|
||||
String file=data.getString("file");
|
||||
String token=data.getString("token");
|
||||
JSONObject json=new JSONObject();
|
||||
File music=new File(file);
|
||||
if(music.exists()){
|
||||
String key=Tools.getMD5(UUID.randomUUID().toString()+music.getAbsolutePath());
|
||||
RedisTools.set(key,file,3600);
|
||||
JSONObject item=new JSONObject();
|
||||
item.put("share",key);
|
||||
json.put("code",1);
|
||||
json.put("msg","ok");
|
||||
json.put("data",item);
|
||||
}else{
|
||||
json.put("code",-1);
|
||||
json.put("msg","文件不存在");
|
||||
json.put("data","{}");
|
||||
String md5 = data.getString("file");
|
||||
boolean isDir = data.getBoolean("isDir");
|
||||
JSONObject json = new JSONObject();
|
||||
File music;
|
||||
if (isDir) {
|
||||
music = new File(md5);
|
||||
} else {
|
||||
music = musicTools.getMusicOfMd5(md5, false);
|
||||
}
|
||||
if (music.exists()) {
|
||||
String key = Tools.getMD5(UUID.randomUUID() + music.getAbsolutePath());
|
||||
RedisTools.set(key, music.getAbsolutePath(), 3600);
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("share", key);
|
||||
json.put("code", 1);
|
||||
json.put("msg", "ok");
|
||||
json.put("data", item);
|
||||
} else {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "文件不存在");
|
||||
json.put("data", "{}");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/nas/music/playShare.do")
|
||||
@ResponseBody
|
||||
public JSONObject playShare(String token) throws UnsupportedEncodingException {
|
||||
JSONObject json=new JSONObject();
|
||||
String redis=RedisTools.get(token);
|
||||
if(redis!=null&&!"-999".equals(token)){
|
||||
String file=redis;
|
||||
JSONObject item=new JSONObject();
|
||||
item.put("file",file);
|
||||
json.put("code",0);
|
||||
json.put("data",item);
|
||||
}else{
|
||||
json.put("code",-1);
|
||||
json.put("msg","分享已过期");
|
||||
public JSONObject playShare(String token) {
|
||||
JSONObject json = new JSONObject();
|
||||
String redis = RedisTools.get(token);
|
||||
if (redis != null && !"-999".equals(token)) {
|
||||
File file = new File(redis);
|
||||
JSONArray array = new JSONArray();
|
||||
if (file.isFile()) {
|
||||
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) {
|
||||
array.add(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("file", array);
|
||||
json.put("code", 0);
|
||||
json.put("data", item);
|
||||
} else {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "分享已过期");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.yutou.nas.Controllers;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.mybatis.dao.MusicDataDao;
|
||||
import com.yutou.nas.mybatis.dao.MusicFavoritesDao;
|
||||
import com.yutou.nas.mybatis.dao.MusicFavoritesDirDao;
|
||||
@@ -146,13 +147,13 @@ public class MusicFavoritesController {
|
||||
MusicDataExample dataExample = new MusicDataExample();
|
||||
dataExample.createCriteria().andMd5EqualTo(favorites.getMusisMd5());
|
||||
try {
|
||||
dataList.add(musicDataDao.selectByExample(dataExample).get(0));
|
||||
dataList.add(musicDataDao.selectByExample(dataExample,true).get(0));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
list.clear();
|
||||
json.put("code", 0);
|
||||
json.put("data", JSONArray.toJSON(dataList));
|
||||
json.put("data", JSON.toJSON(dataList));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
json.put("code", -1);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.yutou.nas.Controllers;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import com.yutou.nas.utils.QQBotManager;
|
||||
import com.yutou.nas.utils.Tools;
|
||||
@@ -30,20 +30,7 @@ public class QQBot {
|
||||
if(StringUtils.isEmpty(imgUrl)){
|
||||
ret= QQBotManager.getInstance().sendMessage(msg);
|
||||
}else{
|
||||
Tools.download(imgUrl, new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
super.onDownload(file);
|
||||
QQBotManager.getInstance().sendMessage(file,msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
super.onError(e);
|
||||
QQBotManager.getInstance().sendMessage(imgUrl+"\n"+msg);
|
||||
}
|
||||
});
|
||||
ret="图片下载中";
|
||||
ret=QQBotManager.getInstance().sendMessage(imgUrl,msg);
|
||||
}
|
||||
json.put("code",0);
|
||||
json.put("msg",ret);
|
||||
@@ -66,7 +53,7 @@ public class QQBot {
|
||||
String ret;
|
||||
try {
|
||||
String path = Tools.createFile("qq_image",file, file.getName());
|
||||
ret=QQBotManager.getInstance().sendMessage(new File(path),msg);
|
||||
ret=QQBotManager.getInstance().sendMessage(path,msg);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ret=e.getLocalizedMessage();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.yutou.nas.Controllers;
|
||||
|
||||
import com.yutou.nas.utils.HttpTools;
|
||||
import com.yutou.nas.utils.RedisTools;
|
||||
import com.yutou.nas.utils.StringUtils;
|
||||
import com.yutou.nas.utils.Tools;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.yutou.nas.utils.*;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@Controller
|
||||
@@ -41,4 +41,15 @@ public class ToolsController {
|
||||
Tools.sendServer(title, msg);
|
||||
return "ok";
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/tools/anim/items.do")
|
||||
public JSONArray getAnimItems(){
|
||||
return new JellyfinAPIManager().getAnimPaths();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "/tools/anim/set.do",method = RequestMethod.POST)
|
||||
public String setAnimMeta(String path,String id){
|
||||
new JellyfinAPIManager().init(new File(path),id);
|
||||
return "1";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yutou.nas.Controllers;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.utils.RedisTools;
|
||||
import com.yutou.nas.utils.Tools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -60,7 +61,7 @@ public class UpdateIp {
|
||||
if(isNas){
|
||||
String adminAddress= RedisTools.get("adminAddress");
|
||||
if(adminAddress!=null) {
|
||||
JSONObject json=JSONObject.parseObject(adminAddress);
|
||||
JSONObject json= JSON.parseObject(adminAddress);
|
||||
line = "proxy_pass http://" +ip+":"+json.getInteger("port")+"/;";
|
||||
}else{
|
||||
line = line.replace(testIp, ip);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.yutou.nas.Datas.Jellyfin;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.utils.AppTools;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
@@ -18,28 +20,28 @@ public class EpisodeData {
|
||||
private boolean canDownload;
|
||||
private String container;
|
||||
private String sortName;
|
||||
private Object[] externalUrls;
|
||||
private MediaSource[] mediaSources;
|
||||
private JSONArray externalUrls;
|
||||
private List<MediaSource> mediaSources;
|
||||
private String path;
|
||||
private boolean enableMediaSourceDisplay;
|
||||
private Object channelID;
|
||||
private Object[] taglines;
|
||||
private Object[] genres;
|
||||
private JSONArray taglines;
|
||||
private JSONArray genres;
|
||||
private long runTimeTicks;
|
||||
private String playAccess;
|
||||
private long parentIndexNumber;
|
||||
private Object[] remoteTrailers;
|
||||
private JSONArray remoteTrailers;
|
||||
private JSONObject providerIDS;
|
||||
private boolean isHD;
|
||||
private boolean isFolder;
|
||||
private String parentID;
|
||||
private String type;
|
||||
private Object[] people;
|
||||
private Object[] studios;
|
||||
private Object[] genreItems;
|
||||
private List<People> people;
|
||||
private List<Studios> studios;
|
||||
private JSONArray genreItems;
|
||||
private String parentLogoItemID;
|
||||
private String parentBackdropItemID;
|
||||
private String[] parentBackdropImageTags;
|
||||
private JSONArray parentBackdropImageTags;
|
||||
private long localTrailerCount;
|
||||
private UserData userData;
|
||||
private String seriesName;
|
||||
@@ -47,22 +49,22 @@ public class EpisodeData {
|
||||
private String seasonID;
|
||||
private long specialFeatureCount;
|
||||
private String displayPreferencesID;
|
||||
private Object[] tags;
|
||||
private JSONArray tags;
|
||||
private double primaryImageAspectRatio;
|
||||
private String seriesPrimaryImageTag;
|
||||
private String seasonName;
|
||||
private MediaStream[] mediaStreams;
|
||||
private List<MediaStream> mediaStreams;
|
||||
private String videoType;
|
||||
private ImageTags imageTags;
|
||||
private Object[] backdropImageTags;
|
||||
private Object[] screenshotImageTags;
|
||||
private JSONArray backdropImageTags;
|
||||
private JSONArray screenshotImageTags;
|
||||
private String parentLogoImageTag;
|
||||
private ImageBlurHashes imageBlurHashes;
|
||||
private String seriesStudio;
|
||||
private Chapter[] chapters;
|
||||
private List<Chapter> chapters;
|
||||
private String locationType;
|
||||
private String mediaType;
|
||||
private Object[] lockedFields;
|
||||
private JSONArray lockedFields;
|
||||
private boolean lockData;
|
||||
private long width;
|
||||
private long height;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.yutou.nas.Datas.Jellyfin;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.nas.utils.AppTools;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ItemInfo {
|
||||
@@ -13,38 +16,38 @@ public class ItemInfo {
|
||||
private String etag;
|
||||
private String dateCreated;
|
||||
private String dateLastMediaAdded;
|
||||
private boolean canDelete;
|
||||
private boolean canDownload;
|
||||
private String sortName;
|
||||
private Object[] externalUrls;
|
||||
private String path;
|
||||
private boolean enableMediaSourceDisplay;
|
||||
private Object channelID;
|
||||
private Object[] taglines;
|
||||
private Object[] genres;
|
||||
private String playAccess;
|
||||
private Object[] remoteTrailers;
|
||||
private boolean isFolder;
|
||||
private String sortName;
|
||||
@JSONField(name = "ParentId")
|
||||
private String parentID;
|
||||
private String playAccess;
|
||||
private String type;
|
||||
private Object[] people;
|
||||
private Object[] studios;
|
||||
private Object[] genreItems;
|
||||
private String displayPreferencesID;
|
||||
private String locationType;
|
||||
private long localTrailerCount;
|
||||
private UserData userData;
|
||||
private long recursiveItemCount;
|
||||
private long childCount;
|
||||
private long specialFeatureCount;
|
||||
private String displayPreferencesID;
|
||||
private Object[] airDays;
|
||||
private Object[] tags;
|
||||
private double primaryImageAspectRatio;
|
||||
private ImageTags imageTags;
|
||||
private String[] backdropImageTags;
|
||||
private Object[] screenshotImageTags;
|
||||
private String locationType;
|
||||
private Object[] lockedFields;
|
||||
private boolean canDownload;
|
||||
private boolean canDelete;
|
||||
private boolean enableMediaSourceDisplay;
|
||||
private boolean isFolder;
|
||||
private boolean lockData;
|
||||
private double primaryImageAspectRatio;
|
||||
private Object channelID;
|
||||
|
||||
private Object[] externalUrls;
|
||||
private Object[] remoteTrailers;
|
||||
private Object[] genreItems;
|
||||
private Object[] airDays;
|
||||
private Object[] screenshotImageTags;
|
||||
private Object[] lockedFields;
|
||||
private List<Studios> studios;
|
||||
private List<People> people;
|
||||
private JSONArray backdropImageTags;
|
||||
private JSONArray genres;
|
||||
private JSONArray taglines;
|
||||
private JSONArray tags;
|
||||
|
||||
public String getPath() {
|
||||
if (AppTools.isRuntimeSystemOfWindow()) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.yutou.nas.Datas.Jellyfin;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
||||
11
src/main/java/com/yutou/nas/Datas/Jellyfin/People.java
Normal file
11
src/main/java/com/yutou/nas/Datas/Jellyfin/People.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.yutou.nas.Datas.Jellyfin;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class People {
|
||||
private String name;
|
||||
private String id;
|
||||
private String role;
|
||||
private String type;
|
||||
}
|
||||
9
src/main/java/com/yutou/nas/Datas/Jellyfin/Studios.java
Normal file
9
src/main/java/com/yutou/nas/Datas/Jellyfin/Studios.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.yutou.nas.Datas.Jellyfin;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Studios {
|
||||
private String id;
|
||||
private String name;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.yutou.nas.FileListener;
|
||||
|
||||
import com.yutou.nas.Services.IMusicToolsService;
|
||||
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
|
||||
import org.apache.commons.io.monitor.FileAlterationObserver;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FileListener extends FileAlterationListenerAdaptor {
|
||||
private IMusicToolsService musicToolsService;
|
||||
// 采用构造函数注入服务
|
||||
public FileListener( IMusicToolsService musicToolsService) {
|
||||
this.musicToolsService=musicToolsService;
|
||||
}
|
||||
|
||||
// 文件创建执行
|
||||
@Override
|
||||
public void onFileCreate(File file) {
|
||||
musicToolsService.addMusic(file);
|
||||
|
||||
}
|
||||
|
||||
// 文件创建修改
|
||||
@Override
|
||||
public void onFileChange(File file) {
|
||||
// 触发业务
|
||||
musicToolsService.addMusic(file);
|
||||
}
|
||||
|
||||
// 文件创建删除
|
||||
@Override
|
||||
public void onFileDelete(File file) {
|
||||
musicToolsService.delMusic(file);
|
||||
}
|
||||
|
||||
// 目录创建
|
||||
@Override
|
||||
public void onDirectoryCreate(File directory) {
|
||||
}
|
||||
|
||||
// 目录修改
|
||||
@Override
|
||||
public void onDirectoryChange(File directory) {
|
||||
}
|
||||
|
||||
// 目录删除
|
||||
@Override
|
||||
public void onDirectoryDelete(File directory) {
|
||||
}
|
||||
|
||||
|
||||
// 轮询开始
|
||||
@Override
|
||||
public void onStart(FileAlterationObserver observer) {
|
||||
super.onStart(observer);
|
||||
}
|
||||
|
||||
// 轮询结束
|
||||
@Override
|
||||
public void onStop(FileAlterationObserver observer) {
|
||||
super.onStop(observer);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.yutou.nas.FileListener;
|
||||
|
||||
import com.yutou.nas.Services.IMusicToolsService;
|
||||
import org.apache.commons.io.filefilter.FileFilterUtils;
|
||||
import org.apache.commons.io.filefilter.HiddenFileFilter;
|
||||
import org.apache.commons.io.filefilter.IOFileFilter;
|
||||
import org.apache.commons.io.monitor.FileAlterationMonitor;
|
||||
import org.apache.commons.io.monitor.FileAlterationObserver;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class FileListenerFactory {
|
||||
// 设置监听路径
|
||||
private final String monitorDir = "/media/yutou/disk_lvm/public/音乐";
|
||||
|
||||
// 设置轮询间隔
|
||||
private final long interval = TimeUnit.SECONDS.toMillis(1);
|
||||
|
||||
@Resource
|
||||
IMusicToolsService musicToolsService;
|
||||
|
||||
|
||||
public FileAlterationMonitor getMonitor() {
|
||||
// 创建过滤器
|
||||
IOFileFilter directories = FileFilterUtils.and(
|
||||
FileFilterUtils.directoryFileFilter(),
|
||||
HiddenFileFilter.VISIBLE);
|
||||
IOFileFilter files = FileFilterUtils.and(
|
||||
FileFilterUtils.fileFileFilter()
|
||||
);
|
||||
IOFileFilter filter = FileFilterUtils.or(directories, files);
|
||||
|
||||
// 装配过滤器
|
||||
// FileAlterationObserver observer = new FileAlterationObserver(new File(monitorDir));
|
||||
FileAlterationObserver observer = new FileAlterationObserver(new File(monitorDir), filter);
|
||||
|
||||
// 向监听者添加监听器,并注入业务服务
|
||||
observer.addListener(new FileListener(musicToolsService));
|
||||
|
||||
// 返回监听者
|
||||
return new FileAlterationMonitor(interval, observer);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.yutou.nas.FileListener;
|
||||
|
||||
import org.apache.commons.io.monitor.FileAlterationMonitor;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Component
|
||||
public class FileListenerRunner implements CommandLineRunner {
|
||||
@Resource
|
||||
private FileListenerFactory fileListenerFactory;
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
FileAlterationMonitor fileAlterationMonitor = fileListenerFactory.getMonitor();
|
||||
try {
|
||||
fileAlterationMonitor.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.yutou.nas;
|
||||
|
||||
import com.yutou.nas.Datas.AppData;
|
||||
import com.yutou.nas.utils.BTDownloadManager;
|
||||
import com.yutou.nas.utils.DmhyRssDownloadManager;
|
||||
import com.yutou.nas.utils.ConfigTools;
|
||||
import com.yutou.nas.utils.QQBotManager;
|
||||
import com.yutou.nas.utils.RedisTools;
|
||||
@@ -9,15 +9,16 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Import(BTDownloadManager.class)
|
||||
@Import(DmhyRssDownloadManager.class)
|
||||
@SpringBootApplication
|
||||
public class NasApplication {
|
||||
public static final String version="1.2.3";
|
||||
public static final String version = "1.2.17.7.1";
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(NasApplication.class, args);
|
||||
AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
||||
RedisTools.initRedisPoolSub();
|
||||
QQBotManager.getInstance();
|
||||
QQBotManager.getInstance().sendMessage("NasManager已上线:"+version);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,4 +6,6 @@ import java.util.List;
|
||||
|
||||
public interface IBangumiService {
|
||||
List<BangumiItem> getAllBangumi();
|
||||
|
||||
void download(int id,boolean isDownloadNext, String url);
|
||||
}
|
||||
|
||||
@@ -11,15 +11,17 @@ public interface IMusicToolsService {
|
||||
|
||||
void scanMusic();
|
||||
|
||||
List<MusicData> getPath(String path, boolean isDir);
|
||||
List<MusicData> getPath(String path, boolean isDir,boolean delPath);
|
||||
List<MusicData> getPath(String path, boolean isDir,boolean delPath,boolean filter);
|
||||
|
||||
MusicData getMusicData(String md5);
|
||||
MusicData getMusicDataOfMd5(String md5,boolean isDelFile);
|
||||
MusicData getMusicData(String path,boolean isDelFile);
|
||||
|
||||
List<MusicData> findOfTitle(String title);
|
||||
List<MusicData> findOfTitle(String title,boolean isDelFile);
|
||||
|
||||
List<MusicData> findOfArtist(String by);
|
||||
List<MusicData> findOfArtist(String by,boolean isDelFile);
|
||||
|
||||
List<MusicData> getMusicList();
|
||||
List<MusicData> getMusicList(boolean isDelFile);
|
||||
|
||||
int getLength();
|
||||
|
||||
@@ -29,6 +31,7 @@ public interface IMusicToolsService {
|
||||
|
||||
byte[] readImage(String path) throws Exception;
|
||||
|
||||
void addMusic(File file);
|
||||
void delMusic(File file);
|
||||
File getMusicOfMd5(String md5,boolean isDelFile);
|
||||
|
||||
File getMusicLrcMd5(String md5);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.yutou.nas.Services.IBangumiService;
|
||||
import com.yutou.nas.mybatis.dao.BangumiItemDao;
|
||||
import com.yutou.nas.mybatis.model.BangumiItem;
|
||||
import com.yutou.nas.mybatis.model.BangumiItemExample;
|
||||
import com.yutou.nas.utils.BTDownloadManager;
|
||||
import com.yutou.nas.utils.Log;
|
||||
import com.yutou.nas.utils.RedisTools;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -15,6 +18,20 @@ public class BangumiServiceImpl implements IBangumiService {
|
||||
BangumiItemDao itemDao;
|
||||
@Override
|
||||
public List<BangumiItem> getAllBangumi() {
|
||||
return itemDao.selectByExample(new BangumiItemExample());
|
||||
BangumiItemExample example=new BangumiItemExample();
|
||||
example.createCriteria().andEnableEqualTo(1);
|
||||
return itemDao.selectByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(int id,boolean isDownloadNext, String url) {
|
||||
BangumiItem item = itemDao.selectByPrimaryKey(id);
|
||||
if(item!=null){
|
||||
BTDownloadManager.download(item.getTitle(),url);
|
||||
if(!isDownloadNext){
|
||||
Log.i("跳过下载","确定跳过:"+item.getTitle()+"的下载,id = "+item.getId());
|
||||
RedisTools.set(item.getId()+"","next");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.yutou.nas.Services.impl;
|
||||
|
||||
import com.yutou.nas.Datas.AppData;
|
||||
import com.yutou.nas.Services.IMusicToolsService;
|
||||
import com.yutou.nas.mybatis.dao.MusicDataDao;
|
||||
import com.yutou.nas.mybatis.model.MusicData;
|
||||
import com.yutou.nas.mybatis.model.MusicDataExample;
|
||||
import com.yutou.nas.Services.IMusicToolsService;
|
||||
|
||||
import com.yutou.nas.utils.*;
|
||||
import ealvatag.audio.AudioFile;
|
||||
import ealvatag.audio.AudioFileIO;
|
||||
@@ -25,10 +24,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.text.Collator;
|
||||
import java.util.*;
|
||||
|
||||
@Service("MusicToolsService")
|
||||
public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
@@ -60,10 +57,11 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
new Thread(() -> {
|
||||
long startTime = System.currentTimeMillis();
|
||||
QQBotManager.getInstance().sendMessage("开始扫描音乐夹");
|
||||
musicDataDao.truncate();
|
||||
isScan = true;
|
||||
scan(new File(musicPath));
|
||||
isScan = false;
|
||||
com.yutou.nas.utils.Log.i("扫描完成");
|
||||
Log.i("扫描完成");
|
||||
QQBotManager.getInstance().sendMessage("音乐扫描完成,共" + getLength() + "首歌,耗时:"
|
||||
+ (System.currentTimeMillis() - startTime));
|
||||
}).start();
|
||||
@@ -71,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()) {
|
||||
@@ -90,7 +88,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
|
||||
public void getPathOrDir(String path, List<MusicData> list) {
|
||||
File files = new File(path);
|
||||
for (File file : files.listFiles()) {
|
||||
for (File file : Objects.requireNonNull(files.listFiles())) {
|
||||
if (file.isFile()) {
|
||||
list.add(getMetadata(file));
|
||||
} else {
|
||||
@@ -99,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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定目录下的音乐
|
||||
@@ -108,23 +110,27 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
* @return 音乐列表
|
||||
*/
|
||||
@Override
|
||||
public List<MusicData> getPath(String path, boolean isDir) {
|
||||
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 (isDir) {
|
||||
example.createCriteria().andFileLike(tmpPath.replace(File.separator, replacement) + "%");
|
||||
main = musicDataDao.selectByExample(example);
|
||||
main = musicDataDao.selectByExample(example, delPath);
|
||||
}else {
|
||||
tmpPath = tmpPath.replace(File.separator, replacement)
|
||||
.replace("+", "\\+")
|
||||
.replace("[", "\\[")
|
||||
.replace("(", "\\(")
|
||||
.replace(")", "\\)")
|
||||
.replace("]", "\\]");
|
||||
main = new ArrayList<>(musicDataDao.selectByRegexp(tmpPath + replacement + "([^" + replacement + "]+)$", delPath));
|
||||
}
|
||||
tmpPath = tmpPath.replace(File.separator, replacement)
|
||||
.replace("+", "\\+")
|
||||
.replace("[", "\\[")
|
||||
.replace("(", "\\(")
|
||||
.replace(")", "\\)")
|
||||
.replace("]", "\\]");
|
||||
main.addAll(musicDataDao.selectByRegexp(tmpPath + replacement + "([^" + replacement + "]+)$"));
|
||||
|
||||
if (!path.equals(AppData.defaultMusicPath) && !"root".equals(path)) {
|
||||
MusicData t2 = new MusicData();
|
||||
@@ -141,30 +147,42 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
}
|
||||
getDirList(path, list);
|
||||
list.addAll(main);
|
||||
|
||||
list.sort((o1, o2) -> {
|
||||
if ("返回".equals(o2.getTitle())) {
|
||||
return 1;
|
||||
}
|
||||
Comparator<Object> compare = Collator.getInstance(Locale.CHINA);
|
||||
return compare.compare(o1.getTitle(), o2.getTitle());
|
||||
});
|
||||
if (filter) {
|
||||
list.removeIf(data -> data.getTitle().toLowerCase().contains("instrumental"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<String> getAllAlbum() {
|
||||
|
||||
public List<MusicData> getAllAlbum() {
|
||||
return musicDataDao.selectAllAlbum();
|
||||
}
|
||||
|
||||
public List<String> getAllArtist() {
|
||||
public List<MusicData> getAllArtist() {
|
||||
return musicDataDao.selectAllArtist();
|
||||
}
|
||||
|
||||
public List<MusicData> selectAlbum(String album) {
|
||||
return musicDataDao.selectAlbum(album);
|
||||
public List<MusicData> selectAlbum(String album, boolean isDelFile) {
|
||||
return musicDataDao.selectAlbum(album, isDelFile);
|
||||
}
|
||||
|
||||
public List<MusicData> selectArtist(String artist) {
|
||||
return musicDataDao.selectArtist(artist);
|
||||
public List<MusicData> selectArtist(String artist, boolean isDelFile) {
|
||||
return musicDataDao.selectArtist(artist, isDelFile);
|
||||
}
|
||||
|
||||
private void getDirList(String path, List<MusicData> list) {
|
||||
File file = new File(path);
|
||||
com.yutou.nas.utils.Log.i("扫描文件:" + path);
|
||||
if (file.isDirectory()) {
|
||||
for (File listFile : file.listFiles()) {
|
||||
for (File listFile : Objects.requireNonNull(file.listFiles())) {
|
||||
if (listFile.isDirectory()) {
|
||||
MusicData data = new MusicData();
|
||||
data.setTitle(listFile.getName());
|
||||
@@ -183,30 +201,37 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
}
|
||||
|
||||
private void add(File file) {
|
||||
MusicDataExample example=new MusicDataExample();
|
||||
example.createCriteria().andFileEqualTo(file.getAbsolutePath());
|
||||
if(musicDataDao.selectByExample(example).isEmpty()) {
|
||||
MusicData data = getMetadata(file);
|
||||
if (data != null) {
|
||||
try {
|
||||
if (getMusicData(file.getAbsolutePath()) == null) {
|
||||
// System.out.println(data);
|
||||
musicDataDao.insert(data);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
QQBotManager.getInstance().sendMessage("音乐文件添加失败:" + data.toString());
|
||||
MusicData data = getMetadata(file);
|
||||
if (data != null) {
|
||||
try {
|
||||
if (getMusicData(file.getAbsolutePath(), false) == null) {
|
||||
// System.out.println(data);
|
||||
musicDataDao.insert(data);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
QQBotManager.getInstance().sendMessage("音乐文件添加失败:" + data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MusicData getMusicData(String path) {
|
||||
public MusicData getMusicData(String path, boolean delFile) {
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
example.createCriteria().andFileEqualTo(path);
|
||||
List<MusicData> list = musicDataDao.selectByExample(example);
|
||||
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);
|
||||
if (list != null && list.size() > 0) {
|
||||
return list.get(0);
|
||||
}
|
||||
@@ -226,6 +251,8 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
|| file.getName().endsWith(".dff")
|
||||
|| file.getName().endsWith(".cue")
|
||||
|| file.getName().endsWith(".m3u")
|
||||
|| file.getName().endsWith(".txt")
|
||||
|| file.getName().endsWith(".db")
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
@@ -235,27 +262,27 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
MusicData data = new MusicData();
|
||||
try {
|
||||
data.setAlbum(tag.getFirst(FieldKey.ALBUM));
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
data.setArtist(tag.getFirst(FieldKey.ARTIST));
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
data.setArtistSort(tag.getFirst(FieldKey.ARTIST_SORT));
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
data.setComment(tag.getFirst(FieldKey.COMMENT));
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
data.setComposer(tag.getFirst(FieldKey.COMPOSER));
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
data.setDiscNo(tag.getFirst(FieldKey.DISC_NO));
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
if (StringUtils.isEmpty(tag.getFirst(FieldKey.TITLE))) {
|
||||
@@ -268,11 +295,11 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
}
|
||||
try {
|
||||
data.setTrack(tag.getFirst(FieldKey.TRACK));
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
try {
|
||||
data.setYear(tag.getFirst(FieldKey.YEAR));
|
||||
} catch (Exception e) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
data.setFile(file.getAbsolutePath());
|
||||
data.setIsdir(file.isDirectory() ? 1 : 0);
|
||||
@@ -289,6 +316,9 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
data.setVariablebitrate(header.isVariableBitRate() ? 1 : 0);
|
||||
try {
|
||||
data.setMd5(header.getClass().getMethod("getMd5").invoke(header).toString());
|
||||
if(data.getMd5().startsWith("00000")&&data.getMd5().endsWith("00000")){
|
||||
throw new NullPointerException("md5 is null");
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
data.setMd5(Tools.getFileMD5(file));
|
||||
}
|
||||
@@ -362,6 +392,9 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
data.setVariablebitrate(header.isVariableBitRate() ? 1 : 0);
|
||||
try {
|
||||
data.setMd5(header.getClass().getMethod("getMd5").invoke(header).toString());
|
||||
if(data.getMd5().startsWith("00000")&&data.getMd5().endsWith("00000")){
|
||||
throw new NullPointerException("md5 is null");
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
data.setMd5(Tools.getFileMD5(file));
|
||||
}
|
||||
@@ -422,7 +455,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
data.setIsdir(file.isDirectory() ? 1 : 0);
|
||||
data.setLastdir(file.getParentFile().getParent());
|
||||
data.setMd5(Tools.getFileMD5(file));
|
||||
QQBotManager.getInstance().sendMessage("添加音乐文件失败:\n" + data.toString() + "\n" + Tools.getExceptionString(e));
|
||||
QQBotManager.getInstance().sendMessage("添加音乐文件失败:\n" + data + "\n" + Tools.getExceptionString(e));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -472,23 +505,23 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MusicData> findOfTitle(String title) {
|
||||
return find(title, FIND_TITLE);
|
||||
public List<MusicData> findOfTitle(String title, boolean delFile) {
|
||||
return find(title, FIND_TITLE, delFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MusicData> findOfArtist(String by) {
|
||||
return find(by, FIND_ARTIST);
|
||||
public List<MusicData> findOfArtist(String by, boolean delFile) {
|
||||
return find(by, FIND_ARTIST, delFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MusicData> getMusicList() {
|
||||
return musicDataDao.selectByExample(new MusicDataExample());
|
||||
public List<MusicData> getMusicList(boolean delFile) {
|
||||
return musicDataDao.selectByExample(new MusicDataExample(), delFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return musicDataDao.selectByExample(new MusicDataExample()).size();
|
||||
return musicDataDao.selectByExample(new MusicDataExample(), true).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -496,7 +529,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
return isScan;
|
||||
}
|
||||
|
||||
private List<MusicData> find(String title, int type) {
|
||||
private List<MusicData> find(String title, int type, boolean delFile) {
|
||||
List<MusicData> list;
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
if (type == FIND_TITLE) {
|
||||
@@ -504,7 +537,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
} else if (type == FIND_ARTIST) {
|
||||
example.createCriteria().andArtistEqualTo(title);
|
||||
}
|
||||
list = musicDataDao.selectByExample(example);
|
||||
list = musicDataDao.selectByExample(example, delFile);
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -521,7 +554,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
@Override
|
||||
public byte[] readImage(String path) throws Exception {
|
||||
File file = new File(path);
|
||||
AudioFile audioFile = null;
|
||||
AudioFile audioFile;
|
||||
audioFile = AudioFileIO.read(file);
|
||||
Tag tag = audioFile.getTag().or(NullTag.INSTANCE);
|
||||
byte[] bytes = tag.getFirstArtwork().or(NullArtwork.INSTANCE).getBinaryData();
|
||||
@@ -532,15 +565,33 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMusic(File file) {
|
||||
add(file);
|
||||
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()) {
|
||||
Log.i("Music File", list.get(0).toString());
|
||||
return new File(list.get(0).getFile());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delMusic(File file) {
|
||||
MusicDataExample example=new MusicDataExample();
|
||||
example.createCriteria().andFileEqualTo(file.getAbsolutePath());
|
||||
musicDataDao.deleteByExample(example);
|
||||
public File getMusicLrcMd5(String md5) {
|
||||
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");
|
||||
System.out.println("fileName = " + fileName);
|
||||
File file = new File(fileName);
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private byte[] readImageFile(File file) throws Exception {
|
||||
@@ -564,6 +615,8 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
file = new File("Z:\\音乐\\终将成为你\\[OP]君にふれて\\rise.flac");
|
||||
// file = new File("Z:\\音乐\\周董\\2012 十二新作\\03 公公偏头痛.ape");
|
||||
com.yutou.nas.utils.Log.i(new MusicToolsServiceImpl().getMetadataOfFFmpeg(file));
|
||||
|
||||
new MusicToolsServiceImpl().getMusicLrcMd5("84d3180883e6447c3b86bfc55b05608e");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.yutou.nas.Services.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.Services.IVideoToolsService;
|
||||
import com.yutou.nas.bangumi.BangumiTools;
|
||||
import com.yutou.nas.interfaces.ObjectInterface;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.yutou.nas.bangumi;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.mybatis.dao.BangumiItemDao;
|
||||
import com.yutou.nas.mybatis.dao.BangumiListDao;
|
||||
import com.yutou.nas.mybatis.model.BangumiItem;
|
||||
@@ -67,7 +68,7 @@ public class AnimationController {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
json.put("msg", "ok");
|
||||
json.put("data", JSONArray.toJSON(listDao.selectByExample(new BangumiListExample())));
|
||||
json.put("data", JSON.toJSON(listDao.selectByExample(new BangumiListExample())));
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@@ -107,7 +108,7 @@ public class AnimationController {
|
||||
example.createCriteria().andBidEqualTo(type);
|
||||
json.put("code", 0);
|
||||
json.put("msg", "ok");
|
||||
json.put("data", JSONArray.toJSON(itemDao.selectByExample(example)));
|
||||
json.put("data", JSON.toJSON(itemDao.selectByExample(example)));
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@@ -128,7 +129,7 @@ public class AnimationController {
|
||||
item.setCategories(animationData.nameToValue(item.getCategories(),false)+"");
|
||||
item.setAuthor(animationData.nameToValue(item.getAuthor(),true)+"");
|
||||
}
|
||||
JSONArray array= (JSONArray) JSONArray.toJSON(list);
|
||||
JSONArray array= (JSONArray) JSON.toJSON(list);
|
||||
return array.toJSONString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.yutou.nas.bangumi;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.utils.HttpTools;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
@@ -25,7 +26,7 @@ public class AnimationData {
|
||||
com.yutou.nas.utils.Log.i(String.format(animUrl, "" + index, title,type,team));
|
||||
com.yutou.nas.utils.Log.i(rss2jsonUrl + URLEncoder.encode(String.format(animUrl, "" + index, title,type,team), "UTF-8") +String.format( "&api_key=%s&count=500",rss2jsonApi_2));
|
||||
String js= HttpTools.get(rss2jsonUrl+ URLEncoder.encode(String.format(animUrl,""+index,title,type,team),"UTF-8")+String.format( "&api_key=%s&count=500",rss2jsonApi_2));
|
||||
JSONObject json=JSONObject.parseObject(js);
|
||||
JSONObject json= JSON.parseObject(js);
|
||||
if(json.getString("status").equals("ok")){
|
||||
return json.getJSONArray("items");
|
||||
}
|
||||
@@ -37,9 +38,9 @@ public class AnimationData {
|
||||
public int nameToValue(String name,boolean isTeam){
|
||||
JSONArray array;
|
||||
if(isTeam){
|
||||
array=JSONArray.parseArray(team);
|
||||
array=JSON.parseArray(team);
|
||||
}else{
|
||||
array=JSONArray.parseArray(type);
|
||||
array=JSON.parseArray(type);
|
||||
}
|
||||
for (Object o : array) {
|
||||
JSONObject json= (JSONObject) o;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.yutou.nas.bangumi;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.utils.*;
|
||||
|
||||
import java.text.ParseException;
|
||||
@@ -22,7 +23,7 @@ public class BangumiTools {
|
||||
*/
|
||||
public static JSONObject getBangumi(int day) {
|
||||
String str = HttpTools.get(toDayBangumi);
|
||||
JSONArray main = JSONArray.parseArray(str);
|
||||
JSONArray main = JSON.parseArray(str);
|
||||
if (day == -1) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("bangumi", main);
|
||||
@@ -57,7 +58,7 @@ public class BangumiTools {
|
||||
*/
|
||||
public static JSONObject getBangumiInfo(int id) {
|
||||
String str = HttpTools.get(String.format(BangumiInfo, id + ""));
|
||||
return JSONObject.parseObject(str);
|
||||
return JSON.parseObject(str);
|
||||
}
|
||||
|
||||
public static JSONArray getPeople(int id) {
|
||||
@@ -114,7 +115,7 @@ public class BangumiTools {
|
||||
*/
|
||||
public static JSONObject search(String key) {
|
||||
String str = HttpTools.get(String.format(SearchBangumi, key));
|
||||
return JSONObject.parseObject(str);
|
||||
return JSON.parseObject(str);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -376,31 +377,6 @@ public class BangumiTools {
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveInfoToJellyfin(String name) {
|
||||
JSONObject json = search(name);
|
||||
JSONArray array = json.getJSONArray("list");
|
||||
int id = 0;
|
||||
StringBuilder bangumiName = new StringBuilder();
|
||||
for (Object o : array) {
|
||||
JSONObject _item = (JSONObject) o;
|
||||
bangumiName.append(_item.getString("name_cn"))
|
||||
.append(":")
|
||||
.append(QQBotManager.QQCommands.QQ_BANGUMI_INFO)
|
||||
.append(_item.getString("id"))
|
||||
.append("\n");
|
||||
if (_item.getString("name_cn").equals(name)) {
|
||||
id = _item.getInteger("id");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (id == 0) {
|
||||
QQBotManager.getInstance().sendMessage("没有与《" + name + "》完全匹配的信息,请填写。 \n" + bangumiName.toString());
|
||||
return;
|
||||
}
|
||||
json = getBangumiInfo(id);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
/* JSONObject json = search("小林家的龙女仆S");
|
||||
System.out.println(json);
|
||||
|
||||
@@ -19,9 +19,9 @@ public interface MusicDataDao {
|
||||
|
||||
int insertSelective(MusicData record);
|
||||
|
||||
List<MusicData> selectByExample(MusicDataExample example);
|
||||
List<MusicData> selectByExample(@Param("example") MusicDataExample example,@Param("isDelFile") boolean isDelFile);
|
||||
|
||||
MusicData selectByPrimaryKey(Integer id);
|
||||
MusicData selectByPrimaryKey(@Param("id")Integer id,@Param("isDelFile")boolean isDelFile);
|
||||
|
||||
int updateByExampleSelective(@Param("record") MusicData record, @Param("example") MusicDataExample example);
|
||||
|
||||
@@ -32,10 +32,11 @@ public interface MusicDataDao {
|
||||
int updateByPrimaryKey(MusicData record);
|
||||
|
||||
void truncate();
|
||||
List<MusicData> selectByRegexp(String regexp);
|
||||
List<MusicData> selectByRegexp(@Param("regexp")String regexp,@Param("isDelFile")boolean isDelFile);
|
||||
|
||||
List<MusicData> selectAllAlbum();
|
||||
List<MusicData> selectAllArtist();
|
||||
List<MusicData> selectAlbum(@Param("album")String album,@Param("isDelFile")boolean isDelFile);
|
||||
List<MusicData> selectArtist(@Param("artist")String artist,@Param("isDelFile")boolean isDelFile);
|
||||
|
||||
List<String> selectAllAlbum();
|
||||
List<String> selectAllArtist();
|
||||
List<MusicData> selectAlbum(String album);
|
||||
List<MusicData> selectArtist(String artist);
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.yutou.nas.mybatis.model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.yutou.nas.utils.AppTools;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -113,5 +116,14 @@ public class MusicData implements Serializable {
|
||||
*/
|
||||
private String md5;
|
||||
|
||||
public String getFile() {
|
||||
if(AppTools.isRuntimeSystemOfWindow()){
|
||||
if (file != null) {
|
||||
file = file.replace("/media/yutou/disk_lvm/public/", "Z:\\").replace("/", File.separator);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
package com.yutou.nas.other;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.nas.utils.Log;
|
||||
import com.yutou.nas.utils.QQBotManager;
|
||||
import com.yutou.nas.utils.RedisTools;
|
||||
import com.yutou.nas.utils.Tools;
|
||||
import net.mamoe.mirai.event.events.GroupMessageEvent;
|
||||
import net.mamoe.mirai.message.data.At;
|
||||
import net.mamoe.mirai.message.data.Image;
|
||||
import net.mamoe.mirai.message.data.MessageChainBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class QQSetu {
|
||||
public static void printTodaySetu() {
|
||||
String redisKey=Tools.getToDayTime() + "_setu";
|
||||
com.yutou.nas.utils.Log.i("今日涩图 redisKey = " + redisKey);
|
||||
String js = RedisTools.get(redisKey, 1);
|
||||
if (js != null) {
|
||||
JSONObject json = JSONObject.parseObject(js);
|
||||
if(json.containsKey("isPrint")&&json.getBoolean("isPrint")){
|
||||
return;
|
||||
}
|
||||
Map<String,Float> groupAverage=new HashMap<>();
|
||||
Map<String,String> groupImage=new HashMap<>();
|
||||
JSONObject setu=null;
|
||||
for (String id : json.keySet()) {
|
||||
String group=json.getJSONObject(id).getJSONObject("info").getLong("group")+"";
|
||||
if(groupAverage.containsKey(group)){
|
||||
if(groupAverage.get(group)<=json.getJSONObject(id).getFloat("average")){
|
||||
groupAverage.put(group,json.getJSONObject(id).getFloat("average"));
|
||||
groupImage.put(group,id);
|
||||
}
|
||||
}else{
|
||||
groupAverage.put(group,json.getJSONObject(id).getFloat("average"));
|
||||
groupImage.put(group,id);
|
||||
}
|
||||
}
|
||||
for (String id : groupImage.keySet()) {
|
||||
setu=json.getJSONObject(groupImage.get(id));
|
||||
if(setu!=null){
|
||||
json.put("isPrint",true);
|
||||
RedisTools.set(1,redisKey,json.toJSONString());
|
||||
JSONObject info=setu.getJSONObject("info");
|
||||
JSONObject score=setu.getJSONObject("score");
|
||||
MessageChainBuilder builder = new MessageChainBuilder();
|
||||
builder.append(Image.fromId(info.getString("id")));
|
||||
builder.append("本日最佳涩图由").append(new At(info.getLong("sourQQ"))).append("提供\n");
|
||||
builder.append("获得分数 ").append(String.valueOf(setu.getFloat("average"))).append("\n");
|
||||
builder.append("共有 ").append(String.valueOf(score.getIntValue("userNumber"))).append(" 人参与投票");
|
||||
QQBotManager.getInstance().sendMessage(info.getLong("group"),builder);
|
||||
Log.i("今日涩图:"+builder.toString());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
Log.i("今日没有涩图");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSetu(Image image) {
|
||||
String url = Image.queryUrl(image);
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
int length = connection.getContentLength();
|
||||
connection.disconnect();
|
||||
if (length > 50000) {
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setuBuilder(Image image, GroupMessageEvent event) {
|
||||
if (!isSetu(image)) {
|
||||
return;
|
||||
}
|
||||
if (RedisTools.get(event.getGroup().getId()+"setu") != null) {
|
||||
printSetu(event.getGroup().getId());
|
||||
}
|
||||
setuScore.clear();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", image.getImageId());
|
||||
json.put("sourName", event.getSenderName());
|
||||
json.put("sourQQ", event.getSender().getId());
|
||||
json.put("group", event.getGroup().getId());
|
||||
RedisTools.set(event.getGroup().getId()+"setu", json.toJSONString(),6*60);
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
startTimer(event.getGroup().getId());
|
||||
}
|
||||
|
||||
private void startTimer(long group) {
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(!setuScore.isEmpty()){
|
||||
printSetu(group);
|
||||
}
|
||||
timer = null;
|
||||
}
|
||||
}, 5 * 60 * 1000);
|
||||
}
|
||||
|
||||
private void printSetu(long group) {
|
||||
JSONObject jt = JSONObject.parseObject(RedisTools.get(group+"setu"));
|
||||
String id = jt.getString("id");
|
||||
float average = 0;
|
||||
float max = 0;
|
||||
float min = 10;
|
||||
float length = 0;
|
||||
String maxName = "";
|
||||
String minName = "";
|
||||
if(setuScore.size()<=1){
|
||||
return;
|
||||
}
|
||||
for (String name : setuScore.keySet()) {
|
||||
length += setuScore.get(name);
|
||||
average += setuScore.get(name);
|
||||
if (setuScore.get(name) > max) {
|
||||
max = setuScore.get(name);
|
||||
maxName = name.split("\\|")[0];
|
||||
}
|
||||
if (setuScore.get(name) < min) {
|
||||
min = setuScore.get(name);
|
||||
minName = name.split("\\|")[0];
|
||||
}
|
||||
}
|
||||
JSONObject score = new JSONObject();
|
||||
score.put("max", max);
|
||||
score.put("min", min);
|
||||
score.put("sum", length);
|
||||
score.put("maxName", maxName);
|
||||
score.put("minName", minName);
|
||||
score.put("userNumber", setuScore.size());
|
||||
|
||||
average = average / setuScore.size();
|
||||
String builder = "涩图评分:" + average +"\n "+
|
||||
"其中最高分由:" + maxName + " 给与:" + max +"\n "+
|
||||
"其中最低分由:" + minName + " 给与:" + min;
|
||||
QQBotManager.getInstance().sendMessage(group, builder);
|
||||
String st = RedisTools.get(Tools.getToDayTime() + "_setu", 1);
|
||||
JSONObject json;
|
||||
if (st == null) {
|
||||
json = new JSONObject();
|
||||
} else {
|
||||
json = JSONObject.parseObject(st);
|
||||
}
|
||||
if (!json.containsKey(id)) {
|
||||
JSONObject item;
|
||||
if (json.containsKey("item")) {
|
||||
item = json.getJSONObject("item");
|
||||
} else {
|
||||
item = new JSONObject();
|
||||
}
|
||||
|
||||
item.put("score", score);
|
||||
item.put("info", jt);
|
||||
item.put("average", average);
|
||||
json.put(id, item);
|
||||
RedisTools.set(1, Tools.getToDayTime() + "_setu", json.toJSONString());
|
||||
}
|
||||
RedisTools.remove(group+"setu",0);
|
||||
setuScore.clear();
|
||||
}
|
||||
public void setu(String msg, GroupMessageEvent event) {
|
||||
if (msg.trim().equals("[图片]")) {
|
||||
Image image = (Image) event.getMessage().stream().filter(Image.class::isInstance).findFirst().orElse(null);
|
||||
if (image != null) {
|
||||
setuBuilder(image, event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if(msg.trim().length()>3){
|
||||
return;
|
||||
}
|
||||
float i = Float.parseFloat(msg.trim());
|
||||
if (i > 0 && i <= 10) {
|
||||
String name = event.getSenderName();
|
||||
String qq=event.getSender().getId()+"";
|
||||
if (!setuScore.containsKey(name)) {
|
||||
setuScore.put(name+"|"+qq, i);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private Timer timer;
|
||||
private static Map<String, Float> setuScore = new HashMap<>();
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.yutou.nas.other;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.NasApplication;
|
||||
import com.yutou.nas.Services.IVideoToolsService;
|
||||
import com.yutou.nas.utils.AppTools;
|
||||
@@ -79,7 +80,7 @@ public class tools {
|
||||
}
|
||||
if (request.getCookies() != null) {
|
||||
for (Cookie cookie : request.getCookies()) {
|
||||
JSONObject ck = JSONObject.parseObject(JSONObject.toJSONString(cookie));
|
||||
JSONObject ck = JSON.parseObject(JSON.toJSONString(cookie));
|
||||
cookies.add(ck);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +98,8 @@ public class tools {
|
||||
json.put("params", params);
|
||||
json.put("cookie", cookies);
|
||||
json.put("header", header);
|
||||
Tools.sendServer("打印请求", json.toJSONString());
|
||||
System.out.println("json = " + json);
|
||||
// Tools.sendServer("打印请求", json.toJSONString());
|
||||
try {
|
||||
switch (RedisTools.get("request")) {
|
||||
case "success":
|
||||
@@ -153,7 +155,7 @@ public class tools {
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/public/getUPSPower.do")
|
||||
public float getUPSPower(){
|
||||
public int getUPSPower(){
|
||||
return Tools.getSystemUPSPower();
|
||||
}
|
||||
|
||||
|
||||
35
src/main/java/com/yutou/nas/utils/AnimRssManager.java
Normal file
35
src/main/java/com/yutou/nas/utils/AnimRssManager.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.Controllers.UpdateIp;
|
||||
|
||||
public class AnimRssManager {
|
||||
public static void scan() {
|
||||
String tmp=HttpTools.https_get("https://tools.yutou233.cn/anim/rss/list.do?type=-1&token=zIrsh9TUZP2lfRW753PannG49E7VJvor",null);
|
||||
if(tmp==null){
|
||||
return;
|
||||
}
|
||||
JSONObject json= JSON.parseObject(tmp);
|
||||
if(json.getInteger("code")==0){
|
||||
JSONArray data=json.getJSONArray("data");
|
||||
for (Object datum : data) {
|
||||
String url= ((JSONObject) datum).getString("title");
|
||||
String title= ((JSONObject) datum).getString("titlekey");
|
||||
download(title,url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void download(String title,String url) {
|
||||
JSONObject rss=RssXMLtoJson.toJSON(url);
|
||||
if (rss != null && "ok".equals(rss.getString("status"))) {
|
||||
BTDownloadManager.download(title, rss);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
scan();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.yutou.nas.Services.impl.MusicToolsServiceImpl;
|
||||
import com.yutou.nas.other.QQSetu;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -37,7 +36,7 @@ public class ApplicationInit implements ApplicationRunner {
|
||||
if (time.equals(oldTime)) {
|
||||
return;
|
||||
}
|
||||
float power = Tools.getSystemUPSPower();
|
||||
/*float power = Tools.getSystemUPSPower();
|
||||
if (power > 0) {
|
||||
if (power == 100) {
|
||||
AppTools.exec("wakeonlan 00:F0:D2:D0:6B:B5", null, false, true);
|
||||
@@ -54,21 +53,14 @@ public class ApplicationInit implements ApplicationRunner {
|
||||
Log.i("UPS电池低于30%,即将关机");
|
||||
QQBotManager.getInstance().sendMessage("UPS电池低于30%,即将关机");
|
||||
}
|
||||
}
|
||||
}*/
|
||||
oldTime = time;
|
||||
switch (time) {
|
||||
case "00:00":
|
||||
// musicTools.scanMusic();
|
||||
//musicTools.scanMusic();
|
||||
break;
|
||||
case "01:00":
|
||||
DepotManager.scan();
|
||||
break;
|
||||
case "08:00":
|
||||
case "20:00":
|
||||
QQBotManager.getInstance().reportToDayBangumi();
|
||||
break;
|
||||
case "23:59":
|
||||
QQSetu.printTodaySetu();
|
||||
//DepotManager.scan();
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -97,7 +89,8 @@ public class ApplicationInit implements ApplicationRunner {
|
||||
case "21:00":
|
||||
case "22:00":
|
||||
case "23:00":
|
||||
BTDownloadManager.getInstance().start();
|
||||
DmhyRssDownloadManager.getInstance().start();
|
||||
AnimRssManager.scan();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("AppTimer", e);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.iflytek.cloud.speech.*;
|
||||
import com.yutou.nas.interfaces.ObjectInterface;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class AudioTools {
|
||||
private static boolean init = false;
|
||||
@@ -19,6 +22,7 @@ public class AudioTools {
|
||||
|
||||
public static void playText(String text) {
|
||||
SpeechSynthesizer mss = SpeechSynthesizer.createSynthesizer();
|
||||
|
||||
mss.startSpeaking(text, new SynthesizerListener() {
|
||||
@Override
|
||||
public void onBufferProgress(int progress, int beginPos, int endPos,
|
||||
@@ -26,6 +30,7 @@ public class AudioTools {
|
||||
if (progress == 100) {
|
||||
mss.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,9 +63,54 @@ public class AudioTools {
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void getAudio(String text, ObjectInterface objectInterface){
|
||||
SpeechSynthesizer mss = SpeechSynthesizer.createSynthesizer();
|
||||
mss.setParameter(SpeechConstant.VOICE_NAME, "xiaoyu");
|
||||
// 设置语速,范围0~100
|
||||
mss.setParameter(SpeechConstant.SPEED, "50");
|
||||
// 设置语调,范围0~100
|
||||
//mss.setParameter(SpeechConstant.PITCH, "50");
|
||||
// 设置音量,范围0~100
|
||||
mss.setParameter(SpeechConstant.VOLUME, "100");
|
||||
|
||||
String fileName="html" + File.separator + "audio" + File.separator + System.currentTimeMillis() + ".wav";
|
||||
mss.synthesizeToUri(
|
||||
text,
|
||||
fileName,
|
||||
new SynthesizeToUriListener() {
|
||||
@Override
|
||||
public void onBufferProgress(int progress) {
|
||||
System.out.println("progress = " + progress);
|
||||
if (progress == 100) {
|
||||
objectInterface.out(fileName);
|
||||
mss.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSynthesizeCompleted(String s, SpeechError speechError) {
|
||||
System.out.println("s = " + s);
|
||||
System.out.println("speechError = " + speechError.getErrorDesc());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int i, int i1, int i2, int i3, Object o, Object o1) {
|
||||
System.out.println("i = " + i + ", i1 = " + i1 + ", i2 = " + i2 + ", i3 = " + i3 + ", o = " + o + ", o1 = " + o1);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
init();
|
||||
playText("小爱同学,开灯");
|
||||
getAudio("警告!你已经进入监控范围,请立即离开!", new ObjectInterface() {
|
||||
@Override
|
||||
public void out(String data) {
|
||||
super.out(data);
|
||||
System.out.println(data);
|
||||
File file=new File(data);
|
||||
System.out.println(file.getAbsolutePath());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,7 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashSet;
|
||||
@@ -45,7 +46,7 @@ public class ConfigTools {
|
||||
String src = readFile(file);
|
||||
if (src != null) {
|
||||
try {
|
||||
JSONObject json = JSONObject.parseObject(src);
|
||||
JSONObject json = JSON.parseObject(src);
|
||||
return json.getObject(key, t);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
@@ -81,7 +82,7 @@ public class ConfigTools {
|
||||
if (src == null) {
|
||||
src = "{}";
|
||||
}
|
||||
JSONObject json = JSONObject.parseObject(src);
|
||||
JSONObject json = JSON.parseObject(src);
|
||||
json.put(key, data);
|
||||
saveFile(file, json.toJSONString());
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import com.yutou.nas.utils.StringUtils;
|
||||
|
||||
@@ -22,12 +23,12 @@ public class DepotManager {
|
||||
public void run() {
|
||||
String str = HttpTools.get("http://tools.yutou233.cn/nas/depot/list.do?token=" + HttpTools.serverKey);
|
||||
if (!StringUtils.isEmpty(str)) {
|
||||
JSONObject json = JSONObject.parseObject(str);
|
||||
JSONObject json = JSON.parseObject(str);
|
||||
if (json.getInteger("code") == 1) {
|
||||
JSONArray array = json.getJSONArray("data");
|
||||
for (Object o : array) {
|
||||
List<File> list = new ArrayList<>();
|
||||
JSONObject item = JSONObject.parseObject(o.toString());
|
||||
JSONObject item = JSON.parseObject(o.toString());
|
||||
scanFile(new File(item.getString("path")), new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.Services.IBangumiService;
|
||||
import com.yutou.nas.bangumi.AnimationData;
|
||||
import com.yutou.nas.mybatis.model.BangumiItem;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DmhyRssDownloadManager implements ApplicationContextAware {
|
||||
private static ApplicationContext applicationContext;
|
||||
@Resource
|
||||
IBangumiService bangumiService;
|
||||
private static DmhyRssDownloadManager manager;
|
||||
|
||||
|
||||
public static DmhyRssDownloadManager getInstance() {
|
||||
if (manager == null) {
|
||||
manager = new DmhyRssDownloadManager();
|
||||
if (manager.bangumiService == null) {
|
||||
manager.bangumiService = getBean(IBangumiService.class);
|
||||
}
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
private DmhyRssDownloadManager() {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
List<BangumiItem> list = bangumiService.getAllBangumi();
|
||||
AnimationData data = new AnimationData();
|
||||
Log.i("BT", "启动BT检测,总数:" + list.size());
|
||||
File path = new File(BTDownloadManager.DownloadHomePath);
|
||||
if (!path.exists()) {
|
||||
Log.i("BT", "下载目录已离线,取消扫描");
|
||||
return;
|
||||
}
|
||||
for (BangumiItem item : list) {
|
||||
if (item.getEnable() == 0) {
|
||||
continue;
|
||||
}
|
||||
JSONObject json = RssXMLtoJson.toJSON(getDmhyUrl(item));
|
||||
item.setAuthor(data.nameToValue(item.getAuthor(), true) + "");
|
||||
item.setCategories(data.nameToValue(item.getCategories(), false) + "");
|
||||
if (json != null) {
|
||||
String s = RedisTools.get(item.getId() + "");
|
||||
if ("next".equals(s)) {
|
||||
if(BTDownloadManager.skipDownload(item.getTitle(), json)) {
|
||||
RedisTools.remove(item.getId() + "");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
BTDownloadManager.download(item.getTitle(), json);
|
||||
} else {
|
||||
//QQBotManager.getInstance().sendMessage(item.getTitle() + "\n下载失败\n" + getDmhyUrl(item));
|
||||
Log.i(item.getTitle() + "\n下载失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getDmhyUrl(BangumiItem item) {
|
||||
String dmhyUrl = "https://share.dmhy.org/topics/rss/page/1/rss.xml?keyword=%s%s&order=date-desc";
|
||||
String sort_id=new AnimationData().nameToValue(item.getCategories(),false)+"";
|
||||
dmhyUrl = String.format(dmhyUrl,
|
||||
item.getTitlekey().replace(" ", "+"),
|
||||
"-1".equals(sort_id) ? "" : String.format("&sort_id=%s", sort_id)
|
||||
);
|
||||
return dmhyUrl;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(@NotNull ApplicationContext applicationContext) throws BeansException {
|
||||
if (DmhyRssDownloadManager.applicationContext == null) {
|
||||
DmhyRssDownloadManager.applicationContext = applicationContext;
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T getBean(Class<T> clazz) {
|
||||
return applicationContext.getBean(clazz);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import com.yutou.nas.utils.Interfaces.NetworkInterface;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
@@ -33,7 +31,7 @@ public class HttpTools {
|
||||
try {
|
||||
URLConnection connection;
|
||||
connection = new URL(url).openConnection();
|
||||
connection.setRequestProperty("User-Agent", getExtUa());
|
||||
connection.setRequestProperty("User-Agent", getUa());
|
||||
if (header != null) {
|
||||
for (String key : header.keySet()) {
|
||||
connection.addRequestProperty(key, header.get(key));
|
||||
@@ -66,9 +64,12 @@ public class HttpTools {
|
||||
connection.addRequestProperty(key, headers.get(key));
|
||||
}
|
||||
}
|
||||
if(body==null){
|
||||
body="".getBytes();
|
||||
}
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
connection.addRequestProperty("User-Agent", getExtUa());
|
||||
connection.addRequestProperty("User-Agent", getUa());
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(10 * 1000);
|
||||
//connection.addRequestProperty("Connection", "keep-alive");
|
||||
@@ -100,8 +101,8 @@ public class HttpTools {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getExtUa() {
|
||||
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36";
|
||||
public static String getUa() {
|
||||
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36";
|
||||
}
|
||||
|
||||
private static String getKuKuUA() {
|
||||
@@ -165,7 +166,7 @@ public class HttpTools {
|
||||
}
|
||||
Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName);
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.addRequestProperty("User-Agent", getExtUa());
|
||||
connection.addRequestProperty("User-Agent", getUa());
|
||||
// Log.i(TAG,"获取到网络请求:"+connection.getResponseCode());
|
||||
|
||||
|
||||
@@ -222,7 +223,7 @@ public class HttpTools {
|
||||
}
|
||||
Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName);
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.addRequestProperty("User-Agent", getExtUa());
|
||||
connection.addRequestProperty("User-Agent", getUa());
|
||||
// Log.i(TAG,"获取到网络请求:"+connection.getResponseCode());
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.Datas.Jellyfin.Episode;
|
||||
import com.yutou.nas.Datas.Jellyfin.EpisodeData;
|
||||
import com.yutou.nas.Datas.Jellyfin.ItemInfo;
|
||||
@@ -17,21 +18,24 @@ import java.util.*;
|
||||
|
||||
public class JellyfinAPIManager {
|
||||
private List<LibsItem> mediaItem = new ArrayList<>();
|
||||
private static String userId="389438aeda0a4972ac66a23cbe5c289c";
|
||||
private static String token="7f8efec6c950415cbaa8a0b54b3a832b";
|
||||
|
||||
public JellyfinAPIManager() {
|
||||
login();
|
||||
mediaItem = getAllItem();
|
||||
}
|
||||
|
||||
public LibsItem getLibs(String key) {
|
||||
HashMap<String, String> header = getHeader();
|
||||
String httpText = HttpTools.https_get("http://192.168.31.88:8096/Users/e8a13675bb64466dbd81f1e5985ef8c7/Items", header);
|
||||
JSONObject json = JSONObject.parseObject(httpText);
|
||||
String httpText = HttpTools.https_get("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Users/"+userId+"/Items", header);
|
||||
JSONObject json = JSON.parseObject(httpText);
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
JSONArray items = json.getJSONArray("Items");
|
||||
for (Object o : items) {
|
||||
LibsItem item = JSONObject.parseObject(o.toString(), LibsItem.class);
|
||||
LibsItem item = JSON.parseObject(o.toString(), LibsItem.class);
|
||||
if (item.getName().equals(key)) {
|
||||
return item;
|
||||
}
|
||||
@@ -40,16 +44,16 @@ public class JellyfinAPIManager {
|
||||
}
|
||||
|
||||
public ItemInfo getInfo(String id) {
|
||||
String http = HttpTools.https_get("http://192.168.31.88:8096/Users/e8a13675bb64466dbd81f1e5985ef8c7/Items/" + id, getHeader());
|
||||
return JSONObject.parseObject(http, ItemInfo.class);
|
||||
String http = HttpTools.https_get("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Users/"+userId+"/Items/" + id, getHeader());
|
||||
return JSON.parseObject(http).toJavaObject(ItemInfo.class);
|
||||
}
|
||||
|
||||
public List<LibsItem> getAllItem() {
|
||||
String http = HttpTools.https_get("http://192.168.31.88:8096/Users/e8a13675bb64466dbd81f1e5985ef8c7/Items?SortBy=SortName&SortOrder=Ascending&IncludeItemTypes=Series&Recursive=true&Fields=PrimaryImageAspectRatio%2CBasicSyncInfo&ImageTypeLimit=1&EnableImageTypes=Primary%2CBackdrop%2CBanner%2CThumb&ParentId=28e774baf8f2fd279e7d58da9890a7d2", getHeader());
|
||||
JSONObject json = JSONObject.parseObject(http);
|
||||
String http = HttpTools.https_get("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Users/"+userId+"/Items?SortBy=SortName&SortOrder=Ascending&IncludeItemTypes=Series&Recursive=true&Fields=PrimaryImageAspectRatio%2CBasicSyncInfo&ImageTypeLimit=1&EnableImageTypes=Primary%2CBackdrop%2CBanner%2CThumb&ParentId=28e774baf8f2fd279e7d58da9890a7d2", getHeader());
|
||||
JSONObject json = JSON.parseObject(http);
|
||||
|
||||
JSONArray items = json.getJSONArray("Items");
|
||||
List<LibsItem> list = JSONArray.parseArray(items.toJSONString(), LibsItem.class);
|
||||
List<LibsItem> list =items.toJavaList(LibsItem.class);
|
||||
for (LibsItem item : list) {
|
||||
item.setInfo(getInfo(item.getId()));
|
||||
}
|
||||
@@ -57,54 +61,58 @@ public class JellyfinAPIManager {
|
||||
}
|
||||
|
||||
public List<LibsItem> getLibsItems(String id) {
|
||||
String httpText = HttpTools.https_get("http://192.168.31.88:8096/Users/e8a13675bb64466dbd81f1e5985ef8c7/Items?ParentId=" + id, getHeader());
|
||||
JSONObject json = JSONObject.parseObject(httpText);
|
||||
String httpText = HttpTools.https_get("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Users/"+userId+"/Items?ParentId=" + id, getHeader());
|
||||
JSONObject json = JSON.parseObject(httpText);
|
||||
JSONArray items = json.getJSONArray("Items");
|
||||
return JSONArray.parseArray(items.toJSONString(), LibsItem.class);
|
||||
return items.toJavaList(LibsItem.class);
|
||||
}
|
||||
|
||||
public JSONObject getItemShows(String id) {
|
||||
String data = HttpTools.https_get(String.format("http://192.168.31.88:8096/Shows/%s/Seasons?userId=e8a13675bb64466dbd81f1e5985ef8c7",
|
||||
String data = HttpTools.https_get(String.format("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Shows/%s/Seasons?userId="+userId+"",
|
||||
id
|
||||
), getHeader());
|
||||
return JSONObject.parseObject(data);
|
||||
return JSON.parseObject(data);
|
||||
}
|
||||
public JSONObject getEpisodesForJson(String parentID,String id){
|
||||
String data = HttpTools.https_get(String.format("http://192.168.31.88:8096/Shows/%s/Episodes?seasonId=%s&userId=e8a13675bb64466dbd81f1e5985ef8c7",
|
||||
|
||||
public JSONObject getEpisodesForJson(String parentID, String id) {
|
||||
String data = HttpTools.https_get(String.format("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Shows/%s/Episodes?seasonId=%s&userId="+userId+"",
|
||||
parentID,
|
||||
id
|
||||
), getHeader());
|
||||
return JSONObject.parseObject(data);
|
||||
return JSON.parseObject(data);
|
||||
}
|
||||
public List<Episode> getEpisodes(String parentId,String id){
|
||||
JSONObject json=getEpisodesForJson(parentId, id);
|
||||
JSONArray episodes=json.getJSONArray("Items");
|
||||
return JSONArray.parseArray(episodes.toJSONString(), Episode.class);
|
||||
|
||||
public List<Episode> getEpisodes(String parentId, String id) {
|
||||
JSONObject json = getEpisodesForJson(parentId, id);
|
||||
JSONArray episodes = json.getJSONArray("Items");
|
||||
return episodes.toJavaList(Episode.class);
|
||||
}
|
||||
public JSONObject getEpisodesDataForJson(String id){
|
||||
String data = HttpTools.https_get(String.format("http://192.168.31.88:8096/Users/e8a13675bb64466dbd81f1e5985ef8c7/Items/%s",
|
||||
|
||||
public JSONObject getEpisodesDataForJson(String id) {
|
||||
String data = HttpTools.https_get(String.format("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Users/"+userId+"/Items/%s",
|
||||
id
|
||||
), getHeader());
|
||||
return JSONObject.parseObject(data);
|
||||
return JSON.parseObject(data);
|
||||
}
|
||||
public EpisodeData getEpisodeData(String id){
|
||||
return JSONObject.parseObject(getEpisodesDataForJson(id).toString(), EpisodeData.class);
|
||||
|
||||
public EpisodeData getEpisodeData(String id) {
|
||||
return getEpisodesDataForJson(id).toJavaObject(EpisodeData.class);
|
||||
}
|
||||
public String getPathForEpisode(String parentId,String id){
|
||||
List<Episode> list=getEpisodes(parentId, id);
|
||||
if(!list.isEmpty()){
|
||||
|
||||
public String getPathForEpisode(String parentId, String id) {
|
||||
List<Episode> list = getEpisodes(parentId, id);
|
||||
if (!list.isEmpty()) {
|
||||
return getEpisodeData(list.get(0).getId()).getPath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void uploadImage(File image, String id, String model) {
|
||||
try {
|
||||
HashMap<String, String> header = getHeader();
|
||||
header.put("Content-Type", "image/jpg");
|
||||
String url = String.format("http://192.168.31.88:8096/Items/%s/Images/%s",
|
||||
header.put("Content-Type", "image/jpeg");
|
||||
String url = String.format("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Items/%s/Images/%s",
|
||||
id,
|
||||
model
|
||||
);
|
||||
@@ -170,12 +178,10 @@ public class JellyfinAPIManager {
|
||||
metadata.put("Taglines", new JSONArray());
|
||||
HashMap<String, String> headers = getHeader();
|
||||
headers.put("Content-Type", "application/json");
|
||||
System.out.println(metadata.toString().replace("\"null\"", "null"));
|
||||
String ret = HttpTools.http_post("http://192.168.31.88:8096/Items/" + item.getId()
|
||||
String ret = HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Items/" + item.getId()
|
||||
, metadata.toString().replace("\"null\"", "null").getBytes(StandardCharsets.UTF_8)
|
||||
, 4
|
||||
, headers);
|
||||
System.out.println(ret);
|
||||
HttpTools.download(
|
||||
info.getJSONObject("images").getString("large").replace("http:", "https:"),
|
||||
item.getName() + "_poster.jpg",
|
||||
@@ -197,17 +203,11 @@ public class JellyfinAPIManager {
|
||||
|
||||
public HashMap<String, String> getHeader() {
|
||||
HashMap<String, String> header = new HashMap<>();
|
||||
header.put("X-Emby-Authorization", "MediaBrowser Client=\"Jellyfin CLI\", Device=\"Jellyfin-CLI\", DeviceId=\"None\", Version=\"10.7.6\", Token=\"81be0169523e463a8c36a7b752d60ab2\"");
|
||||
header.put("X-Emby-Authorization", "MediaBrowser Client=\"Jellyfin Web\", Device=\"Chrome\", DeviceId=\"TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzg2LjAuNDI0MC43NSBTYWZhcmkvNTM3LjM2fDE2MDI4NDYzMDc5NjE1\", Version=\"10.8.1\",Token=\""+token+"\"");
|
||||
return header;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void testItem(String id) {
|
||||
JellyfinAPIManager manager = new JellyfinAPIManager();
|
||||
LibsItem item = manager.getLibs("番剧");
|
||||
@@ -229,19 +229,19 @@ public class JellyfinAPIManager {
|
||||
System.out.println(_json.getString("Name"));
|
||||
|
||||
if (_json.getString("Name").equals("第一季")) {
|
||||
LibsItem _item = JSONObject.parseObject(_json.toJSONString(), LibsItem.class);
|
||||
LibsItem _item = JSON.parseObject(_json.toJSONString(), LibsItem.class);
|
||||
manager.saveJellyfinMetaData(
|
||||
BangumiTools.getBangumiInfo(1424),
|
||||
_item
|
||||
);
|
||||
} else if (_json.getString("Name").equals("第二季")) {
|
||||
LibsItem _item = JSONObject.parseObject(_json.toJSONString(), LibsItem.class);
|
||||
LibsItem _item = JSON.parseObject(_json.toJSONString(), LibsItem.class);
|
||||
manager.saveJellyfinMetaData(
|
||||
BangumiTools.getBangumiInfo(3774),
|
||||
_item
|
||||
);
|
||||
} else if (_json.getString("Name").contains("[剧场版]")) {
|
||||
LibsItem _item = JSONObject.parseObject(_json.toJSONString(), LibsItem.class);
|
||||
LibsItem _item = JSON.parseObject(_json.toJSONString(), LibsItem.class);
|
||||
manager.saveJellyfinMetaData(
|
||||
BangumiTools.getBangumiInfo(12426),
|
||||
_item
|
||||
@@ -257,97 +257,110 @@ public class JellyfinAPIManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void search(String name, File path) {
|
||||
public JSONArray getAnimPaths() {
|
||||
JSONArray array = new JSONArray();
|
||||
for (LibsItem item : mediaItem) {
|
||||
System.out.println(item.getName() + " > " + item.getInfo().getPath());
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("name", item.getInfo().getName());
|
||||
List<LibsItem> list = getLibsItems(item.getId());
|
||||
json.put("size",list.size());
|
||||
JSONArray _items = new JSONArray();
|
||||
if (list.size() > 1) {
|
||||
for (LibsItem libsItem : list) {
|
||||
JSONObject _item = new JSONObject();
|
||||
_item.put("name", libsItem.getName());
|
||||
_item.put("path", getInfo(libsItem.getId()).getPath());
|
||||
_items.add(_item);
|
||||
}
|
||||
json.put("path",_items);
|
||||
}
|
||||
json.put("root",item.getInfo().getPath());
|
||||
array.add(json);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
public void refresh(){
|
||||
String url="http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Items/28e774baf8f2fd279e7d58da9890a7d2/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&ReplaceAllMetadata=false";
|
||||
String tmp=HttpTools.http_post(url,null,1,getHeader());
|
||||
System.out.println(tmp);
|
||||
}
|
||||
|
||||
public void init(File path) {
|
||||
if (path.isDirectory()) {
|
||||
File file = new File(path.getAbsolutePath() + File.separator + "info.ini");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
System.out.println("创建:" + file.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
String id = ConfigTools.loadIni(file, "id");
|
||||
if (id != null) {
|
||||
for (LibsItem item : mediaItem) {
|
||||
/*if (item.getName().equals("你遭难了吗?")) {
|
||||
|
||||
// System.out.println(item.getName()+" "+item.getId());
|
||||
//System.out.println(getItemShows(item.getId()));
|
||||
List<LibsItem> _temp = getLibsItems(item.getId());
|
||||
System.out.println(item.getInfo().getPath() + " " + _temp.size());
|
||||
if (_temp.size() > 1) {
|
||||
for (LibsItem libsItem : _temp) {
|
||||
ItemInfo info = getInfo(libsItem.getId());
|
||||
if (info.getPath()==null){
|
||||
System.out.println(getPathForEpisode(info.getParentID(),info.getId())+" > "+path.getPath());
|
||||
//System.out.println(getPathForEpisode(info.getParentID(),info.getId()).contains(path.getPath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
break;
|
||||
|
||||
}*/
|
||||
List<LibsItem> _temp = getLibsItems(item.getId());
|
||||
if(_temp.size()==1){
|
||||
if (item.getInfo().getPath().contains(path.getPath())) {
|
||||
System.out.println(item.getName()+" "+id);
|
||||
new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)),item);
|
||||
public void init(File path,String id) {
|
||||
if (id != null) {
|
||||
for (LibsItem item : mediaItem) {
|
||||
List<LibsItem> _temp = getLibsItems(item.getId());
|
||||
if (_temp.size() == 1) {
|
||||
if (item.getInfo().getPath().contains(path.getPath())) {
|
||||
System.out.println(item.getName() + " " + id);
|
||||
new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)), item);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
System.out.println(item.getName() + " > " + _temp.size());
|
||||
for (LibsItem libsItem : _temp) {
|
||||
ItemInfo info = getInfo(libsItem.getId());
|
||||
if (info.getPath() != null) {
|
||||
if (info.getPath().contains(path.getPath())) {
|
||||
System.out.println("list > " + item.getName() + " " + id);
|
||||
new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)), libsItem);
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
System.out.println(item.getName()+" > "+_temp.size());
|
||||
for (LibsItem libsItem : _temp) {
|
||||
ItemInfo info = getInfo(libsItem.getId());
|
||||
if(info.getPath()!=null) {
|
||||
if (info.getPath().contains(path.getPath())) {
|
||||
System.out.println("list > " + item.getName() + " " + id);
|
||||
new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)), libsItem);
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
String ep_Path=getPathForEpisode(info.getParentID(),info.getId());
|
||||
if(ep_Path!=null&&ep_Path.contains(path.getPath())){
|
||||
System.out.println("list > " + item.getName() + " " + id);
|
||||
new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)), libsItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String ep_Path = getPathForEpisode(info.getParentID(), info.getId());
|
||||
if (ep_Path != null && ep_Path.contains(path.getPath())) {
|
||||
System.out.println("list > " + item.getName() + " " + id);
|
||||
new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)), libsItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* if (item.getInfo().getPath().contains(path.getPath())) {
|
||||
//System.out.println(item.getName()+" "+id);
|
||||
// new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)),item);
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
if (item.getInfo().getPath().contains(path.getPath())) {
|
||||
System.out.println(item.getName() + " " + id);
|
||||
new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)), item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (File file : path.listFiles()) {
|
||||
/*for (File file : path.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
// System.out.println("搜索目录:"+file.getAbsolutePath());
|
||||
init(file);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
public static String mainPath = "Z:\\download\\anim\\";
|
||||
|
||||
public void login(){
|
||||
String url="http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Users/authenticatebyname";
|
||||
HashMap<String, String> header=getHttpHeader();
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("Pw","34864394");
|
||||
json.put("Username","home");
|
||||
String post = HttpTools.http_post(url, json.toJSONString().getBytes(StandardCharsets.UTF_8), 3, header);
|
||||
json=JSONObject.parseObject(post,JSONObject.class);
|
||||
token=json.getString("AccessToken");
|
||||
userId=json.getJSONObject("User").getString("Id");
|
||||
}
|
||||
private HashMap<String, String> getHttpHeader(){
|
||||
HashMap<String, String> header = new HashMap<>();
|
||||
header.put("content-type", "application/json");
|
||||
header.put("accept", "application/json");
|
||||
header.put("Connection", "keep-alive");
|
||||
header.put("User-Agent", HttpTools.getUa());
|
||||
header.put("Origin", "http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096");
|
||||
header.put("X-Emby-Authorization", "MediaBrowser Client=\"Jellyfin Web\", Device=\"Chrome\", DeviceId=\"TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzg2LjAuNDI0MC43NSBTYWZhcmkvNTM3LjM2fDE2MDI4NDYzMDc5NjE1\", Version=\"10.8.1\"");
|
||||
return header;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
File file = new File("Z:\\download\\anim\\");
|
||||
File file = new File("Z:\\download\\anim\\神渣☆偶像");
|
||||
//new JellyfinAPIManager().search(file.getName(), file);
|
||||
JellyfinAPIManager manager=new JellyfinAPIManager();
|
||||
manager.init(file);
|
||||
JellyfinAPIManager manager = new JellyfinAPIManager();
|
||||
manager.init(file,"359985");
|
||||
// JSONArray search = manager.getAnimPaths();
|
||||
// System.out.println(search);
|
||||
}
|
||||
}
|
||||
|
||||
24
src/main/java/com/yutou/nas/utils/PatternTools.java
Normal file
24
src/main/java/com/yutou/nas/utils/PatternTools.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PatternTools {
|
||||
private static String exec(String regex,String input){
|
||||
Pattern pattern=Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
if(matcher.find()){
|
||||
return matcher.group();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String getMagnetHash(String magnetLink){
|
||||
System.out.println("magnetLink = " + magnetLink);
|
||||
String ret=exec(".(?<=btih:).*(?=&dn)", magnetLink);
|
||||
if(ret==null){
|
||||
ret=exec(".(?<=btih:).*(?=&dn)",magnetLink);
|
||||
}
|
||||
return Objects.requireNonNull(ret).substring(1);
|
||||
}
|
||||
}
|
||||
@@ -1,380 +1,67 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.yutou.nas.NasApplication;
|
||||
import com.yutou.nas.bangumi.BangumiTools;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import com.yutou.nas.other.QQAudio;
|
||||
import com.yutou.nas.other.QQSetu;
|
||||
import net.mamoe.mirai.Bot;
|
||||
import net.mamoe.mirai.BotFactory;
|
||||
import net.mamoe.mirai.event.GlobalEventChannel;
|
||||
import net.mamoe.mirai.event.events.GroupMessageEvent;
|
||||
import net.mamoe.mirai.message.data.Image;
|
||||
import net.mamoe.mirai.message.data.MessageChainBuilder;
|
||||
import net.mamoe.mirai.utils.BotConfiguration;
|
||||
import net.mamoe.mirai.utils.ExternalResource;
|
||||
import com.yutou.nas.utils.StringUtils;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class QQBotManager {
|
||||
|
||||
|
||||
public static class QQCommands {
|
||||
private final static String QQ_HELP = "!help";
|
||||
private final static String QQ_SYSTEM_RESTART = "!restart";
|
||||
private final static String QQ_UPDATE_IP = "!更新ip";
|
||||
private final static String QQ_GET_IP = "!ip";
|
||||
private final static String QQ_OPEN_PC = "!开机";
|
||||
private final static String QQ_GET_VERSION = "!version";
|
||||
private final static String QQ_CMD = "!cmd";
|
||||
private final static String QQ_BANGUMI_TODAY = "!今日动画";
|
||||
private final static String QQ_BANGUMI_LIST = "!新番";
|
||||
private final static String QQ_BANGUMI_SUB = "!查动画";
|
||||
private final static String QQ_AUDIO = "!语音";
|
||||
private final static String QQ_AUDIO_OPEN_LAMP = "!开灯";
|
||||
private final static String QQ_AUDIO_OPEN_AIR = "!开空调";
|
||||
private final static String QQ_BT_RELOAD = "!刷bt";
|
||||
private final static String QQ_TOOLS_IDEA = "!idea";
|
||||
private final static String QQ_TOOLS_IDEA_FILE = "!idea>";
|
||||
private final static String QQ_TOOLS_IDEA_URL = "!idea_url";
|
||||
|
||||
public final static String QQ_BANGUMI_INFO="!保存动画信息>";
|
||||
}
|
||||
|
||||
private static QQBotManager botManager = null;
|
||||
private Bot bot;
|
||||
private static final long qqGroup = 891655174L;
|
||||
private boolean isLogin = false;
|
||||
private static boolean isInit = false;
|
||||
|
||||
|
||||
private QQBotManager() {
|
||||
Object isRun = ConfigTools.load(ConfigTools.CONFIG, "qq_bot");
|
||||
if (isRun != null && (boolean) isRun) {
|
||||
isLogin = true;
|
||||
isInit = true;
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long qq = 2476945931L;
|
||||
String password = "zhang34864394";
|
||||
if ("dev".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) {
|
||||
qq = 3620756944L;
|
||||
password = "UAs6YBYMyxJU";
|
||||
}
|
||||
|
||||
bot = BotFactory.INSTANCE.newBot(qq, password, new BotConfiguration() {
|
||||
{
|
||||
setProtocol(MiraiProtocol.ANDROID_PAD);
|
||||
fileBasedDeviceInfo("qq_bot_devices_info.json");
|
||||
if ("nas".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) {
|
||||
noBotLog();
|
||||
noNetworkLog();
|
||||
}
|
||||
}
|
||||
});
|
||||
//Events.registerEvents(bot, new MessageListener());
|
||||
GlobalEventChannel.INSTANCE.subscribeAlways(GroupMessageEvent.class, new MessageListener());
|
||||
bot.login();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String str = sendMessage("姬妻酱上线拉~☆Daze~ 当前版本:"+NasApplication.version);
|
||||
com.yutou.nas.utils.Log.i(str);
|
||||
|
||||
}
|
||||
}).start();
|
||||
bot.join();
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
public static QQBotManager getInstance() {
|
||||
if (botManager == null && !isInit) {
|
||||
if (botManager == null) {
|
||||
botManager = new QQBotManager();
|
||||
}
|
||||
return botManager;
|
||||
}
|
||||
|
||||
public boolean isLogin() {
|
||||
return isLogin;
|
||||
}
|
||||
|
||||
private Image getImage(File file) {
|
||||
if (bot != null) {
|
||||
return Objects.requireNonNull(bot.getGroup(qqGroup)).uploadImage(ExternalResource.create(file));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getNotLoginQQ() {
|
||||
return "没有登录QQ";
|
||||
}
|
||||
|
||||
public void reportToDayBangumi() {
|
||||
getInstance().sendMessage(BangumiTools.reportToDayBangumi());
|
||||
}
|
||||
|
||||
public String sendMessage(String text) {
|
||||
if (bot != null&&!StringUtils.isEmpty(text)) {
|
||||
try {
|
||||
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(text).toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return getNotLoginQQ();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("qq", 891655174);
|
||||
json.put("message",text);
|
||||
Map<String, String> header = new HashMap<>();
|
||||
header.put("content-type", "application/json");
|
||||
return HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":802/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||
}
|
||||
|
||||
public String sendMessage(Long group, String text) {
|
||||
if (bot != null) {
|
||||
try {
|
||||
return Objects.requireNonNull(bot.getGroup(group)).sendMessage(text).toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return getNotLoginQQ();
|
||||
public String sendMessage(long qq,String text) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("qq", qq);
|
||||
json.put("message",text);
|
||||
Map<String, String> header = new HashMap<>();
|
||||
header.put("content-type", "application/json");
|
||||
return HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":802/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||
}
|
||||
|
||||
public void sendMessage(Long group, MessageChainBuilder builder) {
|
||||
if (bot != null) {
|
||||
Objects.requireNonNull(bot.getGroup(group)).sendMessage(builder.asMessageChain());
|
||||
}
|
||||
public String sendMessage(String imageUrl, String message) {
|
||||
return sendMessage(891655174,imageUrl,message);
|
||||
}
|
||||
public String sendMessage(long qq,String imageUrl, String message) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("qq", qq);
|
||||
json.put("message",message);
|
||||
json.put("image", imageUrl);
|
||||
Map<String, String> header = new HashMap<>();
|
||||
header.put("content-type", "application/json");
|
||||
return HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":802/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||
}
|
||||
|
||||
|
||||
public String sendMessage(File imageFile, String text) {
|
||||
try {
|
||||
if (bot != null) {
|
||||
Image image = getImage(imageFile);
|
||||
MessageChainBuilder builder = new MessageChainBuilder();
|
||||
if (image != null) {
|
||||
builder.append(image);
|
||||
}
|
||||
builder.append(text);
|
||||
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(builder.asMessageChain()).toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return getNotLoginQQ();
|
||||
}
|
||||
|
||||
public String sendMessage(List<File> imgs, String text) {
|
||||
if (bot != null) {
|
||||
MessageChainBuilder builder = new MessageChainBuilder();
|
||||
for (File img : imgs) {
|
||||
builder.append(Objects.requireNonNull(getImage(img)));
|
||||
}
|
||||
builder.append(text);
|
||||
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(builder.asMessageChain()).toString();
|
||||
}
|
||||
return getNotLoginQQ();
|
||||
}
|
||||
|
||||
public static List<String> getImages(String str) {
|
||||
List<String> list = new ArrayList<>();
|
||||
String regex = "<img(.*?)/img>";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
while (matcher.find()) {
|
||||
list.add(matcher.group().replace("<img", "")
|
||||
.replace("/img>", "")
|
||||
.trim());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
getInstance();
|
||||
}
|
||||
|
||||
private static class MessageListener implements Consumer<GroupMessageEvent> {
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(GroupMessageEvent event) {
|
||||
String msg = event.getMessage().contentToString();
|
||||
switch (event.getGroup().getId() + "") {
|
||||
case qqGroup + "":
|
||||
myGroup(msg);
|
||||
case "570197155":
|
||||
new QQSetu().setu(msg, event);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void myGroup(String msg) {
|
||||
StringBuilder builder;
|
||||
String msgSrc=msg;
|
||||
msg = msg.replace("!", "!").toLowerCase();
|
||||
Log.i("QQBot","command = "+msg);
|
||||
switch (msg) {
|
||||
case QQCommands.QQ_OPEN_PC:
|
||||
RedisTools.Consumer.system("openPC", null);
|
||||
String time = new SimpleDateFormat("HH").format(new Date());
|
||||
if (Integer.parseInt(time) < 18) {
|
||||
break;
|
||||
}
|
||||
case QQCommands.QQ_AUDIO_OPEN_LAMP:
|
||||
QQAudio.playText("小爱同学,开灯");
|
||||
break;
|
||||
case QQCommands.QQ_AUDIO_OPEN_AIR:
|
||||
QQAudio.playText("小爱同学,开空调");
|
||||
break;
|
||||
case QQCommands.QQ_UPDATE_IP:
|
||||
RedisTools.Consumer.system("updateIP", null);
|
||||
break;
|
||||
case QQCommands.QQ_GET_IP:
|
||||
RedisTools.Consumer.bot("getip");
|
||||
break;
|
||||
case QQCommands.QQ_GET_VERSION:
|
||||
sendVersion();
|
||||
break;
|
||||
case QQCommands.QQ_BANGUMI_TODAY:
|
||||
RedisTools.remove("reportToDayBangumi");
|
||||
QQBotManager.getInstance().sendMessage(BangumiTools.reportToDayBangumi());
|
||||
break;
|
||||
case QQCommands.QQ_BANGUMI_LIST:
|
||||
getInstance().sendMessage("获取中...");
|
||||
getInstance().sendMessage(BangumiTools.reportBangumiList());
|
||||
break;
|
||||
case QQCommands.QQ_BT_RELOAD:
|
||||
BTDownloadManager.getInstance().start();
|
||||
break;
|
||||
case QQCommands.QQ_SYSTEM_RESTART:
|
||||
getInstance().sendMessage("正在重启服务");
|
||||
System.out.println("结束进程");
|
||||
AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh",null,true,false);
|
||||
break;
|
||||
case QQCommands.QQ_HELP:
|
||||
builder = new StringBuilder();
|
||||
for (Field field : QQCommands.class.getDeclaredFields()) {
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
builder.append(field.get(null)).append("\n");
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
getInstance().sendMessage(builder.toString());
|
||||
break;
|
||||
case QQCommands.QQ_TOOLS_IDEA:
|
||||
builder = new StringBuilder();
|
||||
if(StringUtils.isEmpty(RedisTools.get("ideaUrl"))){
|
||||
builder.append("暂未设置IDEA激活码下载地址");
|
||||
}else {
|
||||
for (String name : IdeaTools.getIdeaList(RedisTools.get("ideaUrl"))) {
|
||||
builder.append(QQCommands.QQ_TOOLS_IDEA_FILE).append(name).append("\n");
|
||||
}
|
||||
if(builder.toString().trim().length()==0){
|
||||
builder.append("激活码文件中未包含txt文件");
|
||||
}
|
||||
}
|
||||
getInstance().sendMessage(builder.toString());
|
||||
break;
|
||||
default:
|
||||
if (msg.startsWith(QQCommands.QQ_CMD)) {
|
||||
RedisTools.Consumer.system("cmd", msg.replace(QQCommands.QQ_CMD, ""));
|
||||
} else if (msg.startsWith(QQCommands.QQ_BANGUMI_SUB)) {
|
||||
List<String> infos = null;
|
||||
try {
|
||||
int id = Integer.parseInt(msg.replace(QQCommands.QQ_BANGUMI_SUB, "").trim());
|
||||
infos = BangumiTools.reportBangumiInfo(id);
|
||||
} catch (Exception e) {
|
||||
String key = msg.replace(QQCommands.QQ_BANGUMI_SUB, "").trim();
|
||||
infos = BangumiTools.reportSearchBangumi(key);
|
||||
}
|
||||
for (String info : infos) {
|
||||
List<String> imgs = new ArrayList<>();
|
||||
if (info.contains("<img") && info.contains(" /img>")) {
|
||||
imgs = getImages(info);
|
||||
for (String img : imgs) {
|
||||
info = info.replace("<img " + img + " /img>", "");
|
||||
}
|
||||
}
|
||||
sendImagesMsg(imgs, info);
|
||||
}
|
||||
|
||||
} else if (msg.startsWith(QQCommands.QQ_AUDIO)) {
|
||||
QQAudio.playText(msg.replace(QQCommands.QQ_AUDIO, ""));
|
||||
}else if(msg.startsWith(QQCommands.QQ_TOOLS_IDEA_FILE)){
|
||||
getInstance().sendMessage(IdeaTools.getIdea(msgSrc.replace(QQCommands.QQ_TOOLS_IDEA_FILE,"")));
|
||||
}else if(msg.startsWith(QQCommands.QQ_TOOLS_IDEA_URL)){
|
||||
RedisTools.set("ideaUrl",msg.replace(QQCommands.QQ_TOOLS_IDEA_URL,"").trim());
|
||||
getInstance().sendMessage("已设定下载地址:"+RedisTools.get("ideaUrl"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<File> files;
|
||||
private int index = 0;
|
||||
|
||||
private void sendImagesMsg(List<String> imgs, String text) {
|
||||
files = new ArrayList<>();
|
||||
index = 0;
|
||||
if (imgs.size() == 0) {
|
||||
getInstance().sendMessage(text);
|
||||
return;
|
||||
}
|
||||
for (String img : imgs) {
|
||||
Tools.download(img, new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
super.onDownload(file);
|
||||
files.add(file);
|
||||
send(imgs.size(), text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
super.onError(e);
|
||||
index++;
|
||||
send(imgs.size(), text);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void send(int size, String text) {
|
||||
if ((files.size() + index) == size) {
|
||||
String str = getInstance().sendMessage(files, text);
|
||||
com.yutou.nas.utils.Log.i("str = " + str);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendVersion() {
|
||||
String localVersion = NasApplication.version;
|
||||
String serverVersion = HttpTools.get("http://tools.yutou233.cn:8000/public/version.do?token=zIrsh9TUZP2lfRW753PannG49E7VJvor");
|
||||
String msg = "本地版本:" + localVersion + "\n" + "服务器版本:" + serverVersion;
|
||||
QQBotManager.getInstance().sendMessage(msg);
|
||||
Tools.sendServer("服务版本查询", msg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import com.yutou.nas.interfaces.ObjectInterface;
|
||||
import redis.clients.jedis.Jedis;
|
||||
@@ -12,6 +13,8 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -149,6 +152,68 @@ public class RedisTools {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static long list_add(String listName, String... value) {
|
||||
Jedis jedis = getRedis();
|
||||
long index = jedis.sadd(listName, value);
|
||||
jedis.close();
|
||||
return index;
|
||||
}
|
||||
|
||||
public static Set<String> list_get(String listName) {
|
||||
Jedis jedis = getRedis();
|
||||
Set<String> set = jedis.smembers(listName);
|
||||
jedis.close();
|
||||
if (set == null) {
|
||||
set = new HashSet<>();
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public static boolean list_remove(String listName, String... value) {
|
||||
Jedis jedis = getRedis();
|
||||
long index = jedis.srem(listName, value);
|
||||
jedis.close();
|
||||
return index != 0;
|
||||
}
|
||||
|
||||
public static boolean list_isExist(String listName, String value) {
|
||||
Jedis jedis = getRedis();
|
||||
boolean flag = jedis.sismember(listName, value);
|
||||
jedis.close();
|
||||
return flag;
|
||||
}
|
||||
|
||||
public static String getHashMap(String hashKey, String key) {
|
||||
Jedis jedis = getRedis();
|
||||
return jedis.hget(hashKey, key);
|
||||
}
|
||||
|
||||
public static Map<String, String> getHashMap(String hashKey) {
|
||||
return getRedis().hgetAll(hashKey);
|
||||
}
|
||||
|
||||
public static boolean setHashMap(String hashKey, String key, String value) {
|
||||
Jedis jedis = getRedis();
|
||||
long l = jedis.hset(hashKey, key, value);
|
||||
jedis.close();
|
||||
return l == 0;
|
||||
}
|
||||
|
||||
public static boolean removeHashMap(String hashKey, String key) {
|
||||
Jedis jedis = getRedis();
|
||||
long l = jedis.hdel(hashKey, key);
|
||||
jedis.close();
|
||||
return l > 0;
|
||||
}
|
||||
|
||||
public static boolean removeHashMap(String hashKey) {
|
||||
Jedis jedis = getRedis();
|
||||
long del = jedis.del(hashKey);
|
||||
return del > 0;
|
||||
|
||||
}
|
||||
|
||||
private static class PropertyUtil {
|
||||
|
||||
// 加载property文件到io流里面
|
||||
@@ -270,7 +335,7 @@ public class RedisTools {
|
||||
public static void bot(String value) {
|
||||
switch (value) {
|
||||
case "getip":
|
||||
JSONObject json = JSONObject.parseObject(HttpTools.get("https://api.asilu.com/ip/"));
|
||||
JSONObject json = JSON.parseObject(HttpTools.get("https://api.asilu.com/ip/"));
|
||||
String ip = json.getString("ip");
|
||||
QQBotManager.getInstance().sendMessage("服务器IP:\n" + ip);
|
||||
break;
|
||||
|
||||
23
src/main/java/com/yutou/nas/utils/RssXMLtoJson.java
Normal file
23
src/main/java/com/yutou/nas/utils/RssXMLtoJson.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class RssXMLtoJson {
|
||||
public static JSONObject toJSON(String xmlUrl){
|
||||
String url = "https://api.rss2json.com/v1/api.json?rss_url=%s&api_key=wtfm5pebya13pnl8rtu51wfgfpte0mb9sap1foll&count=500";
|
||||
try {
|
||||
String ret = HttpTools.get(String.format(url, URLEncoder.encode(xmlUrl, "UTF-8")));
|
||||
if(ret!=null){
|
||||
return JSON.parseObject(ret, JSONObject.class);
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,15 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
public class StringUtils {
|
||||
public static boolean isEmpty(String str){
|
||||
public static boolean isEmpty(String str) {
|
||||
return str == null || str.trim().length() == 0;
|
||||
}
|
||||
|
||||
public static String toLowerCaseFirstOne(String s) {
|
||||
if (Character.isLowerCase(s.charAt(0))) {
|
||||
return s;
|
||||
} else {
|
||||
return Character.toLowerCase(s.charAt(0)) + s.substring(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.yutou.nas.Controllers.UpdateIp;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import com.yutou.nas.interfaces.ObjectInterface;
|
||||
@@ -25,12 +26,13 @@ import java.security.MessageDigest;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Tools {
|
||||
private static float UPSPower=-1.0f;
|
||||
private static int UPSPower=-1;
|
||||
/**
|
||||
* 设置Cookie
|
||||
*
|
||||
@@ -111,23 +113,8 @@ public class Tools {
|
||||
if (img == null) {
|
||||
QQBotManager.getInstance().sendMessage(title + "\n" + msg);
|
||||
} else {
|
||||
String finalMsg = msg;
|
||||
String finalImg = img;
|
||||
if (QQBotManager.getInstance().isLogin()) {
|
||||
download(img, new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
super.onDownload(file);
|
||||
QQBotManager.getInstance().sendMessage(file, title + "\n" + finalMsg);
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(img, title + "\n" + msg);
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
super.onError(e);
|
||||
QQBotManager.getInstance().sendMessage(title + "\n" + finalMsg + "\n" + finalImg);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (!StringUtils.isEmpty(UpdateIp.nas_ip)) {
|
||||
String img = null;
|
||||
@@ -221,7 +208,7 @@ public class Tools {
|
||||
public static int checkWebLogin(HttpServletRequest request) {
|
||||
JSONArray array = new JSONArray();
|
||||
if (RedisTools.get("bean") != null) {
|
||||
array = JSONArray.parseArray(RedisTools.get("bean"));
|
||||
array = JSON.parseArray(RedisTools.get("bean"));
|
||||
}
|
||||
if (array.contains(Tools.getRemoteAddress(request))) {
|
||||
com.yutou.nas.utils.Log.i("IP已被封禁");
|
||||
@@ -264,7 +251,7 @@ public class Tools {
|
||||
file.transferTo(saveFile);
|
||||
fileName = URLEncoder.encode(fileName, "UTF-8");
|
||||
com.yutou.nas.utils.Log.i("上传文件保存路径:" + saveFile.getAbsolutePath());
|
||||
return path + fileName;
|
||||
return path+"/"+ fileName;
|
||||
}
|
||||
|
||||
public static void download(String url, DownloadInterface downloadInterface) {
|
||||
@@ -301,6 +288,9 @@ public class Tools {
|
||||
* @return 前端获取的文件
|
||||
*/
|
||||
public static ResponseEntity<FileSystemResource> getFile(File file) {
|
||||
if(file==null){
|
||||
return null;
|
||||
}
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
try {
|
||||
@@ -393,7 +383,7 @@ public class Tools {
|
||||
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
}
|
||||
|
||||
public static float getSystemUPSPower(){
|
||||
public static int getSystemUPSPower(){
|
||||
AppTools.exec("/sbin/apcaccess |grep BCHARGE ", new ObjectInterface() {
|
||||
@Override
|
||||
public void out(String data) {
|
||||
@@ -402,10 +392,28 @@ public class Tools {
|
||||
Matcher matcher=pattern.matcher(data);
|
||||
if(matcher.find()) {
|
||||
String ups = matcher.group();
|
||||
UPSPower=Float.parseFloat(ups);
|
||||
UPSPower= (int) Float.parseFloat(ups);
|
||||
}
|
||||
}
|
||||
},false,true);
|
||||
return UPSPower;
|
||||
}
|
||||
|
||||
public static void delDir(String path){
|
||||
File file = new File(path);
|
||||
if(file.exists()){
|
||||
for (File listFile : Objects.requireNonNull(file.listFiles())) {
|
||||
if(listFile.isFile()){
|
||||
listFile.delete();
|
||||
}else{
|
||||
if(Objects.requireNonNull(listFile.listFiles()).length > 0){
|
||||
delDir(listFile.getAbsolutePath());
|
||||
}else{
|
||||
listFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
src/main/resources/application.properties.debug
Normal file
12
src/main/resources/application.properties.debug
Normal file
@@ -0,0 +1,12 @@
|
||||
server.port=8000
|
||||
spring.datasource.url=jdbc:mysql://127.0.0.1/databases?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&userAffectedRows=true
|
||||
spring.datasource.username=user
|
||||
spring.datasource.password=password
|
||||
mybatis.mapper-locations=classpath:mappers/*.xml
|
||||
#mybatis.config-location=classpath:mybatis-config.xml
|
||||
mybatis.type-aliases-package=com.yutou.nas.mybatis
|
||||
#<23><>ӡmybatis<69><73>־
|
||||
#logging.level.com.yutou.nas=debug
|
||||
|
||||
#oss
|
||||
log4j.logger.com.aliyun.oss=OFF
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,24 +1,17 @@
|
||||
package com.yutou.nas;
|
||||
|
||||
import com.yutou.nas.Services.IVideoToolsService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
|
||||
@SpringBootTest
|
||||
class NasApplicationTests {
|
||||
|
||||
@Resource
|
||||
IVideoToolsService toolsService;
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
@Test
|
||||
void testOutSub(){
|
||||
toolsService.scanVideo();
|
||||
// toolsService.outSubtitle(0,"0:2",new File("Z:\\download\\anim\\小林家的龙女仆S\\[NC-Raws] 小林家的龙女仆S - 01 [B-Global][WEB-DL][2160p][AVC AAC][CHS_CHT_ENG_TH_SRT][MKV].mkv"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user