Add getProxyUrl for py

Fix py proguard
pull/553/head
okjack 1 year ago
parent 0627c1e35f
commit 08deb19357
  1. 1
      app/proguard-rules.pro
  2. 9
      pyramid/src/main/java/com/undcover/freedom/pyramid/Spider.java
  3. 32
      pyramid/src/main/python/base/spider.py

@ -33,6 +33,7 @@
-keep class okhttp3.** { *; } -keep class okhttp3.** { *; }
# CatVod # CatVod
-keep class com.github.catvod.Proxy { *; }
-keep class com.github.catvod.crawler.** { *; } -keep class com.github.catvod.crawler.** { *; }
-keep class * extends com.github.catvod.crawler.Spider -keep class * extends com.github.catvod.crawler.Spider

@ -3,7 +3,6 @@ package com.undcover.freedom.pyramid;
import android.content.Context; import android.content.Context;
import com.chaquo.python.PyObject; import com.chaquo.python.PyObject;
import com.github.catvod.Proxy;
import com.github.catvod.utils.Path; import com.github.catvod.utils.Path;
import com.github.catvod.utils.UriUtil; import com.github.catvod.utils.UriUtil;
import com.github.catvod.utils.Util; import com.github.catvod.utils.Util;
@ -72,7 +71,7 @@ public class Spider extends com.github.catvod.crawler.Spider {
@Override @Override
public String playerContent(String flag, String id, List<String> vipFlags) { public String playerContent(String flag, String id, List<String> vipFlags) {
return replaceProxy(app.callAttr("playerContent", obj, flag, id, gson.toJson(vipFlags)).toString()); return app.callAttr("playerContent", obj, flag, id, gson.toJson(vipFlags)).toString();
} }
@Override @Override
@ -108,7 +107,7 @@ public class Spider extends com.github.catvod.crawler.Spider {
if (o.type().toString().contains("bytes")) { if (o.type().toString().contains("bytes")) {
return new ByteArrayInputStream(o.toJava(byte[].class)); return new ByteArrayInputStream(o.toJava(byte[].class));
} else { } else {
String content = replaceProxy(o.toString()); String content = o.toString();
if (base64 && content.contains("base64,")) content = content.split("base64,")[1]; if (base64 && content.contains("base64,")) content = content.split("base64,")[1];
return new ByteArrayInputStream(base64 ? Util.decode(content) : content.getBytes()); return new ByteArrayInputStream(base64 ? Util.decode(content) : content.getBytes());
} }
@ -119,8 +118,4 @@ public class Spider extends com.github.catvod.crawler.Spider {
String url = UriUtil.resolve(api, name); String url = UriUtil.resolve(api, name);
app.callAttr("download", path, url); app.callAttr("download", path, url);
} }
private String replaceProxy(String content) {
return content.replace("http://127.0.0.1:UndCover/proxy", Proxy.getUrl(true));
}
} }

@ -6,6 +6,7 @@ from lxml import etree
from com.chaquo.python import Python from com.chaquo.python import Python
from abc import abstractmethod, ABCMeta from abc import abstractmethod, ABCMeta
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader
from com.github.catvod import Proxy
class Spider(metaclass=ABCMeta): class Spider(metaclass=ABCMeta):
@ -99,3 +100,34 @@ class Spider(metaclass=ABCMeta):
def html(self, content): def html(self, content):
return etree.HTML(content) return etree.HTML(content)
def getProxyUrl(self, local=True):
return f'{Proxy.getUrl(local)}?do=py'
def getCache(self, key):
value = self.fetch(f'http://127.0.0.1:{Proxy.getPort()}/cache?do=get&key={key}', timeout=5).text
if len(value) > 0:
if value.startswith('{') and value.endswith('}') or value.startswith('[') and value.endswith(']'):
value = json.loads(value)
if type(value) == dict:
if not 'expiresAt' in value or value['expiresAt'] >= int(time.time()):
return value
else:
self.delCache(key)
return None
return value
else:
return None
def setCache(self, key, value):
if type(value) in [int, float]:
value = str(value)
if len(value) > 0:
if type(value) == dict or type(value) == list:
value = json.dumps(value, ensure_ascii=False)
r = self.post(f'http://127.0.0.1:{Proxy.getPort()}/cache?do=set&key={key}', data={"value": value}, timeout=5)
return 'succeed' if r.status_code == 200 else 'failed'
def delCache(self, key):
r = self.fetch(f'http://127.0.0.1:{Proxy.getPort()}/cache?do=del&key={key}', timeout=5)
return 'succeed' if r.status_code == 200 else 'failed'

Loading…
Cancel
Save