|
|
|
|
@ -24,7 +24,9 @@ import com.github.tvbox.osc.util.DefaultConfig; |
|
|
|
|
import com.github.tvbox.osc.util.FileUtils; |
|
|
|
|
import com.github.tvbox.osc.util.HawkConfig; |
|
|
|
|
import com.github.tvbox.osc.util.LOG; |
|
|
|
|
import com.github.tvbox.osc.util.MD5; |
|
|
|
|
import com.github.tvbox.osc.util.thunder.Thunder; |
|
|
|
|
import com.github.tvbox.osc.util.urlhttp.OkHttpUtil; |
|
|
|
|
import com.google.gson.Gson; |
|
|
|
|
import com.google.gson.JsonArray; |
|
|
|
|
import com.google.gson.JsonElement; |
|
|
|
|
@ -54,6 +56,7 @@ import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.concurrent.Callable; |
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
@ -76,6 +79,7 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
public MutableLiveData<AbsXml> quickSearchResult; |
|
|
|
|
public MutableLiveData<AbsXml> detailResult; |
|
|
|
|
public MutableLiveData<JSONObject> playResult; |
|
|
|
|
public Gson gson; |
|
|
|
|
|
|
|
|
|
public SourceViewModel() { |
|
|
|
|
sortResult = new MutableLiveData<>(); |
|
|
|
|
@ -84,6 +88,7 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
quickSearchResult = new MutableLiveData<>(); |
|
|
|
|
detailResult = new MutableLiveData<>(); |
|
|
|
|
playResult = new MutableLiveData<>(); |
|
|
|
|
gson=new Gson(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static final ExecutorService spThreadPool = Executors.newSingleThreadExecutor(); |
|
|
|
|
@ -91,7 +96,7 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
//homeContent缓存,最多存储10个sourceKey的AbsSortXml对象
|
|
|
|
|
private static final Map<String, AbsSortXml> sortCache = new LinkedHashMap<String, AbsSortXml>(10, 0.75f, true) { |
|
|
|
|
@Override |
|
|
|
|
protected boolean removeEldestEntry(Map.Entry<String, AbsSortXml> eldest) { |
|
|
|
|
protected boolean removeEldestEntry(Entry<String, AbsSortXml> eldest) { |
|
|
|
|
return size() > 10; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
@ -375,7 +380,6 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
String ext= ""; |
|
|
|
|
String extend=homeSourceBean.getExt(); |
|
|
|
|
extend=getFixUrl(extend); |
|
|
|
|
if(URLEncoder.encode(extend).length()>1000)extend=""; |
|
|
|
|
if (sortData.filterSelect != null && sortData.filterSelect.size() > 0) { |
|
|
|
|
try { |
|
|
|
|
String selectExt = new JSONObject(sortData.filterSelect).toString(); |
|
|
|
|
@ -569,7 +573,6 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
} else if (type == 0 || type == 1|| type == 4) { |
|
|
|
|
String extend=sourceBean.getExt(); |
|
|
|
|
extend=getFixUrl(extend); |
|
|
|
|
if(URLEncoder.encode(extend).length()>1000)extend=""; |
|
|
|
|
OkGo.<String>get(sourceBean.getApi()) |
|
|
|
|
.tag("detail") |
|
|
|
|
.params("ac", type == 0 ? "videolist" : "detail") |
|
|
|
|
@ -661,7 +664,6 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
}else if (type == 4) { |
|
|
|
|
String extend=sourceBean.getExt(); |
|
|
|
|
extend=getFixUrl(extend); |
|
|
|
|
if(URLEncoder.encode(extend).length()>1000)extend=""; |
|
|
|
|
OkGo.<String>get(sourceBean.getApi()) |
|
|
|
|
.params("wd", wd) |
|
|
|
|
.params("ac" ,"detail") |
|
|
|
|
@ -743,7 +745,6 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
}else if (type == 4) { |
|
|
|
|
String extend=sourceBean.getExt(); |
|
|
|
|
extend=getFixUrl(extend); |
|
|
|
|
if(URLEncoder.encode(extend).length()>1000)extend=""; |
|
|
|
|
OkGo.<String>get(sourceBean.getApi()) |
|
|
|
|
.params("wd", wd) |
|
|
|
|
.params("ac" ,"detail") |
|
|
|
|
@ -854,7 +855,6 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
} else if (type == 4) { |
|
|
|
|
String extend=sourceBean.getExt(); |
|
|
|
|
extend=getFixUrl(extend); |
|
|
|
|
if(URLEncoder.encode(extend).length()>1000)extend=""; |
|
|
|
|
OkGo.<String>get(sourceBean.getApi()) |
|
|
|
|
.params("play", url) |
|
|
|
|
.params("flag" ,playFlag) |
|
|
|
|
@ -899,13 +899,57 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String getFixUrl(String content){ |
|
|
|
|
if (content.startsWith("http://127.0.0.1")) { |
|
|
|
|
String path = content.replaceAll("^http.+/file/", FileUtils.getRootPath()+"/"); |
|
|
|
|
path = path.replaceAll("localhost/", "/"); |
|
|
|
|
content = FileUtils.readFileToString(path,"UTF-8"); |
|
|
|
|
private static final ConcurrentHashMap<String, String> extendCache = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
|
private String getFixUrl(final String extend) { |
|
|
|
|
if(!extend.startsWith("http"))return extend; |
|
|
|
|
final String key = MD5.string2MD5(extend); |
|
|
|
|
if (extendCache.containsKey(key)) { |
|
|
|
|
LOG.i("echo-getFixUrl Cache"); |
|
|
|
|
return extendCache.get(key); |
|
|
|
|
} |
|
|
|
|
LOG.i("echo-getFixUrl load"); |
|
|
|
|
Future<String> future = spThreadPool.submit(new Callable<String>() { |
|
|
|
|
@Override |
|
|
|
|
public String call() { |
|
|
|
|
String result = extend; |
|
|
|
|
if (extend.startsWith("http://127.0.0.1")) { |
|
|
|
|
String path = extend.replaceAll("^http.+/file/", FileUtils.getRootPath() + "/"); |
|
|
|
|
path = path.replaceAll("localhost/", "/"); |
|
|
|
|
result = FileUtils.readFileToString(path, "UTF-8"); |
|
|
|
|
result = tryMinifyJson(result); |
|
|
|
|
extendCache.putIfAbsent(key, result); |
|
|
|
|
} else if (extend.startsWith("http")) { |
|
|
|
|
result = OkHttpUtil.string(extend, null); |
|
|
|
|
if (!result.isEmpty()) { |
|
|
|
|
result = tryMinifyJson(result); |
|
|
|
|
extendCache.putIfAbsent(key, result); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
return future.get(5, TimeUnit.SECONDS); |
|
|
|
|
} catch (TimeoutException te) { |
|
|
|
|
te.printStackTrace(); |
|
|
|
|
future.cancel(true); |
|
|
|
|
return extend; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
return extend; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String tryMinifyJson(String raw) { |
|
|
|
|
try { |
|
|
|
|
raw = raw.trim(); |
|
|
|
|
JsonElement jsonElement = JsonParser.parseString(raw); |
|
|
|
|
return gson.toJson(jsonElement); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
return raw; |
|
|
|
|
} |
|
|
|
|
return content; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private MovieSort.SortFilter getSortFilter(JsonObject obj) { |
|
|
|
|
@ -929,7 +973,7 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
private AbsSortXml sortJson(MutableLiveData<AbsSortXml> result, String json) { |
|
|
|
|
try { |
|
|
|
|
JsonObject obj = JsonParser.parseString(json).getAsJsonObject(); |
|
|
|
|
AbsSortJson sortJson = new Gson().fromJson(obj, new TypeToken<AbsSortJson>() { |
|
|
|
|
AbsSortJson sortJson = gson.fromJson(obj, new TypeToken<AbsSortJson>() { |
|
|
|
|
}.getType()); |
|
|
|
|
AbsSortXml data = sortJson.toAbsSortXml(); |
|
|
|
|
try { |
|
|
|
|
@ -1073,7 +1117,7 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
String res = response.body(); |
|
|
|
|
if (!TextUtils.isEmpty(res)) { |
|
|
|
|
try { |
|
|
|
|
AbsJson absJson = new Gson().fromJson(res, new TypeToken<AbsJson>() { |
|
|
|
|
AbsJson absJson = gson.fromJson(res, new TypeToken<AbsJson>() { |
|
|
|
|
}.getType()); |
|
|
|
|
resData[0] = absJson.toAbsXml(); |
|
|
|
|
absXml(resData[0], sb.getKey()); |
|
|
|
|
@ -1099,7 +1143,7 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
String res = sp.detailContent(ids); |
|
|
|
|
if (!TextUtils.isEmpty(res)) { |
|
|
|
|
try { |
|
|
|
|
AbsJson absJson = new Gson().fromJson(res, new TypeToken<AbsJson>() {}.getType()); |
|
|
|
|
AbsJson absJson = gson.fromJson(res, new TypeToken<AbsJson>() {}.getType()); |
|
|
|
|
resData[0] = absJson.toAbsXml(); |
|
|
|
|
absXml(resData[0], sb.getKey()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
@ -1274,7 +1318,7 @@ public class SourceViewModel extends ViewModel { |
|
|
|
|
// "\t\t\"vod_play_url\": \"0$magnet:?xt=urn:btih:e398ca38fb9d64897ed19b4d16efeea11af4d03b\"\n" +
|
|
|
|
|
// "\t}]\n" +
|
|
|
|
|
// "}";
|
|
|
|
|
AbsJson absJson = new Gson().fromJson(json, new TypeToken<AbsJson>() { |
|
|
|
|
AbsJson absJson = gson.fromJson(json, new TypeToken<AbsJson>() { |
|
|
|
|
}.getType()); |
|
|
|
|
AbsXml data = absJson.toAbsXml(); |
|
|
|
|
absXml(data, sourceKey); |
|
|
|
|
|