From ef1ba6f61fbc0d08a89936c0c5c6617d7f9a5cc1 Mon Sep 17 00:00:00 2001
From: Yutousama <583819556@qq.com>
Date: Thu, 30 Sep 2021 09:32:51 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=B9Jellyfin=E7=9A=84?=
=?UTF-8?q?=E6=90=9C=E5=88=AE=EF=BC=88=E4=BD=86=E6=9C=AA=E5=AE=8C=E6=88=90?=
=?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 21 +-
.../java/com/yutou/nas/Datas/AppData.java | 2 +-
.../java/com/yutou/nas/NasApplication.java | 2 +-
.../Services/impl/MusicToolsServiceImpl.java | 12 +-
.../com/yutou/nas/bangumi/BangumiTools.java | 122 ++++++++---
src/main/java/com/yutou/nas/other/tools.java | 5 +
.../com/yutou/nas/utils/ApplicationInit.java | 18 ++
.../java/com/yutou/nas/utils/AudioTools.java | 4 +-
.../yutou/nas/utils/BTDownloadManager.java | 14 +-
.../java/com/yutou/nas/utils/HttpTools.java | 129 ++++++------
.../yutou/nas/utils/JellyfinAPIManager.java | 195 ++++++++++++++++++
.../com/yutou/nas/utils/QQBotManager.java | 8 +-
.../java/com/yutou/nas/utils/RedisTools.java | 2 +-
src/main/java/com/yutou/nas/utils/Tools.java | 25 ++-
14 files changed, 446 insertions(+), 113 deletions(-)
create mode 100644 src/main/java/com/yutou/nas/utils/JellyfinAPIManager.java
diff --git a/pom.xml b/pom.xml
index ce6bee0..3bdcbf0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -144,6 +144,25 @@
${project.basedir}/src/main/java
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 1.8
+
+
+ test
+
+ run
+
+
+
+ 复制正式文件
+
+
+
+
+
+
org.jetbrains.kotlin
kotlin-maven-plugin
@@ -184,7 +203,7 @@
- Z:\servier\tools\
+ X:\servier\tools\
diff --git a/src/main/java/com/yutou/nas/Datas/AppData.java b/src/main/java/com/yutou/nas/Datas/AppData.java
index d3ddf6c..4232c57 100644
--- a/src/main/java/com/yutou/nas/Datas/AppData.java
+++ b/src/main/java/com/yutou/nas/Datas/AppData.java
@@ -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/音乐";
}
diff --git a/src/main/java/com/yutou/nas/NasApplication.java b/src/main/java/com/yutou/nas/NasApplication.java
index 12579eb..f7f0a6a 100644
--- a/src/main/java/com/yutou/nas/NasApplication.java
+++ b/src/main/java/com/yutou/nas/NasApplication.java
@@ -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");
diff --git a/src/main/java/com/yutou/nas/Services/impl/MusicToolsServiceImpl.java b/src/main/java/com/yutou/nas/Services/impl/MusicToolsServiceImpl.java
index afea16b..5f11ff1 100644
--- a/src/main/java/com/yutou/nas/Services/impl/MusicToolsServiceImpl.java
+++ b/src/main/java/com/yutou/nas/Services/impl/MusicToolsServiceImpl.java
@@ -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()) {
diff --git a/src/main/java/com/yutou/nas/bangumi/BangumiTools.java b/src/main/java/com/yutou/nas/bangumi/BangumiTools.java
index 364551b..38f42ca 100644
--- a/src/main/java/com/yutou/nas/bangumi/BangumiTools.java
+++ b/src/main/java/com/yutou/nas/bangumi/BangumiTools.java
@@ -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;
+ }
+
/**
* 搜索番剧
*
@@ -106,10 +145,10 @@ public class BangumiTools {
* @return 详细内容
*/
public static List reportBangumiInfo(int id) {
- List bangumiList=new ArrayList<>();
+ List bangumiList = new ArrayList<>();
JSONObject json = getBangumiInfo(id);
- if(json.containsKey("code")){
- bangumiList.add("error = "+json.toJSONString());
+ if (json.containsKey("code")) {
+ bangumiList.add("error = " + json.toJSONString());
return bangumiList;
}
JSONArray eps = json.getJSONArray("eps");
@@ -190,44 +229,45 @@ public class BangumiTools {
/**
* 格式化输出新番列表
+ *
* @return 新番信息
*/
- public static String reportBangumiList(){
+ public static String reportBangumiList() {
try {
- JSONObject json=getBangumi(-1);
- StringBuilder builder=new StringBuilder();
+ JSONObject json = getBangumi(-1);
+ StringBuilder builder = new StringBuilder();
assert json != null;
- JSONArray array=json.getJSONArray("bangumi");
+ JSONArray array = json.getJSONArray("bangumi");
for (Object o : array) {
- JSONObject data= (JSONObject) o;
- JSONObject weekday=data.getJSONObject("weekday");
- JSONArray items=data.getJSONArray("items");
+ JSONObject data = (JSONObject) o;
+ JSONObject weekday = data.getJSONObject("weekday");
+ JSONArray items = data.getJSONArray("items");
builder.append(weekday.getString("cn")).append("(").append(weekday.getString("ja")).append(")");
builder.append(":").append("\n");
- reportBangumi(builder, items,false);
+ reportBangumi(builder, items, false);
builder.append("\n");
}
return builder.toString();
- }catch (Exception e){
+ } catch (Exception e) {
e.printStackTrace();
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;
String epName = "N/A";
for (Object oj : items) {
JSONObject item = (JSONObject) oj;
builder.append("[").append(item.getInteger("id")).append("]");
builder.append(StringUtils.isEmpty(item.getString("name_cn"))
- ?item.getString("name"):item.getString("name_cn"));
- if(!reportEp){
+ ? item.getString("name") : item.getString("name_cn"));
+ if (!reportEp) {
builder.append("\n");
continue;
}
- JSONObject info=getBangumiInfo(item.getInteger("id"));
- if(info.get("eps")==null){
+ JSONObject info = getBangumiInfo(item.getInteger("id"));
+ if (info.get("eps") == null) {
continue;
}
JSONArray eps = info.getJSONArray("eps");
@@ -264,7 +304,7 @@ public class BangumiTools {
JSONArray items = toDay.getJSONArray("items");
builder.append("今日 ").append(weekday.get("cn")).append("(").append(weekday.get("ja")).append(")");
builder.append(" 放送列表:").append("\n");
- reportBangumi(builder, items,true);
+ reportBangumi(builder, items, true);
}
RedisTools.set("toDayBangumi", builder.toString());
return builder.toString();
@@ -281,7 +321,7 @@ public class BangumiTools {
* @return 详细内容
*/
public static List reportSearchBangumi(String key) {
- List bangumiList=new ArrayList<>();
+ List bangumiList = new ArrayList<>();
JSONObject main = search(key);
if (main.getInteger("results") > 0) {
StringBuilder builder = new StringBuilder();
@@ -289,7 +329,7 @@ public class BangumiTools {
Collections.reverse(list);
for (Object items : list) {
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")).append("\n");
String type;
@@ -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);
+ }
}
diff --git a/src/main/java/com/yutou/nas/other/tools.java b/src/main/java/com/yutou/nas/other/tools.java
index b78e86f..606d770 100644
--- a/src/main/java/com/yutou/nas/other/tools.java
+++ b/src/main/java/com/yutou/nas/other/tools.java
@@ -151,5 +151,10 @@ public class tools {
videoToolsService.scanVideo();
return "ok";
}
+ @ResponseBody
+ @RequestMapping("/public/getUPSPower.do")
+ public float getUPSPower(){
+ return Tools.getSystemUPSPower();
+ }
}
diff --git a/src/main/java/com/yutou/nas/utils/ApplicationInit.java b/src/main/java/com/yutou/nas/utils/ApplicationInit.java
index 82adee2..5ec3a67 100644
--- a/src/main/java/com/yutou/nas/utils/ApplicationInit.java
+++ b/src/main/java/com/yutou/nas/utils/ApplicationInit.java
@@ -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":
diff --git a/src/main/java/com/yutou/nas/utils/AudioTools.java b/src/main/java/com/yutou/nas/utils/AudioTools.java
index 6c20c04..63f4a99 100644
--- a/src/main/java/com/yutou/nas/utils/AudioTools.java
+++ b/src/main/java/com/yutou/nas/utils/AudioTools.java
@@ -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("讯飞语音已初始化");
}
diff --git a/src/main/java/com/yutou/nas/utils/BTDownloadManager.java b/src/main/java/com/yutou/nas/utils/BTDownloadManager.java
index 574426c..b60b38e 100644
--- a/src/main/java/com/yutou/nas/utils/BTDownloadManager.java
+++ b/src/main/java/com/yutou/nas/utils/BTDownloadManager.java
@@ -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 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;
diff --git a/src/main/java/com/yutou/nas/utils/HttpTools.java b/src/main/java/com/yutou/nas/utils/HttpTools.java
index 567e0a8..02e74d2 100644
--- a/src/main/java/com/yutou/nas/utils/HttpTools.java
+++ b/src/main/java/com/yutou/nas/utils/HttpTools.java
@@ -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 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 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;
diff --git a/src/main/java/com/yutou/nas/utils/JellyfinAPIManager.java b/src/main/java/com/yutou/nas/utils/JellyfinAPIManager.java
new file mode 100644
index 0000000..0502a4a
--- /dev/null
+++ b/src/main/java/com/yutou/nas/utils/JellyfinAPIManager.java
@@ -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 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 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 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 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 getHeader() {
+ HashMap 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