新增对Jellyfin的搜刮(但未完成自动化)

This commit is contained in:
Yutousama 2021-09-30 09:32:51 +08:00
parent f30530d61d
commit ef1ba6f61f
14 changed files with 446 additions and 113 deletions

21
pom.xml
View File

@ -144,6 +144,25 @@
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<!-- <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>-->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>复制正式文件</echo>
<copy file="src/main/resources/application.properties.release" tofile="${project.build.outputDirectory}/application.properties" overwrite="true"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
@ -184,7 +203,7 @@
<configuration>
<outputDirectory>
Z:\servier\tools\
X:\servier\tools\
</outputDirectory>
</configuration>

View File

@ -1,5 +1,5 @@
package com.yutou.nas.Datas;
public class AppData {
public static String defaultMusicPath = "/media/yutou/4t/public/音乐";
public static String defaultMusicPath = "/media/yutou/disk_lvm/public/音乐";
}

View File

@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import;
@Import(BTDownloadManager.class)
@SpringBootApplication
public class NasApplication {
public static final String version="1.1.6";
public static final String version="1.1.9";
public static void main(String[] args) {
SpringApplication.run(NasApplication.class, args);
AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");

View File

@ -6,10 +6,7 @@ import com.yutou.nas.mybatis.model.MusicData;
import com.yutou.nas.mybatis.model.MusicDataExample;
import com.yutou.nas.Services.IMusicToolsService;
import com.yutou.nas.utils.ConfigTools;
import com.yutou.nas.utils.OSSManager;
import com.yutou.nas.utils.QQBotManager;
import com.yutou.nas.utils.Tools;
import com.yutou.nas.utils.*;
import ealvatag.audio.AudioFile;
import ealvatag.audio.AudioFileIO;
import ealvatag.audio.AudioHeader;
@ -22,7 +19,6 @@ import net.bramp.ffmpeg.probe.FFmpegFormat;
import net.bramp.ffmpeg.probe.FFmpegProbeResult;
import net.bramp.ffmpeg.probe.FFmpegStream;
import org.springframework.stereotype.Service;
import com.yutou.nas.utils.StringUtils;
import javax.annotation.Resource;
import java.io.File;
@ -39,7 +35,7 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
public static final int FIND_TITLE = 1;
public static final int FIND_ARTIST = 2;
private String musicPath = "/media/yutou/4t/public/音乐";
private String musicPath = "/media/yutou/disk_lvm/public/音乐";
private boolean isScan = false;
@Resource
@ -75,6 +71,10 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
private void scan(File path) {
if(!path.exists()){
Log.i("MusicScan","文件夹不存在,取消扫描");
return;
}
if (path.isFile()) {
add(path);
} else if (path.isDirectory()) {

View File

@ -2,10 +2,7 @@ package com.yutou.nas.bangumi;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yutou.nas.utils.HttpTools;
import com.yutou.nas.utils.RedisTools;
import com.yutou.nas.utils.Tools;
import com.yutou.nas.utils.StringUtils;
import com.yutou.nas.utils.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -63,6 +60,48 @@ public class BangumiTools {
return JSONObject.parseObject(str);
}
public static JSONArray getPeople(int id) {
/**
* Actor 演员
* Composer 作曲家
* Director 导演
* GuestStar 特邀明星
* Producer 制片人
* Writer 编剧
*/
JSONArray people = new JSONArray();
JSONObject bangumi = getBangumiInfo(id);
JSONArray crt = bangumi.getJSONArray("crt");
for (Object o : crt) {
JSONObject item = (JSONObject) o;
JSONObject pel = new JSONObject();
pel.put("Name", item.getString("name_cn"));
pel.put("Role", item.getString("role_name"));
pel.put("Type", "Actor");
people.add(pel);
}
crt = bangumi.getJSONArray("staff");
for (Object o : crt) {
JSONObject item = (JSONObject) o;
JSONObject pel = new JSONObject();
pel.put("Name", item.getString("name_cn"));
String jobsName="";
for (Object _jobs : item.getJSONArray("jobs")) {
jobsName+=_jobs+"";
}
jobsName=jobsName.substring(0,jobsName.length()-1);
pel.put("Role", jobsName);
pel.put("Type", "");
if (jobsName.contains("导演")) {
pel.put("Type", "Director");
} else if (jobsName.contains("脚本")) {
pel.put("Type", "DirectorDirector");
}
people.add(pel);
}
return people;
}
/**
* 搜索番剧
*
@ -190,6 +229,7 @@ public class BangumiTools {
/**
* 格式化输出新番列表
*
* @return 新番信息
*/
public static String reportBangumiList() {
@ -332,10 +372,36 @@ public class BangumiTools {
}
}
public static void main(String[] args) {
RedisTools.remove("reportToDayBangumi");
String str = reportToDayBangumi();
System.out.println(str);
public static void saveInfoToJellyfin(String name) {
JSONObject json = search(name);
JSONArray array = json.getJSONArray("list");
int id = 0;
StringBuilder bangumiName = new StringBuilder();
for (Object o : array) {
JSONObject _item = (JSONObject) o;
bangumiName.append(_item.getString("name_cn"))
.append(":")
.append(QQBotManager.QQCommands.QQ_BANGUMI_INFO)
.append(_item.getString("id"))
.append("\n");
if (_item.getString("name_cn").equals(name)) {
id = _item.getInteger("id");
break;
}
}
if (id == 0) {
QQBotManager.getInstance().sendMessage("没有与《" + name + "》完全匹配的信息,请填写。 \n" + bangumiName.toString());
return;
}
json = getBangumiInfo(id);
}
public static void main(String[] args) {
JSONObject json = search("小林家的龙女仆S");
System.out.println(json);
json = getBangumiInfo(274234);
System.err.println("------------");
System.out.println(json);
}
}

View File

@ -151,5 +151,10 @@ public class tools {
videoToolsService.scanVideo();
return "ok";
}
@ResponseBody
@RequestMapping("/public/getUPSPower.do")
public float getUPSPower(){
return Tools.getSystemUPSPower();
}
}

View File

@ -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":

View File

@ -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("讯飞语音已初始化");
}

View File

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

View File

@ -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,6 +10,7 @@ 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 {
@ -18,18 +18,27 @@ public class HttpTools {
private static final int HttpRequestIndex = 3;
public static String get(String url) {
return new HttpTools().http_get(url,0);
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) {
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,29 +47,25 @@ 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);
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() {
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));
}
}
connection.setDoOutput(true);
connection.setDoInput(true);
connection.addRequestProperty("User-Agent", getExtUa());
@ -71,36 +76,29 @@ public class HttpTools {
//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);
}
final String finalStr = str.toString();
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();
return finalStr;
} catch (Exception e) {
if (index < HttpRequestIndex) {
http_post(url, body, index+1, networkInterface);
return http_post(url, body, index + 1, headers);
} else {
e.printStackTrace();
return null;
}
}
}
}).start();
}
private static String getExtUa() {
return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36";
@ -205,6 +203,7 @@ public class HttpTools {
if (jar != null) {
jar.delete();
}
if (downloadInterface != null)
downloadInterface.onError(e);
}
}

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

View File

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

View File

@ -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) {

View File

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