完善BT下载器,机器人可以控制刷新下载了

This commit is contained in:
yutou 2021-04-08 15:40:59 +08:00
parent 07a239ab1e
commit bdc74957aa
17 changed files with 89 additions and 59 deletions

View File

@ -47,9 +47,9 @@ public class MavenWrapperDownloader {
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
com.yutou.nas.utils.Log.i("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
com.yutou.nas.utils.Log.i("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
@ -63,7 +63,7 @@ public class MavenWrapperDownloader {
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
com.yutou.nas.utils.Log.i("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
@ -74,22 +74,22 @@ public class MavenWrapperDownloader {
}
}
}
System.out.println("- Downloading from: " + url);
com.yutou.nas.utils.Log.i("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
com.yutou.nas.utils.Log.i(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
com.yutou.nas.utils.Log.i("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
com.yutou.nas.utils.Log.i("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
com.yutou.nas.utils.Log.i("- Error downloading");
e.printStackTrace();
System.exit(1);
}

View File

@ -0,0 +1,17 @@
package com.yutou.nas.Controllers;
import com.yutou.nas.utils.BTDownloadManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class BTDownloadController {
@ResponseBody
@RequestMapping("/bt/down.do")
public String bt(){
BTDownloadManager.getInstance().start();
return "ok";
}
}

View File

@ -48,7 +48,7 @@ public class MusicController {
public String getMusicListOfPath(@RequestBody JSONObject body) {
String path = body.getString("path");
boolean type = body.containsKey("type") ? body.getBoolean("type") : false;
System.out.println("接收到地址:" + path);
com.yutou.nas.utils.Log.i("接收到地址:" + path);
if (StringUtils.isEmpty(path)
|| path.equals("root")
|| !path.contains(defaultMusicPath)

View File

@ -37,7 +37,7 @@ public class UpdateIp {
updateList();
File file = new File("/etc/nginx/nginx.conf");
if (file.exists()) {
System.out.println("文件存在,修改 ip>" + ip);
com.yutou.nas.utils.Log.i("文件存在,修改 ip>" + ip);
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder stringBuffer = new StringBuilder();
@ -46,7 +46,7 @@ public class UpdateIp {
boolean isNas=false;
nas_ip=ip;
while ((line = reader.readLine()) != null) {
//System.out.println(line.trim().replace("server_name","").replace("upstream","").trim());
//com.yutou.nas.utils.Log.i(line.trim().replace("server_name","").replace("upstream","").trim());
if (keys.contains(line.trim().replace("server_name", "").replace("upstream", "").replace("{", "").trim())) {
isIp = true;
}
@ -56,7 +56,7 @@ public class UpdateIp {
if (isIp) {
String testIp = testIp(line);
if (testIp != null) {
System.out.println("检测到目标:" + line + " 修改IP " + testIp + " > " + ip);
com.yutou.nas.utils.Log.i("检测到目标:" + line + " 修改IP " + testIp + " > " + ip);
if(isNas){
String adminAddress= RedisTools.get("adminAddress");
if(adminAddress!=null) {
@ -80,7 +80,7 @@ public class UpdateIp {
writer.write(stringBuffer.toString());
writer.flush();
writer.close();
System.out.println("修改完成");
com.yutou.nas.utils.Log.i("修改完成");
Runtime.getRuntime().exec("nginx -s reload");
} catch (Exception e) {
e.printStackTrace();
@ -107,7 +107,7 @@ public class UpdateIp {
String pattern = "((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}";
Pattern p = Pattern.compile(pattern);
Matcher matcher = p.matcher(ip);
// System.out.println("送检测IP:"+ip);
// com.yutou.nas.utils.Log.i("送检测IP:"+ip);
if (matcher.find())
return ip.substring(matcher.start(), matcher.end());
return null;
@ -119,7 +119,7 @@ public class UpdateIp {
if (!file.exists()) {
boolean create = file.createNewFile();
if (create)
System.out.println("创建文件完成:" + file.getAbsolutePath());
com.yutou.nas.utils.Log.i("创建文件完成:" + file.getAbsolutePath());
}
BufferedReader reader = new BufferedReader(new FileReader(file));
String tmp;

View File

@ -18,12 +18,12 @@ public class AnimationData {
try {
String title = "";
for (String key : keys) {
System.out.println(key);
com.yutou.nas.utils.Log.i(key);
title += key + "+";
}
title = title.substring(1, title.length() - 1);
System.out.println(String.format(animUrl, "" + index, title,type,team));
System.out.println(rss2jsonUrl + URLEncoder.encode(String.format(animUrl, "" + index, title,type,team), "UTF-8") +String.format( "&api_key=%s&count=500",rss2jsonApi_2));
com.yutou.nas.utils.Log.i(String.format(animUrl, "" + index, title,type,team));
com.yutou.nas.utils.Log.i(rss2jsonUrl + URLEncoder.encode(String.format(animUrl, "" + index, title,type,team), "UTF-8") +String.format( "&api_key=%s&count=500",rss2jsonApi_2));
String js= HttpTools.get(rss2jsonUrl+ URLEncoder.encode(String.format(animUrl,""+index,title,type,team),"UTF-8")+String.format( "&api_key=%s&count=500",rss2jsonApi_2));
JSONObject json=JSONObject.parseObject(js);
if(json.getString("status").equals("ok")){
@ -54,7 +54,7 @@ public class AnimationData {
public static void initData(){
String url="https://share.dmhy.org/topics/advanced-search?team_id=0&sort_id=0&orderby=";
String data=HttpTools.get(url);
System.out.println(data);
com.yutou.nas.utils.Log.i(data);
}
public static void main(String[] args) {
initData();

View File

@ -324,7 +324,7 @@ public class BangumiTools {
public static void main(String[] args) {
String str = reportBangumiList();
System.out.println(str);
com.yutou.nas.utils.Log.i(str);
}
}

View File

@ -21,7 +21,7 @@ import java.util.TimerTask;
public class QQSetu {
public static void printTodaySetu() {
String redisKey=Tools.getToDayTime() + "_setu";
System.out.println("redisKey = " + redisKey);
com.yutou.nas.utils.Log.i("redisKey = " + redisKey);
String js = RedisTools.get(redisKey, 1);
if (js != null) {
JSONObject json = JSONObject.parseObject(js);

View File

@ -28,7 +28,7 @@ public class tools {
Enumeration<String> name = request.getHeaderNames();
while (name.hasMoreElements()) {
String na = name.nextElement();
System.out.println(na + " " + request.getHeader(na));
com.yutou.nas.utils.Log.i(na + " " + request.getHeader(na));
}
File file = new File("D:\\IDEA\\web_toolset\\web\\js\\my.js");
BufferedReader reader = new BufferedReader(new FileReader(file));

View File

@ -14,7 +14,7 @@ public class AudioTools {
SpeechUtility.getUtility().setParameter(SpeechConstant.LIB_NAME_64,"/media/yutou/4t/public/servier/tools/");
SpeechUtility.getUtility().setParameter(SpeechConstant.LIB_NAME_32,"/media/yutou/4t/public/servier/tools/");
init = true;
System.out.println("讯飞语音已初始化");
com.yutou.nas.utils.Log.i("讯飞语音已初始化");
}
public static void playText(String text) {
@ -50,7 +50,7 @@ public class AudioTools {
@Override
public void onCompleted(SpeechError speechError) {
System.out.println(speechError.getErrorDesc() + " code " + speechError.getErrorCode());
com.yutou.nas.utils.Log.i(speechError.getErrorDesc() + " code " + speechError.getErrorCode());
}
@Override

View File

@ -39,12 +39,18 @@ public class BTDownloadManager implements ApplicationContextAware {
public void start() {
List<BangumiItem> list = bangumiService.getAllBangumi();
AnimationData data = new AnimationData();
for (BangumiItem item : list) {
String url = getRSSUrl(item);
String _json = HttpTools.get(url);
if (!StringUtils.isEmpty(_json)) {
JSONObject json = JSONObject.parseObject(_json);
item.setAuthor(data.nameToValue(item.getAuthor(),true)+"");
item.setCategories(data.nameToValue(item.getCategories(),false)+"");
download(item, json);
}else{
QQBotManager.getInstance().sendMessage(item.getTitle()+"\n下载失败");
Log.i(item.getTitle()+"\n下载失败");
}
}
}
@ -76,7 +82,7 @@ public class BTDownloadManager implements ApplicationContextAware {
//发通知到QQ
JSONArray array = getDownload(bangumiItem.getTitle());
array.add(item.getString("title"));
RedisTools.set(bangumiItem.getTitle(), item.getString("title"));
RedisTools.set(bangumiItem.getTitle(), array.toJSONString());
if (item.containsKey("thumbnail")) {
HttpTools.download(item.getString("thumbnail"), bangumiItem.getTitle() + ".jpg", new DownloadInterface() {
@Override
@ -102,8 +108,9 @@ public class BTDownloadManager implements ApplicationContextAware {
}
}
public void onSend(File file, JSONObject item) {
private void onSend(File file, JSONObject item) {
String text = "启动下载器\n已提交到下载:" + item.getString("title");
Log.i(text);
if (file == null) {
QQBotManager.getInstance().sendMessage(text);
} else {
@ -154,7 +161,7 @@ public class BTDownloadManager implements ApplicationContextAware {
item.setTitle("無職轉生~到了異世界就拿出真本事~");
item.setTitlekey("无职转生");
String url = new BTDownloadManager().getRSSUrl(item);
System.out.println(url);
com.yutou.nas.utils.Log.i(url);
}
@Override
@ -163,7 +170,7 @@ public class BTDownloadManager implements ApplicationContextAware {
BTDownloadManager.applicationContext = applicationContext;
}
public static <T> T getBean(Class<T> clazz) {
private static <T> T getBean(Class<T> clazz) {
return applicationContext.getBean(clazz);
}
}

View File

@ -29,7 +29,7 @@ public class ConfigTools {
}
public static Object load(String type,String key){
File file=new File(type);
//System.out.println(type+"配置文件地址:"+file.getAbsolutePath());
//com.yutou.nas.utils.Log.i(type+"配置文件地址:"+file.getAbsolutePath());
String src=readFile(file);
if(src!=null){
try {

View File

@ -124,7 +124,7 @@ public class HttpTools {
}
});
}*/
System.out.println(url);
com.yutou.nas.utils.Log.i(url);
//String str=get(url);
}
private static String donwloadPath="tmp"+File.separator;

View File

@ -1,10 +1,12 @@
package com.yutou.nas.utils;
public class Log {
public static void i(String tag,Object log){
i('['+tag+']'+log);
public static void i(String tag, Object log) {
i('[' + tag + ']' + log);
}
public static void i(Object log){
public static void i(Object log) {
if (ConfigTools.load(ConfigTools.CONFIG, "logout").equals("true"))
System.out.printf("[%s]%s%n",
AppTools.getToDayNowTimeToString(),
log

View File

@ -57,14 +57,14 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
}
musicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
musicDataDao.truncate();
System.out.println("执行扫描:" + musicPath);
com.yutou.nas.utils.Log.i("执行扫描:" + musicPath);
new Thread(() -> {
long startTime = System.currentTimeMillis();
QQBotManager.getInstance().sendMessage("开始扫描音乐夹");
isScan = true;
scan(new File(musicPath));
isScan = false;
System.out.println("扫描完成");
com.yutou.nas.utils.Log.i("扫描完成");
QQBotManager.getInstance().sendMessage("音乐扫描完成,共" + getLength() + "首歌,耗时:"
+ (System.currentTimeMillis() - startTime));
}).start();
@ -131,7 +131,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
MusicData tmp = main.get(0);
t2.setFile(new File(tmp.getLastdir()).getAbsolutePath());
}
System.out.println("查询地址:" + path + " 设置返回地址:" + t2.getFile());
com.yutou.nas.utils.Log.i("查询地址:" + path + " 设置返回地址:" + t2.getFile());
t2.setIsdir(1);
list.add(t2);
}
@ -158,7 +158,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
private void getDirList(String path, List<MusicData> list) {
File file = new File(path);
System.out.println("扫描文件:"+path);
com.yutou.nas.utils.Log.i("扫描文件:"+path);
if(file.isDirectory()) {
for (File listFile : file.listFiles()) {
if (listFile.isDirectory()) {
@ -538,7 +538,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
File file = new File("Z:\\音乐\\总之就是非常酸\\ED\\カノエラナ - 月と星空\\カノエラナ.wav");
file = new File("Z:\\音乐\\终将成为你\\[OP]君にふれて\\rise.flac");
// file = new File("Z:\\音乐\\周董\\2012 十二新作\\03 公公偏头痛.ape");
System.out.println(new MusicToolsServiceImpl().getMetadataOfFFmpeg(file));
com.yutou.nas.utils.Log.i(new MusicToolsServiceImpl().getMetadataOfFFmpeg(file));
}

View File

@ -41,6 +41,7 @@ public class QQBotManager {
private final static String QQ_AUDIO = "!语音";
private final static String QQ_AUDIO_OPEN_LAMP = "!开灯";
private final static String QQ_AUDIO_OPEN_AIR = "!开空调";
private final static String QQ_BT_RELOAD = "!刷BT";
}
private static QQBotManager botManager = null;
@ -92,7 +93,7 @@ public class QQBotManager {
e.printStackTrace();
}
String str = sendMessage("姬妻酱上线拉~");
System.out.println(str);
com.yutou.nas.utils.Log.i(str);
}
}).start();
@ -251,6 +252,9 @@ public class QQBotManager {
getInstance().sendMessage("获取中...");
getInstance().sendMessage(BangumiTools.reportBangumiList());
break;
case QQCommands.QQ_BT_RELOAD:
BTDownloadManager.getInstance().start();
break;
case QQCommands.QQ_HELP:
StringBuilder builder = new StringBuilder();
@ -323,7 +327,7 @@ public class QQBotManager {
private void send(int size, String text) {
if ((files.size() + index) == size) {
String str = getInstance().sendMessage(files, text);
System.out.println("str = " + str);
com.yutou.nas.utils.Log.i("str = " + str);
}
}

View File

@ -41,7 +41,7 @@ public class RedisTools {
Jedis jedis = getRedis();
jedis.select(dbIndex);
String ret = jedis.set(key, value);
System.out.println("Redis set =" + ret);
com.yutou.nas.utils.Log.i("Redis set =" + ret);
jedis.close();
} catch (Exception e) {
// TODO: handle exception
@ -176,13 +176,13 @@ public class RedisTools {
}
public static void pullMsg(String channel, String msg) {
System.out.println("1");
com.yutou.nas.utils.Log.i("1");
Jedis jedis = getPoolRedis();
System.out.println("2");
com.yutou.nas.utils.Log.i("2");
jedis.publish(channel, msg);
System.out.println("3");
com.yutou.nas.utils.Log.i("3");
jedis.close();
System.out.println("4");
com.yutou.nas.utils.Log.i("4");
}
private static boolean init = false;
@ -191,7 +191,7 @@ public class RedisTools {
if (init)
return;
init = true;
System.out.println("初始化订阅");
com.yutou.nas.utils.Log.i("初始化订阅");
new Thread(new Runnable() {
@Override
public void run() {
@ -207,7 +207,7 @@ public class RedisTools {
@Override
public void onPMessage(String pattern, String channel, String message) {
super.onPMessage(pattern, channel, message);
System.out.println("onPMessage: channel=" + channel + " msg=" + message + " pattern=" + pattern);
com.yutou.nas.utils.Log.i("onPMessage: channel=" + channel + " msg=" + message + " pattern=" + pattern);
switch (channel) {
case "system":
switch (message) {
@ -234,7 +234,7 @@ public class RedisTools {
@Override
public void onMessage(String channel, String message) {
super.onMessage(channel, message);
System.out.println("onMessage: channel=" + channel + " msg=" + message);
com.yutou.nas.utils.Log.i("onMessage: channel=" + channel + " msg=" + message);
}
public static void system(String type, String value) {
@ -288,9 +288,9 @@ public class RedisTools {
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("cmd > " + str);
com.yutou.nas.utils.Log.i("cmd > " + str);
QQBotManager.getInstance().sendMessage(str.toString());
System.out.println("线程结束");
com.yutou.nas.utils.Log.i("线程结束");
}
public static void main(String[] args) {
RedisTools.pullMsg("msg", "abc");

View File

@ -77,7 +77,7 @@ public class Tools {
public static String deleteCookie(HttpServletRequest request, HttpServletResponse response, String key) {
for (Cookie cookie : request.getCookies()) {
if (cookie.getName().equals(key)) {
System.out.println("删除key=" + key);
com.yutou.nas.utils.Log.i("删除key=" + key);
cookie.setMaxAge(0);
cookie.setPath("/");
cookie.setValue(null);
@ -89,7 +89,7 @@ public class Tools {
public static void sendServer(String title, String msg) {
try {
System.out.println("title=" + title + " msg=" + msg);
com.yutou.nas.utils.Log.i("title=" + title + " msg=" + msg);
HttpTools.post("https://sctapi.ftqq.com/SCT2619Tpqu93OYtQCrK4LOZYEfr2irm.send",
("title="+URLEncoder.encode(title, "UTF-8") + "&desp=" + URLEncoder.encode(msg, "UTF-8")).getBytes(StandardCharsets.UTF_8),
null);
@ -144,7 +144,7 @@ public class Tools {
+ "&imgUrl=" + img
+ "&token=zIrsh9TUZP2lfRW753PannG49E7VJvor";
}
System.out.println(url);
com.yutou.nas.utils.Log.i(url);
HttpTools.get(url);
}
} catch (Exception e) {
@ -220,7 +220,7 @@ public class Tools {
array = JSONArray.parseArray(RedisTools.get("bean"));
}
if (array.contains(Tools.getRemoteAddress(request))) {
System.out.println("IP已被封禁");
com.yutou.nas.utils.Log.i("IP已被封禁");
return -100;
}
Cookie cookie = Tools.getCookie(request, "user");
@ -259,7 +259,7 @@ public class Tools {
}
file.transferTo(saveFile);
fileName = URLEncoder.encode(fileName, "UTF-8");
System.out.println("上传文件保存路径:" + saveFile.getAbsolutePath());
com.yutou.nas.utils.Log.i("上传文件保存路径:" + saveFile.getAbsolutePath());
return path + fileName;
}