调整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 {
|
||||||
@ -19,23 +23,50 @@ public class BTDownloadController {
|
|||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping("/bt/down.do")
|
@RequestMapping("/bt/down.do")
|
||||||
public String bt(){
|
public String bt() {
|
||||||
DmhyRssDownloadManager.getInstance().start();
|
DmhyRssDownloadManager.getInstance().start();
|
||||||
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) {
|
||||||
Log.i("BTDownloadController.done","path = " + path + ", filename = " + filename + ", hash1 = " + hash1 + ", hash2 = " + hash2 + ", tid = " + tid);
|
Log.i("BTDownloadController.done", "path = " + path + ", filename = " + filename + ", hash1 = " + hash1 + ", hash2 = " + hash2 + ", tid = " + tid);
|
||||||
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) {
|
||||||
Log.i("跳过下载","手动下载 id = " + id + ", isDownloadNext = " + isDownloadNext + ", url = " + url);
|
Log.i("跳过下载", "手动下载 id = " + id + ", isDownloadNext = " + isDownloadNext + ", url = " + url);
|
||||||
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();
|
||||||
}
|
}
|
||||||
@ -117,16 +130,16 @@ public class BTDownloadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static void done(String path, String filename, String hash1, String hash2, String tid) {
|
public synchronized static void done(String path, String filename, String hash1, String hash2, String tid) {
|
||||||
grep(path,filename);
|
grep(path, filename);
|
||||||
String hash = StringUtils.isEmpty(hash1) ? StringUtils.isEmpty(hash2) ? null : hash2 : hash1;
|
String hash = StringUtils.isEmpty(hash1) ? StringUtils.isEmpty(hash2) ? null : hash2 : hash1;
|
||||||
if (hash != null) {
|
if (hash != null) {
|
||||||
String map = RedisTools.getHashMap("rss", hash);
|
String map = RedisTools.getHashMap("rss", hash);
|
||||||
JSONObject item = JSON.parseObject(map);
|
JSONObject item = JSON.parseObject(map);
|
||||||
String text="添加到库:"+item.getString("title")+"\n动漫花园地址:"+item.getString("link");
|
String text = "添加到库:" + item.getString("title") + "\n动漫花园地址:" + item.getString("link");
|
||||||
if (!item.containsKey("thumbnail")) {
|
if (!item.containsKey("thumbnail")) {
|
||||||
QQBotManager.getInstance().sendMessage(734332887,text);
|
QQBotManager.getInstance().sendMessage(734332887, text);
|
||||||
} else {
|
} else {
|
||||||
QQBotManager.getInstance().sendMessage(734332887,item.getString("thumbnail"),text);
|
QQBotManager.getInstance().sendMessage(734332887, item.getString("thumbnail"), text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,11 +162,11 @@ public class BTDownloadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getTorrentFileHash(String magnet) {
|
public static String getTorrentFileHash(String magnet) {
|
||||||
String hash=null;
|
String hash = null;
|
||||||
try {
|
try {
|
||||||
ProtocolContext.getInstance().register(MagnetProtocol.getInstance());
|
ProtocolContext.getInstance().register(MagnetProtocol.getInstance());
|
||||||
ITaskSession session = ProtocolContext.getInstance().buildTaskSession(magnet);
|
ITaskSession session = ProtocolContext.getInstance().buildTaskSession(magnet);
|
||||||
hash=session.getName();
|
hash = session.getName();
|
||||||
Tools.delDir("download");
|
Tools.delDir("download");
|
||||||
} catch (DownloadException e) {
|
} catch (DownloadException 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