Merge pull request #100 from watson1982/main

push://地址转推送(by waston & by idcard)
pull/101/head
q215613905 3 years ago committed by GitHub
commit 41d59c355d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      app/src/main/java/com/github/tvbox/osc/server/RemoteServer.java
  2. 25
      app/src/main/java/com/github/tvbox/osc/ui/activity/DetailActivity.java
  3. 151
      app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java

@ -4,9 +4,11 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Environment;
import android.util.Base64;
import com.github.tvbox.osc.R;
import com.github.tvbox.osc.api.ApiConfig;
import com.github.tvbox.osc.event.RefreshEvent;
import com.github.tvbox.osc.event.ServerEvent;
import com.github.tvbox.osc.util.FileUtils;
import com.github.tvbox.osc.util.OkGoHelper;
@ -22,10 +24,13 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@ -148,7 +153,20 @@ public class RemoteServer extends NanoHTTPD {
rs = new byte[0];
}
return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, "application/dns-message", new ByteArrayInputStream(rs), rs.length);
}
} else if (fileName.startsWith("/push/")) {
String url = fileName.substring(6);
if (url.startsWith("b64:")) {
try {
url = new String(Base64.decode(url.substring(4), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
url = URLDecoder.decode(url);
}
EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_PUSH_URL, url));
return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_PLAINTEXT, "ok");
}
} else if (session.getMethod() == Method.POST) {
Map<String, String> files = new HashMap<String, String>();
try {

@ -126,6 +126,7 @@ public class DetailActivity extends BaseActivity {
private SeriesAdapter seriesAdapter;
public String vodId;
public String sourceKey;
public String firstsourceKey;
boolean seriesSelect = false;
private View seriesFlagFocus = null;
private boolean isReverse;
@ -459,7 +460,8 @@ public class DetailActivity extends BaseActivity {
setTextShow(tvPlayUrl, "播放地址:", vodInfo.seriesMap.get(vodInfo.playFlag).get(vodInfo.playIndex).url);
Bundle bundle = new Bundle();
//保存历史
insertVod(sourceKey, vodInfo);
insertVod(firstsourceKey, vodInfo);
// insertVod(sourceKey, vodInfo);
bundle.putString("sourceKey", sourceKey);
// bundle.putSerializable("VodInfo", vodInfo);
App.getInstance().setVodInfo(vodInfo);
@ -600,16 +602,26 @@ public class DetailActivity extends BaseActivity {
if (absXml != null && absXml.movie != null && absXml.movie.videoList != null && absXml.movie.videoList.size() > 0) {
showSuccess();
mVideo = absXml.movie.videoList.get(0);
mVideo.id = vodId;
if (TextUtils.isEmpty(mVideo.name))
mVideo.name = "片名被谁吃了";
vodInfo = new VodInfo();
vodInfo.setVideo(mVideo);
vodInfo.sourceKey = mVideo.sourceKey;
sourceKey = mVideo.sourceKey;
tvName.setText(mVideo.name);
setTextShow(tvSite, "来源:", ApiConfig.get().getSource(mVideo.sourceKey).getName());
setTextShow(tvSite, "来源:", ApiConfig.get().getSource(firstsourceKey).getName());
setTextShow(tvYear, "年份:", mVideo.year == 0 ? "" : String.valueOf(mVideo.year));
setTextShow(tvArea, "地区:", mVideo.area);
setTextShow(tvLang, "语言:", mVideo.lang);
setTextShow(tvType, "类型:", mVideo.type);
if (!firstsourceKey.equals(sourceKey)) {
setTextShow(tvType, "类型:", "[" + ApiConfig.get().getSource(sourceKey).getName() + "] 解析");
} else {
setTextShow(tvType, "类型:", mVideo.type);
}
setTextShow(tvActor, "演员:", mVideo.actor);
setTextShow(tvDirector, "导演:", mVideo.director);
setTextShow(tvDes, "内容简介:", removeHtmlTag(mVideo.des));
@ -711,6 +723,7 @@ public class DetailActivity extends BaseActivity {
if (vid != null) {
vodId = vid;
sourceKey = key;
firstsourceKey = key;
showLoading();
sourceViewModel.getDetail(sourceKey, vodId);
boolean isVodCollect = RoomDataManger.isVodCollect(sourceKey, vodId);
@ -737,11 +750,13 @@ public class DetailActivity extends BaseActivity {
mGridView.setSelection(index);
vodInfo.playIndex = index;
//保存历史
insertVod(sourceKey, vodInfo);
insertVod(firstsourceKey, vodInfo);
// insertVod(sourceKey, vodInfo);
} else if (event.obj instanceof JSONObject) {
vodInfo.playerCfg = ((JSONObject) event.obj).toString();
//保存历史
insertVod(sourceKey, vodInfo);
insertVod(firstsourceKey, vodInfo);
// insertVod(sourceKey, vodInfo);
}
}

@ -38,12 +38,14 @@ import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -427,7 +429,23 @@ public class SourceViewModel extends ViewModel {
}
}
// detailContent
public void getDetail(String sourceKey, String id) {
public void getDetail(String sourceKey, String urlid) {
if (urlid.startsWith("push://") && ApiConfig.get().getSource("push_agent") != null) {
String pushUrl = urlid.substring(7);
if (pushUrl.startsWith("b64:")) {
try {
pushUrl = new String(Base64.decode(pushUrl.substring(4), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
pushUrl = URLDecoder.decode(pushUrl);
}
sourceKey = "push_agent";
urlid = pushUrl;
}
String id = urlid;
SourceBean sourceBean = ApiConfig.get().getSource(sourceKey);
int type = sourceBean.getType();
if (type == 3) {
@ -858,6 +876,135 @@ public class SourceViewModel extends ViewModel {
}
}
}
private AbsXml checkPush(AbsXml data) {
if (data.movie != null && data.movie.videoList != null && data.movie.videoList.size() > 0) {
Movie.Video video = data.movie.videoList.get(0);
if (video != null && video.urlBean != null && video.urlBean.infoList != null && video.urlBean.infoList.size() > 0) {
for (int i = 0; i < video.urlBean.infoList.size(); i++) {
Movie.Video.UrlBean.UrlInfo urlinfo = video.urlBean.infoList.get(i);
if (urlinfo != null && urlinfo.beanList != null && !urlinfo.beanList.isEmpty()) {
for (Movie.Video.UrlBean.UrlInfo.InfoBean infoBean : urlinfo.beanList) {
if (infoBean.url.startsWith("push://")) {
String pushUrl = infoBean.url.substring(7);
if (pushUrl.startsWith("b64:")) {
try {
pushUrl = new String(Base64.decode(pushUrl.substring(4), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
pushUrl = URLDecoder.decode(pushUrl);
}
final AbsXml[] resData = {null};
final CountDownLatch countDownLatch = new CountDownLatch(1);
ExecutorService threadPool = Executors.newSingleThreadExecutor();
String finalPushUrl = pushUrl;
threadPool.execute(new Runnable() {
@Override
public void run() {
SourceBean sb = ApiConfig.get().getSource("push_agent");
if (sb == null) {
countDownLatch.countDown();
return;
}
if (sb.getType() == 4) {
OkGo.<String>get(sb.getApi())
.tag("detail")
.params("ac","detail")
.params("ids", finalPushUrl)
.execute(new AbsCallback<String>() {
@Override
public String convertResponse(okhttp3.Response response) throws Throwable {
if (response.body() != null) {
return response.body().string();
} else {
return "";
}
}
@Override
public void onSuccess(Response<String> response) {
String res = response.body();
if (!TextUtils.isEmpty(res)) {
try {
AbsJson absJson = new Gson().fromJson(res, new TypeToken<AbsJson>() {
}.getType());
resData[0] = absJson.toAbsXml();
absXml(resData[0], sb.getKey());
} catch (Exception e) {
e.printStackTrace();
}
}
countDownLatch.countDown();
}
@Override
public void onError(Response<String> response) {
super.onError(response);
countDownLatch.countDown();
}
});
} else {
try {
Spider sp = ApiConfig.get().getCSP(sb);
// ApiConfig.get().setPlayJarKey(sb.getJar());
List<String> ids = new ArrayList<>();
ids.add(finalPushUrl);
String res = sp.detailContent(ids);
if (!TextUtils.isEmpty(res)) {
try {
AbsJson absJson = new Gson().fromJson(res, new TypeToken<AbsJson>() {}.getType());
resData[0] = absJson.toAbsXml();
absXml(resData[0], sb.getKey());
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Throwable th) {
th.printStackTrace();
}
countDownLatch.countDown();
}
}
});
try {
countDownLatch.await(15, TimeUnit.SECONDS);
threadPool.shutdown();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (resData[0] != null) {
AbsXml res = resData[0];
if (res.movie != null && res.movie.videoList != null && res.movie.videoList.size() > 0) {
Movie.Video resVideo = res.movie.videoList.get(0);
if (resVideo != null && resVideo.urlBean != null && resVideo.urlBean.infoList != null && resVideo.urlBean.infoList.size() > 0) {
if (urlinfo.beanList.size() == 1) {
video.urlBean.infoList.remove(i);
} else {
urlinfo.beanList.remove(infoBean);
}
for (Movie.Video.UrlBean.UrlInfo resUrlinfo : resVideo.urlBean.infoList) {
if (resUrlinfo != null && resUrlinfo.beanList != null && !resUrlinfo.beanList.isEmpty()) {
video.urlBean.infoList.add(resUrlinfo);
}
}
video.sourceKey = "push_agent";
return data;
}
}
}
infoBean.name = "解析失败 >>> " + infoBean.name;
}
}
}
}
}
}
return data;
}
public void checkThunder(AbsXml data, int index) {
boolean thunderParse = false;
@ -943,6 +1090,7 @@ public class SourceViewModel extends ViewModel {
EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_QUICK_SEARCH_RESULT, data));
} else if (result != null) {
if (result == detailResult) {
data = checkPush(data);
checkThunder(data,0);
}else {
result.postValue(data);
@ -990,6 +1138,7 @@ public class SourceViewModel extends ViewModel {
EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_QUICK_SEARCH_RESULT, data));
} else if (result != null) {
if (result == detailResult) {
data = checkPush(data);
checkThunder(data,0);
}else {
result.postValue(data);

Loading…
Cancel
Save