Clean code

This commit is contained in:
FongMi 2023-12-13 14:11:01 +08:00
parent 9c4d5663ac
commit 2cc546311a
43 changed files with 213 additions and 204 deletions

View File

@ -34,10 +34,12 @@ import com.github.catvod.net.OkHttp;
import com.github.catvod.net.OkResult; import com.github.catvod.net.OkResult;
import com.github.catvod.spider.Init; import com.github.catvod.spider.Init;
import com.github.catvod.spider.Proxy; import com.github.catvod.spider.Proxy;
import com.github.catvod.utils.Notify;
import com.github.catvod.utils.Path; import com.github.catvod.utils.Path;
import com.github.catvod.utils.ProxyVideo; import com.github.catvod.utils.ProxyVideo;
import com.github.catvod.utils.QRCode; import com.github.catvod.utils.QRCode;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.ResUtil;
import com.github.catvod.utils.Util;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
@ -99,7 +101,7 @@ public class AliYun {
public HashMap<String, String> getHeader() { public HashMap<String, String> getHeader() {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
headers.put("Referer", "https://www.aliyundrive.com/"); headers.put("Referer", "https://www.aliyundrive.com/");
return headers; return headers;
} }
@ -153,7 +155,7 @@ public class AliYun {
private boolean isManyRequest(String result) { private boolean isManyRequest(String result) {
if (!result.contains("Too Many Requests")) return false; if (!result.contains("Too Many Requests")) return false;
Utils.notify("洗洗睡吧Too Many Requests。"); Notify.show("洗洗睡吧Too Many Requests。");
cache.getOAuth().clean(); cache.getOAuth().clean();
return true; return true;
} }
@ -171,7 +173,7 @@ public class AliYun {
param.addProperty("share_pwd", ""); param.addProperty("share_pwd", "");
String json = post("v2/share_link/get_share_token", param); String json = post("v2/share_link/get_share_token", param);
share = Share.objectFrom(json).setShareId(shareId).setTime(); share = Share.objectFrom(json).setShareId(shareId).setTime();
if (share.getShareToken().isEmpty()) Utils.notify("來晚啦,該分享已失效。"); if (share.getShareToken().isEmpty()) Notify.show("來晚啦,該分享已失效。");
} }
private boolean refreshAccessToken() { private boolean refreshAccessToken() {
@ -276,7 +278,7 @@ public class AliYun {
folders.add(file); folders.add(file);
} else if (file.getCategory().equals("video") || file.getCategory().equals("audio")) { } else if (file.getCategory().equals("video") || file.getCategory().equals("audio")) {
files.add(file.parent(parent.getName())); files.add(file.parent(parent.getName()));
} else if (Utils.isSub(file.getExt())) { } else if (Util.isSub(file.getExt())) {
subs.add(file); subs.add(file);
} }
} }
@ -297,17 +299,17 @@ public class AliYun {
private void pair(String name1, List<Item> items, List<Item> subs) { private void pair(String name1, List<Item> items, List<Item> subs) {
for (Item item : items) { for (Item item : items) {
String name2 = Utils.removeExt(item.getName()).toLowerCase(); String name2 = Util.removeExt(item.getName()).toLowerCase();
if (name1.contains(name2) || name2.contains(name1)) subs.add(item); if (name1.contains(name2) || name2.contains(name1)) subs.add(item);
} }
} }
private String findSubs(String name1, List<Item> items) { private String findSubs(String name1, List<Item> items) {
List<Item> subs = new ArrayList<>(); List<Item> subs = new ArrayList<>();
pair(Utils.removeExt(name1).toLowerCase(), items, subs); pair(Util.removeExt(name1).toLowerCase(), items, subs);
if (subs.isEmpty()) subs.addAll(items); if (subs.isEmpty()) subs.addAll(items);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Item sub : subs) sb.append("+").append(Utils.removeExt(sub.getName())).append("@@@").append(sub.getExt()).append("@@@").append(sub.getFileId()); for (Item sub : subs) sb.append("+").append(Util.removeExt(sub.getName())).append("@@@").append(sub.getExt()).append("@@@").append(sub.getFileId());
return sb.toString(); return sb.toString();
} }
@ -558,7 +560,7 @@ public class AliYun {
String fileId = params.get("fileId"); String fileId = params.get("fileId");
String shareId = params.get("shareId"); String shareId = params.get("shareId");
Response res = OkHttp.newCall(getDownloadUrl(shareId, fileId), getHeaderAuth()); Response res = OkHttp.newCall(getDownloadUrl(shareId, fileId), getHeaderAuth());
byte[] body = Utils.toUtf8(res.body().bytes()); byte[] body = Util.toUtf8(res.body().bytes());
Object[] result = new Object[3]; Object[] result = new Object[3];
result[0] = 200; result[0] = 200;
result[1] = "application/octet-stream"; result[1] = "application/octet-stream";
@ -572,9 +574,10 @@ public class AliYun {
private void showInput() { private void showInput() {
try { try {
int margin = ResUtil.dp2px(16);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(Utils.dp2px(16), Utils.dp2px(16), Utils.dp2px(16), Utils.dp2px(16));
FrameLayout frame = new FrameLayout(Init.context()); FrameLayout frame = new FrameLayout(Init.context());
params.setMargins(margin, margin, margin, margin);
EditText input = new EditText(Init.context()); EditText input = new EditText(Init.context());
frame.addView(input, params); frame.addView(input, params);
dialog = new AlertDialog.Builder(Init.getActivity()).setTitle("請輸入Token").setView(frame).setNeutralButton("QRCode", (dialog, which) -> onNeutral()).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, (dialog, which) -> onPositive(input.getText().toString())).show(); dialog = new AlertDialog.Builder(Init.getActivity()).setTitle("請輸入Token").setView(frame).setNeutralButton("QRCode", (dialog, which) -> onNeutral()).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, (dialog, which) -> onPositive(input.getText().toString())).show();
@ -616,16 +619,17 @@ public class AliYun {
private void showQRCode(Data data) { private void showQRCode(Data data) {
try { try {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Utils.dp2px(240), Utils.dp2px(240)); int size = ResUtil.dp2px(240);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(size, size);
ImageView image = new ImageView(Init.context()); ImageView image = new ImageView(Init.context());
image.setScaleType(ImageView.ScaleType.CENTER_CROP); image.setScaleType(ImageView.ScaleType.CENTER_CROP);
image.setImageBitmap(QRCode.getBitmap(data.getCodeContent(), 240, 2)); image.setImageBitmap(QRCode.getBitmap(data.getCodeContent(), size, 2));
FrameLayout frame = new FrameLayout(Init.context()); FrameLayout frame = new FrameLayout(Init.context());
params.gravity = Gravity.CENTER; params.gravity = Gravity.CENTER;
frame.addView(image, params); frame.addView(image, params);
dialog = new AlertDialog.Builder(Init.getActivity()).setView(frame).setOnCancelListener(this::dismiss).setOnDismissListener(this::dismiss).show(); dialog = new AlertDialog.Builder(Init.getActivity()).setView(frame).setOnCancelListener(this::dismiss).setOnDismissListener(this::dismiss).show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Utils.notify("請使用阿里雲盤 App 掃描二維碼"); Notify.show("請使用阿里雲盤 App 掃描二維碼");
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
@ -642,7 +646,7 @@ public class AliYun {
private void setToken(String value) { private void setToken(String value) {
cache.getUser().setRefreshToken(value); cache.getUser().setRefreshToken(value);
SpiderDebug.log("Token:" + value); SpiderDebug.log("Token:" + value);
Utils.notify("Token:" + value); Notify.show("Token:" + value);
refreshAccessToken(); refreshAccessToken();
stopService(); stopService();
} }

View File

@ -2,7 +2,7 @@ package com.github.catvod.bean.ali;
import android.text.TextUtils; import android.text.TextUtils;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ -70,7 +70,7 @@ public class Item implements Comparable<Item> {
} }
public String getSize() { public String getSize() {
return size == 0 ? "" : "[" + Utils.getSize(size) + "]"; return size == 0 ? "" : "[" + Util.getSize(size) + "]";
} }
public String getParent() { public String getParent() {
@ -87,7 +87,7 @@ public class Item implements Comparable<Item> {
} }
public String getSortName() { public String getSortName() {
return TextUtils.join(" ", Arrays.asList(getParent(), Utils.getDigit(getName()))).trim(); return TextUtils.join(" ", Arrays.asList(getParent(), Util.getDigit(getName()))).trim();
} }
@Override @Override

View File

@ -6,7 +6,7 @@ import android.text.TextUtils;
import com.github.catvod.bean.Class; import com.github.catvod.bean.Class;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Image; import com.github.catvod.utils.Image;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ -164,7 +164,7 @@ public class Drive {
public HashMap<String, String> getHeader() { public HashMap<String, String> getHeader() {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
if (!getToken().isEmpty()) headers.put("Authorization", token); if (!getToken().isEmpty()) headers.put("Authorization", token);
return headers; return headers;
} }

View File

@ -3,7 +3,7 @@ package com.github.catvod.bean.alist;
import android.text.TextUtils; import android.text.TextUtils;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
@ -110,7 +110,7 @@ public class Item {
} }
public String getExt() { public String getExt() {
return Utils.getExt(getName()); return Util.getExt(getName());
} }
public String getVodId(String id) { public String getVodId(String id) {
@ -122,7 +122,7 @@ public class Item {
} }
public String getRemark() { public String getRemark() {
return Utils.getSize(getSize()); return Util.getSize(getSize());
} }
public Vod getVod(String id, String pic) { public Vod getVod(String id, String pic) {

View File

@ -3,7 +3,7 @@ package com.github.catvod.bean.bili;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -40,8 +40,8 @@ public class Wbi {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
params.put("wts", System.currentTimeMillis() / 1000); params.put("wts", System.currentTimeMillis() / 1000);
for (String key : params.keySet()) sb.append(key).append("=").append(URLEncoder.encode(params.get(key).toString())).append("&"); for (String key : params.keySet()) sb.append(key).append("=").append(URLEncoder.encode(params.get(key).toString())).append("&");
String param = Utils.substring(sb.toString()); String param = Util.substring(sb.toString());
String wbiSign = Utils.MD5(param + mixinKey); String wbiSign = Util.MD5(param + mixinKey);
return param + "&w_rid=" + wbiSign; return param + "&w_rid=" + wbiSign;
} }
} }

View File

@ -3,7 +3,7 @@ package com.github.catvod.bean.jianpian;
import android.text.TextUtils; import android.text.TextUtils;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.util.Collections; import java.util.Collections;
@ -91,13 +91,13 @@ public class Data {
public String getValues(List<Value> items, boolean link) { public String getValues(List<Value> items, boolean link) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Value value : items) sb.append(value.getValue(link)).append(" "); for (Value value : items) sb.append(value.getValue(link)).append(" ");
return Utils.substring(sb.toString()); return Util.substring(sb.toString());
} }
public String getPlayUrl() { public String getPlayUrl() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (BtboDown value : getBtboDownlist()) sb.append(value.getVal()).append("#"); for (BtboDown value : getBtboDownlist()) sb.append(value.getVal()).append("#");
return Utils.substring(sb.toString()); return Util.substring(sb.toString());
} }
public static class Value { public static class Value {

View File

@ -5,7 +5,7 @@ import android.text.TextUtils;
import com.github.catvod.bean.Class; import com.github.catvod.bean.Class;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.thegrizzlylabs.sardineandroid.DavResource; import com.thegrizzlylabs.sardineandroid.DavResource;
@ -88,7 +88,7 @@ public class Drive {
} }
public Vod vod(DavResource item, String vodPic) { public Vod vod(DavResource item, String vodPic) {
return new Vod(getName() + item.getPath(), item.getName(), vodPic, Utils.getSize(item.getContentLength()), item.isDirectory()); return new Vod(getName() + item.getPath(), item.getName(), vodPic, Util.getSize(item.getContentLength()), item.isDirectory());
} }
@Override @Override

View File

@ -1,6 +1,6 @@
package com.github.catvod.js; package com.github.catvod.js;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Notify;
import com.whl.quickjs.wrapper.JSMethod; import com.whl.quickjs.wrapper.JSMethod;
import com.whl.quickjs.wrapper.QuickJSContext; import com.whl.quickjs.wrapper.QuickJSContext;
@ -14,6 +14,6 @@ public class Method {
@JSMethod @JSMethod
public void showToast(String msg) { public void showToast(String msg) {
Utils.notify(msg); Notify.show(msg);
} }
} }

View File

@ -2,7 +2,7 @@ package com.github.catvod.net;
import android.text.TextUtils; import android.text.TextUtils;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
@ -65,7 +65,7 @@ class OkRequest {
private void setParams() { private void setParams() {
url = url + "?"; url = url + "?";
for (String key : params.keySet()) url = url.concat(key + "=" + params.get(key) + "&"); for (String key : params.keySet()) url = url.concat(key + "=" + params.get(key) + "&");
url = Utils.substring(url); url = Util.substring(url);
} }
public OkResult execute(OkHttpClient client) { public OkResult execute(OkHttpClient client) {

View File

@ -1,6 +1,6 @@
package com.github.catvod.net; package com.github.catvod.net;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import java.io.IOException; import java.io.IOException;
import java.util.zip.Inflater; import java.util.zip.Inflater;
@ -42,7 +42,7 @@ public class OkhttpInterceptor implements Interceptor {
private Request getRequest(Chain chain) { private Request getRequest(Chain chain) {
Request request = chain.request(); Request request = chain.request();
if (request.url().host().equals("gitcode.net")) return request.newBuilder().addHeader("User-Agent", Utils.CHROME).build(); if (request.url().host().equals("gitcode.net")) return request.newBuilder().addHeader("User-Agent", Util.CHROME).build();
return request; return request;
} }
} }

View File

@ -14,7 +14,7 @@ import com.github.catvod.bean.alist.Sorter;
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.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
@ -225,7 +225,7 @@ public class AList extends Spider {
private String findSubs(String path, List<Item> items) { private String findSubs(String path, List<Item> items) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Item item : items) if (Utils.isSub(item.getExt())) sb.append("~~~").append(item.getName()).append("@@@").append(item.getExt()).append("@@@").append(item.getVodId(path)); for (Item item : items) if (Util.isSub(item.getExt())) sb.append("~~~").append(item.getName()).append("@@@").append(item.getExt()).append("@@@").append(item.getVodId(path));
return sb.toString(); return sb.toString();
} }
@ -265,7 +265,7 @@ public class AList extends Spider {
String[] splits = a.text().split("#"); String[] splits = a.text().split("#");
if (!splits[0].contains("/")) continue; if (!splits[0].contains("/")) continue;
int index = splits[0].lastIndexOf("/"); int index = splits[0].lastIndexOf("/");
boolean file = Utils.isMedia(splits[0]); boolean file = Util.isMedia(splits[0]);
Item item = new Item(); Item item = new Item();
item.setType(file ? 0 : 1); item.setType(file ? 0 : 1);
item.setThumb(splits.length > 3 ? splits[4] : ""); item.setThumb(splits.length > 3 ? splits[4] : "");

View File

@ -6,7 +6,7 @@ import android.text.TextUtils;
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.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -310,7 +310,7 @@ public class AppYsV2 extends Spider {
@Override @Override
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception { public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
if (flag.contains("fanqie") && Utils.isVideoFormat(id)) { if (flag.contains("fanqie") && Util.isVideoFormat(id)) {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("parse", 0); result.put("parse", 0);
result.put("playUrl", ""); result.put("playUrl", "");
@ -323,7 +323,7 @@ public class AppYsV2 extends Spider {
JSONObject result = getFinalVideo(flag, parseUrls, id); JSONObject result = getFinalVideo(flag, parseUrls, id);
if (result != null) return result.toString(); if (result != null) return result.toString();
} }
if (Utils.isVideoFormat(id)) { if (Util.isVideoFormat(id)) {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("parse", 0); result.put("parse", 0);
result.put("playUrl", ""); result.put("playUrl", "");
@ -735,7 +735,7 @@ public class AppYsV2 extends Spider {
@Override @Override
public boolean isVideoFormat(String url) { public boolean isVideoFormat(String url) {
return Utils.isVideoFormat(url); return Util.isVideoFormat(url);
} }
private String getApiUrl() { private String getApiUrl() {
@ -759,11 +759,11 @@ public class AppYsV2 extends Spider {
return null; return null;
} }
if (url.equals(input)) { if (url.equals(input)) {
if (Utils.isVip(url) || !Utils.isVideoFormat(url)) { if (Util.isVip(url) || !Util.isVideoFormat(url)) {
return null; return null;
} }
} }
if (Utils.isBlackVodUrl(url)) { if (Util.isBlackVodUrl(url)) {
return null; return null;
} }
JSONObject headers = new JSONObject(); JSONObject headers = new JSONObject();
@ -813,7 +813,7 @@ public class AppYsV2 extends Spider {
headers.put("User-Agent", " Mozilla/5.0"); headers.put("User-Agent", " Mozilla/5.0");
} else if (input.contains("bilibili")) { } else if (input.contains("bilibili")) {
headers.put("Referer", " https://www.bilibili.com/"); headers.put("Referer", " https://www.bilibili.com/");
headers.put("User-Agent", " " + Utils.CHROME); headers.put("User-Agent", " " + Util.CHROME);
} }
return headers; return headers;
} }

View File

@ -16,7 +16,7 @@ import com.github.catvod.bean.bili.Resp;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Path; import com.github.catvod.utils.Path;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
@ -50,7 +50,7 @@ public class Bili extends Spider {
private static Map<String, String> getHeader() { private static Map<String, String> getHeader() {
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
if (cookie != null) headers.put("cookie", cookie); if (cookie != null) headers.put("cookie", cookie);
headers.put("Referer", "https://www.bilibili.com"); headers.put("Referer", "https://www.bilibili.com");
return headers; return headers;

View File

@ -8,7 +8,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -31,8 +31,8 @@ public class Dm84 extends Spider {
private HashMap<String, String> getHeaders() { private HashMap<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
headers.put("Accept", Utils.ACCEPT); headers.put("Accept", Util.ACCEPT);
return headers; return headers;
} }

View File

@ -7,7 +7,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import org.json.JSONArray; import org.json.JSONArray;
@ -123,7 +123,7 @@ public class Douban extends Spider {
private String getPic(JSONObject item) { private String getPic(JSONObject item) {
try { try {
return item.getJSONObject("pic").optString("normal") + "@Referer=https://api.douban.com/@User-Agent=" + Utils.CHROME; return item.getJSONObject("pic").optString("normal") + "@Referer=https://api.douban.com/@User-Agent=" + Util.CHROME;
} catch (Exception e) { } catch (Exception e) {
return ""; return "";
} }
@ -133,7 +133,7 @@ public class Douban extends Spider {
try { try {
StringBuilder tags = new StringBuilder(); StringBuilder tags = new StringBuilder();
for (String key : extend.keySet()) if (!key.equals("sort")) tags.append(extend.get(key)).append(","); for (String key : extend.keySet()) if (!key.equals("sort")) tags.append(extend.get(key)).append(",");
return Utils.substring(tags.toString()); return Util.substring(tags.toString());
} catch (Exception e) { } catch (Exception e) {
return ""; return "";
} }

View File

@ -8,7 +8,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
@ -34,7 +34,7 @@ public class Duanju extends Spider {
private Map<String, String> getHeader() { private Map<String, String> getHeader() {
Map<String, String> header = new HashMap<>(); Map<String, String> header = new HashMap<>();
header.put("User-Agent", Utils.CHROME); header.put("User-Agent", Util.CHROME);
return header; return header;
} }

View File

@ -9,7 +9,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -89,7 +89,7 @@ public class Eighteen extends Spider {
@Override @Override
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception { public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
HashMap<String, String> result = new HashMap<>(); HashMap<String, String> result = new HashMap<>();
Utils.loadWebView(url + id, getClient(result)); Util.loadWebView(url + id, getClient(result));
while (result.isEmpty()) SystemClock.sleep(10); while (result.isEmpty()) SystemClock.sleep(10);
return Result.get().url(result.get("url")).string(); return Result.get().url(result.get("url")).string();
} }

View File

@ -6,7 +6,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
@ -24,7 +24,7 @@ public class Hanime extends Spider {
private HashMap<String, String> getHeaders() { private HashMap<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
return headers; return headers;
} }

View File

@ -5,7 +5,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -26,7 +26,7 @@ public class Jable extends Spider {
private HashMap<String, String> getHeaders() { private HashMap<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
return headers; return headers;
} }
@ -79,7 +79,7 @@ public class Jable extends Spider {
vod.setVodYear(year.replace("上市於 ", "")); vod.setVodYear(year.replace("上市於 ", ""));
vod.setVodName(name); vod.setVodName(name);
vod.setVodPlayFrom("Jable"); vod.setVodPlayFrom("Jable");
vod.setVodPlayUrl("播放$" + Utils.getVar(doc.html(), "hlsUrl")); vod.setVodPlayUrl("播放$" + Util.getVar(doc.html(), "hlsUrl"));
return Result.string(vod); return Result.string(vod);
} }

View File

@ -8,7 +8,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -31,7 +31,7 @@ public class Kanqiu extends Spider {
private Map<String, String> getHeader() { private Map<String, String> getHeader() {
Map<String, String> header = new HashMap<>(); Map<String, String> header = new HashMap<>();
header.put("User-Agent", Utils.CHROME); header.put("User-Agent", Util.CHROME);
return header; return header;
} }

View File

@ -7,7 +7,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -29,7 +29,7 @@ public class Kugou extends Spider {
private Map<String, String> getHeader() { private Map<String, String> getHeader() {
Map<String, String> header = new HashMap<>(); Map<String, String> header = new HashMap<>();
header.put("User-Agent", Utils.CHROME); header.put("User-Agent", Util.CHROME);
return header; return header;
} }

View File

@ -10,7 +10,7 @@ import com.github.catvod.bean.Sub;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.utils.Image; import com.github.catvod.utils.Image;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import java.io.File; import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -55,7 +55,7 @@ public class Local extends Spider {
for (File file : files) { for (File file : files) {
if (file.getName().startsWith(".")) continue; if (file.getName().startsWith(".")) continue;
if (file.isDirectory()) folders.add(create(file)); if (file.isDirectory()) folders.add(create(file));
else if (Utils.isMedia(file.getName())) media.add(create(file)); else if (Util.isMedia(file.getName())) media.add(create(file));
} }
items.addAll(folders); items.addAll(folders);
items.addAll(media); items.addAll(media);
@ -109,8 +109,8 @@ public class Local extends Spider {
if (file.getParentFile() == null) return Collections.emptyList(); if (file.getParentFile() == null) return Collections.emptyList();
List<Sub> subs = new ArrayList<>(); List<Sub> subs = new ArrayList<>();
for (File f : file.getParentFile().listFiles()) { for (File f : file.getParentFile().listFiles()) {
String ext = Utils.getExt(f.getName()); String ext = Util.getExt(f.getName());
if (Utils.isSub(ext)) subs.add(Sub.create().name(Utils.removeExt(f.getName())).ext(ext).url("file://" + f.getAbsolutePath())); if (Util.isSub(ext)) subs.add(Sub.create().name(Util.removeExt(f.getName())).ext(ext).url("file://" + f.getAbsolutePath()));
} }
return subs; return subs;
} }

View File

@ -13,8 +13,9 @@ import com.github.catvod.bean.market.Item;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.FileUtil; import com.github.catvod.utils.FileUtil;
import com.github.catvod.utils.Notify;
import com.github.catvod.utils.Path; import com.github.catvod.utils.Path;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File; import java.io.File;
@ -89,11 +90,11 @@ public class Market extends Spider {
download(file, response.body().byteStream(), Double.parseDouble(response.header("Content-Length", "1"))); download(file, response.body().byteStream(), Double.parseDouble(response.header("Content-Length", "1")));
if (file.getName().endsWith(".zip")) FileUtil.unzip(file, Path.download()); if (file.getName().endsWith(".zip")) FileUtil.unzip(file, Path.download());
if (file.getName().endsWith(".apk")) FileUtil.openFile(Path.chmod(file)); if (file.getName().endsWith(".apk")) FileUtil.openFile(Path.chmod(file));
else Utils.notify("下載完成"); else Notify.show("下載完成");
checkCopy(url); checkCopy(url);
dismiss(); dismiss();
} catch (Exception e) { } catch (Exception e) {
Utils.notify(e.getMessage()); Notify.show(e.getMessage());
dismiss(); dismiss();
} }
} }
@ -117,7 +118,7 @@ public class Market extends Spider {
int index = data.getList().indexOf(new Item(url)); int index = data.getList().indexOf(new Item(url));
if (index == -1) continue; if (index == -1) continue;
String text = data.getList().get(index).getCopy(); String text = data.getList().get(index).getCopy();
if (!text.isEmpty()) Utils.copy(text); if (!text.isEmpty()) Util.copy(text);
break; break;
} }
} }

View File

@ -10,7 +10,8 @@ import android.widget.FrameLayout;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.ui.ScrollTextView; import com.github.catvod.ui.ScrollTextView;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.ResUtil;
import com.github.catvod.utils.Util;
import org.json.JSONObject; import org.json.JSONObject;
@ -69,7 +70,7 @@ public class Notice extends Spider {
view.setDuration(duration); view.setDuration(duration);
view.setText(sb.toString()); view.setText(sb.toString());
view.setTypeface(null, Typeface.BOLD); view.setTypeface(null, Typeface.BOLD);
view.setPadding(0, Utils.dp2px(16), 0, Utils.dp2px(16)); view.setPadding(0, ResUtil.dp2px(16), 0, ResUtil.dp2px(16));
view.setBackgroundColor(Color.argb(200, 255, 255, 255)); view.setBackgroundColor(Color.argb(200, 255, 255, 255));
view.startScroll(); view.startScroll();
} }
@ -77,11 +78,11 @@ public class Notice extends Spider {
private void createRoot() { private void createRoot() {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.TOP; params.gravity = Gravity.TOP;
Utils.addView(view, params); Util.addView(view, params);
} }
private void hide() { private void hide() {
Init.run(() -> Utils.removeView(view), duration * 1000); Init.run(() -> Util.removeView(view), duration * 1000);
} }
private void setColor() { private void setColor() {

View File

@ -3,7 +3,7 @@ package com.github.catvod.spider;
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.Util;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -24,7 +24,7 @@ public class PanSearch extends Ali {
private Map<String, String> getHeader() { private Map<String, String> getHeader() {
Map<String, String> header = new HashMap<>(); Map<String, String> header = new HashMap<>();
header.put("User-Agent", Utils.CHROME); header.put("User-Agent", Util.CHROME);
return header; return header;
} }

View File

@ -3,7 +3,7 @@ package com.github.catvod.spider;
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.Util;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
@ -25,7 +25,7 @@ public class PanSou extends Ali {
private Map<String, String> getHeaders(String id) { private Map<String, String> getHeaders(String id) {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
headers.put("Referer", siteUrl + id); headers.put("Referer", siteUrl + id);
headers.put("_bid", "6d14a5dd6c07980d9dc089a693805ad8"); headers.put("_bid", "6d14a5dd6c07980d9dc089a693805ad8");
return headers; return headers;
@ -33,7 +33,7 @@ public class PanSou extends Ali {
private Map<String, String> getHeader() { private Map<String, String> getHeader() {
HashMap<String, String> header = new HashMap<>(); HashMap<String, String> header = new HashMap<>();
header.put("User-Agent", Utils.CHROME); header.put("User-Agent", Util.CHROME);
return header; return header;
} }

View File

@ -9,7 +9,7 @@ import com.github.catvod.bean.Sub;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -64,12 +64,12 @@ public class Push extends Spider {
private void setHttpSub(String url, List<Sub> subs) { private void setHttpSub(String url, List<Sub> subs) {
List<String> vodTypes = Arrays.asList("mp4", "mkv"); List<String> vodTypes = Arrays.asList("mp4", "mkv");
List<String> subTypes = Arrays.asList("srt", "ass"); List<String> subTypes = Arrays.asList("srt", "ass");
if (!vodTypes.contains(Utils.getExt(url))) return; if (!vodTypes.contains(Util.getExt(url))) return;
for (String ext : subTypes) detectSub(url, ext, subs); for (String ext : subTypes) detectSub(url, ext, subs);
} }
private void detectSub(String url, String ext, List<Sub> subs) { private void detectSub(String url, String ext, List<Sub> subs) {
url = Utils.removeExt(url).concat(".").concat(ext); url = Util.removeExt(url).concat(".").concat(ext);
if (OkHttp.string(url).length() < 100) return; if (OkHttp.string(url).length() < 100) return;
String name = Uri.parse(url).getLastPathSegment(); String name = Uri.parse(url).getLastPathSegment();
subs.add(Sub.create().name(name).ext(ext).url(url)); subs.add(Sub.create().name(name).ext(ext).url(url));
@ -79,8 +79,8 @@ public class Push extends Spider {
File file = new File(url.replace("file://", "")); File file = new File(url.replace("file://", ""));
if (file.getParentFile() == null) return; if (file.getParentFile() == null) return;
for (File f : file.getParentFile().listFiles()) { for (File f : file.getParentFile().listFiles()) {
String ext = Utils.getExt(f.getName()); String ext = Util.getExt(f.getName());
if (Utils.isSub(ext)) subs.add(Sub.create().name(Utils.removeExt(f.getName())).ext(ext).url("file://" + f.getAbsolutePath())); if (Util.isSub(ext)) subs.add(Sub.create().name(Util.removeExt(f.getName())).ext(ext).url("file://" + f.getAbsolutePath()));
} }
} }
} }

View File

@ -13,7 +13,7 @@ import com.github.catvod.bean.star.Detail;
import com.github.catvod.bean.star.Query; import com.github.catvod.bean.star.Query;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
@ -39,7 +39,7 @@ public class Star extends Spider {
private Map<String, String> getHeader() { private Map<String, String> getHeader() {
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
headers.put("Cookie", "userIP=127.0.0.1; aws-waf-token="); headers.put("Cookie", "userIP=127.0.0.1; aws-waf-token=");
headers.put("Referer", siteUrl); headers.put("Referer", siteUrl);
return headers; return headers;

View File

@ -13,7 +13,7 @@ import com.github.catvod.bean.webdav.Sorter;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Image; import com.github.catvod.utils.Image;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import com.thegrizzlylabs.sardineandroid.DavResource; import com.thegrizzlylabs.sardineandroid.DavResource;
import java.io.IOException; import java.io.IOException;
@ -46,11 +46,11 @@ public class WebDAV extends Spider {
} }
private String getExt(DavResource item) { private String getExt(DavResource item) {
return Utils.getExt(item.getName()); return Util.getExt(item.getName());
} }
private String removeExt(DavResource item) { private String removeExt(DavResource item) {
return Utils.removeExt(item.getName()); return Util.removeExt(item.getName());
} }
private static Drive getDrive(String name) { private static Drive getDrive(String name) {
@ -60,7 +60,7 @@ public class WebDAV extends Spider {
@Override @Override
public void init(Context context, String extend) { public void init(Context context, String extend) {
this.allExt = new ArrayList<>(Arrays.asList("ass", "ssa", "srt")); this.allExt = new ArrayList<>(Arrays.asList("ass", "ssa", "srt"));
this.allExt.addAll(Utils.MEDIA); this.allExt.addAll(Util.MEDIA);
this.extend = extend; this.extend = extend;
fetchRule(); fetchRule();
} }
@ -84,7 +84,7 @@ public class WebDAV extends Spider {
List<DavResource> files = new ArrayList<>(); List<DavResource> files = new ArrayList<>();
List<Vod> list = new ArrayList<>(); List<Vod> list = new ArrayList<>();
Drive drive = getDrive(key); Drive drive = getDrive(key);
for (DavResource item : getList(drive, path, Utils.MEDIA)) { for (DavResource item : getList(drive, path, Util.MEDIA)) {
if (item.isDirectory()) folders.add(item); if (item.isDirectory()) folders.add(item);
else files.add(item); else files.add(item);
} }
@ -110,7 +110,7 @@ public class WebDAV extends Spider {
Sorter.sort("name", "asc", parents); Sorter.sort("name", "asc", parents);
List<String> playUrls = new ArrayList<>(); List<String> playUrls = new ArrayList<>();
for (DavResource item : parents) { for (DavResource item : parents) {
if (Utils.isMedia(item.getName())) { if (Util.isMedia(item.getName())) {
playUrls.add(item.getName() + "$" + drive.getName() + item.getPath() + findSubs(drive, item, subs)); playUrls.add(item.getName() + "$" + drive.getName() + item.getPath() + findSubs(drive, item, subs));
} }
} }
@ -144,7 +144,7 @@ public class WebDAV extends Spider {
private List<DavResource> getSubs(List<DavResource> items) { private List<DavResource> getSubs(List<DavResource> items) {
List<DavResource> subs = new ArrayList<>(); List<DavResource> subs = new ArrayList<>();
for (DavResource item : items) if (Utils.isSub(getExt(item))) subs.add(item); for (DavResource item : items) if (Util.isSub(getExt(item))) subs.add(item);
return subs; return subs;
} }

View File

@ -6,7 +6,7 @@ import com.github.catvod.bean.Class;
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.Util;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
@ -36,7 +36,7 @@ public class Wogg extends Ali {
private Map<String, String> getHeader() { private Map<String, String> getHeader() {
Map<String, String> header = new HashMap<>(); Map<String, String> header = new HashMap<>();
header.put("User-Agent", Utils.CHROME); header.put("User-Agent", Util.CHROME);
return header; return header;
} }

View File

@ -10,7 +10,7 @@ import com.github.catvod.bean.xpath.Rule;
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.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -27,7 +27,7 @@ public class XPath extends Spider {
private HashMap<String, String> getHeaders() { private HashMap<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", rule.getUa().isEmpty() ? Utils.CHROME : rule.getUa()); headers.put("User-Agent", rule.getUa().isEmpty() ? Util.CHROME : rule.getUa());
return headers; return headers;
} }
@ -68,7 +68,7 @@ public class XPath extends Spider {
id = rule.getHomeVodIdR(id); id = rule.getHomeVodIdR(id);
String pic = vodNodes.get(i).selOne(rule.getHomeVodImg()).asString().trim(); String pic = vodNodes.get(i).selOne(rule.getHomeVodImg()).asString().trim();
pic = rule.getHomeVodImgR(pic); pic = rule.getHomeVodImgR(pic);
pic = Utils.fixUrl(webUrl, pic); pic = Util.fixUrl(webUrl, pic);
String mark = ""; String mark = "";
if (!rule.getHomeVodMark().isEmpty()) { if (!rule.getHomeVodMark().isEmpty()) {
try { try {
@ -102,7 +102,7 @@ public class XPath extends Spider {
id = rule.getCateVodIdR(id); id = rule.getCateVodIdR(id);
String pic = vodNodes.get(i).selOne(rule.getCateVodImg()).asString().trim(); String pic = vodNodes.get(i).selOne(rule.getCateVodImg()).asString().trim();
pic = rule.getCateVodImgR(pic); pic = rule.getCateVodImgR(pic);
pic = Utils.fixUrl(webUrl, pic); pic = Util.fixUrl(webUrl, pic);
String mark = ""; String mark = "";
if (!rule.getCateVodMark().isEmpty()) { if (!rule.getCateVodMark().isEmpty()) {
try { try {
@ -129,7 +129,7 @@ public class XPath extends Spider {
title = rule.getDetailNameR(title); title = rule.getDetailNameR(title);
cover = vodNode.selOne(rule.getDetailImg()).asString().trim(); cover = vodNode.selOne(rule.getDetailImg()).asString().trim();
cover = rule.getDetailImgR(cover); cover = rule.getDetailImgR(cover);
cover = Utils.fixUrl(webUrl, cover); cover = Util.fixUrl(webUrl, cover);
if (!rule.getDetailCate().isEmpty()) { if (!rule.getDetailCate().isEmpty()) {
try { try {
category = vodNode.selOne(rule.getDetailCate()).asString().trim(); category = vodNode.selOne(rule.getDetailCate()).asString().trim();
@ -272,7 +272,7 @@ public class XPath extends Spider {
id = rule.getSearchVodIdR(id); id = rule.getSearchVodIdR(id);
String pic = vod.optString(rule.getSearchVodImg()).trim(); String pic = vod.optString(rule.getSearchVodImg()).trim();
pic = rule.getSearchVodImgR(pic); pic = rule.getSearchVodImgR(pic);
pic = Utils.fixUrl(webUrl, pic); pic = Util.fixUrl(webUrl, pic);
String mark = vod.optString(rule.getSearchVodMark()).trim(); String mark = vod.optString(rule.getSearchVodMark()).trim();
mark = rule.getSearchVodMarkR(mark); mark = rule.getSearchVodMarkR(mark);
list.add(new Vod(id, name, pic, mark)); list.add(new Vod(id, name, pic, mark));
@ -291,7 +291,7 @@ public class XPath extends Spider {
id = rule.getSearchVodIdR(id); id = rule.getSearchVodIdR(id);
String pic = vodNodes.get(i).selOne(rule.getSearchVodImg()).asString().trim(); String pic = vodNodes.get(i).selOne(rule.getSearchVodImg()).asString().trim();
pic = rule.getSearchVodImgR(pic); pic = rule.getSearchVodImgR(pic);
pic = Utils.fixUrl(webUrl, pic); pic = Util.fixUrl(webUrl, pic);
String mark = ""; String mark = "";
if (!rule.getCateVodMark().isEmpty()) { if (!rule.getCateVodMark().isEmpty()) {
try { try {
@ -314,7 +314,7 @@ public class XPath extends Spider {
@Override @Override
public boolean isVideoFormat(String url) { public boolean isVideoFormat(String url) {
return Utils.isVideoFormat(url); return Util.isVideoFormat(url);
} }
protected String ext = null; protected String ext = null;

View File

@ -5,7 +5,7 @@ import android.text.TextUtils;
import android.util.Base64; import android.util.Base64;
import com.github.catvod.crawler.SpiderDebug; import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.json.JSONException; import org.json.JSONException;
@ -151,7 +151,7 @@ public class XPathMac extends XPath {
} }
if (videoUrl != null) { if (videoUrl != null) {
// 適配2.0.6的調用應用內解析列表的支持, 需要配合直連分析和匹配官源解析一起使用參考cjt影視和極品直連 // 適配2.0.6的調用應用內解析列表的支持, 需要配合直連分析和匹配官源解析一起使用參考cjt影視和極品直連
if (decodeVipFlag && Utils.isVip(videoUrl)) { // 使用jx:1 if (decodeVipFlag && Util.isVip(videoUrl)) { // 使用jx:1
try { try {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("parse", 1); result.put("parse", 1);

View File

@ -8,7 +8,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -40,14 +40,14 @@ public class Xb6v extends Spider {
private Map<String, String> getHeader() { private Map<String, String> getHeader() {
Map<String, String> header = new HashMap<>(); Map<String, String> header = new HashMap<>();
header.put("User-Agent", Utils.CHROME); header.put("User-Agent", Util.CHROME);
header.put("Referer", siteUrl + "/"); header.put("Referer", siteUrl + "/");
return header; return header;
} }
private Map<String, String> getDetailHeader() { private Map<String, String> getDetailHeader() {
Map<String, String> header = new HashMap<>(); Map<String, String> header = new HashMap<>();
header.put("User-Agent", Utils.CHROME); header.put("User-Agent", Util.CHROME);
return header; return header;
} }
@ -220,7 +220,7 @@ public class Xb6v extends Spider {
.addEncoded("keyboard", key) .addEncoded("keyboard", key)
.build(); .build();
Request request = new Request.Builder().url(searchUrl) Request request = new Request.Builder().url(searchUrl)
.addHeader("User-Agent", Utils.CHROME) .addHeader("User-Agent", Util.CHROME)
.addHeader("Origin", siteUrl) .addHeader("Origin", siteUrl)
.addHeader("Referer", siteUrl + "/") .addHeader("Referer", siteUrl + "/")
.post(formBody) .post(formBody)

View File

@ -6,7 +6,7 @@ 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.Util;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -33,7 +33,7 @@ public class XiaoZhiTiao extends Ali {
private Map<String, String> getHeaders() { private Map<String, String> getHeaders() {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("Host", "gitcafe.net"); params.put("Host", "gitcafe.net");
params.put("User-Agent", Utils.CHROME); params.put("User-Agent", Util.CHROME);
return params; return params;
} }

View File

@ -8,7 +8,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -31,7 +31,7 @@ public class Ying extends Spider {
private HashMap<String, String> getHeaders() { private HashMap<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
return headers; return headers;
} }

View File

@ -8,7 +8,7 @@ import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod; import com.github.catvod.bean.Vod;
import com.github.catvod.crawler.Spider; import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp; import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -32,7 +32,7 @@ public class Ysj extends Spider {
private HashMap<String, String> getHeaders() { private HashMap<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<>(); HashMap<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
return headers; return headers;
} }

View File

@ -5,7 +5,7 @@ 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;
import com.github.catvod.utils.Utils; import com.github.catvod.utils.Util;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -30,7 +30,7 @@ public class Zhaozy extends Ali {
private Map<String, String> getHeader() { private Map<String, String> getHeader() {
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
headers.put("Referer", siteUrl); headers.put("Referer", siteUrl);
headers.put("Cookie", getCookie()); headers.put("Cookie", getCookie());
return headers; return headers;
@ -41,7 +41,7 @@ public class Zhaozy extends Ali {
params.put("username", username); params.put("username", username);
params.put("password", password); params.put("password", password);
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("User-Agent", Utils.CHROME); headers.put("User-Agent", Util.CHROME);
headers.put("Referer", siteUrl + "stop.html"); headers.put("Referer", siteUrl + "stop.html");
headers.put("Origin", siteUrl); headers.put("Origin", siteUrl);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@ -0,0 +1,30 @@
package com.github.catvod.utils;
import android.text.TextUtils;
import android.widget.Toast;
import com.github.catvod.spider.Init;
public class Notify {
private Toast mToast;
private static class Loader {
static volatile Notify INSTANCE = new Notify();
}
private static Notify get() {
return Loader.INSTANCE;
}
public static void show(String text) {
Init.run(() -> get().makeText(text));
}
private void makeText(String message) {
if (TextUtils.isEmpty(message)) return;
if (mToast != null) mToast.cancel();
mToast = Toast.makeText(Init.context(), message, Toast.LENGTH_LONG);
mToast.show();
}
}

View File

@ -1,7 +1,6 @@
package com.github.catvod.utils; package com.github.catvod.utils;
import android.os.Environment; import android.os.Environment;
import android.util.Log;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -15,8 +14,6 @@ import java.util.List;
public class Path { public class Path {
private static final String TAG = Path.class.getSimpleName();
private static File check(File file) { private static File check(File file) {
if (!file.exists()) file.mkdirs(); if (!file.exists()) file.mkdirs();
return file; return file;
@ -47,14 +44,6 @@ public class Path {
} }
} }
public static String read(String path) {
try {
return read(new FileInputStream(path));
} catch (Exception e) {
return "";
}
}
public static String read(InputStream is) { public static String read(InputStream is) {
try { try {
byte[] data = new byte[is.available()]; byte[] data = new byte[is.available()];
@ -84,18 +73,6 @@ public class Path {
} }
} }
public static void move(File in, File out) {
copy(in, out);
clear(in);
}
public static void copy(File in, File out) {
try {
copy(new FileInputStream(in), new FileOutputStream(out));
} catch (Exception ignored) {
}
}
public static void copy(InputStream in, File out) { public static void copy(InputStream in, File out) {
try { try {
copy(in, new FileOutputStream(out)); copy(in, new FileOutputStream(out));
@ -116,12 +93,6 @@ public class Path {
return files == null ? Collections.emptyList() : Arrays.asList(files); return files == null ? Collections.emptyList() : Arrays.asList(files);
} }
public static void clear(File dir) {
if (dir == null) return;
if (dir.isDirectory()) for (File file : list(dir)) clear(file);
if (dir.delete()) Log.d(TAG, "Deleted:" + dir.getAbsolutePath());
}
public static File chmod(File file) { public static File chmod(File file) {
try { try {
Process process = Runtime.getRuntime().exec("chmod 777 " + file); Process process = Runtime.getRuntime().exec("chmod 777 " + file);

View File

@ -26,9 +26,41 @@ public class ProxyVideo {
String hContentLength = response.headers().get("Content-Length"); String hContentLength = response.headers().get("Content-Length");
String contentDisposition = response.headers().get("Content-Disposition"); String contentDisposition = response.headers().get("Content-Disposition");
long contentLength = hContentLength != null ? Long.parseLong(hContentLength) : 0; long contentLength = hContentLength != null ? Long.parseLong(hContentLength) : 0;
if (contentDisposition != null) contentType = Utils.getMimeType(contentDisposition); if (contentDisposition != null) contentType = getMimeType(contentDisposition);
NanoHTTPD.Response resp = newFixedLengthResponse(status, contentType, response.body().byteStream(), contentLength); NanoHTTPD.Response resp = newFixedLengthResponse(status, contentType, response.body().byteStream(), contentLength);
for (String key : response.headers().names()) resp.addHeader(key, response.headers().get(key)); for (String key : response.headers().names()) resp.addHeader(key, response.headers().get(key));
return resp; return resp;
} }
private static String getMimeType(String contentDisposition) {
if (contentDisposition.endsWith(".mp4")) {
return "video/mp4";
} else if (contentDisposition.endsWith(".webm")) {
return "video/webm";
} else if (contentDisposition.endsWith(".avi")) {
return "video/x-msvideo";
} else if (contentDisposition.endsWith(".wmv")) {
return "video/x-ms-wmv";
} else if (contentDisposition.endsWith(".flv")) {
return "video/x-flv";
} else if (contentDisposition.endsWith(".mov")) {
return "video/quicktime";
} else if (contentDisposition.endsWith(".mkv")) {
return "video/x-matroska";
} else if (contentDisposition.endsWith(".mpeg")) {
return "video/mpeg";
} else if (contentDisposition.endsWith(".3gp")) {
return "video/3gpp";
} else if (contentDisposition.endsWith(".ts")) {
return "video/MP2T";
} else if (contentDisposition.endsWith(".mp3")) {
return "audio/mp3";
} else if (contentDisposition.endsWith(".wav")) {
return "audio/wav";
} else if (contentDisposition.endsWith(".aac")) {
return "audio/aac";
} else {
return null;
}
}
} }

View File

@ -35,7 +35,7 @@ public class QRCode {
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class); Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hints.put(EncodeHintType.MARGIN, margin); hints.put(EncodeHintType.MARGIN, margin);
return createBitmap(new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, Utils.dp2px(size), Utils.dp2px(size), hints)); return createBitmap(new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, size, size, hints));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;

View File

@ -0,0 +1,17 @@
package com.github.catvod.utils;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import com.github.catvod.spider.Init;
public class ResUtil {
private static DisplayMetrics getDisplayMetrics() {
return Init.context().getResources().getDisplayMetrics();
}
public static int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getDisplayMetrics());
}
}

View File

@ -5,14 +5,11 @@ import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.Toast;
import com.github.catvod.spider.Init; import com.github.catvod.spider.Init;
@ -26,9 +23,9 @@ import java.util.Locale;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class Utils { public class Util {
public static final Pattern RULE = Pattern.compile("http((?!http).){12,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)\\?.*|http((?!http).){12,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)|http((?!http).)*?video/tos*"); public static final Pattern RULE = Pattern.compile("http((?!http).){12,}?\\.(m3u8|mp4|mkv|flv|mp3|m4a|aac)\\?.*|http((?!http).){12,}\\.(m3u8|mp4|mkv|flv|mp3|m4a|aac)|http((?!http).)*?video/tos*");
public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"; public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36";
public static final String ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"; public static final String ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7";
public static final List<String> MEDIA = Arrays.asList("mp4", "mkv", "wmv", "flv", "avi", "iso", "mpg", "ts", "mp3", "aac", "flac", "m4a", "ape", "ogg"); public static final List<String> MEDIA = Arrays.asList("mp4", "mkv", "wmv", "flv", "avi", "iso", "mpg", "ts", "mp3", "aac", "flac", "m4a", "ape", "ogg");
@ -147,18 +144,10 @@ public class Utils {
} }
} }
public static DisplayMetrics getDisplayMetrics() {
return Init.context().getResources().getDisplayMetrics();
}
public static int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getDisplayMetrics());
}
public static void copy(String text) { public static void copy(String text) {
ClipboardManager manager = (ClipboardManager) Init.context().getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager manager = (ClipboardManager) Init.context().getSystemService(Context.CLIPBOARD_SERVICE);
manager.setPrimaryClip(ClipData.newPlainText("fongmi", text)); manager.setPrimaryClip(ClipData.newPlainText("fongmi", text));
notify("已複製 " + text); Notify.show("已複製 " + text);
} }
public static void loadUrl(WebView webView, String script) { public static void loadUrl(WebView webView, String script) {
@ -170,10 +159,6 @@ public class Utils {
else webView.loadUrl(script); else webView.loadUrl(script);
} }
public static void notify(String msg) {
Init.run(() -> Toast.makeText(Init.context(), msg, Toast.LENGTH_LONG).show());
}
public static void addView(View view, ViewGroup.LayoutParams params) { public static void addView(View view, ViewGroup.LayoutParams params) {
try { try {
ViewGroup group = Init.getActivity().getWindow().getDecorView().findViewById(android.R.id.content); ViewGroup group = Init.getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
@ -216,36 +201,4 @@ public class Utils {
return ""; return "";
} }
} }
public static String getMimeType(String contentDisposition) {
if (contentDisposition.endsWith(".mp4")) {
return "video/mp4";
} else if (contentDisposition.endsWith(".webm")) {
return "video/webm";
} else if (contentDisposition.endsWith(".avi")) {
return "video/x-msvideo";
} else if (contentDisposition.endsWith(".wmv")) {
return "video/x-ms-wmv";
} else if (contentDisposition.endsWith(".flv")) {
return "video/x-flv";
} else if (contentDisposition.endsWith(".mov")) {
return "video/quicktime";
} else if (contentDisposition.endsWith(".mkv")) {
return "video/x-matroska";
} else if (contentDisposition.endsWith(".mpeg")) {
return "video/mpeg";
} else if (contentDisposition.endsWith(".3gp")) {
return "video/3gpp";
} else if (contentDisposition.endsWith(".ts")) {
return "video/MP2T";
} else if (contentDisposition.endsWith(".mp3")) {
return "audio/mp3";
} else if (contentDisposition.endsWith(".wav")) {
return "audio/wav";
} else if (contentDisposition.endsWith(".aac")) {
return "audio/aac";
} else {
return null;
}
}
} }