diff --git a/src/main/java/com/yutou/tools/bangumi/BangumiTools.java b/src/main/java/com/yutou/tools/bangumi/BangumiTools.java new file mode 100644 index 0000000..b044325 --- /dev/null +++ b/src/main/java/com/yutou/tools/bangumi/BangumiTools.java @@ -0,0 +1,65 @@ +package com.yutou.tools.bangumi; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.yutou.tools.utils.HttpTools; +import com.yutou.tools.utils.RedisTools; + +import java.util.Calendar; +import java.util.Date; + +public class BangumiTools { + private static final String url = "http://api.bgm.tv/"; + private static final String toDayBangumi = url + "calendar"; + private static final String BangumiInfo = url + "/subject/%s?responseGroup=large"; + + /** + * 获取番剧列表 + * @param day 周几,-1为全部,非1~7范围则为当天 + * @return 当日数据 + */ + public static JSONObject getBangumi(int day) { + String str = HttpTools.get(toDayBangumi); + JSONArray main = JSONArray.parseArray(str); + if(day==-1){ + JSONObject json=new JSONObject(); + json.put("bangumi",main); + return json; + } + if(day<1||day>7) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + day=calendar.get(Calendar.DAY_OF_WEEK); + } + if (main != null) + for (Object o : main) { + JSONObject json = (JSONObject) o; + if (json.getJSONObject("weekday").getInteger("id") == day) { + return json; + } + } + return null; + } + + /** + * 获取番剧详细信息 + * @param id 剧集id + * @return 详细信息 + */ + public static JSONObject getBangumiInfo(int id){ + String str = HttpTools.get(String.format(BangumiInfo,id+"")); + JSONObject main = JSONObject.parseObject(str); + return main; + } + + public static void reportToDayBangumi(){ + if(!RedisTools.get("reportToDayBangumi").equals("true")){ + JSONObject toDay=getBangumi(0); + + } + } + public static void main(String[] args) { + + System.out.println(getBangumiInfo(293193)); + } +} diff --git a/src/main/java/com/yutou/tools/other/tools.java b/src/main/java/com/yutou/tools/other/tools.java index c534e8e..d7fb244 100644 --- a/src/main/java/com/yutou/tools/other/tools.java +++ b/src/main/java/com/yutou/tools/other/tools.java @@ -75,7 +75,7 @@ public class tools { JSONObject json = new JSONObject(); json.put("code", 0); json.put("address", Tools.getRemoteAddress(request)); - json.put("UA", request.getHeader("")); + json.put("UA", request.getHeader("User-Agent")); json.put("addressUrl", request.getPathInfo()); json.put("params", params); json.put("cookie", cookies); @@ -88,7 +88,7 @@ public class tools { case "-999": case "param": return json.toJSONString(); - case "user": + default: return RedisTools.get("request"); } }catch (Exception e){