From ed70cea2a66d4e4a3b22ae1397c91362651e6e41 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 13 Oct 2022 22:54:38 +0800 Subject: [PATCH] =?UTF-8?q?update:=E6=9B=B4=E6=96=B0=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 11 +++- .../yutou/nas/utils/BTDownloadManager.java | 61 +++++++++++++++---- src/main/java/com/yutou/nas/utils/Tools.java | 19 ++++++ 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 0e92086..f4af728 100644 --- a/pom.xml +++ b/pom.xml @@ -120,17 +120,24 @@ com.aliyun.oss aliyun-sdk-oss - 3.14.1 + 3.15.2 com.drewnoakes metadata-extractor - 2.17.0 + 2.18.0 + + + com.acgist + snail + 1.17.1 + + diff --git a/src/main/java/com/yutou/nas/utils/BTDownloadManager.java b/src/main/java/com/yutou/nas/utils/BTDownloadManager.java index 7db329d..47d9848 100644 --- a/src/main/java/com/yutou/nas/utils/BTDownloadManager.java +++ b/src/main/java/com/yutou/nas/utils/BTDownloadManager.java @@ -1,15 +1,25 @@ package com.yutou.nas.utils; +import com.acgist.snail.Snail; +import com.acgist.snail.context.ProtocolContext; +import com.acgist.snail.context.TaskContext; +import com.acgist.snail.context.exception.DownloadException; +import com.acgist.snail.pojo.ITaskSession; +import com.acgist.snail.protocol.magnet.MagnetProtocol; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; +import org.slf4j.LoggerFactory; +import org.slf4j.event.Level; +import java.io.File; +import java.io.IOException; import java.util.concurrent.TimeUnit; public class BTDownloadManager { protected static final String DownloadHomePath = "/media/yutou/disk_lvm/public/download/"; - public synchronized static boolean skipDownload(String title, JSONObject json){ + public synchronized static boolean skipDownload(String title, JSONObject json) { if ("ok".equals(json.getString("status"))) { JSONArray items = json.getJSONArray("items"); for (Object _item : items) { @@ -18,13 +28,14 @@ public class BTDownloadManager { JSONArray array = getDownload(title); array.add(item.getString("title")); RedisTools.set(title, array.toJSONString()); - Log.i("跳过下载",title); + Log.i("跳过下载", title); return true; } } } return false; } + public synchronized static void download(String title, JSONObject json) { if ("ok".equals(json.getString("status"))) { JSONArray items = json.getJSONArray("items"); @@ -35,14 +46,14 @@ public class BTDownloadManager { //添加到下载器 if (download(title, item.getJSONObject("enclosure").getString("link"))) { //发通知到QQ - RedisTools.setHashMap("rss",PatternTools.getMagnetHash(item.getJSONObject("enclosure").getString("link")),item.toJSONString()); + RedisTools.setHashMap("rss", getTorrentFileHash(item.getJSONObject("enclosure").getString("link")), item.toJSONString()); JSONArray array = getDownload(title); array.add(item.getString("title")); RedisTools.set(title, array.toJSONString()); if (item.containsKey("thumbnail")) { - onSend(item.getString("thumbnail"), item,item.getJSONObject("enclosure").getString("link")); + onSend(item.getString("thumbnail"), item, item.getJSONObject("enclosure").getString("link")); } else { - onSend(null, item,item.getJSONObject("enclosure").getString("link")); + onSend(null, item, item.getJSONObject("enclosure").getString("link")); } } else { Log.i("BT", "添加到下载器失败:" + item.getString("title")); @@ -86,7 +97,7 @@ public class BTDownloadManager { return false; } - private static JSONArray getDownload(String title) { + private static JSONArray getDownload(String title) { String _title = RedisTools.get(title); if (StringUtils.isEmpty(_title)) { return new JSONArray(); @@ -105,18 +116,18 @@ public class BTDownloadManager { return array.contains(key); } - 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); System.out.println("path = " + path + ", filename = " + filename + ", hash1 = " + hash1 + ", hash2 = " + hash2 + ", tid = " + tid); - String hash=StringUtils.isEmpty(hash1)?StringUtils.isEmpty(hash2)?null:hash2:hash1; - if(hash!=null){ + String hash = StringUtils.isEmpty(hash1) ? StringUtils.isEmpty(hash2) ? null : hash2 : hash1; + if (hash != null) { String map = RedisTools.getHashMap("rss", hash); System.out.println("map = " + map); - JSONObject item=JSON.parseObject(map); + JSONObject item = JSON.parseObject(map); if (item.containsKey("thumbnail")) { - onSend(item.getString("thumbnail"), item,item.getJSONObject("enclosure").getString("link")); + onSend(item.getString("thumbnail"), item, item.getJSONObject("enclosure").getString("link")); } else { - onSend(null, item,item.getJSONObject("enclosure").getString("link")); + onSend(null, item, item.getJSONObject("enclosure").getString("link")); } } } @@ -136,4 +147,30 @@ public class BTDownloadManager { }*/ AppTools.exec("/home/yutou/public/servier/tinyMediaManager/tinyMediaManager tvshow -u --scrapeUnscraped", null, false, true); } + + public static String getTorrentFileHash(String magnet) { + String hash=null; + try { + ProtocolContext.getInstance().register(MagnetProtocol.getInstance()); + ITaskSession session = ProtocolContext.getInstance().buildTaskSession(magnet); + hash=session.getName(); + Tools.delDir("download"); + } catch (DownloadException e) { + e.printStackTrace(); + } + return hash; + } + + public static void main(String[] args) { + File file = new File("[织梦字幕组]与猫共度的夜晚 夜は猫といっしょ[17][第十七夜][GB_JP][AVC][1080P].mp4.torrent"); + //Snail snail = Snail.SnailBuilder.newBuilder().enableAllProtocol().buildSync(); + try { + ProtocolContext.getInstance().register(MagnetProtocol.getInstance()); + ITaskSession session = ProtocolContext.getInstance().buildTaskSession("magnet:?xt=urn:btih:IQ4GD4AYEJP3PSLB26QTLUP27UDQ4RRX&dn=&tr=http%3A%2F%2F104.143.10.186%3A8000%2Fannounce&tr=udp%3A%2F%2F104.143.10.186%3A8000%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=http%3A%2F%2Ftracker3.itzmx.com%3A6961%2Fannounce&tr=http%3A%2F%2Ftracker4.itzmx.com%3A2710%2Fannounce&tr=http%3A%2F%2Ftracker.publicbt.com%3A80%2Fannounce&tr=http%3A%2F%2Ftracker.prq.to%2Fannounce&tr=http%3A%2F%2Fopen.acgtracker.com%3A1096%2Fannounce&tr=https%3A%2F%2Ft-115.rhcloud.com%2Fonly_for_ylbud&tr=http%3A%2F%2Ftracker1.itzmx.com%3A8080%2Fannounce&tr=http%3A%2F%2Ftracker2.itzmx.com%3A6961%2Fannounce&tr=udp%3A%2F%2Ftracker1.itzmx.com%3A8080%2Fannounce&tr=udp%3A%2F%2Ftracker2.itzmx.com%3A6961%2Fannounce&tr=udp%3A%2F%2Ftracker3.itzmx.com%3A6961%2Fannounce&tr=udp%3A%2F%2Ftracker4.itzmx.com%3A2710%2Fannounce&tr=http%3A%2F%2Ftr.bangumi.moe%3A6969%2Fannounce&tr=http%3A%2F%2Ft.nyaatracker.com%2Fannounce&tr=http%3A%2F%2Fopen.nyaatorrents.info%3A6544%2Fannounce&tr=http%3A%2F%2Ft2.popgo.org%3A7456%2Fannonce&tr=http%3A%2F%2Fshare.camoe.cn%3A8080%2Fannounce&tr=http%3A%2F%2Fopentracker.acgnx.se%2Fannounce&tr=http%3A%2F%2Ftracker.acgnx.se%2Fannounce&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr=http%3A%2F%2Fsukebei.tracker.wf%3A8888%2Fannounce&tr=http%3A%2F%2Ft.acg.rip%3A6699%2Fannounce&tr=https%3A%2F%2Ftr.bangumi.moe%3A9696%2Fannounce&tr=http%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=wss%3A%2F%2Ftracker.openwebtorrent.com%3A443%2Fannounce&tr=http%3A%2F%2F1337.abcvg.info%2Fannounce&tr=http%3A%2F%2F207.241.226.111%3A6969%2Fannounce&tr=http%3A%2F%2F207.241.231.226%3A6969%2Fannounce&tr=http%3A%2F%2F%5B2001%3A1b10%3A1000%3A8101%3A0%3A242%3Aac11%3A2%5D%3A6969%2Fannounce&tr=http%3A%2F%2F%5B2001%3A470%3A1%3A189%3A0%3A1%3A2%3A3%5D%3A6969%2Fannounce&tr=http%3A%2F%2F%5B2a04%3Aac00%3A1%3A3dd8%3A%3A1%3A2710%5D%3A2710%2Fannounce&tr=http%3A%2F%2Fbt.okmp3.ru%3A2710%2Fannounce&tr=http%3A%2F%2Ffxtt.ru%2Fannounce&tr=http%3A%2F%2Fhome.yxgz.vip%3A6969%2Fannounce&tr=http%3A%2F%2Fmediaclub.tv%2Fannounce.php&tr=http%3A%2F%2Fmilanesitracker.tekcities.com%2Fannounce&tr=http%3A%2F%2Fopen.acgnxtracker.com%2Fannounce&tr=http%3A%2F%2Fopen.tracker.ink%3A6969%2Fannounce&tr=http%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=http%3A%2F%2Fopentracker.xyz%2Fannounce&tr=http%3A%2F%2Fretracker.hotplug.ru%3A2710%2Fannounce&tr=http%3A%2F%2Ft.overflow.biz%3A6969%2Fannounce&tr=http%3A%2F%2Ft.publictracker.xyz%3A6969%2Fannounce&tr=http%3A%2F%2Ftorrenttracker.nwc.acsalaska.net%3A6969%2Fannounce&tr=http%3A%2F%2Ftr.cili001.com%3A8070%2Fannounce&tr=http%3A%2F%2Ftracker.birkenwald.de%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.bt4g.com%3A2095%2Fannounce&tr=http%3A%2F%2Ftracker.dler.org%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.files.fm%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.gbitt.info%2Fannounce&tr=http%3A%2F%2Ftracker.hiyj.cn%2Fannounce&tr=http%3A%2F%2Ftracker.ipv6tracker.ru%2Fannounce&tr=http%3A%2F%2Ftracker.lelux.fi%2Fannounce&tr=http%3A%2F%2Ftracker.mywaifu.best%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.srv00.com%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.zerobytes.xyz%3A1337%2Fannounce&tr=http%3A%2F%2Ftracker2.dler.org%2Fannounce&tr=http%3A%2F%2Fvps02.net.orel.ru%2Fannounce&tr=https%3A%2F%2F1337.abcvg.info%2Fannounce&tr=https%3A%2F%2Fcarbon-bonsai-621.appspot.com%2Fannounce&tr=https%3A%2F%2Fchihaya-heroku.120181311.xyz%2Fannounce&tr=https%3A%2F%2Fopentracker.cc%2Fannounce&tr=https%3A%2F%2Fopentracker.i2p.rocks%2Fannounce&tr=https%3A%2F%2Ftp.m-team.cc%2Fannounce.php&tr=https%3A%2F%2Ftr.abiir.top%2Fannounce&tr=https%3A%2F%2Ftr.abir.ga%2Fannounce&tr=https%3A%2F%2Ftr.abirxo.cf%2Fannounce&tr=https%3A%2F%2Ftr.burnabyhighstar.com%2Fannounce&tr=https%3A%2F%2Ftr.doogh.club%2Fannounce&tr=https%3A%2F%2Ftr.fuckbitcoin.xyz%2Fannounce&tr=https%3A%2F%2Ftr.highstar.shop%2Fannounce&tr=https%3A%2F%2Ftr.ready4.icu%2Fannounce&tr=https%3A%2F%2Ftr.torland.ga%2Fannounce&tr=https%3A%2F%2Ftracker.babico.name.tr%2Fannounce&tr=https%3A%2F%2Ftracker.imgoingto.icu%2Fannounce&tr=https%3A%2F%2Ftracker.iriseden.fr%2Fannounce&tr=https%3A%2F%2Ftracker.kuroy.me%2Fannounce&tr=https%3A%2F%2Ftracker.lelux.fi%2Fannounce&tr=https%3A%2F%2Ftracker.lilithraws.cf%2Fannounce&tr=https%3A%2F%2Ftracker.lilithraws.org%2Fannounce&tr=https%3A%2F%2Ftracker.nanoha.org%2Fannounce&tr=https%3A%2F%2Ftracker.nitrix.me%2Fannounce&tr=https%3A%2F%2Ftracker.yarr.pt%2Fannounce&tr=https%3A%2F%2Ftrackme.theom.nz%2Fannounce&tr=ws%3A%2F%2Fhub.bugout.link%3A80%2Fannounce&tr=http%3A%2F%2Fretracker.joxnet.ru%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%2Fannounce&tr=http%3A%2F%2Ftracker.skyts.net%3A6969%2Fannounce&tr=https%3A%2F%2Fabir0dev.github.io%2Fannounce&tr=https%3A%2F%2Ftracker.foreverpirates.co%2Fannounce&tr=http%3A%2F%2Ftracker.loadbt.com%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.swarm3.network%3A6969%2Fannounce&tr=http%3A%2F%2Fopenbittorrent.com%2Fannounce&tr=http%3A%2F%2Fpow7.com%2Fannounce&tr=http%3A%2F%2Fbuny.uk%3A6969%2Fannounce&tr=http%3A%2F%2Ffosstorrents.com%3A6969%2Fannounce&tr=http%3A%2F%2Fftp.pet%3A7777%2Fannounce&tr=http%3A%2F%2Frt.optizone.ru%2Fannounce&tr=http%3A%2F%2Ftracker.merded.xyz%3A8000%2Fannounce&tr=http%3A%2F%2Ftracker1.bt.moack.co.kr%2Fannounce&tr=https%3A%2F%2Ftracker.moeblog.cn%2Fannounce&tr=https%3A%2F%2Ftracker.tamersunion.org%2Fannounce&tr=http%3A%2F%2Fipv6.1337.cx%3A6969%2Fannounce&tr=http%3A%2F%2Fipv6.govt.hu%3A6969%2Fannounce&tr=http%3A%2F%2Ftracker.k.vu%3A6969%2Fannounce&tr=https%3A%2F%2Ftracker.feb217.tk%3A8443%2Fannounce&tr=https%3A%2F%2Ftracker.m-team.cc%2Fannounce.php"); + System.out.println(session.getName()); + Tools.delDir("download"); + } catch (DownloadException e) { + throw new RuntimeException(e); + } + } } diff --git a/src/main/java/com/yutou/nas/utils/Tools.java b/src/main/java/com/yutou/nas/utils/Tools.java index be5546b..2c20623 100644 --- a/src/main/java/com/yutou/nas/utils/Tools.java +++ b/src/main/java/com/yutou/nas/utils/Tools.java @@ -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(); + } + } }