Compare commits
52 Commits
584779cc13
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| a07e9f2a33 | |||
| af963f0af8 | |||
| 88527c5716 | |||
| dcb56e8873 | |||
| a366e15765 | |||
| 25bee81d05 | |||
| 16c0f9816d | |||
| 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 |
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
|
||||
35
pom.xml
35
pom.xml
@@ -60,14 +60,14 @@
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>4.2.2</version>
|
||||
<version>4.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<version>2.0.17</version>
|
||||
</dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
@@ -120,17 +120,40 @@
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.14.1</version>
|
||||
<version>3.15.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.drewnoakes</groupId>
|
||||
<artifactId>metadata-extractor</artifactId>
|
||||
<version>2.17.0</version>
|
||||
<version>2.18.0</version>
|
||||
</dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.acgist</groupId>
|
||||
<artifactId>snail</artifactId>
|
||||
<version>1.17.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>2.1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.12.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.squareup.retrofit2/retrofit -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.retrofit2</groupId>
|
||||
<artifactId>retrofit</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -179,8 +202,8 @@
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
<compilerArguments>
|
||||
<extdirs>${basedir}/libs</extdirs>
|
||||
</compilerArguments>
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
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 com.yutou.nas.utils.*;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Controller
|
||||
public class BTDownloadController {
|
||||
@@ -18,23 +21,59 @@ public class BTDownloadController {
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/bt/down.do")
|
||||
public String bt(){
|
||||
public String bt() {
|
||||
DmhyRssDownloadManager.getInstance().start();
|
||||
AnimRssManager.scan();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/bt/done.do")
|
||||
public String done(String id,String name){
|
||||
Log.i("BTDownloadController.done","id = " + id + ", name = " + name);
|
||||
BTDownloadManager.done(id,name);
|
||||
public String done(String path, String filename, String hash1, String hash2, String tid) {
|
||||
//BTDownloadManager.done(path, filename, hash1, hash2, tid);
|
||||
try {
|
||||
String exec = ConfigTools.load(ConfigTools.CONFIG, "tiny.exec", String.class);
|
||||
Process process = Runtime.getRuntime().exec(new String[]{"sh"
|
||||
, "-c"
|
||||
, exec});
|
||||
process.waitFor(120, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
Log.e("下崽器", e);
|
||||
}
|
||||
|
||||
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);
|
||||
public String download(int id, boolean isDownloadNext, String url) {
|
||||
Log.i("跳过下载", "手动下载 id = " + id + ", isDownloadNext = " + isDownloadNext + ", url = " + url);
|
||||
bangumiService.download(id, isDownloadNext, url);
|
||||
return "1";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/qq/bt/download.do")
|
||||
public String download(HttpServletRequest request) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
String title = null;
|
||||
String url = null;
|
||||
try {
|
||||
BufferedInputStream stream = new BufferedInputStream(request.getInputStream());
|
||||
byte[] bytes = new byte[1024];
|
||||
int len = 0, size;
|
||||
while ((len = stream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, len);
|
||||
outputStream.flush();
|
||||
}
|
||||
String str = outputStream.toString();
|
||||
JSONObject json = JSONObject.parseObject(str);
|
||||
title = json.getString("title");
|
||||
url = json.getString("url");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.i("QQ下载", "手动下载 title = " + title + ", url = " + url);
|
||||
return "" + BTDownloadManager.download(title, url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -31,7 +32,7 @@ public class DoorController {
|
||||
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://192.168.31.88:803/apk/door/"+ Objects.requireNonNull(file.listFiles())[0].getName());
|
||||
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");
|
||||
@@ -57,7 +58,7 @@ public class DoorController {
|
||||
System.out.println("收到音频");
|
||||
try {
|
||||
String path=Tools.createFile("audio",audio,System.currentTimeMillis()+".mp3");
|
||||
RedisTools.set("door_audio","http://192.168.31.88:801/"+path);
|
||||
RedisTools.set("door_audio","http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":801/"+path);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.yutou.nas.Controllers;
|
||||
|
||||
import com.yutou.nas.utils.AppTools;
|
||||
import com.yutou.nas.utils.QQBotManager;
|
||||
import com.yutou.nas.utils.StringUtils;
|
||||
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")
|
||||
@@ -15,6 +16,7 @@ public class JellyfinController {
|
||||
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";
|
||||
}
|
||||
@@ -23,6 +25,64 @@ public class JellyfinController {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,20 +47,21 @@ public class MusicController {
|
||||
public String getMusicListOfPath(@RequestBody JSONObject body) {
|
||||
String path = body.getString("path");
|
||||
boolean type = body.containsKey("type") ? body.getBoolean("type") : false;
|
||||
boolean filter = body.containsKey("filter") ? body.getBoolean("filter") : false;
|
||||
if (StringUtils.isEmpty(path)
|
||||
|| "root".equals(path)
|
||||
|| !path.contains(defaultMusicPath)
|
||||
) {
|
||||
path = defaultMusicPath;
|
||||
}
|
||||
com.yutou.nas.utils.Log.i("接收到地址:" + path);
|
||||
com.yutou.nas.utils.Log.i("接收到地址:" + body);
|
||||
|
||||
//path=path.replace(defaultMusicPath+File.separator,"");
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
json.put("scan", musicTools.isScan());
|
||||
json.put("size", musicTools.getLength());
|
||||
json.put("data", JSON.toJSON(musicTools.getPath(path, type, true)));
|
||||
json.put("data", JSON.toJSON(musicTools.getPath(path, type, true, filter)));
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
@@ -162,8 +163,15 @@ public class MusicController {
|
||||
|
||||
@RequestMapping("/nas/music/random.do")
|
||||
@ResponseBody
|
||||
public String random() {
|
||||
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);
|
||||
@@ -189,8 +197,9 @@ public class MusicController {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/nas/music/lrc.do")
|
||||
public ResponseEntity<FileSystemResource> lrc(String filePath){
|
||||
public ResponseEntity<FileSystemResource> lrc(String filePath) {
|
||||
return Tools.getFile(musicTools.getMusicLrcMd5(filePath));
|
||||
}
|
||||
|
||||
@@ -235,8 +244,8 @@ public class MusicController {
|
||||
array.add(musicTools.getMusicData(file.getAbsolutePath(), true));
|
||||
} else {
|
||||
for (File listFile : Objects.requireNonNull(file.listFiles())) {
|
||||
MusicData data=musicTools.getMusicData(listFile.getAbsolutePath(), true);
|
||||
if(data!=null) {
|
||||
MusicData data = musicTools.getMusicData(listFile.getAbsolutePath(), true);
|
||||
if (data != null) {
|
||||
array.add(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yutou.nas;
|
||||
|
||||
import com.yutou.nas.Datas.AppData;
|
||||
import com.yutou.nas.okhttp.HttpLoggingInterceptor;
|
||||
import com.yutou.nas.utils.DmhyRssDownloadManager;
|
||||
import com.yutou.nas.utils.ConfigTools;
|
||||
import com.yutou.nas.utils.QQBotManager;
|
||||
@@ -12,13 +13,16 @@ import org.springframework.context.annotation.Import;
|
||||
@Import(DmhyRssDownloadManager.class)
|
||||
@SpringBootApplication
|
||||
public class NasApplication {
|
||||
public static final String version = "1.2.17.1";
|
||||
public static final String version = "1.4.3";
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(NasApplication.class, args);
|
||||
AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
||||
RedisTools.initRedisPoolSub();
|
||||
QQBotManager.getInstance().sendMessage("NasManager已上线:"+version);
|
||||
QQBotManager.getInstance().sendMessage("NasManager已上线:" + version);
|
||||
if (ConfigTools.load(ConfigTools.CONFIG, "okhttp.log", boolean.class)) {
|
||||
HttpLoggingInterceptor.setLog(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ public interface IMusicToolsService {
|
||||
void scanMusic();
|
||||
|
||||
List<MusicData> getPath(String path, boolean isDir,boolean delPath);
|
||||
List<MusicData> getPath(String path, boolean isDir,boolean delPath,boolean filter);
|
||||
|
||||
MusicData getMusicDataOfMd5(String md5,boolean isDelFile);
|
||||
MusicData getMusicData(String path,boolean isDelFile);
|
||||
|
||||
@@ -69,8 +69,8 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
|
||||
|
||||
private void scan(File path) {
|
||||
if(!path.exists()){
|
||||
Log.i("MusicScan","文件夹不存在,取消扫描");
|
||||
if (!path.exists()) {
|
||||
Log.i("MusicScan", "文件夹不存在,取消扫描");
|
||||
return;
|
||||
}
|
||||
if (path.isFile()) {
|
||||
@@ -97,6 +97,10 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MusicData> getPath(String path, boolean isDir, boolean delPath) {
|
||||
return getPath(path, isDir, delPath, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定目录下的音乐
|
||||
@@ -106,26 +110,27 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
* @return 音乐列表
|
||||
*/
|
||||
@Override
|
||||
public List<MusicData> getPath(String path, boolean isDir,boolean delPath) {
|
||||
public List<MusicData> getPath(String path, boolean isDir, boolean delPath, boolean filter) {
|
||||
List<MusicData> list = new ArrayList<>();
|
||||
List<MusicData> main = new ArrayList<>();
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
String replacement = "windows".equals(ConfigTools.load(ConfigTools.CONFIG, "os")) ? "\\\\" : "/";
|
||||
String tmpPath = path;
|
||||
if(StringUtils.isEmpty(path)){
|
||||
tmpPath=AppData.defaultMusicPath;
|
||||
if (StringUtils.isEmpty(path)) {
|
||||
tmpPath = AppData.defaultMusicPath;
|
||||
}
|
||||
if (isDir) {
|
||||
example.createCriteria().andFileLike(tmpPath.replace(File.separator, replacement) + "%");
|
||||
main = musicDataDao.selectByExample(example,delPath);
|
||||
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 + "]+)$",delPath));
|
||||
|
||||
if (!path.equals(AppData.defaultMusicPath) && !"root".equals(path)) {
|
||||
MusicData t2 = new MusicData();
|
||||
@@ -144,18 +149,19 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
list.addAll(main);
|
||||
|
||||
list.sort((o1, o2) -> {
|
||||
if("返回".equals(o2.getTitle())){
|
||||
if ("返回".equals(o2.getTitle())) {
|
||||
return 1;
|
||||
}
|
||||
Comparator<Object> compare = Collator.getInstance(Locale.CHINA);
|
||||
return compare.compare(o1.getTitle(),o2.getTitle());
|
||||
return compare.compare(o1.getTitle(), o2.getTitle());
|
||||
});
|
||||
|
||||
if (filter) {
|
||||
list.removeIf(data -> data.getTitle().toLowerCase().contains("instrumental"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<MusicData> getAllAlbum() {
|
||||
return musicDataDao.selectAllAlbum();
|
||||
}
|
||||
@@ -164,12 +170,12 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
return musicDataDao.selectAllArtist();
|
||||
}
|
||||
|
||||
public List<MusicData> selectAlbum(String album,boolean isDelFile) {
|
||||
return musicDataDao.selectAlbum(album,isDelFile);
|
||||
public List<MusicData> selectAlbum(String album, boolean isDelFile) {
|
||||
return musicDataDao.selectAlbum(album, isDelFile);
|
||||
}
|
||||
|
||||
public List<MusicData> selectArtist(String artist,boolean isDelFile) {
|
||||
return musicDataDao.selectArtist(artist,isDelFile);
|
||||
public List<MusicData> selectArtist(String artist, boolean isDelFile) {
|
||||
return musicDataDao.selectArtist(artist, isDelFile);
|
||||
}
|
||||
|
||||
private void getDirList(String path, List<MusicData> list) {
|
||||
@@ -198,7 +204,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
MusicData data = getMetadata(file);
|
||||
if (data != null) {
|
||||
try {
|
||||
if (getMusicData(file.getAbsolutePath(),false) == null) {
|
||||
if (getMusicData(file.getAbsolutePath(), false) == null) {
|
||||
// System.out.println(data);
|
||||
musicDataDao.insert(data);
|
||||
}
|
||||
@@ -211,20 +217,21 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MusicData getMusicData(String path,boolean delFile) {
|
||||
public MusicData getMusicData(String path, boolean delFile) {
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
example.createCriteria().andFileEqualTo(path);
|
||||
List<MusicData> list = musicDataDao.selectByExample(example,delFile);
|
||||
List<MusicData> list = musicDataDao.selectByExample(example, delFile);
|
||||
if (list != null && list.size() > 0) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MusicData getMusicDataOfMd5(String md5, boolean isDelFile) {
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
example.createCriteria().andMd5EqualTo(md5);
|
||||
List<MusicData> list = musicDataDao.selectByExample(example,isDelFile);
|
||||
List<MusicData> list = musicDataDao.selectByExample(example, isDelFile);
|
||||
if (list != null && list.size() > 0) {
|
||||
return list.get(0);
|
||||
}
|
||||
@@ -244,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;
|
||||
}
|
||||
@@ -307,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));
|
||||
}
|
||||
@@ -380,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));
|
||||
}
|
||||
@@ -490,23 +505,23 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MusicData> findOfTitle(String title,boolean delFile) {
|
||||
return find(title, FIND_TITLE,delFile);
|
||||
public List<MusicData> findOfTitle(String title, boolean delFile) {
|
||||
return find(title, FIND_TITLE, delFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MusicData> findOfArtist(String by,boolean delFile) {
|
||||
return find(by, FIND_ARTIST,delFile);
|
||||
public List<MusicData> findOfArtist(String by, boolean delFile) {
|
||||
return find(by, FIND_ARTIST, delFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MusicData> getMusicList(boolean delFile) {
|
||||
return musicDataDao.selectByExample(new MusicDataExample(),delFile);
|
||||
return musicDataDao.selectByExample(new MusicDataExample(), delFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return musicDataDao.selectByExample(new MusicDataExample(),true).size();
|
||||
return musicDataDao.selectByExample(new MusicDataExample(), true).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -514,7 +529,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
return isScan;
|
||||
}
|
||||
|
||||
private List<MusicData> find(String title, int type,boolean delFile) {
|
||||
private List<MusicData> find(String title, int type, boolean delFile) {
|
||||
List<MusicData> list;
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
if (type == FIND_TITLE) {
|
||||
@@ -522,7 +537,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
} else if (type == FIND_ARTIST) {
|
||||
example.createCriteria().andArtistEqualTo(title);
|
||||
}
|
||||
list = musicDataDao.selectByExample(example,delFile);
|
||||
list = musicDataDao.selectByExample(example, delFile);
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -550,12 +565,12 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getMusicOfMd5(String md5,boolean delFile) {
|
||||
MusicDataExample example=new MusicDataExample();
|
||||
public File getMusicOfMd5(String md5, boolean delFile) {
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
example.createCriteria().andMd5EqualTo(md5);
|
||||
List<MusicData> list=musicDataDao.selectByExample(example,delFile);
|
||||
Log.i("Music Size",list.size());
|
||||
if(!list.isEmpty()){
|
||||
List<MusicData> list = musicDataDao.selectByExample(example, delFile);
|
||||
Log.i("Music Size", list.size());
|
||||
if (!list.isEmpty()) {
|
||||
Log.i("Music File", list.get(0).toString());
|
||||
return new File(list.get(0).getFile());
|
||||
}
|
||||
@@ -564,15 +579,15 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
||||
|
||||
@Override
|
||||
public File getMusicLrcMd5(String md5) {
|
||||
MusicDataExample example=new MusicDataExample();
|
||||
MusicDataExample example = new MusicDataExample();
|
||||
example.createCriteria().andMd5EqualTo(md5);
|
||||
List<MusicData> list=musicDataDao.selectByExample(example,false);
|
||||
if(!list.isEmpty()){
|
||||
String fileName=list.get(0).getFile();
|
||||
fileName=fileName.replace(fileName.substring(fileName.lastIndexOf(".")),".lrc");
|
||||
List<MusicData> list = musicDataDao.selectByExample(example, false);
|
||||
if (!list.isEmpty()) {
|
||||
String fileName = list.get(0).getFile();
|
||||
fileName = fileName.replace(fileName.substring(fileName.lastIndexOf(".")), ".lrc");
|
||||
System.out.println("fileName = " + fileName);
|
||||
File file=new File(fileName);
|
||||
if(file.exists()){
|
||||
File file = new File(fileName);
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
6
src/main/java/com/yutou/nas/okhttp/BaseBean.java
Normal file
6
src/main/java/com/yutou/nas/okhttp/BaseBean.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.yutou.nas.okhttp;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BaseBean implements Serializable {
|
||||
}
|
||||
25
src/main/java/com/yutou/nas/okhttp/GetRequestParams.java
Normal file
25
src/main/java/com/yutou/nas/okhttp/GetRequestParams.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.yutou.nas.okhttp;
|
||||
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GetRequestParams implements IRequestParam {
|
||||
/**
|
||||
* 构建Request
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Request getRequest(HashMap<String, String> map, Request request) {
|
||||
//添加公共参数
|
||||
HttpUrl.Builder builder = request.url().newBuilder();
|
||||
for (String key : map.keySet()) {
|
||||
builder.addQueryParameter(key, String.valueOf(map.get(key)));
|
||||
}
|
||||
return request.newBuilder().url(builder.build()).build();
|
||||
}
|
||||
}
|
||||
14
src/main/java/com/yutou/nas/okhttp/HttpBody.java
Normal file
14
src/main/java/com/yutou/nas/okhttp/HttpBody.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.yutou.nas.okhttp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HttpBody<T> {
|
||||
private String msg;
|
||||
private String status;
|
||||
private int code;
|
||||
private int retcode;
|
||||
private T data;
|
||||
private String src;
|
||||
|
||||
}
|
||||
33
src/main/java/com/yutou/nas/okhttp/HttpCallback.java
Normal file
33
src/main/java/com/yutou/nas/okhttp/HttpCallback.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.yutou.nas.okhttp;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public abstract class HttpCallback<T> implements Callback<HttpBody<T>> {
|
||||
|
||||
public abstract void onResponse(Headers headers,int code, String status, T response, String rawResponse);
|
||||
|
||||
public abstract void onFailure(Throwable throwable);
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<HttpBody<T>> call, Response<HttpBody<T>> response) {
|
||||
if (response.body() != null) {
|
||||
onResponse(
|
||||
response.headers(),
|
||||
response.body().getRetcode(),
|
||||
response.body().getStatus(),
|
||||
response.body().getData(),
|
||||
response.body().getSrc()
|
||||
);
|
||||
} else {
|
||||
onFailure(new NullPointerException("response body is null"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<HttpBody<T>> call, Throwable throwable) {
|
||||
onFailure(throwable);
|
||||
}
|
||||
}
|
||||
209
src/main/java/com/yutou/nas/okhttp/HttpLoggingInterceptor.java
Normal file
209
src/main/java/com/yutou/nas/okhttp/HttpLoggingInterceptor.java
Normal file
@@ -0,0 +1,209 @@
|
||||
package com.yutou.nas.okhttp;
|
||||
|
||||
|
||||
import com.yutou.nas.utils.Log;
|
||||
import okhttp3.*;
|
||||
import okhttp3.internal.http.HttpHeaders;
|
||||
import okio.Buffer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class HttpLoggingInterceptor implements Interceptor {
|
||||
private static final String TAG = "HttpLogging";
|
||||
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
private volatile Level printLevel = Level.NONE;
|
||||
private java.util.logging.Level colorLevel;
|
||||
private Logger logger;
|
||||
|
||||
private static boolean prLog;
|
||||
|
||||
public static void setLog(boolean log) {
|
||||
prLog = log;
|
||||
}
|
||||
|
||||
public enum Level {
|
||||
NONE, //不打印log
|
||||
BASIC, //只打印 请求首行 和 响应首行
|
||||
HEADERS, //打印请求和响应的所有 Header
|
||||
BODY //所有数据全部打印
|
||||
}
|
||||
|
||||
public HttpLoggingInterceptor(String tag) {
|
||||
logger = Logger.getLogger(tag);
|
||||
colorLevel = java.util.logging.Level.INFO;
|
||||
}
|
||||
|
||||
public void setPrintLevel(Level level) {
|
||||
if (printLevel == null)
|
||||
throw new NullPointerException("printLevel == null. Use Level.NONE instead.");
|
||||
printLevel = level;
|
||||
}
|
||||
|
||||
public void setColorLevel(java.util.logging.Level level) {
|
||||
colorLevel = level;
|
||||
}
|
||||
|
||||
private void log(String message) {
|
||||
//logger.log(colorLevel, message);
|
||||
if (prLog) {
|
||||
Log.i(TAG, message);
|
||||
}
|
||||
//Log.e(TAG,message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
if (request.body() != null && request.body().contentLength() == 0) {
|
||||
request = chain.call().request();
|
||||
}
|
||||
if (printLevel == Level.NONE) {
|
||||
return chain.proceed(request);
|
||||
}
|
||||
|
||||
//请求日志拦截
|
||||
logForRequest(request, chain.connection());
|
||||
|
||||
//执行请求,计算请求时间
|
||||
long startNs = System.nanoTime();
|
||||
Response response;
|
||||
try {
|
||||
response = chain.proceed(request);
|
||||
} catch (Exception e) {
|
||||
log("<-- HTTP FAILED: " + e);
|
||||
throw e;
|
||||
}
|
||||
long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
|
||||
|
||||
//响应日志拦截
|
||||
return logForResponse(response, tookMs);
|
||||
}
|
||||
|
||||
private void logForRequest(Request request, Connection connection) throws IOException {
|
||||
boolean logBody = (printLevel == Level.BODY);
|
||||
boolean logHeaders = (printLevel == Level.BODY || printLevel == Level.HEADERS);
|
||||
RequestBody requestBody = request.body();
|
||||
boolean hasRequestBody = requestBody != null;
|
||||
Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
|
||||
|
||||
try {
|
||||
String requestStartMessage = "--> " + request.method() + ' ' + request.url() + ' ' + protocol;
|
||||
log(requestStartMessage);
|
||||
|
||||
if (logHeaders) {
|
||||
if (hasRequestBody) {
|
||||
// Request body headers are only present when installed as a network interceptor. Force
|
||||
// them to be included (when available) so there values are known.
|
||||
if (requestBody.contentType() != null) {
|
||||
log("\tContent-Type: " + requestBody.contentType());
|
||||
}
|
||||
if (requestBody.contentLength() != -1) {
|
||||
log("\tContent-Length: " + requestBody.contentLength());
|
||||
}
|
||||
}
|
||||
Headers headers = request.headers();
|
||||
for (int i = 0, count = headers.size(); i < count; i++) {
|
||||
String name = headers.name(i);
|
||||
// Skip headers from the request body as they are explicitly logged above.
|
||||
if (!"Content-Type".equalsIgnoreCase(name) && !"Content-Length".equalsIgnoreCase(name)) {
|
||||
log("\t" + name + ": " + headers.value(i));
|
||||
}
|
||||
}
|
||||
|
||||
log(" ");
|
||||
if (logBody && hasRequestBody) {
|
||||
if (isPlaintext(requestBody.contentType())) {
|
||||
bodyToString(request);
|
||||
} else {
|
||||
log("\tbody: maybe [binary body], omitted!");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(java.util.logging.Level.WARNING, e.getMessage(), e);
|
||||
} finally {
|
||||
log("--> END " + request.method());
|
||||
}
|
||||
}
|
||||
|
||||
private Response logForResponse(Response response, long tookMs) {
|
||||
Response.Builder builder = response.newBuilder();
|
||||
Response clone = builder.build();
|
||||
ResponseBody responseBody = clone.body();
|
||||
boolean logBody = (printLevel == Level.BODY);
|
||||
boolean logHeaders = (printLevel == Level.BODY || printLevel == Level.HEADERS);
|
||||
|
||||
try {
|
||||
log("<-- " + clone.code() + ' ' + clone.message() + ' ' + clone.request().url() + " (" + tookMs + "ms)");
|
||||
if (logHeaders) {
|
||||
Headers headers = clone.headers();
|
||||
for (int i = 0, count = headers.size(); i < count; i++) {
|
||||
log("\t" + headers.name(i) + ": " + headers.value(i));
|
||||
}
|
||||
log(" ");
|
||||
if (logBody && HttpHeaders.hasBody(clone)) {
|
||||
if (responseBody == null) return response;
|
||||
|
||||
if (isPlaintext(responseBody.contentType())) {
|
||||
byte[] bytes = responseBody.byteStream().readAllBytes();
|
||||
MediaType contentType = responseBody.contentType();
|
||||
String body = new String(bytes, getCharset(contentType));
|
||||
log("\tbody:" + body);
|
||||
responseBody = ResponseBody.create(responseBody.contentType(), bytes);
|
||||
return response.newBuilder().body(responseBody).build();
|
||||
} else {
|
||||
log("\tbody: maybe [binary body], omitted!");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(java.util.logging.Level.WARNING, e.getMessage(), e);
|
||||
} finally {
|
||||
log("<-- END HTTP");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private static Charset getCharset(MediaType contentType) {
|
||||
Charset charset = contentType != null ? contentType.charset(UTF8) : UTF8;
|
||||
if (charset == null) charset = UTF8;
|
||||
return charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the body in question probably contains human readable text. Uses a small sample
|
||||
* of code points to detect unicode control characters commonly used in binary file signatures.
|
||||
*/
|
||||
private static boolean isPlaintext(MediaType mediaType) {
|
||||
if (mediaType == null) return false;
|
||||
if (mediaType.type() != null && mediaType.type().equals("text")) {
|
||||
return true;
|
||||
}
|
||||
String subtype = mediaType.subtype();
|
||||
if (subtype != null) {
|
||||
subtype = subtype.toLowerCase();
|
||||
if (subtype.contains("x-www-form-urlencoded") || subtype.contains("json") || subtype.contains("xml") || subtype.contains("html")) //
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void bodyToString(Request request) {
|
||||
try {
|
||||
Request copy = request.newBuilder().build();
|
||||
RequestBody body = copy.body();
|
||||
if (body == null) return;
|
||||
Buffer buffer = new Buffer();
|
||||
body.writeTo(buffer);
|
||||
Charset charset = getCharset(body.contentType());
|
||||
log("\tbody:" + buffer.readString(charset));
|
||||
} catch (Exception e) {
|
||||
logger.log(java.util.logging.Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/main/java/com/yutou/nas/okhttp/IRequestParam.java
Normal file
9
src/main/java/com/yutou/nas/okhttp/IRequestParam.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.yutou.nas.okhttp;
|
||||
|
||||
import okhttp3.Request;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface IRequestParam {
|
||||
Request getRequest(HashMap<String,String> map, Request request);
|
||||
}
|
||||
31
src/main/java/com/yutou/nas/okhttp/ParamsContext.java
Normal file
31
src/main/java/com/yutou/nas/okhttp/ParamsContext.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.yutou.nas.okhttp;
|
||||
|
||||
import okhttp3.Request;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ParamsContext {
|
||||
private IRequestParam iRequestParam;
|
||||
private Request request;
|
||||
private HashMap<String,String> map;
|
||||
|
||||
public ParamsContext(HashMap<String,String> map,Request request) {
|
||||
if(map==null){
|
||||
map=new HashMap<>();
|
||||
}
|
||||
this.map=map;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public Request getInRequest() {
|
||||
switch (request.method()) {
|
||||
case "GET":
|
||||
iRequestParam = new GetRequestParams();
|
||||
break;
|
||||
case "POST":
|
||||
iRequestParam = new PostRequestParams();
|
||||
break;
|
||||
}
|
||||
return iRequestParam.getRequest(map,request);
|
||||
}
|
||||
}
|
||||
69
src/main/java/com/yutou/nas/okhttp/PostRequestParams.java
Normal file
69
src/main/java/com/yutou/nas/okhttp/PostRequestParams.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.yutou.nas.okhttp;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class PostRequestParams implements IRequestParam {
|
||||
@Override
|
||||
public Request getRequest(HashMap<String, String> map, Request request) {
|
||||
if (request.body() instanceof FormBody) {
|
||||
FormBody.Builder bodyBuilder = new FormBody.Builder();
|
||||
FormBody formBody = (FormBody) request.body();
|
||||
|
||||
for (int i = 0; i < formBody.size(); i++) {
|
||||
bodyBuilder.addEncoded(formBody.encodedName(i), formBody.encodedValue(i));
|
||||
}
|
||||
for (String key : map.keySet()) {
|
||||
bodyBuilder.addEncoded(key, String.valueOf(map.get(key)));
|
||||
}
|
||||
formBody = bodyBuilder.build();
|
||||
request = request.newBuilder().post(formBody).build();
|
||||
} else if (request.body() != null) {
|
||||
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),toUrlParams(map));
|
||||
request = request.newBuilder().post(request.body())
|
||||
.post(requestBody).build();
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
public static String toUrlParams(JSONObject json) {
|
||||
StringBuilder string = new StringBuilder();
|
||||
Set<String> keys = json.keySet();
|
||||
for (String key : keys) {
|
||||
try {
|
||||
string.append("&").append(key).append("=").append(URLEncoder.encode(json.getString(key), "UTF-8"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
string.append("&").append(URLEncoder.encode(key,"UTF-8")).append("=");
|
||||
// string += "&" + key + "=";
|
||||
} catch (Exception e1) {
|
||||
string.append("&").append(key).append("=");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string = new StringBuilder(string.substring(1, string.length()).replaceAll(" ", ""));
|
||||
return string.toString();
|
||||
}
|
||||
|
||||
public static String toUrlParams(Map<String, String> map) {
|
||||
if(map.isEmpty()){
|
||||
return "";
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String key : map.keySet()) {
|
||||
builder.append(key).append("=").append(map.get(key)).append("&");
|
||||
}
|
||||
return builder.substring(0, builder.length() - 1);
|
||||
}
|
||||
}
|
||||
101
src/main/java/com/yutou/nas/okhttp/api/BaseApi.java
Normal file
101
src/main/java/com/yutou/nas/okhttp/api/BaseApi.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package com.yutou.nas.okhttp.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.internal.bind.DateTypeAdapter;
|
||||
import com.yutou.nas.okhttp.HttpLoggingInterceptor;
|
||||
import com.yutou.nas.okhttp.ParamsContext;
|
||||
import com.yutou.nas.okhttp.converter.JsonCallAdapter;
|
||||
import com.yutou.nas.okhttp.converter.JsonConverterFactory;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import retrofit2.CallAdapter;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class BaseApi {
|
||||
private String URL;
|
||||
private HashMap<String, String> params;
|
||||
|
||||
public BaseApi(String URL) {
|
||||
this.URL = URL;
|
||||
}
|
||||
|
||||
public BaseApi setURL(String URL) {
|
||||
this.URL = URL;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseApi setParams(HashMap<String, String> params) {
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个接口方法
|
||||
*
|
||||
* @param okHttpClient okhttp客户端
|
||||
* @param converterFactory 处理工厂类
|
||||
* @param callAdapterFactory 请求适配器工厂
|
||||
* @param baseUrl 基础地质
|
||||
* @param service 接口
|
||||
* @param <T> 接口泛型
|
||||
* @return 接口
|
||||
*/
|
||||
public <T> T create(OkHttpClient okHttpClient, Converter.Factory converterFactory, CallAdapter.Factory callAdapterFactory, String baseUrl, Class<T> service) {
|
||||
Retrofit.Builder builder = new Retrofit.Builder()
|
||||
//基础url
|
||||
.baseUrl(baseUrl)
|
||||
//客户端OKHttp
|
||||
.client(okHttpClient);
|
||||
//添加转换工厂
|
||||
if (null != converterFactory) {
|
||||
builder.addConverterFactory(converterFactory);
|
||||
}
|
||||
//添加请求工厂
|
||||
if (null != callAdapterFactory) {
|
||||
builder.addCallAdapterFactory(callAdapterFactory);
|
||||
}
|
||||
//创建retrofit对象
|
||||
Retrofit retrofit = builder.build();
|
||||
|
||||
//返回创建的api
|
||||
return retrofit.create(service);
|
||||
}
|
||||
|
||||
public <T> T createApi(Class<T> apiClass) {
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Date.class, new DateTypeAdapter())
|
||||
.create();
|
||||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("http");
|
||||
loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
OkHttpClient.Builder builder = new OkHttpClient()
|
||||
.newBuilder()
|
||||
|
||||
.addInterceptor(initQuery())
|
||||
.addInterceptor(loggingInterceptor);
|
||||
return create(builder.build(),
|
||||
JsonConverterFactory.create(gson),
|
||||
JsonCallAdapter.create(),
|
||||
URL,
|
||||
apiClass);
|
||||
}
|
||||
public Interceptor initQuery() {
|
||||
Interceptor addQueryParameterInterceptor = new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
//配置公共参数
|
||||
request = new ParamsContext(params,request).getInRequest();
|
||||
return chain.proceed(request);
|
||||
}
|
||||
};
|
||||
return addQueryParameterInterceptor;
|
||||
}
|
||||
}
|
||||
14
src/main/java/com/yutou/nas/okhttp/api/ToolsNetApi.java
Normal file
14
src/main/java/com/yutou/nas/okhttp/api/ToolsNetApi.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.yutou.nas.okhttp.api;
|
||||
|
||||
import com.yutou.nas.okhttp.BaseBean;
|
||||
import com.yutou.nas.okhttp.HttpBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface ToolsNetApi {
|
||||
@FormUrlEncoded
|
||||
@POST("/api/v2/torrents/add")
|
||||
Call<HttpBody<BaseBean>> postDownloadBt(@Field("urls")String urls, @Field("savepath")String savePath);
|
||||
}
|
||||
17
src/main/java/com/yutou/nas/okhttp/api/ToolsNetManager.java
Normal file
17
src/main/java/com/yutou/nas/okhttp/api/ToolsNetManager.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.yutou.nas.okhttp.api;
|
||||
|
||||
import com.yutou.nas.utils.ConfigTools;
|
||||
|
||||
public class ToolsNetManager extends BaseApi {
|
||||
public ToolsNetManager(String URL) {
|
||||
super(URL);
|
||||
}
|
||||
|
||||
public static ToolsNetManager createQbit() {
|
||||
return new ToolsNetManager(ConfigTools.load(ConfigTools.CONFIG, "Qbittorrent.Url", String.class));
|
||||
}
|
||||
|
||||
public ToolsNetApi getToolsNetApi() {
|
||||
return createApi(ToolsNetApi.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yutou.nas.okhttp.converter;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import retrofit2.CallAdapter;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class JsonCallAdapter extends CallAdapter.Factory{
|
||||
public static JsonCallAdapter create(){
|
||||
return new JsonCallAdapter();
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public CallAdapter<?, ?> get(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.yutou.nas.okhttp.converter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class JsonConverterFactory extends Converter.Factory {
|
||||
Gson gson;
|
||||
public static JsonConverterFactory create(Gson gson) {
|
||||
return new JsonConverterFactory(gson);
|
||||
}
|
||||
|
||||
private JsonConverterFactory(Gson gson) {
|
||||
this.gson = gson;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
|
||||
// return super.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
|
||||
TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
|
||||
return new JsonRequestBodyConverter<>(gson,adapter);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
// return super.responseBodyConverter(type, annotations, retrofit);
|
||||
TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
|
||||
return new JsonResponseBodyConverter<>(gson,adapter,type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yutou.nas.okhttp.converter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okio.Buffer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import retrofit2.Converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class JsonRequestBodyConverter<T> implements Converter<T, RequestBody> {
|
||||
Gson gson;
|
||||
TypeAdapter<T> adapter;
|
||||
public JsonRequestBodyConverter(Gson gson, TypeAdapter<T> adapter) {
|
||||
this.gson=gson;
|
||||
this.adapter=adapter;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RequestBody convert(T value) throws IOException {
|
||||
Buffer buffer = new Buffer();
|
||||
Writer writer = new OutputStreamWriter(buffer.outputStream(), StandardCharsets.UTF_8);
|
||||
JsonWriter jsonWriter = gson.newJsonWriter(writer);
|
||||
adapter.write(jsonWriter, value);
|
||||
jsonWriter.close();
|
||||
byte[] bytes = buffer.readByteArray();
|
||||
return RequestBody.create(MediaType.parse("application/json; charset=UTF-8"),bytes );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.yutou.nas.okhttp.converter;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.yutou.nas.okhttp.HttpBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import retrofit2.Converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class JsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
|
||||
Gson gson;
|
||||
TypeAdapter<?> adapter;
|
||||
Type type;
|
||||
|
||||
public JsonResponseBodyConverter(Gson gson, TypeAdapter<?> adapter, Type type) {
|
||||
this.gson = gson;
|
||||
this.adapter = adapter;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public T convert(ResponseBody responseBody) throws IOException {
|
||||
String string = new String(responseBody.bytes());
|
||||
responseBody.close();
|
||||
HttpBody<T> body;
|
||||
try {
|
||||
body = JSONObject.parseObject(string, type);
|
||||
body.setSrc(string);
|
||||
return (T) body;
|
||||
} catch (Exception e) {
|
||||
body = new HttpBody();
|
||||
body.setSrc(string);
|
||||
}
|
||||
return (T) body;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ 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);
|
||||
System.out.println("tmp = " + tmp);
|
||||
if(tmp==null){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,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);
|
||||
@@ -53,11 +53,11 @@ 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();
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -62,7 +62,7 @@ public class DmhyRssDownloadManager implements ApplicationContextAware {
|
||||
}
|
||||
BTDownloadManager.download(item.getTitle(), json);
|
||||
} else {
|
||||
QQBotManager.getInstance().sendMessage(item.getTitle() + "\n下载失败\n" + getDmhyUrl(item));
|
||||
//QQBotManager.getInstance().sendMessage(item.getTitle() + "\n下载失败\n" + getDmhyUrl(item));
|
||||
Log.i(item.getTitle() + "\n下载失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -16,7 +14,11 @@ public class HttpTools {
|
||||
private static final int HttpRequestIndex = 3;
|
||||
|
||||
public static String get(String url) {
|
||||
return https_get(url, null);
|
||||
return https_get(url, false, null);
|
||||
}
|
||||
|
||||
public static String https_get(String url, Map<String, String> header) {
|
||||
return https_get(url, false, header);
|
||||
}
|
||||
|
||||
public static String post(final String url, final byte[] body) {
|
||||
@@ -27,16 +29,26 @@ public class HttpTools {
|
||||
return new HttpTools().http_syncDownload(url, saveName);
|
||||
}
|
||||
|
||||
public static String https_get(String url, Map<String, String> header) {
|
||||
public static String https_get(String url, boolean isProxy, Map<String, String> header) {
|
||||
try {
|
||||
URLConnection connection;
|
||||
connection = new URL(url).openConnection();
|
||||
Proxy proxy = null;
|
||||
if (isProxy) {
|
||||
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(ConfigTools.load(ConfigTools.CONFIG,"proxy.address",String.class),
|
||||
ConfigTools.load(ConfigTools.CONFIG,"proxy.port",Integer.class)));
|
||||
}
|
||||
if (proxy == null) {
|
||||
connection = new URL(url).openConnection();
|
||||
} else {
|
||||
connection = new URL(url).openConnection(proxy);
|
||||
}
|
||||
connection.setRequestProperty("User-Agent", getUa());
|
||||
if (header != null) {
|
||||
for (String key : header.keySet()) {
|
||||
connection.addRequestProperty(key, header.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
connection.connect();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
StringBuilder str = new StringBuilder();
|
||||
@@ -64,6 +76,9 @@ public class HttpTools {
|
||||
connection.addRequestProperty(key, headers.get(key));
|
||||
}
|
||||
}
|
||||
if (body == null) {
|
||||
body = "".getBytes();
|
||||
}
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
connection.addRequestProperty("User-Agent", getUa());
|
||||
@@ -71,7 +86,7 @@ public class HttpTools {
|
||||
connection.setReadTimeout(10 * 1000);
|
||||
//connection.addRequestProperty("Connection", "keep-alive");
|
||||
//connection.addRequestProperty("User-Agent", getExtUa());
|
||||
//connection.addRequestProperty("content-type", "application/json");
|
||||
connection.addRequestProperty("content-type", "application/json");
|
||||
connection.addRequestProperty("charset", "UTF-8");
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
//System.out.println(new String(body));
|
||||
@@ -98,6 +113,59 @@ public class HttpTools {
|
||||
}
|
||||
}
|
||||
|
||||
public static String http_post_form(String url, byte[] body, int index, Map<String, String> headers) {
|
||||
String tmp;
|
||||
StringBuilder str = new StringBuilder();
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
if (headers != null) {
|
||||
for (String key : headers.keySet()) {
|
||||
connection.addRequestProperty(key, headers.get(key));
|
||||
}
|
||||
}
|
||||
if (body == null) {
|
||||
body = "".getBytes();
|
||||
}
|
||||
Log.i("Http","url = "+url+" body = "+new String(body));
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
connection.addRequestProperty("User-Agent", getUa());
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(10 * 1000);
|
||||
connection.setRequestProperty("Content-Type", "multipart/form-data;");
|
||||
connection.setRequestProperty("charset", "utf-8");
|
||||
connection.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
|
||||
|
||||
//connection.addRequestProperty("Connection", "keep-alive");
|
||||
//connection.addRequestProperty("User-Agent", getExtUa());
|
||||
//connection.addRequestProperty("content-type", "application/json");
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
//System.out.println(new String(body));
|
||||
outputStream.write(body);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
connection.connect();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
str.append(tmp);
|
||||
}
|
||||
String finalStr = str.toString();
|
||||
Log.i("Http","code = "+connection.getResponseCode()+" url = "+url+" body = "+new String(body));
|
||||
connection.disconnect();
|
||||
reader.close();
|
||||
return finalStr;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (index < HttpRequestIndex) {
|
||||
return http_post_form(url, body, index + 1, headers);
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
@@ -131,11 +199,12 @@ public class HttpTools {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("pid", "102");
|
||||
json.put("gid", "100584");
|
||||
json.put("gameKey", "0gha58u1c9FjZkeAsEmYIzTvp");
|
||||
json.put("access_token", "659c-S1gV0DwMXdYjPDlSrSLNYOvA8qUoCSvmdFEHvZugKgNX4Z2BCwF18A7W2gRdG7WiWfKsbZgF6YssZHhaozksI9RBn2QQFTXzmAHtbMd4ginEEtwdKmPCM4JbJGg1ollqoNE0PcGENpa4F3e7EdSOa_JFyE6XyUQN1iurJU3F8MZfLlTIcTR9USYoHX15vsAkCht_0mrapZblkeY1_8HFrmK8rlenbZLxccy7PrMz5eZ9uPPDJL5OYiEahyrtLENB8SVmlGofJfQw8wUjN8_XVZSfLMujdwz24");
|
||||
String url = "http://192.168.1.156:9020/Faxing/reg?" +
|
||||
"&tpyeCode=dimai" +
|
||||
"®ParamJson=" + json.toJSONString();
|
||||
json.put("message", "0gha58u1c9FjZkeAsEmYIzTvp");
|
||||
// json.put("access_token", "659c-S1gV0DwMXdYjPDlSrSLNYOvA8qUoCSvmdFEHvZugKgNX4Z2BCwF18A7W2gRdG7WiWfKsbZgF6YssZHhaozksI9RBn2QQFTXzmAHtbMd4ginEEtwdKmPCM4JbJGg1ollqoNE0PcGENpa4F3e7EdSOa_JFyE6XyUQN1iurJU3F8MZfLlTIcTR9USYoHX15vsAkCht_0mrapZblkeY1_8HFrmK8rlenbZLxccy7PrMz5eZ9uPPDJL5OYiEahyrtLENB8SVmlGofJfQw8wUjN8_XVZSfLMujdwz24");
|
||||
String url = "http://127.0.0.1:8002/qq/send.do";
|
||||
String data = "data=abc&codd=1";
|
||||
data = json.toString();
|
||||
http_post(url, data.getBytes(StandardCharsets.UTF_8), 0, null);
|
||||
/* ExecutorService service= Executors.newCachedThreadPool();
|
||||
for (int i = 0; i < 3000; i++) {
|
||||
service.submit(new Runnable() {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class JellyfinAPIManager {
|
||||
|
||||
public LibsItem getLibs(String key) {
|
||||
HashMap<String, String> header = getHeader();
|
||||
String httpText = HttpTools.https_get("http://192.168.31.88:8096/Users/"+userId+"/Items", header);
|
||||
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;
|
||||
@@ -44,12 +44,12 @@ public class JellyfinAPIManager {
|
||||
}
|
||||
|
||||
public ItemInfo getInfo(String id) {
|
||||
String http = HttpTools.https_get("http://192.168.31.88:8096/Users/"+userId+"/Items/" + id, getHeader());
|
||||
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/"+userId+"/Items?SortBy=SortName&SortOrder=Ascending&IncludeItemTypes=Series&Recursive=true&Fields=PrimaryImageAspectRatio%2CBasicSyncInfo&ImageTypeLimit=1&EnableImageTypes=Primary%2CBackdrop%2CBanner%2CThumb&ParentId=28e774baf8f2fd279e7d58da9890a7d2", getHeader());
|
||||
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");
|
||||
@@ -61,21 +61,21 @@ public class JellyfinAPIManager {
|
||||
}
|
||||
|
||||
public List<LibsItem> getLibsItems(String id) {
|
||||
String httpText = HttpTools.https_get("http://192.168.31.88:8096/Users/"+userId+"/Items?ParentId=" + id, getHeader());
|
||||
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 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="+userId+"",
|
||||
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 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="+userId+"",
|
||||
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());
|
||||
@@ -89,7 +89,7 @@ public class JellyfinAPIManager {
|
||||
}
|
||||
|
||||
public JSONObject getEpisodesDataForJson(String id) {
|
||||
String data = HttpTools.https_get(String.format("http://192.168.31.88:8096/Users/"+userId+"/Items/%s",
|
||||
String data = HttpTools.https_get(String.format("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Users/"+userId+"/Items/%s",
|
||||
id
|
||||
), getHeader());
|
||||
return JSON.parseObject(data);
|
||||
@@ -112,7 +112,7 @@ public class JellyfinAPIManager {
|
||||
try {
|
||||
HashMap<String, String> header = getHeader();
|
||||
header.put("Content-Type", "image/jpeg");
|
||||
String url = String.format("http://192.168.31.88:8096/Items/%s/Images/%s",
|
||||
String url = String.format("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+":8096/Items/%s/Images/%s",
|
||||
id,
|
||||
model
|
||||
);
|
||||
@@ -178,7 +178,7 @@ public class JellyfinAPIManager {
|
||||
metadata.put("Taglines", new JSONArray());
|
||||
HashMap<String, String> headers = getHeader();
|
||||
headers.put("Content-Type", "application/json");
|
||||
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);
|
||||
@@ -279,6 +279,11 @@ public class JellyfinAPIManager {
|
||||
}
|
||||
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,String id) {
|
||||
if (id != null) {
|
||||
@@ -329,7 +334,7 @@ public class JellyfinAPIManager {
|
||||
public static String mainPath = "Z:\\download\\anim\\";
|
||||
|
||||
public void login(){
|
||||
String url="http://192.168.31.88:8096/Users/authenticatebyname";
|
||||
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");
|
||||
@@ -345,7 +350,7 @@ public class JellyfinAPIManager {
|
||||
header.put("accept", "application/json");
|
||||
header.put("Connection", "keep-alive");
|
||||
header.put("User-Agent", HttpTools.getUa());
|
||||
header.put("Origin", "http://192.168.31.88:8096");
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class QQBotManager {
|
||||
json.put("message",text);
|
||||
Map<String, String> header = new HashMap<>();
|
||||
header.put("content-type", "application/json");
|
||||
return HttpTools.http_post("http://192.168.31.88:802/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||
return HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+"/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||
}
|
||||
|
||||
public String sendMessage(long qq,String text) {
|
||||
@@ -44,18 +44,20 @@ public class QQBotManager {
|
||||
json.put("message",text);
|
||||
Map<String, String> header = new HashMap<>();
|
||||
header.put("content-type", "application/json");
|
||||
return HttpTools.http_post("http://192.168.31.88:802/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||
return HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+"/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||
}
|
||||
|
||||
|
||||
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", 891655174);
|
||||
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://192.168.31.88:802/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||
return HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+"/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,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;
|
||||
|
||||
@@ -150,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流里面
|
||||
@@ -199,9 +263,9 @@ public class RedisTools {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Jedis jedis = getPoolRedis();
|
||||
if (jedis != null)
|
||||
jedis.psubscribe(new Consumer(), "*");
|
||||
// Jedis jedis = getPoolRedis();
|
||||
// if (jedis != null)
|
||||
// jedis.psubscribe(new Consumer(), "*");
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
||||
@@ -1,23 +1,79 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.jcraft.jsch.jce.ARCFOUR;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.StringReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
|
||||
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";
|
||||
public static JSONObject toJSON(String xmlUrl) {
|
||||
String xml = HttpTools.https_get(xmlUrl, true, null);
|
||||
SAXReader reader = new SAXReader();
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
String ret = HttpTools.get(String.format(url, URLEncoder.encode(xmlUrl, "UTF-8")));
|
||||
if(ret!=null){
|
||||
return JSON.parseObject(ret, JSONObject.class);
|
||||
json.put("status", "ok");
|
||||
JSONArray array = new JSONArray();
|
||||
BufferedReader br = new BufferedReader(new StringReader(xml));
|
||||
Document document = reader.read(br);
|
||||
Element rootElement = document.getRootElement();
|
||||
List<Element> elements = rootElement.element("channel").elements("item");
|
||||
for (Element element : elements) {
|
||||
JSONObject item = new JSONObject();
|
||||
JSONObject enclosure = new JSONObject();
|
||||
String title = element.element("title").content().get(0).getText();
|
||||
String magnet = element.element("enclosure").attribute("url").getValue();
|
||||
String time = element.element("pubDate").content().get(0).getText();
|
||||
enclosure.put("link", magnet);
|
||||
item.put("title", title);
|
||||
item.put("enclosure", enclosure);
|
||||
item.put("time", time);
|
||||
array.add(item);
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
json.put("items", array);
|
||||
} catch (Exception e) {
|
||||
json.put("status", e.getMessage());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String xmlUrl = "https://share.dmhy.org/topics/rss/rss.xml?keyword=%E5%96%B5%E8%90%8C%E5%A5%B6%E8%8C%B6%E5%B1%8B%20%E8%8D%AF%E5%B1%8B%E5%B0%91%E5%A5%B3%E7%9A%84%E5%91%A2%E5%96%83%20%E7%AE%80%E6%97%A5";
|
||||
String xml = HttpTools.https_get(xmlUrl, true, null);
|
||||
|
||||
SAXReader reader = new SAXReader();
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("status", "ok");
|
||||
JSONArray array = new JSONArray();
|
||||
BufferedReader br = new BufferedReader(new StringReader(xml));
|
||||
Document document = reader.read(br);
|
||||
Element rootElement = document.getRootElement();
|
||||
List<Element> elements = rootElement.element("channel").elements("item");
|
||||
for (Element element : elements) {
|
||||
JSONObject item = new JSONObject();
|
||||
JSONObject enclosure = new JSONObject();
|
||||
String title = element.element("title").content().get(0).getText();
|
||||
String magnet = element.element("enclosure").attribute("url").getValue();
|
||||
String time = element.element("pubDate").content().get(0).getText();
|
||||
enclosure.put("link", magnet);
|
||||
item.put("title", title);
|
||||
item.put("enclosure", enclosure);
|
||||
item.put("time", time);
|
||||
array.add(item);
|
||||
}
|
||||
json.put("items", array);
|
||||
System.out.println(rootElement);
|
||||
} catch (Exception e) {
|
||||
json.put("status", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ 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;
|
||||
@@ -397,4 +398,22 @@ public class Tools {
|
||||
},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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user