update:BT下载完成后执行脚本

add:如果下载的文件名包含265,则文件名替换成贰陸伍,防止搜刮器瞎整
This commit is contained in:
Yutousama 2022-07-17 01:49:13 +08:00
parent 7b2bdca2e6
commit 15e32c9b00
4 changed files with 61 additions and 8 deletions

View File

@ -1,7 +1,9 @@
package com.yutou.nas.Controllers;
import com.yutou.nas.utils.AnimRssManager;
import com.yutou.nas.utils.BTDownloadManager;
import com.yutou.nas.utils.DmhyRssDownloadManager;
import com.yutou.nas.utils.Log;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@ -16,4 +18,11 @@ public class BTDownloadController {
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);
return "ok";
}
}

View File

@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import;
@Import(DmhyRssDownloadManager.class)
@SpringBootApplication
public class NasApplication {
public static final String version = "1.2.16";
public static final String version = "1.2.17.1";
public static void main(String[] args) {
SpringApplication.run(NasApplication.class, args);

View File

@ -98,7 +98,8 @@ public class tools {
json.put("params", params);
json.put("cookie", cookies);
json.put("header", header);
Tools.sendServer("打印请求", json.toJSONString());
System.out.println("json = " + json);
// Tools.sendServer("打印请求", json.toJSONString());
try {
switch (RedisTools.get("request")) {
case "success":

View File

@ -3,12 +3,14 @@ package com.yutou.nas.utils;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.nas.mybatis.model.BangumiItem;
import com.yutou.nas.interfaces.ObjectInterface;
import java.io.File;
import java.util.concurrent.TimeUnit;
public class BTDownloadManager {
protected static final String DownloadHomePath = "/media/yutou/disk_lvm/public/download/";
protected static final String DownloadHomePath = "/media/yutou/disk_lvm/public/download/";
public synchronized static void download(String title, JSONObject json) {
if ("ok".equals(json.getString("status"))) {
JSONArray items = json.getJSONArray("items");
@ -23,9 +25,9 @@ public class BTDownloadManager {
array.add(item.getString("title"));
RedisTools.set(title, array.toJSONString());
if (item.containsKey("thumbnail")) {
onSend(item.getString("thumbnail"), item);
onSend(item.getString("thumbnail"), item,item.getJSONObject("enclosure").getString("link"));
} else {
onSend(null, item);
onSend(null, item,item.getJSONObject("enclosure").getString("link"));
}
} else {
Log.i("BT", "添加到下载器失败:" + item.getString("title"));
@ -39,7 +41,7 @@ public class BTDownloadManager {
}
}
private static void onSend(String fileUrl, JSONObject item) {
private static void onSend(String fileUrl, JSONObject item, String url) {
String text = "启动下载器\n已提交到下载:" + item.getString("title");
Log.i(text);
if (fileUrl == null) {
@ -47,11 +49,12 @@ public class BTDownloadManager {
} else {
QQBotManager.getInstance().sendMessage(fileUrl, text);
}
//RedisTools.set(item.getString("title"),url);
}
private static boolean download(String title, String url) {
try {
String exec = String.format("transmission-remote -n yutou:34864394 -w \"%sanim/%s\" -a \"%s\" "
String exec = String.format("transmission-remote -n yutou:34864394 -w \"%sanim/%s\" -a \"%s\" --torrent-done-script \"/home/yutou/public/servier/btDone.sh\""
, DownloadHomePath
, title
, url
@ -86,4 +89,44 @@ public class BTDownloadManager {
}
return array.contains(key);
}
public synchronized static void done(String id, String name) {
AppTools.exec("transmission-remote -n yutou:34864394 -t"+id+" -i | grep Location", new ObjectInterface() {
String remoteLocation;
String remoteName;
@Override
public void out(String data) {
super.out(data);
Log.i("BTDownloadManager.out.location","location= "+data);
remoteLocation=data.replace("Location:","").trim();
AppTools.exec("transmission-remote -n yutou:34864394 -t"+id+" -i | grep Name:", new ObjectInterface() {
@Override
public void out(String data) {
super.out(data);
Log.i("BTDownloadManager.out.name","name = "+data);
remoteName =data.replace("Name:","").trim();
grep(remoteLocation, remoteName);
}
},false,true);
}
},false,true);
}
private static void grep(String remoteLocation, String remoteName) {
System.out.println("remoteName = " + remoteName.contains("265"));
if(remoteName.contains("265")){
String newName=remoteName.replace("265","贰陸伍");
String exec="mv \"" + remoteLocation + File.separator + remoteName + "\" \"" + remoteLocation + File.separator + newName+"\"";
Log.i("执行改名",exec);
AppTools.exec(exec, new ObjectInterface() {
@Override
public void out(String data) {
super.out(data);
Log.i("改名结果:",data);
}
}, false, true);
}
AppTools.exec("/home/yutou/public/servier/tinyMediaManager/tinyMediaManager tvshow -u --scrapeUnscraped", null, false, true);
}
}