diff --git a/src/main/java/com/yutou/nas/Controllers/QQBot.java b/src/main/java/com/yutou/nas/Controllers/QQBot.java index 74ea796..4a951ab 100644 --- a/src/main/java/com/yutou/nas/Controllers/QQBot.java +++ b/src/main/java/com/yutou/nas/Controllers/QQBot.java @@ -33,9 +33,9 @@ public class QQBot { }else{ Tools.download(imgUrl, new DownloadInterface() { @Override - public void onDownload(String file) { + public void onDownload(File file) { super.onDownload(file); - QQBotManager.getInstance().sendMessage(new File(file),msg); + QQBotManager.getInstance().sendMessage(file,msg); } @Override diff --git a/src/main/java/com/yutou/nas/NasApplication.java b/src/main/java/com/yutou/nas/NasApplication.java index 0b818f0..35502a6 100644 --- a/src/main/java/com/yutou/nas/NasApplication.java +++ b/src/main/java/com/yutou/nas/NasApplication.java @@ -1,12 +1,15 @@ package com.yutou.nas; import com.yutou.nas.Datas.AppData; +import com.yutou.nas.utils.BTDownloadManager; import com.yutou.nas.utils.ConfigTools; import com.yutou.nas.utils.QQBotManager; import com.yutou.nas.utils.RedisTools; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Import; +@Import(BTDownloadManager.class) @SpringBootApplication public class NasApplication { public static final String version="1.0.0"; diff --git a/src/main/java/com/yutou/nas/Services/IBangumiService.java b/src/main/java/com/yutou/nas/Services/IBangumiService.java new file mode 100644 index 0000000..c475b66 --- /dev/null +++ b/src/main/java/com/yutou/nas/Services/IBangumiService.java @@ -0,0 +1,9 @@ +package com.yutou.nas.Services; + +import com.yutou.nas.mybatis.model.BangumiItem; + +import java.util.List; + +public interface IBangumiService { + List getAllBangumi(); +} diff --git a/src/main/java/com/yutou/nas/Services/impl/BangumiServiceImpl.java b/src/main/java/com/yutou/nas/Services/impl/BangumiServiceImpl.java new file mode 100644 index 0000000..089a5ab --- /dev/null +++ b/src/main/java/com/yutou/nas/Services/impl/BangumiServiceImpl.java @@ -0,0 +1,20 @@ +package com.yutou.nas.Services.impl; + +import com.yutou.nas.Services.IBangumiService; +import com.yutou.nas.mybatis.dao.BangumiItemDao; +import com.yutou.nas.mybatis.model.BangumiItem; +import com.yutou.nas.mybatis.model.BangumiItemExample; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service("BangumiService") +public class BangumiServiceImpl implements IBangumiService { + @Resource + BangumiItemDao itemDao; + @Override + public List getAllBangumi() { + return itemDao.selectByExample(new BangumiItemExample()); + } +} diff --git a/src/main/java/com/yutou/nas/interfaces/DownloadInterface.java b/src/main/java/com/yutou/nas/interfaces/DownloadInterface.java index c09ec5b..cec4928 100644 --- a/src/main/java/com/yutou/nas/interfaces/DownloadInterface.java +++ b/src/main/java/com/yutou/nas/interfaces/DownloadInterface.java @@ -1,6 +1,9 @@ package com.yutou.nas.interfaces; +import java.io.File; + public abstract class DownloadInterface { - public void onDownload(String file){}; + public void onDownloading(double soFarBytes, double totalBytes){}; + public void onDownload(File file){}; public void onError(Exception e){}; } diff --git a/src/main/java/com/yutou/nas/utils/AppTools.java b/src/main/java/com/yutou/nas/utils/AppTools.java new file mode 100644 index 0000000..15b324a --- /dev/null +++ b/src/main/java/com/yutou/nas/utils/AppTools.java @@ -0,0 +1,10 @@ +package com.yutou.nas.utils; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class AppTools { + public static String getToDayNowTimeToString(){ + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + } +} diff --git a/src/main/java/com/yutou/nas/utils/BTDownloadManager.java b/src/main/java/com/yutou/nas/utils/BTDownloadManager.java new file mode 100644 index 0000000..f68620e --- /dev/null +++ b/src/main/java/com/yutou/nas/utils/BTDownloadManager.java @@ -0,0 +1,151 @@ +package com.yutou.nas.utils; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.yutou.nas.Services.IBangumiService; +import com.yutou.nas.bangumi.AnimationData; +import com.yutou.nas.interfaces.DownloadInterface; +import com.yutou.nas.mybatis.model.BangumiItem; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.io.File; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +public class BTDownloadManager implements ApplicationContextAware { + private static String tmpJson = "{\"status\":\"ok\",\"feed\":{\"url\":\"http://share.dmhy.org/topics/rss/page/1/rss.xml?keyword=无职转生&order=date-desc&sort_id=2&team_id=604\",\"title\":\"c.c动漫-動畫-動漫花園資源網\",\"link\":\"http://share.dmhy.org/\",\"author\":\"\",\"description\":\"動漫花園資訊網是一個動漫愛好者交流的平台,提供最及時,最全面的動畫,漫畫,動漫音樂,動漫下載,BT,ED,動漫遊戲,資訊,分享,交流,讨论.\",\"image\":\"\"},\"items\":[{\"title\":\"\u200B[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][11][BIG5][1080P][MP4]\",\"pubDate\":\"2021-03-25 07:11:12\",\"link\":\"http://share.dmhy.org/topics/view/563676_c_c_1_11_BIG5_1080P_MP4.html\",\"guid\":\"http://share.dmhy.org/topics/view/563676_c_c_1_11_BIG5_1080P_MP4.html\",\"author\":\"lleeopen\",\"thumbnail\":\"https://img.vim-cn.com/43/a8c19df5571ea68c64ed4945cc0187bd82e2f1.jpg\",\"description\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n

\\n\",\"content\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n

\\n\",\"enclosure\":{\"link\":\"magnet:?xt=urn:btih:LVYN5MDZTBFRNNSPYYXKOKJA5PNGB4FD&dn=&tr=http://104.238.198.186:8000/announce&tr=udp://104.238.198.186:8000/announce&tr=http://tracker.openbittorrent.com:80/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=http://tracker4.itzmx.com:2710/announce&tr=http://tracker.publicbt.com:80/announce&tr=http://tracker.prq.to/announce&tr=http://open.acgtracker.com:1096/announce&tr=https://t-115.rhcloud.com/only_for_ylbud&tr=http://tracker1.itzmx.com:8080/announce&tr=http://tracker2.itzmx.com:6961/announce&tr=udp://tracker1.itzmx.com:8080/announce&tr=udp://tracker2.itzmx.com:6961/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=udp://tracker4.itzmx.com:2710/announce&tr=http://tr.bangumi.moe:6969/announce&tr=http://t.nyaatracker.com/announce&tr=http://open.nyaatorrents.info:6544/announce&tr=http://t2.popgo.org:7456/annonce&tr=http://share.camoe.cn:8080/announce&tr=http://opentracker.acgnx.se/announce&tr=http://tracker.acgnx.se/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=http://t.acg.rip:6699/announce&tr=http://opentracker.acgnx.com:6869/announce\",\"type\":\"application/x-bittorrent\",\"length\":1},\"categories\":[\"動畫\"]},{\"title\":\"\u200B[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][10][BIG5][1080P][MP4]\",\"pubDate\":\"2021-03-15 05:12:42\",\"link\":\"http://share.dmhy.org/topics/view/562725_c_c_1_10_BIG5_1080P_MP4.html\",\"guid\":\"http://share.dmhy.org/topics/view/562725_c_c_1_10_BIG5_1080P_MP4.html\",\"author\":\"lleeopen\",\"thumbnail\":\"https://img.vim-cn.com/43/a8c19df5571ea68c64ed4945cc0187bd82e2f1.jpg\",\"description\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"content\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"enclosure\":{\"link\":\"magnet:?xt=urn:btih:QWEVVDWHSWISWGLOQJWD2PRHP3OYJBD3&dn=&tr=http://104.238.198.186:8000/announce&tr=udp://104.238.198.186:8000/announce&tr=http://tracker.openbittorrent.com:80/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=http://tracker4.itzmx.com:2710/announce&tr=http://tracker.publicbt.com:80/announce&tr=http://tracker.prq.to/announce&tr=http://open.acgtracker.com:1096/announce&tr=https://t-115.rhcloud.com/only_for_ylbud&tr=http://tracker1.itzmx.com:8080/announce&tr=http://tracker2.itzmx.com:6961/announce&tr=udp://tracker1.itzmx.com:8080/announce&tr=udp://tracker2.itzmx.com:6961/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=udp://tracker4.itzmx.com:2710/announce&tr=http://tr.bangumi.moe:6969/announce&tr=http://t.nyaatracker.com/announce&tr=http://open.nyaatorrents.info:6544/announce&tr=http://t2.popgo.org:7456/annonce&tr=http://share.camoe.cn:8080/announce&tr=http://opentracker.acgnx.se/announce&tr=http://tracker.acgnx.se/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=http://t.acg.rip:6699/announce&tr=http://opentracker.acgnx.com:6869/announce\",\"type\":\"application/x-bittorrent\",\"length\":1},\"categories\":[\"動畫\"]},{\"title\":\"\u200B[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][09][BIG5][1080P][MP4]\",\"pubDate\":\"2021-03-14 12:56:28\",\"link\":\"http://share.dmhy.org/topics/view/562653_c_c_1_09_BIG5_1080P_MP4.html\",\"guid\":\"http://share.dmhy.org/topics/view/562653_c_c_1_09_BIG5_1080P_MP4.html\",\"author\":\"lleeopen\",\"thumbnail\":\"https://img.vim-cn.com/43/a8c19df5571ea68c64ed4945cc0187bd82e2f1.jpg\",\"description\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"content\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"enclosure\":{\"link\":\"magnet:?xt=urn:btih:Z6M3M7Y5YTIKY4GGCG7PGEP3WWGORS7T&dn=&tr=http://104.238.198.186:8000/announce&tr=udp://104.238.198.186:8000/announce&tr=http://tracker.openbittorrent.com:80/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=http://tracker4.itzmx.com:2710/announce&tr=http://tracker.publicbt.com:80/announce&tr=http://tracker.prq.to/announce&tr=http://open.acgtracker.com:1096/announce&tr=https://t-115.rhcloud.com/only_for_ylbud&tr=http://tracker1.itzmx.com:8080/announce&tr=http://tracker2.itzmx.com:6961/announce&tr=udp://tracker1.itzmx.com:8080/announce&tr=udp://tracker2.itzmx.com:6961/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=udp://tracker4.itzmx.com:2710/announce&tr=http://tr.bangumi.moe:6969/announce&tr=http://t.nyaatracker.com/announce&tr=http://open.nyaatorrents.info:6544/announce&tr=http://t2.popgo.org:7456/annonce&tr=http://share.camoe.cn:8080/announce&tr=http://opentracker.acgnx.se/announce&tr=http://tracker.acgnx.se/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=http://t.acg.rip:6699/announce&tr=http://opentracker.acgnx.com:6869/announce\",\"type\":\"application/x-bittorrent\",\"length\":1},\"categories\":[\"動畫\"]},{\"title\":\"\u200B[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][08][BIG5][1080P][MP4]\",\"pubDate\":\"2021-03-14 12:56:00\",\"link\":\"http://share.dmhy.org/topics/view/562652_c_c_1_08_BIG5_1080P_MP4.html\",\"guid\":\"http://share.dmhy.org/topics/view/562652_c_c_1_08_BIG5_1080P_MP4.html\",\"author\":\"lleeopen\",\"thumbnail\":\"https://img.vim-cn.com/43/a8c19df5571ea68c64ed4945cc0187bd82e2f1.jpg\",\"description\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"content\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"enclosure\":{\"link\":\"magnet:?xt=urn:btih:BMXA6AZF7BCYQ2CIZOS5I6XPTXUZ2W3E&dn=&tr=http://104.238.198.186:8000/announce&tr=udp://104.238.198.186:8000/announce&tr=http://tracker.openbittorrent.com:80/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=http://tracker4.itzmx.com:2710/announce&tr=http://tracker.publicbt.com:80/announce&tr=http://tracker.prq.to/announce&tr=http://open.acgtracker.com:1096/announce&tr=https://t-115.rhcloud.com/only_for_ylbud&tr=http://tracker1.itzmx.com:8080/announce&tr=http://tracker2.itzmx.com:6961/announce&tr=udp://tracker1.itzmx.com:8080/announce&tr=udp://tracker2.itzmx.com:6961/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=udp://tracker4.itzmx.com:2710/announce&tr=http://tr.bangumi.moe:6969/announce&tr=http://t.nyaatracker.com/announce&tr=http://open.nyaatorrents.info:6544/announce&tr=http://t2.popgo.org:7456/annonce&tr=http://share.camoe.cn:8080/announce&tr=http://opentracker.acgnx.se/announce&tr=http://tracker.acgnx.se/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=http://t.acg.rip:6699/announce&tr=http://opentracker.acgnx.com:6869/announce\",\"type\":\"application/x-bittorrent\",\"length\":1},\"categories\":[\"動畫\"]},{\"title\":\"\u200B[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][07][BIG5][1080P][MP4]\",\"pubDate\":\"2021-02-23 09:41:47\",\"link\":\"http://share.dmhy.org/topics/view/560768_c_c_1_07_BIG5_1080P_MP4.html\",\"guid\":\"http://share.dmhy.org/topics/view/560768_c_c_1_07_BIG5_1080P_MP4.html\",\"author\":\"lleeopen\",\"thumbnail\":\"https://img.vim-cn.com/43/a8c19df5571ea68c64ed4945cc0187bd82e2f1.jpg\",\"description\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"content\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"enclosure\":{\"link\":\"magnet:?xt=urn:btih:DDIM47E2UJAXRV54JJQFFPJ7SLYZZYQJ&dn=&tr=http://104.238.198.186:8000/announce&tr=udp://104.238.198.186:8000/announce&tr=http://tracker.openbittorrent.com:80/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=http://tracker4.itzmx.com:2710/announce&tr=http://tracker.publicbt.com:80/announce&tr=http://tracker.prq.to/announce&tr=http://open.acgtracker.com:1096/announce&tr=https://t-115.rhcloud.com/only_for_ylbud&tr=http://tracker1.itzmx.com:8080/announce&tr=http://tracker2.itzmx.com:6961/announce&tr=udp://tracker1.itzmx.com:8080/announce&tr=udp://tracker2.itzmx.com:6961/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=udp://tracker4.itzmx.com:2710/announce&tr=http://tr.bangumi.moe:6969/announce&tr=http://t.nyaatracker.com/announce&tr=http://open.nyaatorrents.info:6544/announce&tr=http://t2.popgo.org:7456/annonce&tr=http://share.camoe.cn:8080/announce&tr=http://opentracker.acgnx.se/announce&tr=http://tracker.acgnx.se/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=http://t.acg.rip:6699/announce&tr=http://opentracker.acgnx.com:6869/announce\",\"type\":\"application/x-bittorrent\",\"length\":1},\"categories\":[\"動畫\"]},{\"title\":\"\u200B[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][06][BIG5][1080P][MP4]\",\"pubDate\":\"2021-02-14 16:51:36\",\"link\":\"http://share.dmhy.org/topics/view/559914_c_c_1_06_BIG5_1080P_MP4.html\",\"guid\":\"http://share.dmhy.org/topics/view/559914_c_c_1_06_BIG5_1080P_MP4.html\",\"author\":\"lleeopen\",\"thumbnail\":\"https://img.vim-cn.com/43/a8c19df5571ea68c64ed4945cc0187bd82e2f1.jpg\",\"description\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"content\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"enclosure\":{\"link\":\"magnet:?xt=urn:btih:MFQR2G2AEZLHXONGKII47FXP2DPE4C3G&dn=&tr=http://104.238.198.186:8000/announce&tr=udp://104.238.198.186:8000/announce&tr=http://tracker.openbittorrent.com:80/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=http://tracker4.itzmx.com:2710/announce&tr=http://tracker.publicbt.com:80/announce&tr=http://tracker.prq.to/announce&tr=http://open.acgtracker.com:1096/announce&tr=https://t-115.rhcloud.com/only_for_ylbud&tr=http://tracker1.itzmx.com:8080/announce&tr=http://tracker2.itzmx.com:6961/announce&tr=udp://tracker1.itzmx.com:8080/announce&tr=udp://tracker2.itzmx.com:6961/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=udp://tracker4.itzmx.com:2710/announce&tr=http://tr.bangumi.moe:6969/announce&tr=http://t.nyaatracker.com/announce&tr=http://open.nyaatorrents.info:6544/announce&tr=http://t2.popgo.org:7456/annonce&tr=http://share.camoe.cn:8080/announce&tr=http://opentracker.acgnx.se/announce&tr=http://tracker.acgnx.se/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=http://t.acg.rip:6699/announce&tr=http://opentracker.acgnx.com:6869/announce\",\"type\":\"application/x-bittorrent\",\"length\":1},\"categories\":[\"動畫\"]},{\"title\":\"\u200B[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][05][BIG5][1080P][MP4]\",\"pubDate\":\"2021-02-07 16:33:23\",\"link\":\"http://share.dmhy.org/topics/view/559282_c_c_1_05_BIG5_1080P_MP4.html\",\"guid\":\"http://share.dmhy.org/topics/view/559282_c_c_1_05_BIG5_1080P_MP4.html\",\"author\":\"lleeopen\",\"thumbnail\":\"https://img.vim-cn.com/43/a8c19df5571ea68c64ed4945cc0187bd82e2f1.jpg\",\"description\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"content\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"enclosure\":{\"link\":\"magnet:?xt=urn:btih:TUDQWT6OAHYS2LFTCURHRLNZS6PVZXX5&dn=&tr=http://104.238.198.186:8000/announce&tr=udp://104.238.198.186:8000/announce&tr=http://tracker.openbittorrent.com:80/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=http://tracker4.itzmx.com:2710/announce&tr=http://tracker.publicbt.com:80/announce&tr=http://tracker.prq.to/announce&tr=http://open.acgtracker.com:1096/announce&tr=https://t-115.rhcloud.com/only_for_ylbud&tr=http://tracker1.itzmx.com:8080/announce&tr=http://tracker2.itzmx.com:6961/announce&tr=udp://tracker1.itzmx.com:8080/announce&tr=udp://tracker2.itzmx.com:6961/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=udp://tracker4.itzmx.com:2710/announce&tr=http://tr.bangumi.moe:6969/announce&tr=http://t.nyaatracker.com/announce&tr=http://open.nyaatorrents.info:6544/announce&tr=http://t2.popgo.org:7456/annonce&tr=http://share.camoe.cn:8080/announce&tr=http://opentracker.acgnx.se/announce&tr=http://tracker.acgnx.se/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=http://t.acg.rip:6699/announce&tr=http://opentracker.acgnx.com:6869/announce\",\"type\":\"application/x-bittorrent\",\"length\":1},\"categories\":[\"動畫\"]},{\"title\":\"\u200B[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][04][BIG5][1080P][MP4]\",\"pubDate\":\"2021-01-31 16:36:34\",\"link\":\"http://share.dmhy.org/topics/view/558624_c_c_1_04_BIG5_1080P_MP4.html\",\"guid\":\"http://share.dmhy.org/topics/view/558624_c_c_1_04_BIG5_1080P_MP4.html\",\"author\":\"lleeopen\",\"thumbnail\":\"https://img.vim-cn.com/43/a8c19df5571ea68c64ed4945cc0187bd82e2f1.jpg\",\"description\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"content\":\"\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"enclosure\":{\"link\":\"magnet:?xt=urn:btih:MVJ3F3DGW5Y4Z7LONWEWN6GBSQAC3TKQ&dn=&tr=http://104.238.198.186:8000/announce&tr=udp://104.238.198.186:8000/announce&tr=http://tracker.openbittorrent.com:80/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=http://tracker4.itzmx.com:2710/announce&tr=http://tracker.publicbt.com:80/announce&tr=http://tracker.prq.to/announce&tr=http://open.acgtracker.com:1096/announce&tr=https://t-115.rhcloud.com/only_for_ylbud&tr=http://tracker1.itzmx.com:8080/announce&tr=http://tracker2.itzmx.com:6961/announce&tr=udp://tracker1.itzmx.com:8080/announce&tr=udp://tracker2.itzmx.com:6961/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=udp://tracker4.itzmx.com:2710/announce&tr=http://tr.bangumi.moe:6969/announce&tr=http://t.nyaatracker.com/announce&tr=http://open.nyaatorrents.info:6544/announce&tr=http://t2.popgo.org:7456/annonce&tr=http://share.camoe.cn:8080/announce&tr=http://opentracker.acgnx.se/announce&tr=http://tracker.acgnx.se/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=http://t.acg.rip:6699/announce&tr=http://opentracker.acgnx.com:6869/announce\",\"type\":\"application/x-bittorrent\",\"length\":1},\"categories\":[\"動畫\"]},{\"title\":\"\u200B[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][03][BIG5][1080P][MP4]\",\"pubDate\":\"2021-01-25 05:27:50\",\"link\":\"http://share.dmhy.org/topics/view/558007_c_c_1_03_BIG5_1080P_MP4.html\",\"guid\":\"http://share.dmhy.org/topics/view/558007_c_c_1_03_BIG5_1080P_MP4.html\",\"author\":\"lleeopen\",\"thumbnail\":\"https://img.vim-cn.com/43/a8c19df5571ea68c64ed4945cc0187bd82e2f1.jpg\",\"description\":\"\\n

[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][03][BIG5][1080P][MP4]

\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"content\":\"\\n

[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][03][BIG5][1080P][MP4]

\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"enclosure\":{\"link\":\"magnet:?xt=urn:btih:OR6WDFDYDAPOGFR3FY3LLCF25P3PHUTG&dn=&tr=http://104.238.198.186:8000/announce&tr=udp://104.238.198.186:8000/announce&tr=http://tracker.openbittorrent.com:80/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=http://tracker4.itzmx.com:2710/announce&tr=http://tracker.publicbt.com:80/announce&tr=http://tracker.prq.to/announce&tr=http://open.acgtracker.com:1096/announce&tr=https://t-115.rhcloud.com/only_for_ylbud&tr=http://tracker1.itzmx.com:8080/announce&tr=http://tracker2.itzmx.com:6961/announce&tr=udp://tracker1.itzmx.com:8080/announce&tr=udp://tracker2.itzmx.com:6961/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=udp://tracker4.itzmx.com:2710/announce&tr=http://tr.bangumi.moe:6969/announce&tr=http://t.nyaatracker.com/announce&tr=http://open.nyaatorrents.info:6544/announce&tr=http://t2.popgo.org:7456/annonce&tr=http://share.camoe.cn:8080/announce&tr=http://opentracker.acgnx.se/announce&tr=http://tracker.acgnx.se/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=http://t.acg.rip:6699/announce&tr=http://opentracker.acgnx.com:6869/announce\",\"type\":\"application/x-bittorrent\",\"length\":1},\"categories\":[\"動畫\"]},{\"title\":\"\u200B[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][02][BIG5][1080P][MP4]\",\"pubDate\":\"2021-01-17 16:35:55\",\"link\":\"http://share.dmhy.org/topics/view/557306_c_c_1_02_BIG5_1080P_MP4.html\",\"guid\":\"http://share.dmhy.org/topics/view/557306_c_c_1_02_BIG5_1080P_MP4.html\",\"author\":\"lleeopen\",\"thumbnail\":\"https://img.vim-cn.com/43/a8c19df5571ea68c64ed4945cc0187bd82e2f1.jpg\",\"description\":\"\\n

[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][02][BIG5][1080P][MP4]

\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"content\":\"\\n

[c.c動漫][1月新番][無職轉生~到了異世界就拿出真本事~][02][BIG5][1080P][MP4]

\\n

P.s.請使用正規的BT軟件下載(utorrent、qbittorrent、bitcomet),下載完成之後不要立即關閉下載軟件,盡量保持上傳一段時間~~

\\n


\\n\",\"enclosure\":{\"link\":\"magnet:?xt=urn:btih:TGON2SU75VGPYQBOHMCXF7M6MNSYS7J3&dn=&tr=http://104.238.198.186:8000/announce&tr=udp://104.238.198.186:8000/announce&tr=http://tracker.openbittorrent.com:80/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=http://tracker4.itzmx.com:2710/announce&tr=http://tracker.publicbt.com:80/announce&tr=http://tracker.prq.to/announce&tr=http://open.acgtracker.com:1096/announce&tr=https://t-115.rhcloud.com/only_for_ylbud&tr=http://tracker1.itzmx.com:8080/announce&tr=http://tracker2.itzmx.com:6961/announce&tr=udp://tracker1.itzmx.com:8080/announce&tr=udp://tracker2.itzmx.com:6961/announce&tr=udp://tracker3.itzmx.com:6961/announce&tr=udp://tracker4.itzmx.com:2710/announce&tr=http://tr.bangumi.moe:6969/announce&tr=http://t.nyaatracker.com/announce&tr=http://open.nyaatorrents.info:6544/announce&tr=http://t2.popgo.org:7456/annonce&tr=http://share.camoe.cn:8080/announce&tr=http://opentracker.acgnx.se/announce&tr=http://tracker.acgnx.se/announce&tr=http://nyaa.tracker.wf:7777/announce&tr=http://t.acg.rip:6699/announce&tr=http://opentracker.acgnx.com:6869/announce\",\"type\":\"application/x-bittorrent\",\"length\":1},\"categories\":[\"動畫\"]}]}"; + private static ApplicationContext applicationContext; + @Resource + IBangumiService bangumiService; + private static BTDownloadManager manager; + + public static BTDownloadManager getInstance() { + if (manager == null) { + manager = new BTDownloadManager(); + if (manager.bangumiService == null) + manager.bangumiService = getBean(IBangumiService.class); + } + return manager; + } + + private BTDownloadManager() { + } + + public String getRSSUrl(BangumiItem item) { + String url = "https://api.rss2json.com/v1/api.json?rss_url=%s&api_key=wtfm5pebya13pnl8rtu51wfgfpte0mb9sap1foll&count=500"; + String dmhyUrl = "http://share.dmhy.org/topics/rss/page/1/rss.xml?keyword=%s%s%s&order=date-desc"; + dmhyUrl = String.format(dmhyUrl, + item.getTitlekey().replace(" ", "+"), + item.getCategories().equals("-1") ? "" : String.format("&sort_id=%s", item.getCategories()), + item.getAuthor().equals("-1") ? "" : String.format("&team_id=%s", item.getAuthor())); + try { + return String.format(url, URLEncoder.encode(dmhyUrl, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return null; + } + } + + private void download(BangumiItem bangumiItem, JSONObject json) { + if (json.getString("status").equals("ok")) { + JSONArray items = json.getJSONArray("items"); + for (Object _item : items) { + JSONObject item = (JSONObject) _item; + //确认是为下载过的 + if (!isDownload(bangumiItem.getTitle(), item.getString("title"))) { + //添加到下载器 + if (download(bangumiItem.getTitle(), item.getJSONObject("enclosure").getString("link"))) { + //发通知到QQ + if (item.containsKey("thumbnail")) { + HttpTools.download(item.getString("thumbnail"), bangumiItem.getTitle() + ".jpg", new DownloadInterface() { + @Override + public void onDownload(File file) { + super.onDownload(file); + onSend(file,item); + } + + @Override + public void onError(Exception e) { + super.onError(e); + onSend(null,item); + } + + + }); + }else{ + onSend(null,item); + } + } + } + } + } + } + public void onSend(File file, JSONObject item) { + String text="启动下载器\n已提交到下载:"+item.getString("title"); + if(file==null){ + QQBotManager.getInstance().sendMessage(text); + }else{ + QQBotManager.getInstance().sendMessage(file,text); + } + } + public boolean download(String title, String url) { + try { + Runtime.getRuntime().exec(new String[]{"sh" + , "-c" + , String.format("transmission-remote -n yutou:34864394 -w /media/yutou/4t/public/download/anim/%s -a \"%s\" " + , title + , url + )}); + return true; + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + + private JSONArray getDownload(String title) { + String _title = RedisTools.get(title); + if (StringUtils.isEmpty(_title)) { + return new JSONArray(); + } + return JSONArray.parseArray(_title); + } + + private boolean isDownload(String title, String key) { + String _title = RedisTools.get(title); + JSONArray array; + if (StringUtils.isEmpty(_title)) { + return false; + } else { + array = JSONArray.parseArray(_title); + } + return array.contains(key); + } + + public static void main(String[] args) { + AnimationData data = new AnimationData(); + + BangumiItem item = new BangumiItem(); + item.setAuthor(data.nameToValue("lleeopen", true) + ""); + item.setCategories(data.nameToValue("動畫", false) + ""); + item.setTitle("無職轉生~到了異世界就拿出真本事~"); + item.setTitlekey("无职转生"); + String url = new BTDownloadManager().getRSSUrl(item); + System.out.println(url); + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + if (BTDownloadManager.applicationContext == null) + BTDownloadManager.applicationContext = applicationContext; + } + + public static T getBean(Class clazz) { + return applicationContext.getBean(clazz); + } +} diff --git a/src/main/java/com/yutou/nas/utils/HttpTools.java b/src/main/java/com/yutou/nas/utils/HttpTools.java index df7fb2a..714a29d 100644 --- a/src/main/java/com/yutou/nas/utils/HttpTools.java +++ b/src/main/java/com/yutou/nas/utils/HttpTools.java @@ -1,12 +1,10 @@ package com.yutou.nas.utils; import com.alibaba.fastjson.JSONObject; +import com.yutou.nas.interfaces.DownloadInterface; import com.yutou.nas.utils.Interfaces.NetworkInterface; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; +import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; @@ -129,4 +127,60 @@ public class HttpTools { System.out.println(url); //String str=get(url); } + private static String donwloadPath="tmp"+File.separator; + public synchronized static void download(final String url, final String saveName, final DownloadInterface downloadInterface) { + new Thread(new Runnable() { + @Override + public void run() { + File jar = null; + try { + File savePath = new File(donwloadPath); + if (!savePath.exists()) { + savePath.mkdirs(); + } + Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName); + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + + // Log.i(TAG,"获取到网络请求:"+connection.getResponseCode()); + + + InputStream inputStream = connection.getInputStream(); + jar = new File(donwloadPath + saveName + "_tmp.tmp"); + jar.createNewFile(); + Log.i("DOWNLOAD", "临时保存文件:" + jar.getAbsolutePath()); + OutputStream outputStream = new FileOutputStream(jar); + byte[] bytes = new byte[1024]; + double size=connection.getContentLength(); + double downSize=0; + int len; + while ((len = inputStream.read(bytes)) > 0) { + outputStream.write(bytes, 0, len); + downSize+=len; + if(downloadInterface!=null){ + downloadInterface.onDownloading(downSize,size); + } + } + outputStream.close(); + inputStream.close(); + File oldJar = new File(donwloadPath + saveName); + if (oldJar.exists()) { + oldJar.delete(); + } + jar.renameTo(oldJar); + Log.i("DOWNLOAD", "实际保存:" + oldJar.getAbsolutePath() + " " + oldJar.getName()); + if (downloadInterface != null) { + downloadInterface.onDownload(oldJar); + + } + + } catch (Exception e) { + e.printStackTrace(); + if (jar != null) { + jar.delete(); + } + downloadInterface.onError(e); + } + } + }).start(); + } } diff --git a/src/main/java/com/yutou/nas/utils/Log.java b/src/main/java/com/yutou/nas/utils/Log.java new file mode 100644 index 0000000..ff334e4 --- /dev/null +++ b/src/main/java/com/yutou/nas/utils/Log.java @@ -0,0 +1,14 @@ +package com.yutou.nas.utils; + +public class Log { + public static void i(String tag,Object log){ + i('['+tag+']'+log); + } + public static void i(Object log){ + System.out.printf("[%s]%s%n", + AppTools.getToDayNowTimeToString(), + log + ); + + } +} diff --git a/src/main/java/com/yutou/nas/utils/QQBotManager.java b/src/main/java/com/yutou/nas/utils/QQBotManager.java index ecb001b..e60c69f 100644 --- a/src/main/java/com/yutou/nas/utils/QQBotManager.java +++ b/src/main/java/com/yutou/nas/utils/QQBotManager.java @@ -304,9 +304,9 @@ public class QQBotManager { for (String img : imgs) { Tools.download(img, new DownloadInterface() { @Override - public void onDownload(String file) { + public void onDownload(File file) { super.onDownload(file); - files.add(new File(file)); + files.add(file); send(imgs.size(), text); } diff --git a/src/main/java/com/yutou/nas/utils/Tools.java b/src/main/java/com/yutou/nas/utils/Tools.java index 4b57020..926db62 100644 --- a/src/main/java/com/yutou/nas/utils/Tools.java +++ b/src/main/java/com/yutou/nas/utils/Tools.java @@ -112,9 +112,9 @@ public class Tools { if (QQBotManager.getInstance().isLogin()) { download(img, new DownloadInterface() { @Override - public void onDownload(String file) { + public void onDownload(File file) { super.onDownload(file); - QQBotManager.getInstance().sendMessage(new File(file), title + "\n" + finalMsg); + QQBotManager.getInstance().sendMessage(file, title + "\n" + finalMsg); } @Override @@ -283,7 +283,7 @@ public class Tools { } outputStream.close(); inputStream.close(); - downloadInterface.onDownload(file.getAbsolutePath()); + downloadInterface.onDownload(file); } catch (IOException e) { e.printStackTrace(); downloadInterface.onError(e);