pull/590/head
FongMi 11 months ago
parent f4e1150ec2
commit 863baa85ab
  1. BIN
      app/libs/tvbus-release.aar
  2. 12
      app/src/main/java/com/fongmi/android/tv/api/Decoder.java
  3. 2
      app/src/main/java/com/fongmi/android/tv/api/config/LiveConfig.java
  4. 2
      app/src/main/java/com/fongmi/android/tv/api/config/VodConfig.java
  5. 18
      app/src/main/java/com/fongmi/android/tv/api/config/WallConfig.java
  6. 2
      app/src/main/java/com/fongmi/android/tv/api/loader/JarLoader.java
  7. 6
      app/src/main/java/com/fongmi/android/tv/bean/Core.java
  8. 11
      app/src/main/java/com/fongmi/android/tv/player/danmaku/Loader.java
  9. 16
      app/src/main/java/com/fongmi/android/tv/player/extractor/TVBus.java
  10. 8
      app/src/main/java/com/fongmi/android/tv/utils/Download.java
  11. 11
      app/src/mobile/java/com/fongmi/android/tv/utils/ScanTask.java
  12. 21
      catvod/src/main/java/com/github/catvod/net/OkHttp.java
  13. 6
      catvod/src/main/java/com/github/catvod/utils/Path.java
  14. 2
      quickjs/src/main/java/com/fongmi/quickjs/utils/Connect.java
  15. 2
      quickjs/src/main/java/com/fongmi/quickjs/utils/Module.java
  16. 7
      tvbus/src/main/java/com/tvbus/engine/TVCore.java
  17. BIN
      tvbus/src/main/jniLibs/arm64-v8a/libtvcore.so
  18. BIN
      tvbus/src/main/jniLibs/armeabi-v7a/libtvcore.so

Binary file not shown.

