diff --git a/app/src/main/java/com/github/catvod/api/AliYun.java b/app/src/main/java/com/github/catvod/api/AliYun.java index 1090320..9a69c7a 100644 --- a/app/src/main/java/com/github/catvod/api/AliYun.java +++ b/app/src/main/java/com/github/catvod/api/AliYun.java @@ -24,7 +24,7 @@ import com.github.catvod.bean.ali.Drive; import com.github.catvod.bean.ali.Item; import com.github.catvod.bean.ali.OAuth; import com.github.catvod.bean.ali.Preview; -import com.github.catvod.bean.ali.Res; +import com.github.catvod.bean.ali.Resp; import com.github.catvod.bean.ali.Share; import com.github.catvod.bean.ali.User; import com.github.catvod.crawler.SpiderDebug; @@ -401,8 +401,8 @@ public class AliYun { SpiderDebug.log("Copy..." + fileId); String json = "{\"requests\":[{\"body\":{\"file_id\":\"%s\",\"share_id\":\"%s\",\"auto_rename\":true,\"to_parent_file_id\":\"root\",\"to_drive_id\":\"%s\"},\"headers\":{\"Content-Type\":\"application/json\"},\"id\":\"0\",\"method\":\"POST\",\"url\":\"/file/copy\"}],\"resource\":\"file\"}"; json = String.format(json, fileId, shareId, drive.getDriveId()); - Res res = Res.objectFrom(auth("adrive/v2/batch", json, true)); - return res.getResponse().getBody().getFileId(); + Resp resp = Resp.objectFrom(auth("adrive/v2/batch", json, true)); + return resp.getResponse().getBody().getFileId(); } private void deleteAll() { @@ -417,8 +417,8 @@ public class AliYun { SpiderDebug.log("Delete..." + fileId); String json = "{\"requests\":[{\"body\":{\"drive_id\":\"%s\",\"file_id\":\"%s\"},\"headers\":{\"Content-Type\":\"application/json\"},\"id\":\"%s\",\"method\":\"POST\",\"url\":\"/file/delete\"}],\"resource\":\"file\"}"; json = String.format(json, drive.getDriveId(), fileId, fileId); - Res res = Res.objectFrom(auth("adrive/v2/batch", json, true)); - return res.getResponse().getStatus() == 404; + Resp resp = Resp.objectFrom(auth("adrive/v2/batch", json, true)); + return resp.getResponse().getStatus() == 404; } public Object[] proxySub(Map params) throws Exception { diff --git a/app/src/main/java/com/github/catvod/bean/Result.java b/app/src/main/java/com/github/catvod/bean/Result.java index 0a223c7..a8e9857 100644 --- a/app/src/main/java/com/github/catvod/bean/Result.java +++ b/app/src/main/java/com/github/catvod/bean/Result.java @@ -65,6 +65,10 @@ public class Result { return Result.get().classes(classes).filters(filters).string(); } + public static String string(List classes, JsonElement filters) { + return Result.get().classes(classes).filters(filters).string(); + } + public static String string(List classes, JSONObject filters) { return Result.get().classes(classes).filters(filters).string(); } diff --git a/app/src/main/java/com/github/catvod/bean/ali/Res.java b/app/src/main/java/com/github/catvod/bean/ali/Resp.java similarity index 84% rename from app/src/main/java/com/github/catvod/bean/ali/Res.java rename to app/src/main/java/com/github/catvod/bean/ali/Resp.java index 95e7703..65b1454 100644 --- a/app/src/main/java/com/github/catvod/bean/ali/Res.java +++ b/app/src/main/java/com/github/catvod/bean/ali/Resp.java @@ -8,10 +8,10 @@ import com.google.gson.annotations.SerializedName; import java.util.Collections; import java.util.List; -public class Res { +public class Resp { @SerializedName("responses") - private List responses; + private List responses; @SerializedName("body") private Body body; @SerializedName("id") @@ -19,16 +19,16 @@ public class Res { @SerializedName("status") private int status; - public static Res objectFrom(String str) { - return new Gson().fromJson(str, Res.class); + public static Resp objectFrom(String str) { + return new Gson().fromJson(str, Resp.class); } - public List getResponses() { + public List getResponses() { return responses == null ? Collections.emptyList() : responses; } - public Res getResponse() { - return getResponses().isEmpty() ? new Res() : getResponses().get(0); + public Resp getResponse() { + return getResponses().isEmpty() ? new Resp() : getResponses().get(0); } public Body getBody() { diff --git a/app/src/main/java/com/github/catvod/bean/jianpian/Data.java b/app/src/main/java/com/github/catvod/bean/jianpian/Data.java new file mode 100644 index 0000000..03f234e --- /dev/null +++ b/app/src/main/java/com/github/catvod/bean/jianpian/Data.java @@ -0,0 +1,125 @@ +package com.github.catvod.bean.jianpian; + +import android.text.TextUtils; + +import com.github.catvod.bean.Vod; +import com.github.catvod.utils.Utils; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class Data { + + @SerializedName(value = "jump_id", alternate = "id") + private String vodId; + @SerializedName(value = "thumbnail", alternate = "path") + private String vodPic; + @SerializedName(value = "title") + private String vodName; + @SerializedName(value = "mask") + private String vodRemark; + @SerializedName("description") + private String description; + @SerializedName(value = "playlist") + private Value playlist; + @SerializedName("year") + private Value year; + @SerializedName("area") + private Value area; + @SerializedName("types") + private List types; + @SerializedName("actors") + private List actors; + @SerializedName("directors") + private List directors; + @SerializedName("btbo_downlist") + private List btboDownlist; + + public String getVodId() { + return TextUtils.isEmpty(vodId) ? "" : vodId; + } + + public String getVodPic() { + return TextUtils.isEmpty(vodPic) ? "" : vodPic + "@Referer=www.jianpianapp.com@User-Agent=jianpian-version362"; + } + + public String getVodName() { + return TextUtils.isEmpty(vodName) ? "" : vodName; + } + + public String getVodRemark() { + return TextUtils.isEmpty(vodRemark) ? getPlaylist() : vodRemark; + } + + public String getDescription() { + return TextUtils.isEmpty(description) ? "" : description; + } + + public String getPlaylist() { + return playlist == null ? "" : playlist.getTitle(); + } + + public String getYear() { + return year == null ? "" : year.getTitle(); + } + + public String getArea() { + return area == null ? "" : area.getTitle(); + } + + public String getTypes() { + if (types == null) return ""; + StringBuilder sb = new StringBuilder(); + for (Value value : types) sb.append(value.getTitle()).append(" "); + return Utils.substring(sb.toString()); + } + + public String getActors() { + if (actors == null) return ""; + StringBuilder sb = new StringBuilder(); + for (Value value : actors) sb.append(value.getLink()).append(" "); + return Utils.substring(sb.toString()); + } + + public String getDirectors() { + if (directors == null) return ""; + StringBuilder sb = new StringBuilder(); + for (Value value : directors) sb.append(value.getLink()).append(" "); + return Utils.substring(sb.toString()); + } + + public String getBtboDownlist() { + if (btboDownlist == null) return ""; + StringBuilder sb = new StringBuilder(); + for (BtboDown value : btboDownlist) sb.append(value.getVal()).append("#"); + return Utils.substring(sb.toString()); + } + + public Vod vod() { + return new Vod(getVodId(), getVodName(), getVodPic(), getVodRemark()); + } + + public static class Value { + + @SerializedName(value = "title", alternate = "name") + private String title; + + public String getTitle() { + return TextUtils.isEmpty(title) ? "" : title; + } + + public String getLink() { + return String.format("[a=cr:{\"id\":\"%s\",\"name\":\"%s\"}]%s[/a]", getTitle() + "/{pg}", getTitle(), getTitle()); + } + } + + public static class BtboDown { + + @SerializedName("val") + private String val; + + public String getVal() { + return TextUtils.isEmpty(val) ? "" : val.replaceAll("ftp", "tvbox-xg:ftp"); + } + } +} diff --git a/app/src/main/java/com/github/catvod/bean/jianpian/Detail.java b/app/src/main/java/com/github/catvod/bean/jianpian/Detail.java new file mode 100644 index 0000000..4ab7bc7 --- /dev/null +++ b/app/src/main/java/com/github/catvod/bean/jianpian/Detail.java @@ -0,0 +1,18 @@ +package com.github.catvod.bean.jianpian; + +import com.google.gson.Gson; +import com.google.gson.annotations.SerializedName; + +public class Detail { + + @SerializedName("data") + private Data data; + + public static Detail objectFrom(String str) { + return new Gson().fromJson(str, Detail.class); + } + + public Data getData() { + return data == null ? new Data() : data; + } +} diff --git a/app/src/main/java/com/github/catvod/bean/jianpian/Resp.java b/app/src/main/java/com/github/catvod/bean/jianpian/Resp.java new file mode 100644 index 0000000..d21de02 --- /dev/null +++ b/app/src/main/java/com/github/catvod/bean/jianpian/Resp.java @@ -0,0 +1,21 @@ +package com.github.catvod.bean.jianpian; + +import com.google.gson.Gson; +import com.google.gson.annotations.SerializedName; + +import java.util.Collections; +import java.util.List; + +public class Resp { + + @SerializedName("data") + private List data; + + public static Resp objectFrom(String str) { + return new Gson().fromJson(str, Resp.class); + } + + public List getData() { + return data == null ? Collections.emptyList() : data; + } +} diff --git a/app/src/main/java/com/github/catvod/bean/paper/Data.java b/app/src/main/java/com/github/catvod/bean/paper/Data.java deleted file mode 100644 index f52ca95..0000000 --- a/app/src/main/java/com/github/catvod/bean/paper/Data.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.github.catvod.bean.paper; - -import com.github.catvod.bean.Vod; -import com.google.gson.Gson; -import com.google.gson.annotations.SerializedName; -import com.google.gson.reflect.TypeToken; - -import java.lang.reflect.Type; -import java.util.List; - -public class Data { - - @SerializedName("key") - private String key; - @SerializedName("cat") - private String cat; - @SerializedName("title") - private String title; - @SerializedName("date") - private String date; - - public static List arrayFrom(String str) { - Type listType = new TypeToken>() {}.getType(); - return new Gson().fromJson(str, listType); - } - - public String getKey() { - return key; - } - - public String getCat() { - return cat; - } - - public String getTitle() { - return title; - } - - public String getDate() { - return date; - } - - public Vod getVod() { - return new Vod("https://www.aliyundrive.com/s/" + getKey(), getTitle(), "https://www.lgstatic.com/i/image2/M01/15/7E/CgoB5lysLXCADg6ZAABapAHUnQM321.jpg", getDate()); - } -} diff --git a/app/src/main/java/com/github/catvod/spider/Jianpian.java b/app/src/main/java/com/github/catvod/spider/Jianpian.java index b76c6ed..7ab5c9a 100644 --- a/app/src/main/java/com/github/catvod/spider/Jianpian.java +++ b/app/src/main/java/com/github/catvod/spider/Jianpian.java @@ -1,12 +1,19 @@ package com.github.catvod.spider; +import android.content.Context; + +import com.github.catvod.bean.Class; +import com.github.catvod.bean.Result; +import com.github.catvod.bean.Vod; +import com.github.catvod.bean.jianpian.Data; +import com.github.catvod.bean.jianpian.Detail; +import com.github.catvod.bean.jianpian.Resp; import com.github.catvod.crawler.Spider; import com.github.catvod.net.OkHttp; - -import org.json.JSONArray; -import org.json.JSONObject; +import com.google.gson.JsonParser; import java.net.URLEncoder; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -16,7 +23,9 @@ import java.util.Map; * Qile */ public class Jianpian extends Spider { + private final String siteUrl = "http://api2.rinhome.com"; + private String extend; private Map getHeader() { Map headers = new HashMap<>(); @@ -25,156 +34,79 @@ public class Jianpian extends Spider { return headers; } + @Override + public void init(Context context, String extend) throws Exception { + this.extend = extend; + } + @Override public String homeContent(boolean filter) throws Exception { - JSONArray classes = new JSONArray(); + List classes = new ArrayList<>(); List typeIds = Arrays.asList("0", "1", "2", "3", "4"); List typeNames = Arrays.asList("全部", "电影", "电视剧", "动漫", "综艺"); - for (int i = 0; i < typeIds.size(); i++) { - JSONObject obj = new JSONObject() - .put("type_id", typeIds.get(i)) - .put("type_name", typeNames.get(i)); - classes.put(obj); - } - // filter 二级筛选 - String f = "{\"0\": [{\"key\": \"year\", \"name\": \"年份\", \"value\": [{\"n\": \"全部\", \"v\": \"0\"}, {\"n\": \"2023\", \"v\": \"153\"}, {\"n\": \"2022\", \"v\": \"101\"}, {\"n\": \"2021\", \"v\": \"118\"}, {\"n\": \"2020\", \"v\": \"16\"}, {\"n\": \"2019\", \"v\": \"7\"}, {\"n\": \"2018\", \"v\": \"2\"}, {\"n\": \"2017\", \"v\": \"3\"}, {\"n\": \"2016\", \"v\": \"22\"}]}, {\"key\": \"by\", \"name\": \"排序\", \"value\": [{\"n\": \"热门\", \"v\": \"hot\"}, {\"n\": \"更新\", \"v\": \"updata\"}, {\"n\": \"评分\", \"v\": \"rating\"}]}],\"1\": [{\"key\": \"year\", \"name\": \"年份\", \"value\": [{\"n\": \"全部\", \"v\": \"0\"}, {\"n\": \"2023\", \"v\": \"153\"}, {\"n\": \"2022\", \"v\": \"101\"}, {\"n\": \"2021\", \"v\": \"118\"}, {\"n\": \"2020\", \"v\": \"16\"}, {\"n\": \"2019\", \"v\": \"7\"}, {\"n\": \"2018\", \"v\": \"2\"}, {\"n\": \"2017\", \"v\": \"3\"}, {\"n\": \"2016\", \"v\": \"22\"}]}, {\"key\": \"by\", \"name\": \"排序\", \"value\": [{\"n\": \"热门\", \"v\": \"hot\"}, {\"n\": \"更新\", \"v\": \"updata\"}, {\"n\": \"评分\", \"v\": \"rating\"}]}], \"2\": [{\"key\": \"year\", \"name\": \"年份\", \"value\": [{\"n\": \"全部\", \"v\": \"0\"}, {\"n\": \"2023\", \"v\": \"153\"}, {\"n\": \"2022\", \"v\": \"101\"}, {\"n\": \"2021\", \"v\": \"118\"}, {\"n\": \"2020\", \"v\": \"16\"}, {\"n\": \"2019\", \"v\": \"7\"}, {\"n\": \"2018\", \"v\": \"2\"}, {\"n\": \"2017\", \"v\": \"3\"}, {\"n\": \"2016\", \"v\": \"22\"}]}, {\"key\": \"by\", \"name\": \"排序\", \"value\": [{\"n\": \"热门\", \"v\": \"hot\"}, {\"n\": \"更新\", \"v\": \"updata\"}, {\"n\": \"评分\", \"v\": \"rating\"}]}],\"3\": [{\"key\": \"year\", \"name\": \"年份\", \"value\": [{\"n\": \"全部\", \"v\": \"0\"}, {\"n\": \"2023\", \"v\": \"153\"}, {\"n\": \"2022\", \"v\": \"101\"}, {\"n\": \"2021\", \"v\": \"118\"}, {\"n\": \"2020\", \"v\": \"16\"}, {\"n\": \"2019\", \"v\": \"7\"}, {\"n\": \"2018\", \"v\": \"2\"}, {\"n\": \"2017\", \"v\": \"3\"}, {\"n\": \"2016\", \"v\": \"22\"}]}, {\"key\": \"by\", \"name\": \"排序\", \"value\": [{\"n\": \"热门\", \"v\": \"hot\"}, {\"n\": \"更新\", \"v\": \"updata\"}, {\"n\": \"评分\", \"v\": \"rating\"}]}],\"4\": [{\"key\": \"year\", \"name\": \"年份\", \"value\": [{\"n\": \"全部\", \"v\": \"0\"}, {\"n\": \"2023\", \"v\": \"153\"}, {\"n\": \"2022\", \"v\": \"101\"}, {\"n\": \"2021\", \"v\": \"118\"}, {\"n\": \"2020\", \"v\": \"16\"}, {\"n\": \"2019\", \"v\": \"7\"}, {\"n\": \"2018\", \"v\": \"2\"}, {\"n\": \"2017\", \"v\": \"3\"}, {\"n\": \"2016\", \"v\": \"22\"}]}, {\"key\": \"by\", \"name\": \"排序\", \"value\": [{\"n\": \"热门\", \"v\": \"hot\"}, {\"n\": \"更新\", \"v\": \"updata\"}, {\"n\": \"评分\", \"v\": \"rating\"}]}]}"; - JSONObject filterConfig = new JSONObject(f); - JSONObject result = new JSONObject() - .put("class", classes) - .put("filters", filterConfig); - return result.toString(); + for (int i = 0; i < typeIds.size(); i++) classes.add(new Class(typeIds.get(i), typeNames.get(i))); + return Result.string(classes, JsonParser.parseString(OkHttp.string(extend))); } @Override - public String homeVideoContent() throws Exception { + public String homeVideoContent() { + List list = new ArrayList<>(); String url = siteUrl + "/api/slide/list?code=unknown9039b6856c3a3306&pos_id=888&channel=wandoujia"; - String content = OkHttp.string(url, getHeader()); - JSONObject jsonObject = new JSONObject(content); - JSONArray videoArray = jsonObject.getJSONArray("data"); - JSONArray videos = new JSONArray(); - for (int i = 0; i < videoArray.length(); i++) { - JSONObject blockObj = videoArray.getJSONObject(i); - videos.put(new JSONObject() - .put("vod_id", blockObj.getInt("jump_id")) - .put("vod_name", blockObj.getString("title")) - .put("vod_pic", blockObj.getString("thumbnail") + "@Referer=www.jianpianapp.com@User-Agent=jianpian-version362") - ); - } - JSONObject result = new JSONObject() - .put("list", videos); - return result.toString(); + Resp resp = Resp.objectFrom(OkHttp.string(url, getHeader())); + for (Data data : resp.getData()) list.add(data.vod()); + return Result.string(list); } @Override public String categoryContent(String tid, String pg, boolean filter, HashMap extend) throws Exception { - // 筛选处理 + List list = new ArrayList<>(); HashMap ext = new HashMap<>(); - if (extend != null && extend.size() > 0) { - ext.putAll(extend); - } + if (extend != null && extend.size() > 0) ext.putAll(extend); String cateId = ext.get("cateId") == null ? tid : ext.get("cateId"); String year = ext.get("year") == null ? "0" : ext.get("year"); String by = ext.get("by") == null ? "hot" : ext.get("by"); String url = siteUrl + String.format("/api/crumb/list?area=0&category_id=%s&page=%s&type=0&limit=24&sort=%s&year=%s", cateId, pg, by, year); - String content = OkHttp.string(url, getHeader()); - JSONObject jsonObject = new JSONObject(content); - JSONArray dataArray = jsonObject.getJSONArray("data"); - JSONArray videos = new JSONArray(); - for (int i = 0; i < dataArray.length(); i++) { - JSONObject vObj = dataArray.getJSONObject(i); - JSONObject v = new JSONObject(); - JSONObject playlistObj = vObj.getJSONObject("playlist"); - v.put("vod_id", vObj.getInt("id")); - v.put("vod_name", vObj.getString("title")); - v.put("vod_pic", vObj.getString("path") + "@Referer=www.jianpianapp.com@User-Agent=jianpian-version362"); - v.put("vod_remarks", playlistObj.getString("title")); - videos.put(v); - } - JSONObject result = new JSONObject() - .put("page", Integer.parseInt(pg)) - .put("pagecount", Integer.MAX_VALUE) - .put("limit", 24) - .put("total", Integer.MAX_VALUE) - .put("list", videos); - return result.toString(); + Resp resp = Resp.objectFrom(OkHttp.string(url, getHeader())); + for (Data data : resp.getData()) list.add(data.vod()); + return Result.string(list); } @Override public String detailContent(List ids) throws Exception { String url = siteUrl + "/api/node/detail?channel=wandoujia&token=&id=" + ids.get(0); - String content = OkHttp.string(url, getHeader()); - JSONObject dataObject = new JSONObject(content); - JSONObject vObj = dataObject.getJSONObject("data"); - JSONObject result = new JSONObject(); - JSONArray list = new JSONArray(); - JSONObject vodAtom = new JSONObject(); - vodAtom.put("vod_id", vObj.getInt("id")); - vodAtom.put("vod_name", vObj.getString("title")); - vodAtom.put("vod_pic", vObj.getString("thumbnail") + "@Referer=www.jianpianapp.com@User-Agent=jianpian-version362"); - vodAtom.put("type_name", vObj.getJSONArray("types").getJSONObject(0).getString("name")); - vodAtom.put("vod_year", vObj.getJSONObject("year").getString("title")); - vodAtom.put("vod_area", vObj.getJSONObject("area").getString("title")); - vodAtom.put("vod_remarks", vObj.getString("mask")); - vodAtom.put("vod_director", vObj.getJSONArray("directors").getJSONObject(0).getString("name")); - vodAtom.put("vod_content", vObj.getString("description").trim()); - - JSONArray actorsArray = vObj.getJSONArray("actors"); - StringBuilder vod_actor = new StringBuilder(); - for (int i = 0; i < actorsArray.length(); i++) { - JSONObject actorObj = actorsArray.getJSONObject(i); - String actorName = actorObj.getString("name"); - if (i > 0) { - vod_actor.append(" "); - } - vod_actor.append(actorName); - } - vodAtom.put("vod_actor", vod_actor.toString()); + Data data = Detail.objectFrom(OkHttp.string(url, getHeader())).getData(); + Vod vod = data.vod(); + vod.setVodYear(data.getYear()); + vod.setVodArea(data.getArea()); + vod.setTypeName(data.getTypes()); + vod.setVodActor(data.getActors()); + vod.setVodDirector(data.getDirectors()); + vod.setVodContent(data.getDescription()); + vod.setVodPlayUrl(data.getBtboDownlist()); + vod.setVodPlayFrom("荐片"); + return Result.string(vod); + } - JSONArray dataArray = vObj.getJSONArray("btbo_downlist"); - StringBuilder vod_play_url = new StringBuilder(); - for (int i = 0; i < dataArray.length(); i++) { - JSONObject listObj = dataArray.getJSONObject(i); - String vod_play_urls = listObj.getString("val").replaceAll("ftp", "tvbox-xg:ftp"); - if (i > 0) { - vod_play_url.append("#"); - } - vod_play_url.append(vod_play_urls); - } - vodAtom.put("vod_play_url", vod_play_url.toString()); - vodAtom.put("vod_play_from", "边下边播"); - list.put(vodAtom); - result.put("list", list); - return result.toString(); + @Override + public String playerContent(String flag, String id, List vipFlags) throws Exception { + return Result.get().url(id).header(getHeader()).string(); } @Override public String searchContent(String key, boolean quick) throws Exception { - String url = siteUrl + "/api/video/search?page=1&key=" + URLEncoder.encode(key); - String content = OkHttp.string(url, getHeader()); - JSONObject jsonObject = new JSONObject(content); - JSONArray dataArray = jsonObject.getJSONArray("data"); - JSONArray videos = new JSONArray(); - for (int i = 0; i < dataArray.length(); i++) { - JSONObject vObj = dataArray.getJSONObject(i); - JSONObject v = new JSONObject(); - v.put("vod_id", vObj.getInt("id")); - v.put("vod_name", vObj.getString("title")); - v.put("vod_pic", vObj.getString("thumbnail") + "@Referer=www.jianpianapp.com@User-Agent=jianpian-version362"); - v.put("vod_remarks", vObj.getString("mask")); - videos.put(v); - } - JSONObject result = new JSONObject(); - result.put("list", videos); - return result.toString(); + return searchContent(key, "1"); } @Override - public String playerContent(String flag, String id, List vipFlags) throws Exception { - JSONObject result = new JSONObject() - .put("parse", 0) - .put("header", getHeader()) - .put("playUrl", "") - .put("url", id); - return result.toString(); + public String searchContent(String key, boolean quick, String pg) throws Exception { + return searchContent(key, pg); + } + + public String searchContent(String key, String pg) throws Exception { + List list = new ArrayList<>(); + String url = siteUrl + "/api/video/search?page=" + pg + "&key=" + URLEncoder.encode(key); + Resp resp = Resp.objectFrom(OkHttp.string(url, getHeader())); + for (Data data : resp.getData()) list.add(data.vod()); + return Result.string(list); } } \ No newline at end of file