Clean code
This commit is contained in:
parent
8d66153ae3
commit
df635b1a0a
|
|
@ -5,6 +5,7 @@ import android.os.Bundle;
|
||||||
|
|
||||||
import com.github.catvod.R;
|
import com.github.catvod.R;
|
||||||
import com.github.catvod.spider.Init;
|
import com.github.catvod.spider.Init;
|
||||||
|
import com.github.catvod.spider.Miss;
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
|
|
||||||
|
|
@ -16,7 +17,8 @@ public class MainActivity extends Activity {
|
||||||
Init.init(getApplicationContext());
|
Init.init(getApplicationContext());
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
|
Miss m = new Miss();
|
||||||
|
m.homeContent(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.github.catvod.spider;
|
package com.github.catvod.spider;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.github.catvod.bean.Result;
|
import com.github.catvod.bean.Result;
|
||||||
import com.github.catvod.bean.Vod;
|
import com.github.catvod.bean.Vod;
|
||||||
import com.github.catvod.net.OkHttp;
|
import com.github.catvod.net.OkHttp;
|
||||||
|
|
@ -10,11 +8,6 @@ import java.net.URLEncoder;
|
||||||
|
|
||||||
public class Dovx extends Ali {
|
public class Dovx extends Ali {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(Context context, String extend) {
|
|
||||||
super.init(context, extend);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String searchContent(String key, boolean quick) {
|
public String searchContent(String key, boolean quick) {
|
||||||
Result result = Result.objectFrom(OkHttp.string("https://api.dovx.tk/ali/search?wd=" + URLEncoder.encode(key)));
|
Result result = Result.objectFrom(OkHttp.string("https://api.dovx.tk/ali/search?wd=" + URLEncoder.encode(key)));
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,11 @@ public class Miss extends Spider {
|
||||||
List<Class> classes = new ArrayList<>();
|
List<Class> classes = new ArrayList<>();
|
||||||
LinkedHashMap<String, List<Filter>> filters = new LinkedHashMap<>();
|
LinkedHashMap<String, List<Filter>> filters = new LinkedHashMap<>();
|
||||||
Document doc = Jsoup.parse(OkHttp.string(url));
|
Document doc = Jsoup.parse(OkHttp.string(url));
|
||||||
|
List<String> typeIds = Arrays.asList("chinese-subtitle", "new", "release", "uncensored-leak", "genres/VR", "today-hot", "weekly-hot", "monthly-hot", "siro", "luxu", "gana", "maan", "scute", "ara", "uncensored-leak", "fc2", "heyzo", "tokyohot", "1pondo", "caribbeancom", "caribbeancompr", "10musume", "pacopacomama", "gachinco", "xxxav", "marriedslash", "naughty4610", "naughty0930", "madou", "twav", "furuke");
|
||||||
for (Element a : doc.select("nav a")) {
|
for (Element a : doc.select("nav a")) {
|
||||||
String typeName = a.text();
|
|
||||||
if (!a.attr("href").startsWith("http")) continue;
|
|
||||||
String typeId = a.attr("href").replace(url, "");
|
String typeId = a.attr("href").replace(url, "");
|
||||||
if (typeId.startsWith("http")) continue;
|
if (!typeIds.contains(typeId)) continue;
|
||||||
classes.add(new Class(typeId, typeName));
|
classes.add(new Class(typeId, a.text()));
|
||||||
filters.put(typeId, Arrays.asList(new Filter("filters", "過濾", Arrays.asList(new Filter.Value("全部", ""), new Filter.Value("單人作品", "individual"), new Filter.Value("中文字幕", "chinese-subtitle")))));
|
filters.put(typeId, Arrays.asList(new Filter("filters", "過濾", Arrays.asList(new Filter.Value("全部", ""), new Filter.Value("單人作品", "individual"), new Filter.Value("中文字幕", "chinese-subtitle")))));
|
||||||
}
|
}
|
||||||
for (Element div : doc.select("div.thumbnail")) {
|
for (Element div : doc.select("div.thumbnail")) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.github.catvod.spider;
|
package com.github.catvod.spider;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.github.catvod.bean.Result;
|
import com.github.catvod.bean.Result;
|
||||||
import com.github.catvod.bean.Vod;
|
import com.github.catvod.bean.Vod;
|
||||||
import com.github.catvod.net.OkHttp;
|
import com.github.catvod.net.OkHttp;
|
||||||
|
|
@ -37,11 +35,6 @@ public class PanSearch extends Ali {
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(Context context, String extend) {
|
|
||||||
super.init(context, extend);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String searchContent(String key, boolean quick) throws Exception {
|
public String searchContent(String key, boolean quick) throws Exception {
|
||||||
String html = OkHttp.string(URL, getHeader());
|
String html = OkHttp.string(URL, getHeader());
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.github.catvod.spider;
|
package com.github.catvod.spider;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.github.catvod.bean.Result;
|
import com.github.catvod.bean.Result;
|
||||||
import com.github.catvod.bean.Vod;
|
import com.github.catvod.bean.Vod;
|
||||||
import com.github.catvod.net.OkHttp;
|
import com.github.catvod.net.OkHttp;
|
||||||
|
|
@ -33,11 +31,6 @@ public class PanSou extends Ali {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(Context context, String extend) {
|
|
||||||
super.init(context, extend);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String detailContent(List<String> ids) throws Exception {
|
public String detailContent(List<String> ids) throws Exception {
|
||||||
if (pattern.matcher(ids.get(0)).find()) return super.detailContent(ids);
|
if (pattern.matcher(ids.get(0)).find()) return super.detailContent(ids);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.github.catvod.spider;
|
package com.github.catvod.spider;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.github.catvod.bean.Result;
|
import com.github.catvod.bean.Result;
|
||||||
import com.github.catvod.bean.Vod;
|
import com.github.catvod.bean.Vod;
|
||||||
import com.github.catvod.bean.upyun.Data;
|
import com.github.catvod.bean.upyun.Data;
|
||||||
|
|
@ -19,11 +17,6 @@ import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
public class UpYun extends Ali {
|
public class UpYun extends Ali {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(Context context, String extend) {
|
|
||||||
super.init(context, extend);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String searchContent(String key, boolean quick) throws Exception {
|
public String searchContent(String key, boolean quick) throws Exception {
|
||||||
return searchContent(key, "1");
|
return searchContent(key, "1");
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
package com.github.catvod.spider;
|
package com.github.catvod.spider;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.github.catvod.bean.Result;
|
import com.github.catvod.bean.Result;
|
||||||
import com.github.catvod.bean.Vod;
|
import com.github.catvod.bean.Vod;
|
||||||
import com.github.catvod.net.OkHttp;
|
import com.github.catvod.net.OkHttp;
|
||||||
import com.github.catvod.utils.Utils;
|
import com.github.catvod.utils.Utils;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
@ -18,11 +21,10 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
public class XiaoZhiTiao extends Ali {
|
public class XiaoZhiTiao extends Ali {
|
||||||
|
|
||||||
private String token;
|
|
||||||
private Date tokenExpiredAt = new Date();
|
|
||||||
|
|
||||||
private static final String siteUrl = "https://gitcafe.net/tool/alipaper/";
|
private static final String siteUrl = "https://gitcafe.net/tool/alipaper/";
|
||||||
private static final String aliUrl = "https://www.aliyundrive.com/s/";
|
private static final String aliUrl = "https://www.aliyundrive.com/s/";
|
||||||
|
private String token;
|
||||||
|
private Date date;
|
||||||
|
|
||||||
private Map<String, String> getHeaders() {
|
private Map<String, String> getHeaders() {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
|
|
@ -32,19 +34,24 @@ public class XiaoZhiTiao extends Ali {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String searchContent(String key, boolean quick) throws JSONException {
|
public void init(Context context, String extend) {
|
||||||
|
super.init(context, extend);
|
||||||
|
date = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String searchContent(String key, boolean quick) throws Exception {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put("action", "search");
|
params.put("action", "search");
|
||||||
params.put("from", "web");
|
params.put("from", "web");
|
||||||
params.put("token", this.getToken());
|
|
||||||
params.put("keyword", key);
|
params.put("keyword", key);
|
||||||
|
params.put("token", getToken());
|
||||||
JSONObject jsonObject = new JSONObject(OkHttp.post(siteUrl, params, getHeaders()));
|
JSONObject object = new JSONObject(OkHttp.post(siteUrl, params, getHeaders()));
|
||||||
if (jsonObject.getBoolean("success")) {
|
if (!object.optBoolean("success")) return "";
|
||||||
List<Vod> list = new ArrayList<>();
|
List<Vod> list = new ArrayList<>();
|
||||||
JSONArray jsonArray = jsonObject.getJSONArray("data");
|
JSONArray data = object.getJSONArray("data");
|
||||||
for (int i = 0, len = jsonArray.length(); i < len; i++) {
|
for (int i = 0, len = data.length(); i < len; i++) {
|
||||||
JSONObject o = jsonArray.getJSONObject(i);
|
JSONObject o = data.getJSONObject(i);
|
||||||
String alikey = o.getString("alikey");
|
String alikey = o.getString("alikey");
|
||||||
String title = o.getString("title");
|
String title = o.getString("title");
|
||||||
String creatime = o.getString("creatime");
|
String creatime = o.getString("creatime");
|
||||||
|
|
@ -52,19 +59,16 @@ public class XiaoZhiTiao extends Ali {
|
||||||
}
|
}
|
||||||
return Result.string(list);
|
return Result.string(list);
|
||||||
}
|
}
|
||||||
return Result.get().string();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getToken() throws JSONException {
|
private String getToken() throws JSONException {
|
||||||
if (TextUtils.isEmpty(token) || new Date().compareTo(tokenExpiredAt) > 0) {
|
if (TextUtils.isEmpty(token) || new Date().compareTo(date) > 0) {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put("action", "get_token");
|
params.put("action", "get_token");
|
||||||
params.put("from", "web");
|
params.put("from", "web");
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject(OkHttp.post(siteUrl, params, getHeaders()));
|
JSONObject jsonObject = new JSONObject(OkHttp.post(siteUrl, params, getHeaders()));
|
||||||
if (jsonObject.getBoolean("success")) {
|
if (jsonObject.getBoolean("success")) {
|
||||||
token = jsonObject.getString("data");
|
token = jsonObject.getString("data");
|
||||||
tokenExpiredAt = new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000);
|
date = new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
ee906871fa3ef19a87da0fad4947e36b
|
d756d06bfacd67917d3f5da7e7d80571
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue