diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 1902c500..0b507db0 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -198,4 +198,6 @@ ; } --keep class com.github.catvod.crawler.*{*;} \ No newline at end of file +-keep class com.github.catvod.crawler.*{*;} +# 迅雷下载模块 +-keep class com.xunlei.downloadlib.** {*;} \ No newline at end of file diff --git a/app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java b/app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java index d59c8d53..6fad77dc 100644 --- a/app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java +++ b/app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java @@ -2,6 +2,7 @@ package com.github.tvbox.osc.viewmodel; import android.text.TextUtils; +import android.util.Base64; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; @@ -36,6 +37,7 @@ import com.thoughtworks.xstream.io.xml.DomDriver; import org.greenrobot.eventbus.EventBus; import org.json.JSONObject; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -71,6 +73,7 @@ public class SourceViewModel extends ViewModel { public static final ExecutorService spThreadPool = Executors.newSingleThreadExecutor(); + // homeContent public void getSort(String sourceKey) { if (sourceKey == null) { sortResult.postValue(null); @@ -177,11 +180,59 @@ public class SourceViewModel extends ViewModel { sortResult.postValue(null); } }); + }else if (type == 4) { + OkGo.get(sourceBean.getApi()) + .tag(sourceBean.getKey() + "_sort") + .params("filter", "true") + .execute(new AbsCallback() { + @Override + public String convertResponse(okhttp3.Response response) throws Throwable { + if (response.body() != null) { + return response.body().string(); + } else { + throw new IllegalStateException("网络请求错误"); + } + } + + @Override + public void onSuccess(Response response) { + String sortJson = response.body(); + LOG.i(sortJson); + if (sortJson != null) { + AbsSortXml sortXml = sortJson(sortResult, sortJson); + if (sortXml != null && Hawk.get(HawkConfig.HOME_REC, 0) == 1) { + AbsXml absXml = json(null, sortJson, sourceBean.getKey()); + if (absXml != null && absXml.movie != null && absXml.movie.videoList != null && absXml.movie.videoList.size() > 0) { + sortXml.videoList = absXml.movie.videoList; + sortResult.postValue(sortXml); + } else { + getHomeRecList(sourceBean, null, new HomeRecCallback() { + @Override + public void done(List videos) { + sortXml.videoList = videos; + sortResult.postValue(sortXml); + } + }); + } + } else { + sortResult.postValue(sortXml); + } + } else { + sortResult.postValue(null); + } + } + + @Override + public void onError(Response response) { + super.onError(response); + sortResult.postValue(null); + } + }); } else { sortResult.postValue(null); } } - + // categoryContent public void getList(MovieSort.SortData sortData, int page) { SourceBean homeSourceBean = ApiConfig.get().getHomeSourceBean(); int type = homeSourceBean.getType(); @@ -231,6 +282,47 @@ public class SourceViewModel extends ViewModel { listResult.postValue(null); } }); + }else if (type == 4) { + String ext=""; + if (sortData.filterSelect != null && sortData.filterSelect.size() > 0) { + try { + LOG.i(new JSONObject(sortData.filterSelect).toString()); + ext = Base64.encodeToString(new JSONObject(sortData.filterSelect).toString().getBytes("UTF-8"), Base64.DEFAULT | Base64.NO_WRAP); + LOG.i(ext); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + OkGo.get(homeSourceBean.getApi()) + .tag(homeSourceBean.getApi()) + .params("ac", "detail") + .params("filter", "true") + .params("t", sortData.id) + .params("pg", page) + .params("ext", ext) + .execute(new AbsCallback() { + @Override + public String convertResponse(okhttp3.Response response) throws Throwable { + if (response.body() != null) { + return response.body().string(); + } else { + throw new IllegalStateException("网络请求错误"); + } + } + + @Override + public void onSuccess(Response response) { + String json = response.body(); + LOG.i(json); + json(listResult, json, homeSourceBean.getKey()); + } + + @Override + public void onError(Response response) { + super.onError(response); + listResult.postValue(null); + } + }); } else { listResult.postValue(null); } @@ -239,9 +331,10 @@ public class SourceViewModel extends ViewModel { interface HomeRecCallback { void done(List videos); } - +// homeVideoContent void getHomeRecList(SourceBean sourceBean, ArrayList ids, HomeRecCallback callback) { - if (sourceBean.getType() == 3) { + int type = sourceBean.getType(); + if (type == 3) { Runnable waitResponse = new Runnable() { @Override public void run() { @@ -281,7 +374,7 @@ public class SourceViewModel extends ViewModel { } }; spThreadPool.execute(waitResponse); - } else if (sourceBean.getType() == 0 || sourceBean.getType() == 1) { + } else if (type == 0 || type == 1) { OkGo.get(sourceBean.getApi()) .tag("detail") .params("ac", sourceBean.getType() == 0 ? "videolist" : "detail") @@ -324,7 +417,7 @@ public class SourceViewModel extends ViewModel { callback.done(null); } } - + // detailContent public void getDetail(String sourceKey, String id) { SourceBean sourceBean = ApiConfig.get().getSource(sourceKey); int type = sourceBean.getType(); @@ -342,7 +435,7 @@ public class SourceViewModel extends ViewModel { } } }); - } else if (type == 0 || type == 1) { + } else if (type == 0 || type == 1|| type == 4) { OkGo.get(sourceBean.getApi()) .tag("detail") .params("ac", type == 0 ? "videolist" : "detail") @@ -365,6 +458,7 @@ public class SourceViewModel extends ViewModel { xml(detailResult, xml, sourceBean.getKey()); } else { String json = response.body(); + LOG.i(json); json(detailResult, json, sourceBean.getKey()); } } @@ -379,7 +473,7 @@ public class SourceViewModel extends ViewModel { detailResult.postValue(null); } } - + // searchContent public void getSearch(String sourceKey, String wd) { SourceBean sourceBean = ApiConfig.get().getSource(sourceKey); int type = sourceBean.getType(); @@ -423,11 +517,41 @@ public class SourceViewModel extends ViewModel { EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_SEARCH_RESULT, null)); } }); + }else if (type == 4) { + OkGo.get(sourceBean.getApi()) + .params("wd", wd) + .params("ac" ,"detail") + .params("quick" ,"false") + .tag("search") + .execute(new AbsCallback() { + @Override + public String convertResponse(okhttp3.Response response) throws Throwable { + if (response.body() != null) { + return response.body().string(); + } else { + throw new IllegalStateException("网络请求错误"); + } + } + + @Override + public void onSuccess(Response response) { + String json = response.body(); + LOG.i(json); + json(searchResult, json, sourceBean.getKey()); + } + + @Override + public void onError(Response response) { + super.onError(response); + // searchResult.postValue(null); + EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_SEARCH_RESULT, null)); + } + }); } else { searchResult.postValue(null); } } - + // searchContent public void getQuickSearch(String sourceKey, String wd) { SourceBean sourceBean = ApiConfig.get().getSource(sourceKey); int type = sourceBean.getType(); @@ -471,11 +595,41 @@ public class SourceViewModel extends ViewModel { EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_QUICK_SEARCH_RESULT, null)); } }); + }else if (type == 4) { + OkGo.get(sourceBean.getApi()) + .params("wd", wd) + .params("ac" ,"detail") + .params("quick" ,"true") + .tag("search") + .execute(new AbsCallback() { + @Override + public String convertResponse(okhttp3.Response response) throws Throwable { + if (response.body() != null) { + return response.body().string(); + } else { + throw new IllegalStateException("网络请求错误"); + } + } + + @Override + public void onSuccess(Response response) { + String json = response.body(); + LOG.i(json); + json(quickSearchResult, json, sourceBean.getKey()); + } + + @Override + public void onError(Response response) { + super.onError(response); + // searchResult.postValue(null); + EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_SEARCH_RESULT, null)); + } + }); } else { quickSearchResult.postValue(null); } } - + // playerContent public void getPlay(String sourceKey, String playFlag, String progressKey, String url) { SourceBean sourceBean = ApiConfig.get().getSource(sourceKey); int type = sourceBean.getType(); @@ -517,8 +671,46 @@ public class SourceViewModel extends ViewModel { th.printStackTrace(); playResult.postValue(null); } - } else { - quickSearchResult.postValue(null); + } else if (type == 4) { + OkGo.get(sourceBean.getApi()) + .params("play", url) + .params("flag" ,playFlag) + .tag("play") + .execute(new AbsCallback() { + @Override + public String convertResponse(okhttp3.Response response) throws Throwable { + if (response.body() != null) { + return response.body().string(); + } else { + throw new IllegalStateException("网络请求错误"); + } + } + + @Override + public void onSuccess(Response response) { + String json = response.body(); + LOG.i(json); + try { + JSONObject result = new JSONObject(json); + result.put("key", url); + result.put("proKey", progressKey); + if (!result.has("flag")) + result.put("flag", playFlag); + playResult.postValue(result); + } catch (Throwable th) { + th.printStackTrace(); + playResult.postValue(null); + } + } + + @Override + public void onError(Response response) { + super.onError(response); + playResult.postValue(null); + } + }); + }else { + playResult.postValue(null); } } @@ -604,13 +796,23 @@ public class SourceViewModel extends ViewModel { str = new String[]{urlInfo.urls}; } List infoBeanList = new ArrayList<>(); +// for (String s : str) { +// if (s.contains("$")) { +// String[] ss = s.split("\\$"); +// if (ss.length >= 2) { +// infoBeanList.add(new Movie.Video.UrlBean.UrlInfo.InfoBean(ss[0], ss[1])); +// } +// //infoBeanList.add(new Movie.Video.UrlBean.UrlInfo.InfoBean(s.substring(0, s.indexOf("$")), s.substring(s.indexOf("$") + 1))); +// } +// } for (String s : str) { - if (s.contains("$")) { - String[] ss = s.split("\\$"); - if (ss.length >= 2) { + String[] ss = s.split("\\$"); + if (ss.length > 0) { + if (ss.length == 2) { infoBeanList.add(new Movie.Video.UrlBean.UrlInfo.InfoBean(ss[0], ss[1])); + } else if (ss.length == 1) { + infoBeanList.add(new Movie.Video.UrlBean.UrlInfo.InfoBean((infoBeanList.size() + 1) + "", ss[0])); } - //infoBeanList.add(new Movie.Video.UrlBean.UrlInfo.InfoBean(s.substring(0, s.indexOf("$")), s.substring(s.indexOf("$") + 1))); } } urlInfo.beanList = infoBeanList;