调整BT下载
This commit is contained in:
parent
16c0f9816d
commit
25bee81d05
@ -11,6 +11,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class BTDownloadController {
|
public class BTDownloadController {
|
||||||
@ -24,6 +28,7 @@ public class BTDownloadController {
|
|||||||
AnimRssManager.scan();
|
AnimRssManager.scan();
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping("/bt/done.do")
|
@RequestMapping("/bt/done.do")
|
||||||
public String done(String path, String filename, String hash1, String hash2, String tid) {
|
public String done(String path, String filename, String hash1, String hash2, String tid) {
|
||||||
@ -31,6 +36,7 @@ public class BTDownloadController {
|
|||||||
BTDownloadManager.done(path, filename, hash1, hash2, tid);
|
BTDownloadManager.done(path, filename, hash1, hash2, tid);
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping("/bt/download.do")
|
@RequestMapping("/bt/download.do")
|
||||||
public String download(int id, boolean isDownloadNext, String url) {
|
public String download(int id, boolean isDownloadNext, String url) {
|
||||||
@ -38,4 +44,29 @@ public class BTDownloadController {
|
|||||||
bangumiService.download(id, isDownloadNext, url);
|
bangumiService.download(id, isDownloadNext, url);
|
||||||
return "1";
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
@Import(DmhyRssDownloadManager.class)
|
@Import(DmhyRssDownloadManager.class)
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class NasApplication {
|
public class NasApplication {
|
||||||
public static final String version = "1.2.18";
|
public static final String version = "1.3";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(NasApplication.class, args);
|
SpringApplication.run(NasApplication.class, args);
|
||||||
|
@ -14,6 +14,7 @@ import org.slf4j.event.Level;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class BTDownloadManager {
|
public class BTDownloadManager {
|
||||||
@ -80,7 +81,7 @@ public class BTDownloadManager {
|
|||||||
|
|
||||||
public static boolean download(String title, String url) {
|
public static boolean download(String title, String url) {
|
||||||
try {
|
try {
|
||||||
String exec = String.format("qbittorrent-nox --save-path=\"%sanim/%s\" \"%s\""
|
/* String exec = String.format("qbittorrent-nox --save-path=\"%sanim/%s\" \"%s\""
|
||||||
, DownloadHomePath
|
, DownloadHomePath
|
||||||
, title
|
, title
|
||||||
, url
|
, url
|
||||||
@ -89,8 +90,20 @@ public class BTDownloadManager {
|
|||||||
Process process = Runtime.getRuntime().exec(new String[]{"sh"
|
Process process = Runtime.getRuntime().exec(new String[]{"sh"
|
||||||
, "-c"
|
, "-c"
|
||||||
, exec});
|
, exec});
|
||||||
process.waitFor(120, TimeUnit.SECONDS);
|
process.waitFor(120, TimeUnit.SECONDS);*/
|
||||||
return true;
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("urls", url);
|
||||||
|
json.put("savepath", "anim/" + title);
|
||||||
|
|
||||||
|
String data="urls="+url+"&savepath=anim/"+title;
|
||||||
|
String post = HttpTools.http_post_form(
|
||||||
|
ConfigTools.load(ConfigTools.CONFIG, "Qbittorrent.Url", String.class) + "/api/v2/torrents/add",
|
||||||
|
data.getBytes(StandardCharsets.UTF_8),
|
||||||
|
0,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
Log.i("BT下载", post);
|
||||||
|
return post.toLowerCase().contains("ok");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ public class HttpTools {
|
|||||||
connection.setReadTimeout(10 * 1000);
|
connection.setReadTimeout(10 * 1000);
|
||||||
//connection.addRequestProperty("Connection", "keep-alive");
|
//connection.addRequestProperty("Connection", "keep-alive");
|
||||||
//connection.addRequestProperty("User-Agent", getExtUa());
|
//connection.addRequestProperty("User-Agent", getExtUa());
|
||||||
//connection.addRequestProperty("content-type", "application/json");
|
connection.addRequestProperty("content-type", "application/json");
|
||||||
connection.addRequestProperty("charset", "UTF-8");
|
connection.addRequestProperty("charset", "UTF-8");
|
||||||
OutputStream outputStream = connection.getOutputStream();
|
OutputStream outputStream = connection.getOutputStream();
|
||||||
//System.out.println(new String(body));
|
//System.out.println(new String(body));
|
||||||
@ -100,6 +101,56 @@ 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();
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
|
||||||
|
connection.disconnect();
|
||||||
|
reader.close();
|
||||||
|
return finalStr;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (index < HttpRequestIndex) {
|
||||||
|
return http_post(url, body, index + 1, headers);
|
||||||
|
} else {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getUa() {
|
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";
|
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36";
|
||||||
@ -134,11 +185,12 @@ public class HttpTools {
|
|||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("pid", "102");
|
json.put("pid", "102");
|
||||||
json.put("gid", "100584");
|
json.put("gid", "100584");
|
||||||
json.put("gameKey", "0gha58u1c9FjZkeAsEmYIzTvp");
|
json.put("message", "0gha58u1c9FjZkeAsEmYIzTvp");
|
||||||
json.put("access_token", "659c-S1gV0DwMXdYjPDlSrSLNYOvA8qUoCSvmdFEHvZugKgNX4Z2BCwF18A7W2gRdG7WiWfKsbZgF6YssZHhaozksI9RBn2QQFTXzmAHtbMd4ginEEtwdKmPCM4JbJGg1ollqoNE0PcGENpa4F3e7EdSOa_JFyE6XyUQN1iurJU3F8MZfLlTIcTR9USYoHX15vsAkCht_0mrapZblkeY1_8HFrmK8rlenbZLxccy7PrMz5eZ9uPPDJL5OYiEahyrtLENB8SVmlGofJfQw8wUjN8_XVZSfLMujdwz24");
|
// json.put("access_token", "659c-S1gV0DwMXdYjPDlSrSLNYOvA8qUoCSvmdFEHvZugKgNX4Z2BCwF18A7W2gRdG7WiWfKsbZgF6YssZHhaozksI9RBn2QQFTXzmAHtbMd4ginEEtwdKmPCM4JbJGg1ollqoNE0PcGENpa4F3e7EdSOa_JFyE6XyUQN1iurJU3F8MZfLlTIcTR9USYoHX15vsAkCht_0mrapZblkeY1_8HFrmK8rlenbZLxccy7PrMz5eZ9uPPDJL5OYiEahyrtLENB8SVmlGofJfQw8wUjN8_XVZSfLMujdwz24");
|
||||||
String url = "http://192.168.1.156:9020/Faxing/reg?" +
|
String url = "http://127.0.0.1:8002/qq/send.do";
|
||||||
"&tpyeCode=dimai" +
|
String data="data=abc&codd=1";
|
||||||
"®ParamJson=" + json.toJSONString();
|
data=json.toString();
|
||||||
|
http_post(url,data.getBytes(StandardCharsets.UTF_8),0,null);
|
||||||
/* ExecutorService service= Executors.newCachedThreadPool();
|
/* ExecutorService service= Executors.newCachedThreadPool();
|
||||||
for (int i = 0; i < 3000; i++) {
|
for (int i = 0; i < 3000; i++) {
|
||||||
service.submit(new Runnable() {
|
service.submit(new Runnable() {
|
||||||
|
@ -35,7 +35,7 @@ public class QQBotManager {
|
|||||||
json.put("message",text);
|
json.put("message",text);
|
||||||
Map<String, String> header = new HashMap<>();
|
Map<String, String> header = new HashMap<>();
|
||||||
header.put("content-type", "application/json");
|
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);
|
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) {
|
public String sendMessage(long qq,String text) {
|
||||||
@ -44,7 +44,7 @@ public class QQBotManager {
|
|||||||
json.put("message",text);
|
json.put("message",text);
|
||||||
Map<String, String> header = new HashMap<>();
|
Map<String, String> header = new HashMap<>();
|
||||||
header.put("content-type", "application/json");
|
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);
|
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) {
|
public String sendMessage(String imageUrl, String message) {
|
||||||
@ -57,7 +57,7 @@ public class QQBotManager {
|
|||||||
json.put("image", imageUrl);
|
json.put("image", imageUrl);
|
||||||
Map<String, String> header = new HashMap<>();
|
Map<String, String> header = new HashMap<>();
|
||||||
header.put("content-type", "application/json");
|
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);
|
return HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+"/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,9 +263,9 @@ public class RedisTools {
|
|||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Jedis jedis = getPoolRedis();
|
// Jedis jedis = getPoolRedis();
|
||||||
if (jedis != null)
|
// if (jedis != null)
|
||||||
jedis.psubscribe(new Consumer(), "*");
|
// jedis.psubscribe(new Consumer(), "*");
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user