From 15e32c9b009689eb2641b223b1fddabab25a7633 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 17 Jul 2022 01:49:13 +0800 Subject: [PATCH] =?UTF-8?q?update:BT=E4=B8=8B=E8=BD=BD=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=90=8E=E6=89=A7=E8=A1=8C=E8=84=9A=E6=9C=AC=20add:=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E4=B8=8B=E8=BD=BD=E7=9A=84=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E5=8C=85=E5=90=AB265=EF=BC=8C=E5=88=99=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E6=9B=BF=E6=8D=A2=E6=88=90=E8=B4=B0=E9=99=B8=E4=BC=8D?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E6=90=9C=E5=88=AE=E5=99=A8=E7=9E=8E?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nas/Controllers/BTDownloadController.java | 9 +++ .../java/com/yutou/nas/NasApplication.java | 2 +- src/main/java/com/yutou/nas/other/tools.java | 3 +- .../yutou/nas/utils/BTDownloadManager.java | 55 +++++++++++++++++-- 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/yutou/nas/Controllers/BTDownloadController.java b/src/main/java/com/yutou/nas/Controllers/BTDownloadController.java index 6ea2d72..070c09f 100644 --- a/src/main/java/com/yutou/nas/Controllers/BTDownloadController.java +++ b/src/main/java/com/yutou/nas/Controllers/BTDownloadController.java @@ -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"; + } } diff --git a/src/main/java/com/yutou/nas/NasApplication.java b/src/main/java/com/yutou/nas/NasApplication.java index b448bf4..65eda45 100644 --- a/src/main/java/com/yutou/nas/NasApplication.java +++ b/src/main/java/com/yutou/nas/NasApplication.java @@ -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); diff --git a/src/main/java/com/yutou/nas/other/tools.java b/src/main/java/com/yutou/nas/other/tools.java index bbe8d32..74aa455 100644 --- a/src/main/java/com/yutou/nas/other/tools.java +++ b/src/main/java/com/yutou/nas/other/tools.java @@ -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": diff --git a/src/main/java/com/yutou/nas/utils/BTDownloadManager.java b/src/main/java/com/yutou/nas/utils/BTDownloadManager.java index 4880b2a..b830f4a 100644 --- a/src/main/java/com/yutou/nas/utils/BTDownloadManager.java +++ b/src/main/java/com/yutou/nas/utils/BTDownloadManager.java @@ -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); + } }