|
|
|
|
@ -1,21 +1,19 @@ |
|
|
|
|
package com.undcover.freedom.pyramid; |
|
|
|
|
|
|
|
|
|
import android.content.Context; |
|
|
|
|
import android.text.TextUtils; |
|
|
|
|
|
|
|
|
|
import androidx.collection.ArrayMap; |
|
|
|
|
|
|
|
|
|
import com.chaquo.python.PyObject; |
|
|
|
|
import com.github.catvod.Proxy; |
|
|
|
|
import com.github.catvod.net.OkHttp; |
|
|
|
|
import com.github.catvod.utils.Json; |
|
|
|
|
import com.google.gson.Gson; |
|
|
|
|
|
|
|
|
|
import org.json.JSONException; |
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
import com.google.gson.JsonObject; |
|
|
|
|
import com.google.gson.JsonParser; |
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Iterator; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
@ -93,16 +91,15 @@ public class Spider extends com.github.catvod.crawler.Spider { |
|
|
|
|
List<PyObject> list = app.callAttr("localProxy", obj, gson.toJson(params)).asList(); |
|
|
|
|
int code = list.get(0).toInt(); |
|
|
|
|
String type = list.get(1).toString(); |
|
|
|
|
String action = list.get(2).toString(); |
|
|
|
|
String content = list.get(3).toString(); |
|
|
|
|
JSONObject object = new JSONObject(action); |
|
|
|
|
String url = object.optString("url"); |
|
|
|
|
Headers header = getHeader(object.optString("header")); |
|
|
|
|
ArrayMap<String, String> param = getParam(object.optString("param")); |
|
|
|
|
if (object.optString("type").equals("stream")) { |
|
|
|
|
return new Object[]{code, type, OkHttp.newCall(url, header, param).execute().body().byteStream()}; |
|
|
|
|
JsonObject action = JsonParser.parseString(list.get(2).toString()).getAsJsonObject(); |
|
|
|
|
Headers headers = Headers.of(Json.toMap(action.get("header"))); |
|
|
|
|
String url = action.get("url").getAsString(); |
|
|
|
|
if (action.get("type").getAsString().equals("stream")) { |
|
|
|
|
ArrayMap<String, String> param = Json.toArrayMap(action.get("param")); |
|
|
|
|
return new Object[]{code, type, OkHttp.newCall(url, headers, param).execute().body().byteStream()}; |
|
|
|
|
} else { |
|
|
|
|
if (content.isEmpty()) content = OkHttp.newCall(url, header).execute().body().string(); |
|
|
|
|
if (content.isEmpty()) content = OkHttp.newCall(url, headers).execute().body().string(); |
|
|
|
|
return new Object[]{code, type, new ByteArrayInputStream(replaceProxy(content).getBytes())}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -110,26 +107,4 @@ public class Spider extends com.github.catvod.crawler.Spider { |
|
|
|
|
private String replaceProxy(String content) { |
|
|
|
|
return content.replace("http://127.0.0.1:UndCover/proxy", Proxy.getUrl(true)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Headers getHeader(String header) throws JSONException { |
|
|
|
|
Headers.Builder builder = new Headers.Builder(); |
|
|
|
|
if (TextUtils.isEmpty(header)) return builder.build(); |
|
|
|
|
JSONObject object = new JSONObject(header); |
|
|
|
|
for (Iterator<String> iterator = object.keys(); iterator.hasNext(); ) { |
|
|
|
|
String key = iterator.next(); |
|
|
|
|
builder.add(key, object.optString(key)); |
|
|
|
|
} |
|
|
|
|
return builder.build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ArrayMap<String, String> getParam(String param) throws JSONException { |
|
|
|
|
ArrayMap<String, String> params = new ArrayMap<>(); |
|
|
|
|
if (TextUtils.isEmpty(param)) return params; |
|
|
|
|
JSONObject object = new JSONObject(param); |
|
|
|
|
for (Iterator<String> iterator = object.keys(); iterator.hasNext(); ) { |
|
|
|
|
String key = iterator.next(); |
|
|
|
|
params.put(key, object.optString(key)); |
|
|
|
|
} |
|
|
|
|
return params; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|