@ -23,12 +23,12 @@ public class Decoder {
private static final Pattern JS_URI = Pattern.compile("\"(\\.|\\.\\.)/(.?|.+?)\\.js\\?(.?|.+?)\"");
public static String getJson(String url, String tag) throws Exception {
url = UrlUtil.convert(url);
int size = HttpUrl.parse(url).querySize();
Response res = OkHttp.newCall(url, tag).execute();
HttpUrl httpUrl = res.request().url();
if (httpUrl.querySize() == size) url = httpUrl.toString();
return verify(url, res.body().string());
try (Response res = OkHttp.newCall(url, tag).execute()) {
HttpUrl httpUrl = res.request().url();
int size = HttpUrl.parse(url).querySize();
if (httpUrl.querySize() == size) url = httpUrl.toString();
return verify(url, res.body().string());
}
}
private static String verify(String url, String data) throws Exception {

@ -114,7 +114,7 @@ public class LiveConfig {
private void loadConfig(Callback callback) {
try {
OkHttp.cancel("live");
parseConfig(Decoder.getJson(config.getUrl(), "live"), callback);
parseConfig(Decoder.getJson(UrlUtil.convert(config.getUrl()), "live"), callback);
} catch (Throwable e) {
if (TextUtils.isEmpty(config.getUrl())) App.post(() -> callback.error(""));
else App.post(() -> callback.error(Notify.getError(R.string.error_config_get, e)));

@ -112,7 +112,7 @@ public class VodConfig {
private void loadConfig(Callback callback) {
try {
OkHttp.cancel("vod");
checkJson(Json.parse(Decoder.getJson(config.getUrl(), "vod")).getAsJsonObject(), callback);
checkJson(Json.parse(Decoder.getJson(UrlUtil.convert(config.getUrl()), "vod")).getAsJsonObject(), callback);
} catch (Throwable e) {
if (TextUtils.isEmpty(config.getUrl())) App.post(() -> callback.error(""));
else loadCache(callback, e);

@ -85,19 +85,11 @@ public class WallConfig {
}
private File write(File file) throws Exception {
Path.write(file, OkHttp.newCall(UrlUtil.convert(getUrl())).execute().body().bytes());
return resize(file);
}
private File resize(File file) {
try {
Bitmap bitmap = Glide.with(App.get()).asBitmap().load(file).centerCrop().override(ResUtil.getScreenWidth(), ResUtil.getScreenHeight()).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).submit().get();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(file));
bitmap.recycle();
return file;
} catch (Exception e) {
return file;
}
Path.write(file, OkHttp.bytes(UrlUtil.convert(getUrl())));
Bitmap bitmap = Glide.with(App.get()).asBitmap().load(file).centerCrop().override(ResUtil.getScreenWidth(), ResUtil.getScreenHeight()).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).submit().get();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(file));
bitmap.recycle();
return file;
}
public boolean needSync(String url) {

@ -78,7 +78,7 @@ public class JarLoader {
private File download(String url) {
try {
return Path.write(Path.jar(url), OkHttp.newCall(url).execute().body().bytes());
return Path.write(Path.jar(url), OkHttp.bytes(url));
} catch (Exception e) {
return Path.jar(url);
}

@ -26,6 +26,8 @@ public class Core {
private String sign;
@SerializedName("pkg")
private String pkg;
@SerializedName("so")
private String so;
public String getAuth() {
return !getResp().isEmpty() ? Server.get().getAddress("/tvbus") : TextUtils.isEmpty(auth) ? "" : auth;
@ -59,6 +61,10 @@ public class Core {
return TextUtils.isEmpty(pkg) ? "" : pkg;
}
public String getSo() {
return TextUtils.isEmpty(so) ? "" : so;
}
public Hook getHook() {
return !getPkg().isEmpty() && !getSign().isEmpty() ? new Hook(getSign(), getPkg()) : null;
}

@ -11,6 +11,8 @@ import java.io.InputStream;
import master.flame.danmaku.danmaku.loader.ILoader;
import master.flame.danmaku.danmaku.loader.IllegalDataException;
import master.flame.danmaku.danmaku.parser.android.AndroidFileSource;
import okhttp3.OkHttpClient;
import okhttp3.Response;
public class Loader implements ILoader {
@ -26,10 +28,11 @@ public class Loader implements ILoader {
@Override
public void load(String url) throws IllegalDataException {
try {
OkHttp.cancel("danmaku");
if (url.startsWith("/")) url = "file:/" + url;
load(OkHttp.newCall(OkHttp.client(Constant.TIMEOUT_DANMAKU), UrlUtil.convert(url), "danmaku").execute().body().byteStream());
OkHttp.cancel("danmaku");
if (url.startsWith("/")) url = "file:/" + url;
OkHttpClient client = OkHttp.client(Constant.TIMEOUT_DANMAKU);
try (Response res = OkHttp.newCall(client, UrlUtil.convert(url), "danmaku").execute()) {
load(res.body().byteStream());
} catch (IOException e) {
e.printStackTrace();
}

@ -1,5 +1,8 @@
package com.fongmi.android.tv.player.extractor;
import android.net.Uri;
import android.text.TextUtils;
import com.fongmi.android.tv.App;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.Setting;
@ -8,10 +11,13 @@ import com.fongmi.android.tv.bean.Core;
import com.fongmi.android.tv.exception.ExtractException;
import com.fongmi.android.tv.player.Source;
import com.fongmi.android.tv.utils.ResUtil;
import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Path;
import com.google.gson.JsonObject;
import com.tvbus.engine.Listener;
import com.tvbus.engine.TVCore;
import java.io.File;
import java.util.concurrent.CountDownLatch;
public class TVBus implements Source.Extractor, Listener {
@ -29,13 +35,21 @@ public class TVBus implements Source.Extractor, Listener {
private void init(Core core) {
try {
App.get().setHook(core.getHook());
tvcore = new TVCore().listener(this).auth(core.getAuth()).name(core.getName()).pass(core.getPass()).domain(core.getDomain()).broker(core.getBroker()).serv(0).play(8902).mode(1).init();
tvcore = new TVCore(getPath(core.getSo())).listener(this).auth(core.getAuth()).name(core.getName()).pass(core.getPass()).domain(core.getDomain()).broker(core.getBroker()).serv(0).play(8902).mode(1).init();
} catch (Exception ignored) {
} finally {
App.get().setHook(null);
}
}
private String getPath(String url) {
String name = Uri.parse(url).getLastPathSegment();
if (TextUtils.isEmpty(name)) name = "tvcore.so";
File file = new File(Path.so(), name);
if (file.length() < 10240) Path.write(file, OkHttp.bytes(url));
return file.getAbsolutePath();
}
@Override
public String fetch(String url) throws Exception {
Core c = LiveConfig.get().getHome().getCore();

@ -45,10 +45,9 @@ public class Download {
}
private void doInBackground() {
try {
try (Response res = OkHttp.newCall(url, url).execute()) {
Path.create(file);
Response response = OkHttp.newCall(url, url).execute();
download(response.body().byteStream(), Double.parseDouble(response.header(HttpHeaders.CONTENT_LENGTH, "1")));
download(res.body().byteStream(), Double.parseDouble(res.header(HttpHeaders.CONTENT_LENGTH, "1")));
App.post(() -> {if (callback != null) callback.success(file);});
} catch (Exception e) {
App.post(() -> {if (callback != null) callback.error(e.getMessage());});
@ -56,8 +55,7 @@ public class Download {
}
private void download(InputStream is, double length) throws Exception {
FileOutputStream os = new FileOutputStream(file);
try (BufferedInputStream input = new BufferedInputStream(is)) {
try (BufferedInputStream input = new BufferedInputStream(is); FileOutputStream os = new FileOutputStream(file)) {
byte[] buffer = new byte[4096];
int readBytes;
long totalBytes = 0;

@ -15,6 +15,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import okhttp3.OkHttpClient;
import okhttp3.Response;
public class ScanTask {
@ -78,12 +79,10 @@ public class ScanTask {
}
private void findDevice(CountDownLatch cd, String url) {
try {
if (url.contains(Server.get().getAddress())) return;
String result = OkHttp.newCall(client, url.concat("/device")).execute().body().string();
Device device = Device.objectFrom(result);
if (device == null) return;
devices.add(device.save());
if (url.contains(Server.get().getAddress())) return;
try (Response res = OkHttp.newCall(client, url).execute()) {
Device device = Device.objectFrom(res.body().string());
if (device != null) devices.add(device.save());
} catch (Exception ignored) {
} finally {
cd.countDown();

@ -28,6 +28,7 @@ import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.dnsoverhttps.DnsOverHttps;
import okhttp3.logging.HttpLoggingInterceptor;
@ -121,8 +122,9 @@ public class OkHttp {
}
public static String string(String url) {
try {
return url.startsWith("http") ? newCall(url).execute().body().string() : "";
if (!url.startsWith("http")) return "";
try (Response res = newCall(url).execute()) {
return res.body().string();
} catch (Exception e) {
e.printStackTrace();
return "";
@ -130,14 +132,25 @@ public class OkHttp {
}
public static String string(String url, Map<String, String> headers) {
try {
return url.startsWith("http") ? newCall(url, Headers.of(headers)).execute().body().string() : "";
if (!url.startsWith("http")) return "";
try (Response res = newCall(url, Headers.of(headers)).execute()) {
return res.body().string();
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
public static byte[] bytes(String url) {
if (!url.startsWith("http")) return new byte[0];
try (Response res = newCall(url).execute()) {
return res.body().bytes();
} catch (Exception e) {
e.printStackTrace();
return new byte[0];
}
}
public static Call newCall(String url) {
return client().newCall(new Request.Builder().url(url).build());
}

@ -162,8 +162,8 @@ public class Path {
fos.flush();
fos.close();
return file;
} catch (Exception ignored) {
ignored.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
return file;
}
}
@ -212,7 +212,7 @@ public class Path {
if (dir.delete()) Log.d(TAG, "Deleted:" + dir.getAbsolutePath());
}
public static File create(File file) throws Exception {
public static File create(File file) {
try {
if (file.getParentFile() != null) mkdir(file.getParentFile());
if (!file.canWrite()) file.setWritable(true);

@ -30,7 +30,7 @@ public class Connect {
}
public static JSObject success(QuickJSContext ctx, Req req, Response res) {
try {
try (res) {
JSObject jsObject = ctx.createNewJSObject();
JSObject jsHeader = ctx.createNewJSObject();
setHeader(ctx, res, jsHeader);

@ -37,9 +37,9 @@ public class Module {
private String request(String url) {
try {
Uri uri = Uri.parse(url);
byte[] data = OkHttp.bytes(url);
File file = Path.js(uri.getLastPathSegment());
boolean cache = !"127.0.0.1".equals(uri.getHost());
byte[] data = OkHttp.newCall(url).execute().body().bytes();
if (cache) new Thread(() -> Path.write(file, data)).start();
return new String(data, StandardCharsets.UTF_8);
} catch (Exception e) {

@ -9,11 +9,10 @@ public class TVCore implements Runnable {
private final Thread thread;
private final long handle;
public TVCore() {
System.loadLibrary("tvcore");
thread = new Thread(this);
thread.setName("tvcore");
public TVCore(String path) {
System.load(path);
handle = initialise();
thread = new Thread(this);
}
public TVCore listener(Listener listener) {

Loading…
Cancel
Save