From 09d2163af3da033f50ada6ba1f1d5d5addae5624 Mon Sep 17 00:00:00 2001 From: yutou Date: Tue, 18 May 2021 18:31:14 +0800 Subject: [PATCH] =?UTF-8?q?BT=E4=B8=8B=E8=BD=BD=E5=B0=86=E4=BC=9A=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/nas/utils/BTDownloadManager.java | 18 ++++++++++++------ src/main/java/com/yutou/nas/utils/Log.java | 3 ++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/yutou/nas/utils/BTDownloadManager.java b/src/main/java/com/yutou/nas/utils/BTDownloadManager.java index 98b893f..442dba8 100644 --- a/src/main/java/com/yutou/nas/utils/BTDownloadManager.java +++ b/src/main/java/com/yutou/nas/utils/BTDownloadManager.java @@ -6,6 +6,7 @@ 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.jetbrains.annotations.NotNull; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -28,8 +29,9 @@ public class BTDownloadManager implements ApplicationContextAware { public static BTDownloadManager getInstance() { if (manager == null) { manager = new BTDownloadManager(); - if (manager.bangumiService == null) + if (manager.bangumiService == null) { manager.bangumiService = getBean(IBangumiService.class); + } } return manager; } @@ -40,6 +42,7 @@ public class BTDownloadManager implements ApplicationContextAware { public void start() { List list = bangumiService.getAllBangumi(); AnimationData data = new AnimationData(); + Log.i("BT","启动BT检测,总数:"+list.size()); for (BangumiItem item : list) { item.setAuthor(data.nameToValue(item.getAuthor(), true) + ""); item.setCategories(data.nameToValue(item.getCategories(), false) + ""); @@ -60,8 +63,8 @@ public class BTDownloadManager implements ApplicationContextAware { 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())); + "-1".equals(item.getCategories()) ? "" : String.format("&sort_id=%s", item.getCategories()), + "-1".equals(item.getAuthor()) ? "" : String.format("&team_id=%s", item.getAuthor())); try { return String.format(url, URLEncoder.encode(dmhyUrl, "UTF-8")); } catch (UnsupportedEncodingException e) { @@ -71,7 +74,7 @@ public class BTDownloadManager implements ApplicationContextAware { } private void download(BangumiItem bangumiItem, JSONObject json) { - if (json.getString("status").equals("ok")) { + if ("ok".equals(json.getString("status"))) { JSONArray items = json.getJSONArray("items"); for (Object _item : items) { JSONObject item = (JSONObject) _item; @@ -92,6 +95,8 @@ public class BTDownloadManager implements ApplicationContextAware { } } } + }else{ + Log.i("BT","rss2json转换失败:"+bangumiItem.getTitle()); } } @@ -154,9 +159,10 @@ public class BTDownloadManager implements ApplicationContextAware { } @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - if (BTDownloadManager.applicationContext == null) + public void setApplicationContext(@NotNull ApplicationContext applicationContext) throws BeansException { + if (BTDownloadManager.applicationContext == null) { BTDownloadManager.applicationContext = applicationContext; + } } private static T getBean(Class clazz) { diff --git a/src/main/java/com/yutou/nas/utils/Log.java b/src/main/java/com/yutou/nas/utils/Log.java index 21163d5..dd2a5e2 100644 --- a/src/main/java/com/yutou/nas/utils/Log.java +++ b/src/main/java/com/yutou/nas/utils/Log.java @@ -6,11 +6,12 @@ public class Log { } public static void i(Object log) { - if (ConfigTools.load(ConfigTools.CONFIG, "logout").equals("true")) + if ("true".equals(ConfigTools.load(ConfigTools.CONFIG, "logout"))) { System.out.printf("[%s]%s%n", AppTools.getToDayNowTimeToString(), log ); + } } }