BT下载将会打印日志

This commit is contained in:
yutou 2021-05-18 18:31:14 +08:00
parent 96f560e3c9
commit 09d2163af3
2 changed files with 14 additions and 7 deletions

View File

@ -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<BangumiItem> 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> T getBean(Class<T> clazz) {

View File

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