From 998b6bd2a1dc25ec8350f5a691c3cd44a23d6d14 Mon Sep 17 00:00:00 2001 From: admin <2780501319@qq.com> Date: 星期五, 26 三月 2021 01:35:13 +0800 Subject: [PATCH] 全网搜(芒果兼容) --- src/main/java/com/yeshi/buwan/mogotv/MogoTVApiUtil.java | 244 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 166 insertions(+), 78 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/mogotv/MogoTVApiUtil.java b/src/main/java/com/yeshi/buwan/mogotv/MogoTVApiUtil.java index 6bc3ced..898aace 100644 --- a/src/main/java/com/yeshi/buwan/mogotv/MogoTVApiUtil.java +++ b/src/main/java/com/yeshi/buwan/mogotv/MogoTVApiUtil.java @@ -2,13 +2,20 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import com.yeshi.buwan.mogotv.entity.MogoTVClipInfo; +import com.yeshi.buwan.mogotv.entity.MogoTVVideo; import com.yeshi.buwan.youku.entity.YouKuShowDetail; import com.yeshi.buwan.youku.entity.YouKuShowSimple; import com.yeshi.buwan.youku.entity.YouKuVideo; -import org.json.JSONObject; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; import org.yeshi.utils.HttpUtil; import org.yeshi.utils.StringUtil; +import javax.script.Invocable; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; import java.net.URLEncoder; @@ -28,107 +35,188 @@ // isIntact锛�1琛ㄧず姝g墖 - private final static String APP_ID = "758bef946d0050ef"; private final static String APP_SECRET = "e113a131d49e1f837402e2807f2daf58"; - private static String request(String action, Map<String, String> ps) { - Map<String, String> params = new HashMap<>(); - params.put("action", action); - params.put("client_id", APP_ID); - params.put("format", "json"); - params.put("timestamp", System.currentTimeMillis() / 1000 + ""); - params.put("version", "3.0"); - params.put("format", "json"); - params.putAll(ps); + private static ScriptEngine jsEngine; - - List<String> list = new ArrayList<>(); - for (Iterator<String> its = params.keySet().iterator(); its.hasNext(); ) { - String key = its.next(); - try { - list.add(key + URLEncoder.encode(params.get(key), "UTF-8")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - - Collections.sort(list); - - String sign = StringUtil.Md5(StringUtil.concat(list, "") + APP_SECRET); - params.put("sign", sign); - ps.put("opensysparams", new JSONObject(params).toString()); - - return HttpUtil.get("https://openapi.youku.com/router/rest.json", ps, new HashMap<>()); - } /** - * 鑾峰彇鑺傜洰璇︽儏 + * 瑙f瀽缁撴灉鏁版嵁 * - * @param id + * @param callback + * @param result * @return + * @throws Exception */ - public static YouKuShowDetail getShowDetail(String id) { - String url = String.format("https://openapi.youku.com/v2/shows/show.json?client_id=%s&show_id=%s", APP_ID, id); - String result = HttpUtil.get(url); - return new Gson().fromJson(result, YouKuShowDetail.class); - } - - /** - * 鏍规嵁鍒嗙被鎷夊彇鏁版嵁 - * - * @param category - * @param page - */ - public static ListResultDTO getShowListByCategory(String category, int page, int pageSize) { - + private static String parseResult(String callback, String result) throws Exception { + if (jsEngine == null) { + ScriptEngineManager manager = new ScriptEngineManager(); + jsEngine = manager.getEngineByName("javascript"); + } try { - String url = String.format("https://openapi.youku.com/v2/shows/by_category.json?client_id=%s&paid=1&category=%s&page=%s&count=" + pageSize, APP_ID, URLEncoder.encode(category, "UTF-8"), page); - String result = HttpUtil.get(url); - net.sf.json.JSONObject resultJson = net.sf.json.JSONObject.fromObject(result); - int total = resultJson.optInt("total"); - Type type = new TypeToken<List<YouKuShowSimple>>() { - }.getType(); - List<YouKuShowSimple> list = new Gson().fromJson(resultJson.optJSONArray("shows").toString(), type); - return new ListResultDTO(list, total); - } catch (UnsupportedEncodingException e) { + String script = "function getData(){ return " + result + ";}\n"; + script += String.format("function %s(t){return t;}", callback); + jsEngine.eval(script); + } catch ( + ScriptException e) { e.printStackTrace(); } + if (jsEngine instanceof Invocable) { + Invocable in = (Invocable) jsEngine; + Object info = in.invokeFunction("getData"); + return new Gson().toJson(info); + } return null; } - public static ListResultDTO getVideoList(String showId, int page, int pageSize) { - Map<String, String> params = new HashMap<>(); - params.put("show_id", showId); - params.put("show_videotype", "姝g墖"); - params.put("page", page + ""); - params.put("pageLength", pageSize + ""); - String result = MogoTVApiUtil.request("youku.api.video.byprogram.get", params); - System.out.println(result); - net.sf.json.JSONObject resultJson = net.sf.json.JSONObject.fromObject(result); - int total = resultJson.optInt("total"); - Type type = new TypeToken<List<YouKuVideo>>() { - }.getType(); - List<YouKuVideo> videoList = new Gson().fromJson(resultJson.optJSONArray("videos").toString(), type); - if (videoList != null) - for (YouKuVideo video : videoList) { - video.setShowId(showId); + public static String request(String url) throws Exception { + String callback = "jsonp_" + System.currentTimeMillis(); + url += "&callback=" + callback; + String result = HttpUtil.get(url); + return parseResult(callback, result); + } + + + public static ListResultDTO getVideoList(String videoId, int page, int pageSize) { + String url = String.format("https://pcweb.api.mgtv.com/episode/list?src=intelmgtv&abroad=0&_support=10000000&version=5.5.35&video_id=%s&page=%s&size=%s&abroad=0&src=intelmgtv", videoId, page, pageSize); + String result = null; + try { + result = request(url); + } catch (Exception e) { + e.printStackTrace(); + } + JSONObject data = JSONObject.fromObject(result); + if (data.optInt("code") == 200) { + data = data.optJSONObject("data"); + + int totalPage = data.optInt("total_page"); + JSONArray list = data.optJSONArray("list"); + Type type = new TypeToken<List<MogoTVVideo>>() { + }.getType(); + List<MogoTVVideo> videoList = new Gson().fromJson(list.toString(), type); + for (int i = 0; i < videoList.size(); i++) { + if (videoList.get(i).getIsIntact() != 1) { + videoList.remove(i--); + } } - return new ListResultDTO(videoList, total); + + + return new ListResultDTO(videoList, totalPage); + } + return null; + } + + + /** + * 鑾峰彇瑙嗛鍒楄〃 + * + * @param videoId + * @return + */ + public static List<MogoTVVideo> getVideoList(String videoId) { + List<MogoTVVideo> videoList = new ArrayList<>(); + ListResultDTO dto = getVideoList(videoId, 1, 30); + videoList.addAll(dto.getList()); + for (int i = 1; i < dto.getTotal(); i++) { + dto = getVideoList(videoId, i + 1, 30); + videoList.addAll(dto.getList()); + } + + Comparator<MogoTVVideo> cm = new Comparator<MogoTVVideo>() { + @Override + public int compare(MogoTVVideo o1, MogoTVVideo o2) { + return o1.getT1() - o2.getT1(); + } + }; + Collections.sort(videoList, cm); + return videoList; + } + + + /** + * 璇︽儏鑾峰彇 + * + * @param clipInfo + * @return + */ + public static MogoTVClipInfo getClipDetail(MogoTVClipInfo clipInfo) { + String url = String.format("https://pcweb.api.mgtv.com/video/info?cid=%s&vid=%s&_support=10000000&abroad=0&src=intelmgtv", clipInfo.getClipId(), clipInfo.getPlayPartId()); + String result = null; + try { + result = request(url); + } catch (Exception e) { + e.printStackTrace(); + } + JSONObject data = JSONObject.fromObject(result); + if (data.optInt("code") == 200) { + data = data.optJSONObject("data"); + JSONObject info = data.optJSONObject("info"); + clipInfo.setVpicture(info.optString("clipImage2")); + clipInfo.setHpicture(info.optString("clipImage")); + JSONObject detail = info.optJSONObject("detail"); + clipInfo.setArea(detail.optString("area")); + clipInfo.setUpdateInfo(detail.optString("updateInfo")); + clipInfo.setLeader(detail.optString("leader")); + clipInfo.setReleaseTime(detail.optString("releaseTime")); + clipInfo.setPresenter(detail.optString("presenter")); + clipInfo.setKind(detail.optString("kind")); + clipInfo.setDirector(detail.optString("director")); + clipInfo.setTelevision(detail.optString("television")); + clipInfo.setLanguage(detail.optString("language")); + clipInfo.setFstlvlType(detail.optString("fstlvlType")); + clipInfo.setStory(detail.optString("story")); + return clipInfo; + } + return null; + } + + /** + * 鑾峰彇涓撹緫鍒楄〃 + * + * @param channelId + * @param page + * @param pageSize + * @return + */ + public static ListResultDTO getClipList(int channelId, int page, int pageSize) { + String url = String.format("https://pianku.api.mgtv.com/rider/list/pcweb/v4?platform=pcweb&channelId=%s&pn=%s&pc=%s&hudong=0&_support=10000000&kind=a1&area=a1&sort=c2&abroad=0&src=intelmgtv", channelId, page, pageSize); + String result = null; + try { + result = request(url); + } catch (Exception e) { + e.printStackTrace(); + } + JSONObject data = JSONObject.fromObject(result); + if (data.optInt("code") == 200) { + data = data.optJSONObject("data"); + int total = data.optInt("totalHits"); + Type type = new TypeToken<List<MogoTVClipInfo>>() { + }.getType(); + JSONObject hitDocs = data.optJSONObject("hitDocs"); + JSONArray array = new JSONArray(); + if (!hitDocs.isArray()) { + for (Iterator<String> its = hitDocs.keys(); its.hasNext(); ) { + String key = its.next(); + array.add(hitDocs.optJSONObject(key)); + } + } else { + array = data.optJSONArray("hitDocs"); + } + List<MogoTVClipInfo> clipInfos = new Gson().fromJson(array.toString(), type); + return new ListResultDTO(clipInfos, total); + } + return null; } public static void main(String[] args) { -// YouKuShowDetail detail = getShowDetail("1e61efbfbdefbfbd04ef"); -// System.out.println(detail); - getVideoList("0a17e614d7e311e68ce4", 1, 20); -// ListResultDTO resultDTO = getShowListByCategory("鐢佃鍓�", 1); - -// System.out.println(resultDTO); + ListResultDTO dto = getClipList(1, 1, 80); + System.out.println(dto); } -- Gitblit v1.8.0