新增对Jellyfin的搜刮(但未完成自动化)
This commit is contained in:
parent
f30530d61d
commit
ef1ba6f61f
21
pom.xml
21
pom.xml
@ -144,6 +144,25 @@
|
|||||||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
||||||
<!-- <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>-->
|
<!-- <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>-->
|
||||||
<plugins>
|
<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>
|
<plugin>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-maven-plugin</artifactId>
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
@ -184,7 +203,7 @@
|
|||||||
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<outputDirectory>
|
<outputDirectory>
|
||||||
Z:\servier\tools\
|
X:\servier\tools\
|
||||||
</outputDirectory>
|
</outputDirectory>
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package com.yutou.nas.Datas;
|
package com.yutou.nas.Datas;
|
||||||
|
|
||||||
public class AppData {
|
public class AppData {
|
||||||
public static String defaultMusicPath = "/media/yutou/4t/public/音乐";
|
public static String defaultMusicPath = "/media/yutou/disk_lvm/public/音乐";
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
@Import(BTDownloadManager.class)
|
@Import(BTDownloadManager.class)
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class NasApplication {
|
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) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(NasApplication.class, args);
|
SpringApplication.run(NasApplication.class, args);
|
||||||
AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
||||||
|
@ -6,10 +6,7 @@ import com.yutou.nas.mybatis.model.MusicData;
|
|||||||
import com.yutou.nas.mybatis.model.MusicDataExample;
|
import com.yutou.nas.mybatis.model.MusicDataExample;
|
||||||
import com.yutou.nas.Services.IMusicToolsService;
|
import com.yutou.nas.Services.IMusicToolsService;
|
||||||
|
|
||||||
import com.yutou.nas.utils.ConfigTools;
|
import com.yutou.nas.utils.*;
|
||||||
import com.yutou.nas.utils.OSSManager;
|
|
||||||
import com.yutou.nas.utils.QQBotManager;
|
|
||||||
import com.yutou.nas.utils.Tools;
|
|
||||||
import ealvatag.audio.AudioFile;
|
import ealvatag.audio.AudioFile;
|
||||||
import ealvatag.audio.AudioFileIO;
|
import ealvatag.audio.AudioFileIO;
|
||||||
import ealvatag.audio.AudioHeader;
|
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.FFmpegProbeResult;
|
||||||
import net.bramp.ffmpeg.probe.FFmpegStream;
|
import net.bramp.ffmpeg.probe.FFmpegStream;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.yutou.nas.utils.StringUtils;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
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_TITLE = 1;
|
||||||
public static final int FIND_ARTIST = 2;
|
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;
|
private boolean isScan = false;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@ -75,6 +71,10 @@ public class MusicToolsServiceImpl implements IMusicToolsService {
|
|||||||
|
|
||||||
|
|
||||||
private void scan(File path) {
|
private void scan(File path) {
|
||||||
|
if(!path.exists()){
|
||||||
|
Log.i("MusicScan","文件夹不存在,取消扫描");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (path.isFile()) {
|
if (path.isFile()) {
|
||||||
add(path);
|
add(path);
|
||||||
} else if (path.isDirectory()) {
|
} else if (path.isDirectory()) {
|
||||||
|
@ -2,10 +2,7 @@ package com.yutou.nas.bangumi;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.yutou.nas.utils.HttpTools;
|
import com.yutou.nas.utils.*;
|
||||||
import com.yutou.nas.utils.RedisTools;
|
|
||||||
import com.yutou.nas.utils.Tools;
|
|
||||||
import com.yutou.nas.utils.StringUtils;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -63,6 +60,48 @@ public class BangumiTools {
|
|||||||
return JSONObject.parseObject(str);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索番剧
|
* 搜索番剧
|
||||||
*
|
*
|
||||||
@ -106,10 +145,10 @@ public class BangumiTools {
|
|||||||
* @return 详细内容
|
* @return 详细内容
|
||||||
*/
|
*/
|
||||||
public static List<String> reportBangumiInfo(int id) {
|
public static List<String> reportBangumiInfo(int id) {
|
||||||
List<String> bangumiList=new ArrayList<>();
|
List<String> bangumiList = new ArrayList<>();
|
||||||
JSONObject json = getBangumiInfo(id);
|
JSONObject json = getBangumiInfo(id);
|
||||||
if(json.containsKey("code")){
|
if (json.containsKey("code")) {
|
||||||
bangumiList.add("error = "+json.toJSONString());
|
bangumiList.add("error = " + json.toJSONString());
|
||||||
return bangumiList;
|
return bangumiList;
|
||||||
}
|
}
|
||||||
JSONArray eps = json.getJSONArray("eps");
|
JSONArray eps = json.getJSONArray("eps");
|
||||||
@ -190,44 +229,45 @@ public class BangumiTools {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化输出新番列表
|
* 格式化输出新番列表
|
||||||
|
*
|
||||||
* @return 新番信息
|
* @return 新番信息
|
||||||
*/
|
*/
|
||||||
public static String reportBangumiList(){
|
public static String reportBangumiList() {
|
||||||
try {
|
try {
|
||||||
JSONObject json=getBangumi(-1);
|
JSONObject json = getBangumi(-1);
|
||||||
StringBuilder builder=new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
assert json != null;
|
assert json != null;
|
||||||
JSONArray array=json.getJSONArray("bangumi");
|
JSONArray array = json.getJSONArray("bangumi");
|
||||||
for (Object o : array) {
|
for (Object o : array) {
|
||||||
JSONObject data= (JSONObject) o;
|
JSONObject data = (JSONObject) o;
|
||||||
JSONObject weekday=data.getJSONObject("weekday");
|
JSONObject weekday = data.getJSONObject("weekday");
|
||||||
JSONArray items=data.getJSONArray("items");
|
JSONArray items = data.getJSONArray("items");
|
||||||
builder.append(weekday.getString("cn")).append("(").append(weekday.getString("ja")).append(")");
|
builder.append(weekday.getString("cn")).append("(").append(weekday.getString("ja")).append(")");
|
||||||
builder.append(":").append("\n");
|
builder.append(":").append("\n");
|
||||||
reportBangumi(builder, items,false);
|
reportBangumi(builder, items, false);
|
||||||
builder.append("\n");
|
builder.append("\n");
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return e.getMessage();
|
return e.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void reportBangumi(StringBuilder builder, JSONArray items,boolean reportEp) {
|
private static void reportBangumi(StringBuilder builder, JSONArray items, boolean reportEp) {
|
||||||
int epIndex = 0;
|
int epIndex = 0;
|
||||||
String epName = "N/A";
|
String epName = "N/A";
|
||||||
for (Object oj : items) {
|
for (Object oj : items) {
|
||||||
JSONObject item = (JSONObject) oj;
|
JSONObject item = (JSONObject) oj;
|
||||||
builder.append("[").append(item.getInteger("id")).append("]");
|
builder.append("[").append(item.getInteger("id")).append("]");
|
||||||
builder.append(StringUtils.isEmpty(item.getString("name_cn"))
|
builder.append(StringUtils.isEmpty(item.getString("name_cn"))
|
||||||
?item.getString("name"):item.getString("name_cn"));
|
? item.getString("name") : item.getString("name_cn"));
|
||||||
if(!reportEp){
|
if (!reportEp) {
|
||||||
builder.append("\n");
|
builder.append("\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
JSONObject info=getBangumiInfo(item.getInteger("id"));
|
JSONObject info = getBangumiInfo(item.getInteger("id"));
|
||||||
if(info.get("eps")==null){
|
if (info.get("eps") == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
JSONArray eps = info.getJSONArray("eps");
|
JSONArray eps = info.getJSONArray("eps");
|
||||||
@ -264,7 +304,7 @@ public class BangumiTools {
|
|||||||
JSONArray items = toDay.getJSONArray("items");
|
JSONArray items = toDay.getJSONArray("items");
|
||||||
builder.append("今日 ").append(weekday.get("cn")).append("(").append(weekday.get("ja")).append(")");
|
builder.append("今日 ").append(weekday.get("cn")).append("(").append(weekday.get("ja")).append(")");
|
||||||
builder.append(" 放送列表:").append("\n");
|
builder.append(" 放送列表:").append("\n");
|
||||||
reportBangumi(builder, items,true);
|
reportBangumi(builder, items, true);
|
||||||
}
|
}
|
||||||
RedisTools.set("toDayBangumi", builder.toString());
|
RedisTools.set("toDayBangumi", builder.toString());
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
@ -281,7 +321,7 @@ public class BangumiTools {
|
|||||||
* @return 详细内容
|
* @return 详细内容
|
||||||
*/
|
*/
|
||||||
public static List<String> reportSearchBangumi(String key) {
|
public static List<String> reportSearchBangumi(String key) {
|
||||||
List<String> bangumiList=new ArrayList<>();
|
List<String> bangumiList = new ArrayList<>();
|
||||||
JSONObject main = search(key);
|
JSONObject main = search(key);
|
||||||
if (main.getInteger("results") > 0) {
|
if (main.getInteger("results") > 0) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -289,7 +329,7 @@ public class BangumiTools {
|
|||||||
Collections.reverse(list);
|
Collections.reverse(list);
|
||||||
for (Object items : list) {
|
for (Object items : list) {
|
||||||
JSONObject item = (JSONObject) items;
|
JSONObject item = (JSONObject) items;
|
||||||
builder=new StringBuilder();
|
builder = new StringBuilder();
|
||||||
builder.append("标题:").append(item.getString("name_cn")).append("\n");
|
builder.append("标题:").append(item.getString("name_cn")).append("\n");
|
||||||
builder.append("日文标题:").append(item.getString("name")).append("\n");
|
builder.append("日文标题:").append(item.getString("name")).append("\n");
|
||||||
String type;
|
String type;
|
||||||
@ -332,10 +372,36 @@ public class BangumiTools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void saveInfoToJellyfin(String name) {
|
||||||
RedisTools.remove("reportToDayBangumi");
|
JSONObject json = search(name);
|
||||||
String str = reportToDayBangumi();
|
JSONArray array = json.getJSONArray("list");
|
||||||
System.out.println(str);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,5 +151,10 @@ public class tools {
|
|||||||
videoToolsService.scanVideo();
|
videoToolsService.scanVideo();
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
@ResponseBody
|
||||||
|
@RequestMapping("/public/getUPSPower.do")
|
||||||
|
public float getUPSPower(){
|
||||||
|
return Tools.getSystemUPSPower();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,12 +26,30 @@ public class ApplicationInit implements ApplicationRunner {
|
|||||||
public void run(ApplicationArguments args) throws Exception {
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
AudioTools.init();
|
AudioTools.init();
|
||||||
new Timer().schedule(new TimerTask() {
|
new Timer().schedule(new TimerTask() {
|
||||||
|
boolean powerOffice=false;
|
||||||
|
boolean powerLow=false;
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String time = new SimpleDateFormat("HH:mm").format(new Date());
|
String time = new SimpleDateFormat("HH:mm").format(new Date());
|
||||||
if (time.equals(oldTime)) {
|
if (time.equals(oldTime)) {
|
||||||
return;
|
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;
|
oldTime = time;
|
||||||
switch (time) {
|
switch (time) {
|
||||||
case "00:00":
|
case "00:00":
|
||||||
|
@ -11,8 +11,8 @@ public class AudioTools {
|
|||||||
}
|
}
|
||||||
SpeechUtility.createUtility(SpeechConstant.APPID + "=601f7f7d");
|
SpeechUtility.createUtility(SpeechConstant.APPID + "=601f7f7d");
|
||||||
SpeechUtility.getUtility().setParameter(SpeechConstant.VOLUME,"100");
|
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_64,"/media/yutou/disk_lvm/public/servier/tools/");
|
||||||
SpeechUtility.getUtility().setParameter(SpeechConstant.LIB_NAME_32,"/media/yutou/4t/public/servier/tools/");
|
SpeechUtility.getUtility().setParameter(SpeechConstant.LIB_NAME_32,"/media/yutou/disk_lvm/public/servier/tools/");
|
||||||
init = true;
|
init = true;
|
||||||
com.yutou.nas.utils.Log.i("讯飞语音已初始化");
|
com.yutou.nas.utils.Log.i("讯飞语音已初始化");
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ public class BTDownloadManager implements ApplicationContextAware {
|
|||||||
@Resource
|
@Resource
|
||||||
IBangumiService bangumiService;
|
IBangumiService bangumiService;
|
||||||
private static BTDownloadManager manager;
|
private static BTDownloadManager manager;
|
||||||
|
private static final String DownloadHomePath="/media/yutou/disk_lvm/public/";
|
||||||
|
|
||||||
public static BTDownloadManager getInstance() {
|
public static BTDownloadManager getInstance() {
|
||||||
if (manager == null) {
|
if (manager == null) {
|
||||||
@ -41,6 +42,11 @@ public class BTDownloadManager implements ApplicationContextAware {
|
|||||||
List<BangumiItem> list = bangumiService.getAllBangumi();
|
List<BangumiItem> list = bangumiService.getAllBangumi();
|
||||||
AnimationData data = new AnimationData();
|
AnimationData data = new AnimationData();
|
||||||
Log.i("BT","启动BT检测,总数:"+list.size());
|
Log.i("BT","启动BT检测,总数:"+list.size());
|
||||||
|
File path=new File(DownloadHomePath);
|
||||||
|
if(!path.exists()){
|
||||||
|
Log.i("BT","下载目录已离线,取消扫描");
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (BangumiItem item : list) {
|
for (BangumiItem item : list) {
|
||||||
if(item.getEnable()==0){
|
if(item.getEnable()==0){
|
||||||
continue;
|
continue;
|
||||||
@ -119,16 +125,18 @@ public class BTDownloadManager implements ApplicationContextAware {
|
|||||||
|
|
||||||
public boolean download(String title, String url) {
|
public boolean download(String title, String url) {
|
||||||
try {
|
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
|
, title
|
||||||
, url
|
, url
|
||||||
);
|
);
|
||||||
Log.i(exec);
|
Log.i(exec);
|
||||||
Runtime.getRuntime().exec(new String[]{"sh"
|
Process process=Runtime.getRuntime().exec(new String[]{"sh"
|
||||||
, "-c"
|
, "-c"
|
||||||
, exec});
|
, exec});
|
||||||
|
process.exitValue();
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -3,7 +3,6 @@ package com.yutou.nas.utils;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.yutou.nas.interfaces.DownloadInterface;
|
import com.yutou.nas.interfaces.DownloadInterface;
|
||||||
import com.yutou.nas.utils.Interfaces.NetworkInterface;
|
import com.yutou.nas.utils.Interfaces.NetworkInterface;
|
||||||
import com.yutou.nas.utils.StringUtils;
|
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -11,25 +10,35 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class HttpTools {
|
public class HttpTools {
|
||||||
public static final String serverKey="zIrsh9TUZP2lfRW753PannG49E7VJvor";
|
public static final String serverKey = "zIrsh9TUZP2lfRW753PannG49E7VJvor";
|
||||||
private static final int HttpRequestIndex=3;
|
private static final int HttpRequestIndex = 3;
|
||||||
|
|
||||||
public static String get(String url){
|
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){
|
|
||||||
|
public static File syncDownload(final String url, final String saveName) {
|
||||||
return new HttpTools().http_syncDownload(url, 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 {
|
try {
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
URLConnection connection;
|
||||||
|
connection = new URL(url).openConnection();
|
||||||
connection.setRequestProperty("User-Agent", getExtUa());
|
connection.setRequestProperty("User-Agent", getExtUa());
|
||||||
|
if (header != null) {
|
||||||
|
for (String key : header.keySet()) {
|
||||||
|
connection.addRequestProperty(key, header.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
connection.connect();
|
connection.connect();
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
StringBuilder str = new StringBuilder();
|
StringBuilder str = new StringBuilder();
|
||||||
@ -38,29 +47,25 @@ public class HttpTools {
|
|||||||
str.append(tmp);
|
str.append(tmp);
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
connection.disconnect();
|
|
||||||
return str.toString();
|
return str.toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if(index<HttpRequestIndex){
|
System.err.println("error url = " + url);
|
||||||
return http_get(url,++index);
|
|
||||||
}
|
|
||||||
System.err.println("error url = "+url);
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void http_post(final String url, final byte[] body,final int index, final NetworkInterface networkInterface) {
|
public static String http_post(String url, byte[] body, int index, Map<String, String> headers) {
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
String tmp;
|
String tmp;
|
||||||
StringBuilder str = new StringBuilder();
|
StringBuilder str = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
|
if (headers != null) {
|
||||||
|
for (String key : headers.keySet()) {
|
||||||
|
connection.addRequestProperty(key, headers.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.addRequestProperty("User-Agent", getExtUa());
|
connection.addRequestProperty("User-Agent", getExtUa());
|
||||||
@ -71,36 +76,29 @@ public class HttpTools {
|
|||||||
//connection.addRequestProperty("content-type", "application/json");
|
//connection.addRequestProperty("content-type", "application/json");
|
||||||
connection.addRequestProperty("charset", "UTF-8");
|
connection.addRequestProperty("charset", "UTF-8");
|
||||||
OutputStream outputStream = connection.getOutputStream();
|
OutputStream outputStream = connection.getOutputStream();
|
||||||
|
//System.out.println(new String(body));
|
||||||
outputStream.write(body);
|
outputStream.write(body);
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
|
connection.connect();
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
while ((tmp = reader.readLine()) != null) {
|
while ((tmp = reader.readLine()) != null) {
|
||||||
str.append(tmp);
|
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();
|
connection.disconnect();
|
||||||
reader.close();
|
reader.close();
|
||||||
|
return finalStr;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if(index<HttpRequestIndex){
|
if (index < HttpRequestIndex) {
|
||||||
http_post(url, body, index+1, networkInterface);
|
return http_post(url, body, index + 1, headers);
|
||||||
}else {
|
} else {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getExtUa() {
|
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";
|
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) {
|
if (jar != null) {
|
||||||
jar.delete();
|
jar.delete();
|
||||||
}
|
}
|
||||||
|
if (downloadInterface != null)
|
||||||
downloadInterface.onError(e);
|
downloadInterface.onError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +211,7 @@ public class HttpTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized File http_syncDownload(final String url, final String saveName) {
|
public synchronized File http_syncDownload(final String url, final String saveName) {
|
||||||
if(StringUtils.isEmpty(url)){
|
if (StringUtils.isEmpty(url)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
File jar = 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 {
|
public class QQBotManager {
|
||||||
|
|
||||||
|
|
||||||
private static class QQCommands {
|
public static class QQCommands {
|
||||||
private final static String QQ_HELP = "!help";
|
private final static String QQ_HELP = "!help";
|
||||||
private final static String QQ_SYSTEM_RESTART = "!restart";
|
private final static String QQ_SYSTEM_RESTART = "!restart";
|
||||||
private final static String QQ_UPDATE_IP = "!更新ip";
|
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 = "!idea";
|
||||||
private final static String QQ_TOOLS_IDEA_FILE = "!idea>";
|
private final static String QQ_TOOLS_IDEA_FILE = "!idea>";
|
||||||
private final static String QQ_TOOLS_IDEA_URL = "!idea_url";
|
private final static String QQ_TOOLS_IDEA_URL = "!idea_url";
|
||||||
|
|
||||||
|
public final static String QQ_BANGUMI_INFO="!保存动画信息>";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static QQBotManager botManager = null;
|
private static QQBotManager botManager = null;
|
||||||
@ -136,7 +138,7 @@ public class QQBotManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String sendMessage(String text) {
|
public String sendMessage(String text) {
|
||||||
if (bot != null) {
|
if (bot != null&&!StringUtils.isEmpty(text)) {
|
||||||
try {
|
try {
|
||||||
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(text).toString();
|
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(text).toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -266,7 +268,7 @@ public class QQBotManager {
|
|||||||
case QQCommands.QQ_SYSTEM_RESTART:
|
case QQCommands.QQ_SYSTEM_RESTART:
|
||||||
getInstance().sendMessage("正在重启服务");
|
getInstance().sendMessage("正在重启服务");
|
||||||
System.out.println("结束进程");
|
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;
|
break;
|
||||||
case QQCommands.QQ_HELP:
|
case QQCommands.QQ_HELP:
|
||||||
builder = new StringBuilder();
|
builder = new StringBuilder();
|
||||||
|
@ -251,7 +251,7 @@ public class RedisTools {
|
|||||||
exec = value;
|
exec = value;
|
||||||
break;
|
break;
|
||||||
case "updateIP":
|
case "updateIP":
|
||||||
exec = "python3 /media/yutou/4t/public/Python/tools/ip.py";
|
exec = "python3 /media/yutou/disk_lvm/public/Python/tools/ip.py";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (exec != null) {
|
if (exec != null) {
|
||||||
|
@ -3,6 +3,7 @@ package com.yutou.nas.utils;
|
|||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.yutou.nas.Controllers.UpdateIp;
|
import com.yutou.nas.Controllers.UpdateIp;
|
||||||
import com.yutou.nas.interfaces.DownloadInterface;
|
import com.yutou.nas.interfaces.DownloadInterface;
|
||||||
|
import com.yutou.nas.interfaces.ObjectInterface;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -24,8 +25,11 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Tools {
|
public class Tools {
|
||||||
|
private static float UPSPower=-1.0f;
|
||||||
/**
|
/**
|
||||||
* 设置Cookie
|
* 设置Cookie
|
||||||
*
|
*
|
||||||
@ -91,8 +95,7 @@ public class Tools {
|
|||||||
try {
|
try {
|
||||||
com.yutou.nas.utils.Log.i("title=" + title + " msg=" + msg);
|
com.yutou.nas.utils.Log.i("title=" + title + " msg=" + msg);
|
||||||
HttpTools.post("https://sctapi.ftqq.com/SCT2619Tpqu93OYtQCrK4LOZYEfr2irm.send",
|
HttpTools.post("https://sctapi.ftqq.com/SCT2619Tpqu93OYtQCrK4LOZYEfr2irm.send",
|
||||||
("title="+URLEncoder.encode(title, "UTF-8") + "&desp=" + URLEncoder.encode(msg, "UTF-8")).getBytes(StandardCharsets.UTF_8),
|
("title="+URLEncoder.encode(title, "UTF-8") + "&desp=" + URLEncoder.encode(msg, "UTF-8")).getBytes(StandardCharsets.UTF_8));
|
||||||
null);
|
|
||||||
if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("nas")) {
|
if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("nas")) {
|
||||||
String img = null;
|
String img = null;
|
||||||
msg = msg.replace("<br/>", "\n");
|
msg = msg.replace("<br/>", "\n");
|
||||||
@ -384,4 +387,22 @@ public class Tools {
|
|||||||
public static String getToDayTime() {
|
public static String getToDayTime() {
|
||||||
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user