diff --git a/src/main/java/com/yutou/nas/Controllers/ToolsController.java b/src/main/java/com/yutou/nas/Controllers/ToolsController.java index 98fb85a..63da24b 100644 --- a/src/main/java/com/yutou/nas/Controllers/ToolsController.java +++ b/src/main/java/com/yutou/nas/Controllers/ToolsController.java @@ -1,9 +1,7 @@ package com.yutou.nas.Controllers; -import com.yutou.nas.utils.HttpTools; -import com.yutou.nas.utils.RedisTools; -import com.yutou.nas.utils.StringUtils; -import com.yutou.nas.utils.Tools; +import com.alibaba.fastjson.JSONArray; +import com.yutou.nas.utils.*; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @@ -41,4 +39,9 @@ public class ToolsController { Tools.sendServer(title, msg); return "ok"; } + @ResponseBody + @RequestMapping("/tools/anim/items.do") + public JSONArray getAnimItems(){ + return new JellyfinAPIManager().getAnimPaths(); + } } diff --git a/src/main/java/com/yutou/nas/NasApplication.java b/src/main/java/com/yutou/nas/NasApplication.java index e5efb79..bd790de 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.2.8"; + public static final String version="1.2.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/utils/JellyfinAPIManager.java b/src/main/java/com/yutou/nas/utils/JellyfinAPIManager.java index da47b95..6f4bf9c 100644 --- a/src/main/java/com/yutou/nas/utils/JellyfinAPIManager.java +++ b/src/main/java/com/yutou/nas/utils/JellyfinAPIManager.java @@ -69,37 +69,41 @@ public class JellyfinAPIManager { ), getHeader()); return JSONObject.parseObject(data); } - public JSONObject getEpisodesForJson(String parentID,String id){ + + public JSONObject getEpisodesForJson(String parentID, String id) { String data = HttpTools.https_get(String.format("http://192.168.31.88:8096/Shows/%s/Episodes?seasonId=%s&userId=e8a13675bb64466dbd81f1e5985ef8c7", parentID, id ), getHeader()); return JSONObject.parseObject(data); } - public List getEpisodes(String parentId,String id){ - JSONObject json=getEpisodesForJson(parentId, id); - JSONArray episodes=json.getJSONArray("Items"); + + public List getEpisodes(String parentId, String id) { + JSONObject json = getEpisodesForJson(parentId, id); + JSONArray episodes = json.getJSONArray("Items"); return JSONArray.parseArray(episodes.toJSONString(), Episode.class); } - public JSONObject getEpisodesDataForJson(String id){ + + public JSONObject getEpisodesDataForJson(String id) { String data = HttpTools.https_get(String.format("http://192.168.31.88:8096/Users/e8a13675bb64466dbd81f1e5985ef8c7/Items/%s", id ), getHeader()); return JSONObject.parseObject(data); } - public EpisodeData getEpisodeData(String id){ + + public EpisodeData getEpisodeData(String id) { return JSONObject.parseObject(getEpisodesDataForJson(id).toString(), EpisodeData.class); } - public String getPathForEpisode(String parentId,String id){ - List list=getEpisodes(parentId, id); - if(!list.isEmpty()){ + + public String getPathForEpisode(String parentId, String id) { + List list = getEpisodes(parentId, id); + if (!list.isEmpty()) { return getEpisodeData(list.get(0).getId()).getPath(); } return null; } - public void uploadImage(File image, String id, String model) { try { HashMap header = getHeader(); @@ -202,12 +206,6 @@ public class JellyfinAPIManager { } - - - - - - public void testItem(String id) { JellyfinAPIManager manager = new JellyfinAPIManager(); LibsItem item = manager.getLibs("番剧"); @@ -257,10 +255,27 @@ public class JellyfinAPIManager { } } - public void search(String name, File path) { + public JSONArray getAnimPaths() { + JSONArray array = new JSONArray(); for (LibsItem item : mediaItem) { - System.out.println(item.getName() + " > " + item.getInfo().getPath()); + JSONObject json = new JSONObject(); + json.put("name", item.getInfo().getName()); + List list = getLibsItems(item.getId()); + json.put("size",list.size()); + JSONArray _items = new JSONArray(); + if (list.size() > 1) { + for (LibsItem libsItem : list) { + JSONObject _item = new JSONObject(); + _item.put("name", libsItem.getName()); + _item.put("path", getInfo(libsItem.getId()).getPath()); + _items.add(_item); + } + json.put("path",_items); + } + json.put("root",item.getInfo().getPath()); + array.add(json); } + return array; } public void init(File path) { @@ -277,46 +292,26 @@ public class JellyfinAPIManager { String id = ConfigTools.loadIni(file, "id"); if (id != null) { for (LibsItem item : mediaItem) { - /*if (item.getName().equals("你遭难了吗?")) { - - // System.out.println(item.getName()+" "+item.getId()); - //System.out.println(getItemShows(item.getId())); - List _temp = getLibsItems(item.getId()); - System.out.println(item.getInfo().getPath() + " " + _temp.size()); - if (_temp.size() > 1) { - for (LibsItem libsItem : _temp) { - ItemInfo info = getInfo(libsItem.getId()); - if (info.getPath()==null){ - System.out.println(getPathForEpisode(info.getParentID(),info.getId())+" > "+path.getPath()); - //System.out.println(getPathForEpisode(info.getParentID(),info.getId()).contains(path.getPath())); - } - } - } - - System.exit(0); - break; - - }*/ List _temp = getLibsItems(item.getId()); - if(_temp.size()==1){ + if (_temp.size() == 1) { if (item.getInfo().getPath().contains(path.getPath())) { - System.out.println(item.getName()+" "+id); - new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)),item); + System.out.println(item.getName() + " " + id); + new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)), item); break; } - }else{ - System.out.println(item.getName()+" > "+_temp.size()); + } else { + System.out.println(item.getName() + " > " + _temp.size()); for (LibsItem libsItem : _temp) { ItemInfo info = getInfo(libsItem.getId()); - if(info.getPath()!=null) { + if (info.getPath() != null) { if (info.getPath().contains(path.getPath())) { System.out.println("list > " + item.getName() + " " + id); new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)), libsItem); break; } - }else{ - String ep_Path=getPathForEpisode(info.getParentID(),info.getId()); - if(ep_Path!=null&&ep_Path.contains(path.getPath())){ + } else { + String ep_Path = getPathForEpisode(info.getParentID(), info.getId()); + if (ep_Path != null && ep_Path.contains(path.getPath())) { System.out.println("list > " + item.getName() + " " + id); new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)), libsItem); break; @@ -324,11 +319,11 @@ public class JellyfinAPIManager { } } } - /* if (item.getInfo().getPath().contains(path.getPath())) { - //System.out.println(item.getName()+" "+id); - // new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)),item); + if (item.getInfo().getPath().contains(path.getPath())) { + System.out.println(item.getName() + " " + id); + new JellyfinAPIManager().saveJellyfinMetaData(BangumiTools.getBangumiInfo(Integer.parseInt(id)), item); break; - }*/ + } } } } @@ -345,9 +340,11 @@ public class JellyfinAPIManager { public static String mainPath = "Z:\\download\\anim\\"; public static void main(String[] args) { - File file = new File("Z:\\download\\anim\\"); + File file = new File("Z:\\download\\anim\\Bangdream☆pico"); //new JellyfinAPIManager().search(file.getName(), file); - JellyfinAPIManager manager=new JellyfinAPIManager(); - manager.init(file); + JellyfinAPIManager manager = new JellyfinAPIManager(); + // manager.init(file); + JSONArray search = manager.getAnimPaths(); + System.out.println(search); } }