Add getProxyUrl for py

release
FongMi 2 years ago
parent f0bf9dc6af
commit 193ef3b8b4
  1. 9
      chaquo/src/main/java/com/fongmi/chaquo/Spider.java
  2. 10
      chaquo/src/main/python/base/spider.py

@ -3,7 +3,6 @@ package com.fongmi.chaquo;
import android.content.Context;
import com.chaquo.python.PyObject;
import com.github.catvod.Proxy;
import com.github.catvod.utils.Path;
import com.github.catvod.utils.UriUtil;
import com.github.catvod.utils.Util;
@ -72,7 +71,7 @@ public class Spider extends com.github.catvod.crawler.Spider {
@Override
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
@ -108,7 +107,7 @@ public class Spider extends com.github.catvod.crawler.Spider {
if (o.type().toString().contains("bytes")) {
return new ByteArrayInputStream(o.toJava(byte[].class));
} else {
String content = replaceProxy(o.toString());
String content = o.toString();
if (base64 && content.contains("base64,")) content = content.split("base64,")[1];
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);
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 abc import abstractmethod, ABCMeta
from importlib.machinery import SourceFileLoader
from com.github.catvod import Proxy
class Spider(metaclass=ABCMeta):
@ -100,8 +101,11 @@ class Spider(metaclass=ABCMeta):
def html(self, 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:9978/cache?do=get&key={key}', timeout=5).text
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)
@ -121,9 +125,9 @@ class Spider(metaclass=ABCMeta):
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:9978/cache?do=set&key={key}', data={"value": value}, timeout=5)
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:9978/cache?do=del&key={key}', timeout=5)
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