影视仓 v5.0.24版本的 MD5 值为:620341689ccdc375a3b86527e140060e
以下内容为反编译后的 JsUtil.java 源代码,内容仅作参考
package com.github.tvbox.osc.util.js;
import android.text.TextUtils;
import android.util.Base64;
import androidx.media3.session.o000;
import com.androidx.i6;
import com.androidx.kv;
import com.androidx.lh0;
import com.androidx.s70;
import com.androidx.y21;
import com.androidx.yq;
import com.github.tvbox.osc.base.App;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.regex.Pattern;
import okhttp3.Response;
import org.json.JSONObject;
public class JsUtil {
private static final Pattern URLJOIN = Pattern.compile("^http.*\\.(js|txt|json|m3u)$", 10);
public static byte[] byteMerger(byte[] bArr, byte[] bArr2) {
byte[] bArr3 = new byte[bArr.length + bArr2.length];
System.arraycopy(bArr, 0, bArr3, 0, bArr.length);
System.arraycopy(bArr2, 0, bArr3, bArr.length, bArr2.length);
return bArr3;
}
public static void cleanPlayerCache() {
StringBuilder sb = new StringBuilder();
sb.append(getCachePath());
String str = File.separator;
recursiveDelete(new File(o000.OooOo0(sb, str, "thunder")));
recursiveDelete(new File(getExternalCachePath() + str + "ijkcaches"));
recursiveDelete(new File(getExternalCachePath() + str + "jpali" + str + "Downloads"));
}
public static void copyFile(File file, File file2) {
FileOutputStream fileOutputStream;
FileInputStream fileInputStream = null;
try {
FileInputStream fileInputStream2 = new FileInputStream(file);
try {
fileOutputStream = new FileOutputStream(file2);
try {
byte[] bArr = new byte[1024];
while (true) {
int read = fileInputStream2.read(bArr);
if (read > 0) {
fileOutputStream.write(bArr, 0, read);
} else {
fileInputStream2.close();
fileOutputStream.close();
return;
}
}
} catch (Throwable th) {
th = th;
fileInputStream = fileInputStream2;
fileInputStream.close();
fileOutputStream.close();
throw th;
}
} catch (Throwable th2) {
th = th2;
fileOutputStream = null;
}
} catch (Throwable th3) {
th = th3;
fileOutputStream = null;
}
}
public static String get(String str) {
return get(str, null);
}
public static String getAsOpen(String str) {
try {
InputStream open = App.OooO00o().getAssets().open(str);
byte[] bArr = new byte[open.available()];
open.read(bArr);
return new String(bArr, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
public static String getCache(String str) {
String str2;
try {
File open = open(str);
if (!open.exists()) {
str2 = "";
} else {
str2 = new String(readSimple(open));
}
} catch (Exception unused) {
}
if (TextUtils.isEmpty(str2)) {
return "";
}
JsonObject asJsonObject = ((JsonObject) new Gson().fromJson(str2, (Class<Object>) JsonObject.class)).getAsJsonObject();
if (asJsonObject.get("expires").getAsInt() > System.currentTimeMillis() / 1000) {
return asJsonObject.get("data").getAsString();
}
recursiveDelete(open(str));
return "";
}
public static byte[] getCacheByte(String str) {
try {
File open = open("B_" + str);
if (open.exists()) {
return readSimple(open);
}
} catch (Exception unused) {
}
return null;
}
public static File getCacheDir() {
return App.OooO00o().getCacheDir();
}
public static String getCachePath() {
return getCacheDir().getAbsolutePath();
}
public static File getExternalCacheDir() {
return App.OooO00o().getExternalCacheDir();
}
public static String getExternalCachePath() {
return getExternalCacheDir().getAbsolutePath();
}
public static String getFileExt(String str) {
int lastIndexOf;
if (TextUtils.isEmpty(str) || (lastIndexOf = str.lastIndexOf(46)) == -1) {
return "";
}
return str.substring(lastIndexOf).toLowerCase();
}
public static String getFileName(String str) {
if (TextUtils.isEmpty(str)) {
return "";
}
int lastIndexOf = str.lastIndexOf(File.separatorChar);
if (lastIndexOf != -1) {
return str.substring(lastIndexOf + 1);
}
return str;
}
public static String getFileNameWithoutExt(String str) {
if (TextUtils.isEmpty(str)) {
return "";
}
int lastIndexOf = str.lastIndexOf(File.separatorChar);
if (lastIndexOf != -1) {
str = str.substring(lastIndexOf + 1);
}
int indexOf = str.indexOf(46);
if (indexOf != -1) {
return str.substring(0, indexOf);
}
return str;
}
public static boolean hasExtension(String str) {
int lastIndexOf = str.lastIndexOf(".");
if (lastIndexOf > Math.max(str.lastIndexOf("/"), str.lastIndexOf("\\")) && lastIndexOf < str.length() - 1) {
return true;
}
return false;
}
public static boolean isAsFile(String str, String str2) {
try {
for (String str3 : App.OooO00o().getAssets().list(str2)) {
if (str3.equals(str.trim())) {
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static String loadModule(String str) {
try {
if (str.contains("gbk.js")) {
str = "gbk.js";
} else if (str.contains("模板.js")) {
str = "模板.js";
} else if (str.contains("cat.js")) {
str = "cat.js";
}
if (URLJOIN.matcher(str).find()) {
String cache = getCache(s70.OooO00o(str));
if (lh0.OooOOoo(cache)) {
cache = get(str);
if (!TextUtils.isEmpty(cache)) {
setCache(604800, s70.OooO00o(str), cache);
}
}
return cache;
} else if (str.startsWith("assets://")) {
return getAsOpen(str.substring(9));
} else {
if (isAsFile(str, "js/lib")) {
return getAsOpen("js/lib/".concat(str));
}
if (str.startsWith("file://")) {
return get(i6.OooO00o().OooO0O0(true) + "file/" + str.replace("file:///", "").replace("file://", ""));
} else if (str.startsWith("clan://localhost/")) {
return get(i6.OooO00o().OooO0O0(true) + "file/" + str.replace("clan://localhost/", ""));
} else if (str.startsWith("clan://")) {
String substring = str.substring(7);
int indexOf = substring.indexOf(47);
return get("http://" + substring.substring(0, indexOf) + "/file/" + substring.substring(indexOf + 1));
} else {
return str;
}
}
} catch (Exception e) {
e.printStackTrace();
return str;
}
}
public static File open(String str) {
return new File(App.OooO00o().getExternalCacheDir().getAbsolutePath() + "/qjscache_" + str + ".js");
}
public static String readFileToString(String str, String str2) {
StringBuilder sb = new StringBuilder();
BufferedReader bufferedReader = null;
try {
try {
try {
BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(new FileInputStream(str), str2));
while (true) {
try {
String readLine = bufferedReader2.readLine();
if (readLine == null) {
break;
}
sb.append(readLine);
} catch (IOException e) {
e = e;
bufferedReader = bufferedReader2;
e.printStackTrace();
if (bufferedReader != null) {
bufferedReader.close();
}
return sb.toString();
} catch (Throwable th) {
th = th;
bufferedReader = bufferedReader2;
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException unused) {
}
}
throw th;
}
}
bufferedReader2.close();
} catch (IOException unused2) {
}
} catch (IOException e2) {
e = e2;
}
return sb.toString();
} catch (Throwable th2) {
th = th2;
}
}
public static byte[] readSimple(File file) {
try {
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
byte[] bArr = new byte[bufferedInputStream.available()];
bufferedInputStream.read(bArr);
bufferedInputStream.close();
return bArr;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static void recursiveDelete(File file) {
try {
if (!file.exists()) {
return;
}
if (file.isDirectory()) {
for (File file2 : file.listFiles()) {
recursiveDelete(file2);
}
}
file.delete();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setCache(int i, String str, String str2) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("expires", (int) (i + (System.currentTimeMillis() / 1000)));
jSONObject.put("data", str2);
writeSimple(jSONObject.toString().getBytes(), open(str));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void setCacheByte(String str, byte[] bArr) {
try {
byte[] byteMerger = byteMerger("//DRPY".getBytes(), Base64.encode(bArr, 8));
writeSimple(byteMerger, open("B_" + str));
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean writeSimple(byte[] bArr, File file) {
try {
if (file.exists()) {
file.delete();
}
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
bufferedOutputStream.write(bArr);
bufferedOutputStream.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public static String get(String str, Map<String, String> map) {
Response execute;
try {
kv kvVar = new kv();
if (map != null) {
for (String str2 : map.keySet()) {
kvVar.put(str2, map.get(str2));
}
execute = ((yq) new yq(str).headers(kvVar)).execute();
} else {
execute = ((yq) new yq(str).headers("User-Agent", str.startsWith("https://gitcode.net/") ? y21.OooO0Oo() : "okhttp/3.15")).execute();
}
if (execute.isSuccessful() && execute.body() != null) {
return new String(execute.body().bytes(), "UTF-8");
}
} catch (IOException unused) {
}
return "";
}
}