Skip to content

Commit

Permalink
添加type4支持
Browse files Browse the repository at this point in the history
修复某些资源api返回剧集链接没有名称导致不显示的问题,剧集名称不存在时则显示为第几集。
修复混淆导致的磁力播放闪退的问题。
  • Loading branch information
thanatos518 committed Jul 23, 2022
1 parent e8c12d2 commit 7f8ca75
Show file tree
Hide file tree
Showing 2 changed files with 220 additions and 16 deletions.
4 changes: 3 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,6 @@
<methods>;
}

-keep class com.github.catvod.crawler.*{*;}
-keep class com.github.catvod.crawler.*{*;}
# 迅雷下载模块
-keep class com.xunlei.downloadlib.** {*;}
232 changes: 217 additions & 15 deletions app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.text.TextUtils;

import android.util.Base64;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

Expand Down Expand Up @@ -36,6 +37,7 @@
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;
Expand Down Expand Up @@ -71,6 +73,7 @@ public SourceViewModel() {

public static final ExecutorService spThreadPool = Executors.newSingleThreadExecutor();

// homeContent
public void getSort(String sourceKey) {
if (sourceKey == null) {
sortResult.postValue(null);
Expand Down Expand Up @@ -177,11 +180,59 @@ public void onError(Response<String> response) {
sortResult.postValue(null);
}
});
}else if (type == 4) {
OkGo.<String>get(sourceBean.getApi())
.tag(sourceBean.getKey() + "_sort")
.params("filter", "true")
.execute(new AbsCallback<String>() {
@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<String> 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<Movie.Video> videos) {
sortXml.videoList = videos;
sortResult.postValue(sortXml);
}
});
}
} else {
sortResult.postValue(sortXml);
}
} else {
sortResult.postValue(null);
}
}

@Override
public void onError(Response<String> 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();
Expand Down Expand Up @@ -231,6 +282,47 @@ public void onError(Response<String> response) {
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.<String>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<String>() {
@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<String> response) {
String json = response.body();
LOG.i(json);
json(listResult, json, homeSourceBean.getKey());
}

@Override
public void onError(Response<String> response) {
super.onError(response);
listResult.postValue(null);
}
});
} else {
listResult.postValue(null);
}
Expand All @@ -239,9 +331,10 @@ public void onError(Response<String> response) {
interface HomeRecCallback {
void done(List<Movie.Video> videos);
}

// homeVideoContent
void getHomeRecList(SourceBean sourceBean, ArrayList<String> ids, HomeRecCallback callback) {
if (sourceBean.getType() == 3) {
int type = sourceBean.getType();
if (type == 3) {
Runnable waitResponse = new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -281,7 +374,7 @@ public String call() throws Exception {
}
};
spThreadPool.execute(waitResponse);
} else if (sourceBean.getType() == 0 || sourceBean.getType() == 1) {
} else if (type == 0 || type == 1) {
OkGo.<String>get(sourceBean.getApi())
.tag("detail")
.params("ac", sourceBean.getType() == 0 ? "videolist" : "detail")
Expand Down Expand Up @@ -324,7 +417,7 @@ public void onError(Response<String> response) {
callback.done(null);
}
}

// detailContent
public void getDetail(String sourceKey, String id) {
SourceBean sourceBean = ApiConfig.get().getSource(sourceKey);
int type = sourceBean.getType();
Expand All @@ -342,7 +435,7 @@ public void run() {
}
}
});
} else if (type == 0 || type == 1) {
} else if (type == 0 || type == 1|| type == 4) {
OkGo.<String>get(sourceBean.getApi())
.tag("detail")
.params("ac", type == 0 ? "videolist" : "detail")
Expand All @@ -365,6 +458,7 @@ public void onSuccess(Response<String> response) {
xml(detailResult, xml, sourceBean.getKey());
} else {
String json = response.body();
LOG.i(json);
json(detailResult, json, sourceBean.getKey());
}
}
Expand All @@ -379,7 +473,7 @@ public void onError(Response<String> response) {
detailResult.postValue(null);
}
}

// searchContent
public void getSearch(String sourceKey, String wd) {
SourceBean sourceBean = ApiConfig.get().getSource(sourceKey);
int type = sourceBean.getType();
Expand Down Expand Up @@ -423,11 +517,41 @@ public void onError(Response<String> response) {
EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_SEARCH_RESULT, null));
}
});
}else if (type == 4) {
OkGo.<String>get(sourceBean.getApi())
.params("wd", wd)
.params("ac" ,"detail")
.params("quick" ,"false")
.tag("search")
.execute(new AbsCallback<String>() {
@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<String> response) {
String json = response.body();
LOG.i(json);
json(searchResult, json, sourceBean.getKey());
}

@Override
public void onError(Response<String> 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();
Expand Down Expand Up @@ -471,11 +595,41 @@ public void onError(Response<String> response) {
EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_QUICK_SEARCH_RESULT, null));
}
});
}else if (type == 4) {
OkGo.<String>get(sourceBean.getApi())
.params("wd", wd)
.params("ac" ,"detail")
.params("quick" ,"true")
.tag("search")
.execute(new AbsCallback<String>() {
@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<String> response) {
String json = response.body();
LOG.i(json);
json(quickSearchResult, json, sourceBean.getKey());
}

@Override
public void onError(Response<String> 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();
Expand Down Expand Up @@ -517,8 +671,46 @@ public void run() {
th.printStackTrace();
playResult.postValue(null);
}
} else {
quickSearchResult.postValue(null);
} else if (type == 4) {
OkGo.<String>get(sourceBean.getApi())
.params("play", url)
.params("flag" ,playFlag)
.tag("play")
.execute(new AbsCallback<String>() {
@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<String> 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<String> response) {
super.onError(response);
playResult.postValue(null);
}
});
}else {
playResult.postValue(null);
}
}

Expand Down Expand Up @@ -604,13 +796,23 @@ private void absXml(AbsXml data, String sourceKey) {
str = new String[]{urlInfo.urls};
}
List<Movie.Video.UrlBean.UrlInfo.InfoBean> 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;
Expand Down

0 comments on commit 7f8ca75

Please sign in to comment.