update RedisTools
update BTDownload
This commit is contained in:
parent
c3ce37e1b4
commit
32b53a6a16
@ -3,9 +3,7 @@ package com.yutou.nas.utils;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.nas.interfaces.ObjectInterface;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BTDownloadManager {
|
||||
@ -37,6 +35,7 @@ public class BTDownloadManager {
|
||||
//添加到下载器
|
||||
if (download(title, item.getJSONObject("enclosure").getString("link"))) {
|
||||
//发通知到QQ
|
||||
RedisTools.setHashMap("rss",PatternTools.getMagnetHash(item.getJSONObject("enclosure").getString("link")),item.toJSONString());
|
||||
JSONArray array = getDownload(title);
|
||||
array.add(item.getString("title"));
|
||||
RedisTools.set(title, array.toJSONString());
|
||||
@ -108,6 +107,16 @@ public class BTDownloadManager {
|
||||
|
||||
public synchronized static void done(String path,String filename,String hash1,String hash2,String tid) {
|
||||
grep(path,filename);
|
||||
String hash=StringUtils.isEmpty(hash1)?StringUtils.isEmpty(hash2)?null:hash2:hash1;
|
||||
if(hash!=null){
|
||||
String map = RedisTools.getHashMap("rss", hash);
|
||||
JSONObject item=JSON.parseObject(map);
|
||||
if (item.containsKey("thumbnail")) {
|
||||
onSend(item.getString("thumbnail"), item,item.getJSONObject("enclosure").getString("link"));
|
||||
} else {
|
||||
onSend(null, item,item.getJSONObject("enclosure").getString("link"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void grep(String remoteLocation, String remoteName) {
|
||||
|
19
src/main/java/com/yutou/nas/utils/PatternTools.java
Normal file
19
src/main/java/com/yutou/nas/utils/PatternTools.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PatternTools {
|
||||
private static String exec(String regex,String input){
|
||||
Pattern pattern=Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
if(matcher.find()){
|
||||
return matcher.group();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String getMagnetHash(String magnetLink){
|
||||
return Objects.requireNonNull(exec(".(?<=btih:).*(?=&dn)", magnetLink)).substring(1);
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
@ -150,6 +152,68 @@ public class RedisTools {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static long list_add(String listName, String... value) {
|
||||
Jedis jedis = getRedis();
|
||||
long index = jedis.sadd(listName, value);
|
||||
jedis.close();
|
||||
return index;
|
||||
}
|
||||
|
||||
public static Set<String> list_get(String listName) {
|
||||
Jedis jedis = getRedis();
|
||||
Set<String> set = jedis.smembers(listName);
|
||||
jedis.close();
|
||||
if (set == null) {
|
||||
set = new HashSet<>();
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public static boolean list_remove(String listName, String... value) {
|
||||
Jedis jedis = getRedis();
|
||||
long index = jedis.srem(listName, value);
|
||||
jedis.close();
|
||||
return index != 0;
|
||||
}
|
||||
|
||||
public static boolean list_isExist(String listName, String value) {
|
||||
Jedis jedis = getRedis();
|
||||
boolean flag = jedis.sismember(listName, value);
|
||||
jedis.close();
|
||||
return flag;
|
||||
}
|
||||
|
||||
public static String getHashMap(String hashKey, String key) {
|
||||
Jedis jedis = getRedis();
|
||||
return jedis.hget(hashKey, key);
|
||||
}
|
||||
|
||||
public static Map<String, String> getHashMap(String hashKey) {
|
||||
return getRedis().hgetAll(hashKey);
|
||||
}
|
||||
|
||||
public static boolean setHashMap(String hashKey, String key, String value) {
|
||||
Jedis jedis = getRedis();
|
||||
long l = jedis.hset(hashKey, key, value);
|
||||
jedis.close();
|
||||
return l == 0;
|
||||
}
|
||||
|
||||
public static boolean removeHashMap(String hashKey, String key) {
|
||||
Jedis jedis = getRedis();
|
||||
long l = jedis.hdel(hashKey, key);
|
||||
jedis.close();
|
||||
return l > 0;
|
||||
}
|
||||
|
||||
public static boolean removeHashMap(String hashKey) {
|
||||
Jedis jedis = getRedis();
|
||||
long del = jedis.del(hashKey);
|
||||
return del > 0;
|
||||
|
||||
}
|
||||
|
||||
private static class PropertyUtil {
|
||||
|
||||
// 加载property文件到io流里面
|
||||
|
Loading…
Reference in New Issue
Block a user