新增对Jellyfin的搜刮(但未完成自动化)
This commit is contained in:
@@ -26,12 +26,30 @@ public class ApplicationInit implements ApplicationRunner {
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
AudioTools.init();
|
||||
new Timer().schedule(new TimerTask() {
|
||||
boolean powerOffice=false;
|
||||
boolean powerLow=false;
|
||||
@Override
|
||||
public void run() {
|
||||
String time = new SimpleDateFormat("HH:mm").format(new Date());
|
||||
if (time.equals(oldTime)) {
|
||||
return;
|
||||
}
|
||||
float power=Tools.getSystemUPSPower();
|
||||
if(power>0) {
|
||||
if (power == 100) {
|
||||
AppTools.exec("wakeonlan 00:F0:D2:D0:6B:B5", null, false, true);
|
||||
powerLow=false;
|
||||
powerOffice=false;
|
||||
}
|
||||
if (power < 99 && !powerOffice) {
|
||||
powerOffice = true;
|
||||
QQBotManager.getInstance().sendMessage("UPS进入电池模式:" + power);
|
||||
}
|
||||
if (power < 50 && !powerLow) {
|
||||
powerLow = true;
|
||||
QQBotManager.getInstance().sendMessage("UPS电池低于50%,即将关机");
|
||||
}
|
||||
}
|
||||
oldTime = time;
|
||||
switch (time) {
|
||||
case "00:00":
|
||||
|
||||
@@ -11,8 +11,8 @@ public class AudioTools {
|
||||
}
|
||||
SpeechUtility.createUtility(SpeechConstant.APPID + "=601f7f7d");
|
||||
SpeechUtility.getUtility().setParameter(SpeechConstant.VOLUME,"100");
|
||||
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/");
|
||||
SpeechUtility.getUtility().setParameter(SpeechConstant.LIB_NAME_64,"/media/yutou/disk_lvm/public/servier/tools/");
|
||||
SpeechUtility.getUtility().setParameter(SpeechConstant.LIB_NAME_32,"/media/yutou/disk_lvm/public/servier/tools/");
|
||||
init = true;
|
||||
com.yutou.nas.utils.Log.i("讯飞语音已初始化");
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class BTDownloadManager implements ApplicationContextAware {
|
||||
@Resource
|
||||
IBangumiService bangumiService;
|
||||
private static BTDownloadManager manager;
|
||||
private static final String DownloadHomePath="/media/yutou/disk_lvm/public/";
|
||||
|
||||
public static BTDownloadManager getInstance() {
|
||||
if (manager == null) {
|
||||
@@ -41,6 +42,11 @@ public class BTDownloadManager implements ApplicationContextAware {
|
||||
List<BangumiItem> list = bangumiService.getAllBangumi();
|
||||
AnimationData data = new AnimationData();
|
||||
Log.i("BT","启动BT检测,总数:"+list.size());
|
||||
File path=new File(DownloadHomePath);
|
||||
if(!path.exists()){
|
||||
Log.i("BT","下载目录已离线,取消扫描");
|
||||
return;
|
||||
}
|
||||
for (BangumiItem item : list) {
|
||||
if(item.getEnable()==0){
|
||||
continue;
|
||||
@@ -119,16 +125,18 @@ public class BTDownloadManager implements ApplicationContextAware {
|
||||
|
||||
public boolean download(String title, String url) {
|
||||
try {
|
||||
String exec = String.format("transmission-remote -n yutou:34864394 -w /media/yutou/4t/public/download/anim/%s -a \"%s\" "
|
||||
String exec = String.format("transmission-remote -n yutou:34864394 -w %sanim/%s -a \"%s\" "
|
||||
,DownloadHomePath
|
||||
, title
|
||||
, url
|
||||
);
|
||||
Log.i(exec);
|
||||
Runtime.getRuntime().exec(new String[]{"sh"
|
||||
Process process=Runtime.getRuntime().exec(new String[]{"sh"
|
||||
, "-c"
|
||||
, exec});
|
||||
process.exitValue();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.yutou.nas.utils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import com.yutou.nas.utils.Interfaces.NetworkInterface;
|
||||
import com.yutou.nas.utils.StringUtils;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
@@ -11,25 +10,35 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class HttpTools {
|
||||
public static final String serverKey="zIrsh9TUZP2lfRW753PannG49E7VJvor";
|
||||
private static final int HttpRequestIndex=3;
|
||||
public static final String serverKey = "zIrsh9TUZP2lfRW753PannG49E7VJvor";
|
||||
private static final int HttpRequestIndex = 3;
|
||||
|
||||
public static String get(String url){
|
||||
return new HttpTools().http_get(url,0);
|
||||
public static String get(String url) {
|
||||
return https_get(url, null);
|
||||
}
|
||||
public static void post(final String url, final byte[] body, final NetworkInterface networkInterface){
|
||||
new HttpTools().http_post(url, body,0, networkInterface);
|
||||
|
||||
public static String post(final String url, final byte[] body) {
|
||||
return http_post(url, body, 0, null);
|
||||
}
|
||||
public static File syncDownload(final String url, final String saveName){
|
||||
|
||||
public static File syncDownload(final String url, final String saveName) {
|
||||
return new HttpTools().http_syncDownload(url, saveName);
|
||||
}
|
||||
public String http_get(String url,int index) {
|
||||
|
||||
public static String https_get(String url, Map<String, String> header) {
|
||||
try {
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
URLConnection connection;
|
||||
connection = new URL(url).openConnection();
|
||||
connection.setRequestProperty("User-Agent", getExtUa());
|
||||
if (header != null) {
|
||||
for (String key : header.keySet()) {
|
||||
connection.addRequestProperty(key, header.get(key));
|
||||
}
|
||||
}
|
||||
connection.connect();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
StringBuilder str = new StringBuilder();
|
||||
@@ -38,68 +47,57 @@ public class HttpTools {
|
||||
str.append(tmp);
|
||||
}
|
||||
reader.close();
|
||||
connection.disconnect();
|
||||
return str.toString();
|
||||
} catch (Exception e) {
|
||||
if(index<HttpRequestIndex){
|
||||
return http_get(url,++index);
|
||||
}
|
||||
System.err.println("error url = "+url);
|
||||
System.err.println("error url = " + url);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void http_post(final String url, final byte[] body,final int index, final NetworkInterface networkInterface) {
|
||||
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String tmp;
|
||||
StringBuilder str = new StringBuilder();
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
connection.addRequestProperty("User-Agent", getExtUa());
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(10 * 1000);
|
||||
//connection.addRequestProperty("Connection", "keep-alive");
|
||||
//connection.addRequestProperty("User-Agent", getExtUa());
|
||||
//connection.addRequestProperty("content-type", "application/json");
|
||||
connection.addRequestProperty("charset", "UTF-8");
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
|
||||
outputStream.write(body);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
str.append(tmp);
|
||||
}
|
||||
final String finalStr = str.toString();
|
||||
|
||||
// Log.i(TAG + "[" + url + "?" + toGetSplice(body) + "]", "body:" + str + " (" + connection.getResponseCode() + ")");
|
||||
if (networkInterface != null) {
|
||||
try {
|
||||
networkInterface.httpGetData(str.toString(), connection.getResponseCode());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
connection.disconnect();
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
if(index<HttpRequestIndex){
|
||||
http_post(url, body, index+1, networkInterface);
|
||||
}else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static String http_post(String url, byte[] body, int index, Map<String, String> headers) {
|
||||
String tmp;
|
||||
StringBuilder str = new StringBuilder();
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
if (headers != null) {
|
||||
for (String key : headers.keySet()) {
|
||||
connection.addRequestProperty(key, headers.get(key));
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
connection.addRequestProperty("User-Agent", getExtUa());
|
||||
connection.setConnectTimeout(5 * 1000);
|
||||
connection.setReadTimeout(10 * 1000);
|
||||
//connection.addRequestProperty("Connection", "keep-alive");
|
||||
//connection.addRequestProperty("User-Agent", getExtUa());
|
||||
//connection.addRequestProperty("content-type", "application/json");
|
||||
connection.addRequestProperty("charset", "UTF-8");
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
//System.out.println(new String(body));
|
||||
outputStream.write(body);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
connection.connect();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
str.append(tmp);
|
||||
}
|
||||
String finalStr = str.toString();
|
||||
|
||||
connection.disconnect();
|
||||
reader.close();
|
||||
return finalStr;
|
||||
} catch (Exception e) {
|
||||
if (index < HttpRequestIndex) {
|
||||
return http_post(url, body, index + 1, headers);
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getExtUa() {
|
||||
@@ -205,14 +203,15 @@ public class HttpTools {
|
||||
if (jar != null) {
|
||||
jar.delete();
|
||||
}
|
||||
downloadInterface.onError(e);
|
||||
if (downloadInterface != null)
|
||||
downloadInterface.onError(e);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public synchronized File http_syncDownload(final String url, final String saveName) {
|
||||
if(StringUtils.isEmpty(url)){
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
return null;
|
||||
}
|
||||
File jar = null;
|
||||
|
||||
195
src/main/java/com/yutou/nas/utils/JellyfinAPIManager.java
Normal file
195
src/main/java/com/yutou/nas/utils/JellyfinAPIManager.java
Normal file
@@ -0,0 +1,195 @@
|
||||
package com.yutou.nas.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.nas.bangumi.BangumiTools;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.*;
|
||||
|
||||
public class JellyfinAPIManager {
|
||||
public static LibsItem getLibs(String key) {
|
||||
HashMap<String, String> header = getHeader();
|
||||
String httpText = HttpTools.https_get("http://192.168.31.88:8096/Users/e8a13675bb64466dbd81f1e5985ef8c7/Items", header);
|
||||
JSONObject json = JSONObject.parseObject(httpText);
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
JSONArray items = json.getJSONArray("Items");
|
||||
for (Object o : items) {
|
||||
LibsItem item = JSONObject.parseObject(o.toString(), LibsItem.class);
|
||||
if (item.getName().equals(key)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<JellyfinAPIManager.LibsItem> getLibsItems(String id) {
|
||||
String httpText = HttpTools.https_get("http://192.168.31.88:8096/Users/e8a13675bb64466dbd81f1e5985ef8c7/Items?ParentId=" + id, getHeader());
|
||||
JSONObject json = JSONObject.parseObject(httpText);
|
||||
JSONArray items = json.getJSONArray("Items");
|
||||
return JSONArray.parseArray(items.toJSONString(), LibsItem.class);
|
||||
}
|
||||
|
||||
public static JSONObject getItemShows(String id) {
|
||||
String data=HttpTools.https_get(String.format("http://192.168.31.88:8096/Shows/%s/Seasons?userId=e8a13675bb64466dbd81f1e5985ef8c7",
|
||||
id
|
||||
),getHeader());
|
||||
return JSONObject.parseObject(data);
|
||||
}
|
||||
|
||||
public static void uploadImage(File image, String id, String model) {
|
||||
try {
|
||||
HashMap<String, String> header = getHeader();
|
||||
header.put("Content-Type", "image/jpg");
|
||||
String url = String.format("http://192.168.31.88:8096/Items/%s/Images/%s",
|
||||
id,
|
||||
model
|
||||
);
|
||||
//url="http://tools.yutou233.cn/public/request.do";
|
||||
HttpTools.http_post(
|
||||
url,
|
||||
Base64.getEncoder().encode(StreamTools.fileToByte(image)),
|
||||
4,
|
||||
header
|
||||
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static void saveJellyfinMetaData(JSONObject info, JellyfinAPIManager.LibsItem item) {
|
||||
JSONArray airDate = new JSONArray();
|
||||
airDate.add(info.getString("air_date"));
|
||||
JSONObject providerIds = new JSONObject();
|
||||
providerIds.put("Imdb", "");
|
||||
providerIds.put("Tmdb", "");
|
||||
providerIds.put("Zap2It", "");
|
||||
JSONObject metadata = new JSONObject();
|
||||
metadata.put("Id", item.getId());
|
||||
metadata.put("Name", info.getString("name_cn"));
|
||||
metadata.put("OriginalTitle", info.getString("name"));
|
||||
metadata.put("ForcedSortName", "");
|
||||
metadata.put("CommunityRating", info.getJSONObject("rating").getFloat("score") + "");
|
||||
metadata.put("CriticRating", "");
|
||||
metadata.put("IndexNumber", "null");
|
||||
metadata.put("AirsBeforeSeasonNumber", "");
|
||||
metadata.put("AirsAfterSeasonNumber", "");
|
||||
metadata.put("AirsBeforeEpisodeNumber", "");
|
||||
metadata.put("ParentIndexNumber", "null");
|
||||
metadata.put("DisplayOrder", "");
|
||||
metadata.put("Album", "");
|
||||
metadata.put("AlbumArtists", new JSONArray());
|
||||
metadata.put("ArtistItems", new JSONArray());
|
||||
metadata.put("Overview", info.getString("summary"));
|
||||
metadata.put("Status", "");
|
||||
metadata.put("AirDays", new JSONArray());
|
||||
metadata.put("AirTime", "");
|
||||
metadata.put("Genres", new JSONArray());
|
||||
metadata.put("Tags", new JSONArray());
|
||||
metadata.put("Studios", new JSONArray());
|
||||
metadata.put("PremiereDate", "null");
|
||||
metadata.put("DateCreated", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date()));
|
||||
metadata.put("EndDate", "null");
|
||||
metadata.put("ProductionYear", info.getString("air_date").split("-")[0]);
|
||||
metadata.put("AspectRatio", "");
|
||||
metadata.put("Video3DFormat", "");
|
||||
metadata.put("OfficialRating", "14+");
|
||||
metadata.put("CustomRating", "");
|
||||
metadata.put("People", BangumiTools.getPeople(info.getInteger("id")));
|
||||
metadata.put("LockData", false);
|
||||
metadata.put("LockedFields", new JSONArray());
|
||||
metadata.put("ProviderIds", providerIds);
|
||||
// metadata.put("Path", path);
|
||||
metadata.put("PreferredMetadataLanguage", "");
|
||||
metadata.put("PreferredMetadataCountryCode", "");
|
||||
metadata.put("RunTimeTicks", 0);
|
||||
metadata.put("Taglines", new JSONArray());
|
||||
HashMap<String, String> headers = JellyfinAPIManager.getHeader();
|
||||
headers.put("Content-Type", "application/json");
|
||||
System.out.println(metadata.toString().replace("\"null\"", "null"));
|
||||
String ret = HttpTools.http_post("http://192.168.31.88:8096/Items/" + item.getId()
|
||||
, metadata.toString().replace("\"null\"", "null").getBytes(StandardCharsets.UTF_8)
|
||||
, 4
|
||||
, headers);
|
||||
System.out.println(ret);
|
||||
HttpTools.download(
|
||||
info.getJSONObject("images").getString("large").replace("http:", "https:"),
|
||||
"poster.jpg",
|
||||
new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
super.onDownload(file);
|
||||
JellyfinAPIManager.uploadImage(file, item.getId(), "Primary");
|
||||
JSONObject items = JellyfinAPIManager.getItemShows(item.getId());
|
||||
for (Object o : items.getJSONArray("Items")) {
|
||||
JSONObject json = (JSONObject) o;
|
||||
JellyfinAPIManager.uploadImage(file, json.getString("Id"), "Primary");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getHeader() {
|
||||
HashMap<String, String> header = new HashMap<>();
|
||||
header.put("X-Emby-Authorization", "MediaBrowser Client=\"Jellyfin CLI\", Device=\"Jellyfin-CLI\", DeviceId=\"None\", Version=\"10.7.6\", Token=\"81be0169523e463a8c36a7b752d60ab2\"");
|
||||
return header;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class LibsItem {
|
||||
private String name;
|
||||
private String serverID;
|
||||
private String id;
|
||||
private Object channelID;
|
||||
private boolean isFolder;
|
||||
private String type;
|
||||
private UserData userData;
|
||||
private String collectionType;
|
||||
private ImageTags imageTags;
|
||||
private List<Object> backdropImageTags;
|
||||
private Object imageBlurHashes;
|
||||
private String locationType;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class UserData {
|
||||
private long playbackPositionTicks;
|
||||
private long playCount;
|
||||
private boolean isFavorite;
|
||||
private boolean played;
|
||||
private String key;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ImageTags {
|
||||
private String primary;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JellyfinAPIManager.LibsItem item = JellyfinAPIManager.getLibs("番剧");
|
||||
if (item != null) {
|
||||
List<JellyfinAPIManager.LibsItem> list;
|
||||
list = JellyfinAPIManager.getLibsItems(item.getId());
|
||||
for (JellyfinAPIManager.LibsItem libsItem : list) {
|
||||
if ("寒蝉鸣泣之时_卒".equals(libsItem.getName())) {
|
||||
saveJellyfinMetaData(
|
||||
BangumiTools.getBangumiInfo(331033),
|
||||
libsItem
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import java.util.regex.Pattern;
|
||||
public class QQBotManager {
|
||||
|
||||
|
||||
private static class QQCommands {
|
||||
public static class QQCommands {
|
||||
private final static String QQ_HELP = "!help";
|
||||
private final static String QQ_SYSTEM_RESTART = "!restart";
|
||||
private final static String QQ_UPDATE_IP = "!更新ip";
|
||||
@@ -47,6 +47,8 @@ public class QQBotManager {
|
||||
private final static String QQ_TOOLS_IDEA = "!idea";
|
||||
private final static String QQ_TOOLS_IDEA_FILE = "!idea>";
|
||||
private final static String QQ_TOOLS_IDEA_URL = "!idea_url";
|
||||
|
||||
public final static String QQ_BANGUMI_INFO="!保存动画信息>";
|
||||
}
|
||||
|
||||
private static QQBotManager botManager = null;
|
||||
@@ -136,7 +138,7 @@ public class QQBotManager {
|
||||
}
|
||||
|
||||
public String sendMessage(String text) {
|
||||
if (bot != null) {
|
||||
if (bot != null&&!StringUtils.isEmpty(text)) {
|
||||
try {
|
||||
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(text).toString();
|
||||
} catch (Exception e) {
|
||||
@@ -266,7 +268,7 @@ public class QQBotManager {
|
||||
case QQCommands.QQ_SYSTEM_RESTART:
|
||||
getInstance().sendMessage("正在重启服务");
|
||||
System.out.println("结束进程");
|
||||
AppTools.exec("cd /media/yutou/4t/public/servier/tools && ./start.sh",null,true,false);
|
||||
AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh",null,true,false);
|
||||
break;
|
||||
case QQCommands.QQ_HELP:
|
||||
builder = new StringBuilder();
|
||||
|
||||
@@ -251,7 +251,7 @@ public class RedisTools {
|
||||
exec = value;
|
||||
break;
|
||||
case "updateIP":
|
||||
exec = "python3 /media/yutou/4t/public/Python/tools/ip.py";
|
||||
exec = "python3 /media/yutou/disk_lvm/public/Python/tools/ip.py";
|
||||
break;
|
||||
}
|
||||
if (exec != null) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.yutou.nas.utils;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.yutou.nas.Controllers.UpdateIp;
|
||||
import com.yutou.nas.interfaces.DownloadInterface;
|
||||
import com.yutou.nas.interfaces.ObjectInterface;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,8 +25,11 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Tools {
|
||||
private static float UPSPower=-1.0f;
|
||||
/**
|
||||
* 设置Cookie
|
||||
*
|
||||
@@ -91,8 +95,7 @@ public class Tools {
|
||||
try {
|
||||
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);
|
||||
("title="+URLEncoder.encode(title, "UTF-8") + "&desp=" + URLEncoder.encode(msg, "UTF-8")).getBytes(StandardCharsets.UTF_8));
|
||||
if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("nas")) {
|
||||
String img = null;
|
||||
msg = msg.replace("<br/>", "\n");
|
||||
@@ -384,4 +387,22 @@ public class Tools {
|
||||
public static String getToDayTime() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
}
|
||||
|
||||
public static float getSystemUPSPower(){
|
||||
AppTools.exec("/sbin/apcaccess |grep BCHARGE ", new ObjectInterface() {
|
||||
@Override
|
||||
public void out(String data) {
|
||||
super.out(data);
|
||||
System.out.println("尝试获取电量:"+data);
|
||||
Pattern pattern=Pattern.compile("[0-9]*\\.?[0-9]");
|
||||
Matcher matcher=pattern.matcher(data);
|
||||
if(matcher.find()) {
|
||||
String ups = matcher.group();
|
||||
UPSPower=Float.parseFloat(ups);
|
||||
System.out.println("电量:"+UPSPower);
|
||||
}
|
||||
}
|
||||
},false,true);
|
||||
return UPSPower;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user