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 ); + } } }