pull/586/head
FongMi 2 years ago
parent 0828653324
commit 8406a7c465
  1. 4
      app/src/main/java/com/fongmi/android/tv/api/loader/PyLoader.java
  2. 6
      chaquo/src/main/java/com/fongmi/chaquo/Loader.java
  3. 23
      chaquo/src/main/python/app.py

@ -42,8 +42,8 @@ public class PyLoader {
public Spider getSpider(String key, String api, String ext) {
try {
if (spiders.containsKey(key)) return spiders.get(key);
Method method = loader.getClass().getMethod("spider", Context.class, String.class, String.class);
Spider spider = (Spider) method.invoke(loader, App.get(), key, api);
Method method = loader.getClass().getMethod("spider", Context.class, String.class);
Spider spider = (Spider) method.invoke(loader, App.get(), api);
spider.init(App.get(), ext);
spiders.put(key, spider);
return spider;

@ -12,19 +12,17 @@ import com.github.catvod.utils.Path;
public class Loader {
private PyObject app;
private String cache;
@Keep
private void init(Context context) {
if (!Python.isStarted()) Python.start(new AndroidPlatform(context));
app = Python.getInstance().getModule("app");
cache = Path.py().getAbsolutePath();
}
@Keep
public Spider spider(Context context, String key, String api) {
public Spider spider(Context context, String api) {
if (app == null) init(context);
PyObject obj = app.callAttr("spider", cache, key, api);
PyObject obj = app.callAttr("spider", Path.py().getAbsolutePath(), api);
return new Spider(app, obj);
}
}

@ -4,22 +4,23 @@ from importlib.machinery import SourceFileLoader
import json
def spider(cache, key, api):
def spider(cache, api):
name = os.path.basename(api)
path = cache + '/' + name
downloadFile(path, api)
name = name.split('.')[0]
return SourceFileLoader(name, path).load_module().Spider()
def downloadFile(name, api):
def downloadFile(path, api):
if api.startswith('http'):
writeFile(name, redirect(api).content)
writeFile(path, redirect(api).content)
else:
writeFile(name, str.encode(api))
writeFile(path, str.encode(api))
def writeFile(name, content):
with open(name, 'wb') as f:
def writeFile(path, content):
with open(path, 'wb') as f:
f.write(content)
@ -35,6 +36,16 @@ def str2json(content):
return json.loads(content)
def getDependence(ru):
result = ru.getDependence()
return result
def getName(ru):
result = ru.getName()
return result
def init(ru, extend):
ru.init(extend)

Loading…
Cancel
Save