Clean code
This commit is contained in:
parent
99e845d68c
commit
d6da8b6e21
|
|
@ -8,7 +8,9 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -23,11 +25,60 @@ public class Result {
|
||||||
@SerializedName("header")
|
@SerializedName("header")
|
||||||
private String header;
|
private String header;
|
||||||
@SerializedName("parse")
|
@SerializedName("parse")
|
||||||
private String parse;
|
private Integer parse;
|
||||||
@SerializedName("url")
|
@SerializedName("url")
|
||||||
private String url;
|
private String url;
|
||||||
@SerializedName("ua")
|
|
||||||
private String ua;
|
public static Result get() {
|
||||||
|
return new Result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String get(List<Class> classes, List<Vod> list) {
|
||||||
|
return new Result(classes, list).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String get(List<Class> classes, LinkedHashMap<String, List<Filter>> filters) {
|
||||||
|
return new Result(classes, filters).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String get(List<Class> classes, LinkedHashMap<String, List<Filter>> filters, List<Vod> list) {
|
||||||
|
return new Result(classes, filters, list).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String get(List<Vod> list) {
|
||||||
|
return new Result(list).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String get(Vod vod) {
|
||||||
|
return new Result(vod).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(List<Vod> list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(List<Class> classes, List<Vod> list) {
|
||||||
|
this.classes = classes;
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(List<Class> classes, LinkedHashMap<String, List<Filter>> filters) {
|
||||||
|
this.classes = classes;
|
||||||
|
this.filters = filters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(List<Class> classes, LinkedHashMap<String, List<Filter>> filters, List<Vod> list) {
|
||||||
|
this.classes = classes;
|
||||||
|
this.filters = filters;
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(Vod vod) {
|
||||||
|
this.list = Arrays.asList(vod);
|
||||||
|
}
|
||||||
|
|
||||||
public void setClasses(List<Class> classes) {
|
public void setClasses(List<Class> classes) {
|
||||||
this.classes = classes;
|
this.classes = classes;
|
||||||
|
|
@ -41,29 +92,30 @@ public class Result {
|
||||||
return list == null ? Collections.emptyList() : list;
|
return list == null ? Collections.emptyList() : list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFilters(LinkedHashMap<String, List<Filter>> filters) {
|
|
||||||
this.filters = filters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFilters(JSONObject object) {
|
public void setFilters(JSONObject object) {
|
||||||
Type listType = new TypeToken<LinkedHashMap<String, List<Filter>>>() {}.getType();
|
Type listType = new TypeToken<LinkedHashMap<String, List<Filter>>>() {
|
||||||
|
}.getType();
|
||||||
this.filters = new Gson().fromJson(object.toString(), listType);
|
this.filters = new Gson().fromJson(object.toString(), listType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeader(String header) {
|
public Result header(HashMap<String, String> header) {
|
||||||
this.header = header;
|
this.header = new Gson().toJson(header);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParse(String parse) {
|
public Result parse() {
|
||||||
|
this.parse = 1;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result parse(int parse) {
|
||||||
this.parse = parse;
|
this.parse = parse;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUrl(String url) {
|
public Result url(String url) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
return this;
|
||||||
|
|
||||||
public void setUa(String ua) {
|
|
||||||
this.ua = ua;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|
|
||||||
|
|
@ -169,10 +169,7 @@ public class Biubiu extends Spider {
|
||||||
public String playerContent(String flag, String id, List<String> vipFlags) {
|
public String playerContent(String flag, String id, List<String> vipFlags) {
|
||||||
fetchRule();
|
fetchRule();
|
||||||
String webUrl = getRuleVal("url") + id;
|
String webUrl = getRuleVal("url") + id;
|
||||||
Result result = new Result();
|
return Result.get().parse().url(webUrl).toString();
|
||||||
result.setParse("1");
|
|
||||||
result.setUrl(webUrl);
|
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import com.github.catvod.bean.Vod;
|
||||||
import com.github.catvod.crawler.Spider;
|
import com.github.catvod.crawler.Spider;
|
||||||
import com.github.catvod.net.OkHttpUtil;
|
import com.github.catvod.net.OkHttpUtil;
|
||||||
import com.github.catvod.utils.Misc;
|
import com.github.catvod.utils.Misc;
|
||||||
import com.google.gson.Gson;
|
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
|
@ -17,7 +16,6 @@ import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -81,16 +79,11 @@ public class Dm84 extends Spider {
|
||||||
String id = url.split("/")[2];
|
String id = url.split("/")[2];
|
||||||
videos.add(new Vod(id, name, img, remark));
|
videos.add(new Vod(id, name, img, remark));
|
||||||
}
|
}
|
||||||
Result result = new Result();
|
return Result.get(classes, filters, videos);
|
||||||
result.setFilters(filters);
|
|
||||||
result.setClasses(classes);
|
|
||||||
result.setList(videos);
|
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> extend) {
|
public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> extend) {
|
||||||
Result result = new Result();
|
|
||||||
List<Vod> videos = new ArrayList<>();
|
List<Vod> videos = new ArrayList<>();
|
||||||
if (extend.get("type") == null) extend.put("type", "");
|
if (extend.get("type") == null) extend.put("type", "");
|
||||||
if (extend.get("year") == null) extend.put("year", "");
|
if (extend.get("year") == null) extend.put("year", "");
|
||||||
|
|
@ -108,16 +101,11 @@ public class Dm84 extends Spider {
|
||||||
String id = url.split("/")[2];
|
String id = url.split("/")[2];
|
||||||
videos.add(new Vod(id, name, img, remark));
|
videos.add(new Vod(id, name, img, remark));
|
||||||
}
|
}
|
||||||
result.setList(videos);
|
return Result.get(videos);
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String detailContent(List<String> ids) {
|
public String detailContent(List<String> ids) {
|
||||||
Vod vod = new Vod();
|
|
||||||
Result result = new Result();
|
|
||||||
Map<String, String> sites = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
Document doc = Jsoup.parse(OkHttpUtil.string(siteUrl.concat("/v/").concat(ids.get(0)), getHeaders()));
|
Document doc = Jsoup.parse(OkHttpUtil.string(siteUrl.concat("/v/").concat(ids.get(0)), getHeaders()));
|
||||||
String name = doc.select("h1.v_title").text();
|
String name = doc.select("h1.v_title").text();
|
||||||
String remarks = doc.select("p.v_desc > span.desc").text();
|
String remarks = doc.select("p.v_desc > span.desc").text();
|
||||||
|
|
@ -129,6 +117,7 @@ public class Dm84 extends Spider {
|
||||||
String year = doc.select("meta[name=og:video:release_date]").attr("content");
|
String year = doc.select("meta[name=og:video:release_date]").attr("content");
|
||||||
String director = doc.select("meta[name=og:video:director]").attr("content");
|
String director = doc.select("meta[name=og:video:director]").attr("content");
|
||||||
|
|
||||||
|
Vod vod = new Vod();
|
||||||
vod.setVodId(ids.get(0));
|
vod.setVodId(ids.get(0));
|
||||||
vod.setVodPic(img);
|
vod.setVodPic(img);
|
||||||
vod.setVodYear(year);
|
vod.setVodYear(year);
|
||||||
|
|
@ -140,6 +129,7 @@ public class Dm84 extends Spider {
|
||||||
vod.setVodDirector(director);
|
vod.setVodDirector(director);
|
||||||
vod.setTypeName(type);
|
vod.setTypeName(type);
|
||||||
|
|
||||||
|
Map<String, String> sites = new LinkedHashMap<>();
|
||||||
Elements sources = doc.select("ul.tab_control > li");
|
Elements sources = doc.select("ul.tab_control > li");
|
||||||
Elements sourceList = doc.select("ul.play_list");
|
Elements sourceList = doc.select("ul.play_list");
|
||||||
for (int i = 0; i < sources.size(); i++) {
|
for (int i = 0; i < sources.size(); i++) {
|
||||||
|
|
@ -159,13 +149,11 @@ public class Dm84 extends Spider {
|
||||||
vod.setVodPlayFrom(TextUtils.join("$$$", sites.keySet()));
|
vod.setVodPlayFrom(TextUtils.join("$$$", sites.keySet()));
|
||||||
vod.setVodPlayUrl(TextUtils.join("$$$", sites.values()));
|
vod.setVodPlayUrl(TextUtils.join("$$$", sites.values()));
|
||||||
}
|
}
|
||||||
result.setList(Arrays.asList(vod));
|
return Result.get(vod);
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String searchContent(String key, boolean quick) {
|
public String searchContent(String key, boolean quick) {
|
||||||
Result result = new Result();
|
|
||||||
List<Vod> videos = new ArrayList<>();
|
List<Vod> videos = new ArrayList<>();
|
||||||
String target = siteUrl.concat("/s----------.html?wd=").concat(key);
|
String target = siteUrl.concat("/s----------.html?wd=").concat(key);
|
||||||
Document doc = Jsoup.parse(OkHttpUtil.string(target, getHeaders()));
|
Document doc = Jsoup.parse(OkHttpUtil.string(target, getHeaders()));
|
||||||
|
|
@ -177,18 +165,13 @@ public class Dm84 extends Spider {
|
||||||
String id = url.split("/")[2];
|
String id = url.split("/")[2];
|
||||||
videos.add(new Vod(id, name, img, remark));
|
videos.add(new Vod(id, name, img, remark));
|
||||||
}
|
}
|
||||||
result.setList(videos);
|
return Result.get(videos);
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String playerContent(String flag, String id, List<String> vipFlags) {
|
public String playerContent(String flag, String id, List<String> vipFlags) {
|
||||||
Document doc = Jsoup.parse(OkHttpUtil.string(siteUrl.concat(id), getHeaders()));
|
Document doc = Jsoup.parse(OkHttpUtil.string(siteUrl.concat(id), getHeaders()));
|
||||||
String url = doc.select("iframe").attr("src");
|
String url = doc.select("iframe").attr("src");
|
||||||
Result result = new Result();
|
return Result.get().url(url).parse().header(getHeaders()).toString();
|
||||||
result.setUrl(url);
|
|
||||||
result.setParse("1");
|
|
||||||
result.setHeader(new Gson().toJson(getHeaders()));
|
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -272,11 +272,7 @@ public class XPath extends Spider {
|
||||||
fetchRule();
|
fetchRule();
|
||||||
String webUrl = rule.getPlayUrl().isEmpty() ? id : rule.getPlayUrl().replace("{playUrl}", id);
|
String webUrl = rule.getPlayUrl().isEmpty() ? id : rule.getPlayUrl().replace("{playUrl}", id);
|
||||||
SpiderDebug.log(webUrl);
|
SpiderDebug.log(webUrl);
|
||||||
Result result = new Result();
|
return Result.get().parse().url(webUrl).toString();
|
||||||
result.setParse("1");
|
|
||||||
if (!rule.getPlayUa().isEmpty()) result.setUa(rule.getPlayUa());
|
|
||||||
result.setUrl(webUrl);
|
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import com.github.catvod.bean.Vod;
|
||||||
import com.github.catvod.crawler.Spider;
|
import com.github.catvod.crawler.Spider;
|
||||||
import com.github.catvod.crawler.SpiderDebug;
|
import com.github.catvod.crawler.SpiderDebug;
|
||||||
import com.github.catvod.net.OkHttpUtil;
|
import com.github.catvod.net.OkHttpUtil;
|
||||||
import com.google.gson.Gson;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
@ -306,7 +305,6 @@ public class Anime1 extends Spider {
|
||||||
try {
|
try {
|
||||||
authority = "";
|
authority = "";
|
||||||
String url = "https://v.anime1.me/api";
|
String url = "https://v.anime1.me/api";
|
||||||
Result result = new Result();
|
|
||||||
String jsonreq = URLDecoder.decode(id, "UTF-8");
|
String jsonreq = URLDecoder.decode(id, "UTF-8");
|
||||||
HashMap<String, String> reqpayload = new HashMap<>();
|
HashMap<String, String> reqpayload = new HashMap<>();
|
||||||
reqpayload.put("d", jsonreq);
|
reqpayload.put("d", jsonreq);
|
||||||
|
|
@ -315,10 +313,7 @@ public class Anime1 extends Spider {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < 3; i++) sb.append(respHeaderMap.get("set-cookie").get(i).split(";")[0]).append(";");
|
for (int i = 0; i < 3; i++) sb.append(respHeaderMap.get("set-cookie").get(i).split(";")[0]).append(";");
|
||||||
cookies = sb.toString();
|
cookies = sb.toString();
|
||||||
result.setUrl(getVideoUrl(response));
|
return Result.get().url(getVideoUrl(response)).header(getHeaders1()).toString();
|
||||||
result.setHeader(new Gson().toJson(getHeaders1()));
|
|
||||||
result.setParse("0");
|
|
||||||
return result.toString();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SpiderDebug.log(e);
|
SpiderDebug.log(e);
|
||||||
return "";
|
return "";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue