From bcc47f1e8cc768f14bbb6d0e3f8ac846625ee034 Mon Sep 17 00:00:00 2001 From: watson1982 <112817572+watson1982@users.noreply.github.com> Date: Mon, 14 Aug 2023 15:14:50 +0800 Subject: [PATCH 1/5] get-push --- .../github/tvbox/osc/server/RemoteServer.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/tvbox/osc/server/RemoteServer.java b/app/src/main/java/com/github/tvbox/osc/server/RemoteServer.java index 63065c08..566c2554 100644 --- a/app/src/main/java/com/github/tvbox/osc/server/RemoteServer.java +++ b/app/src/main/java/com/github/tvbox/osc/server/RemoteServer.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 files = new HashMap(); try { From 39293e07022d9e064c15a933ee321af6560c889a Mon Sep 17 00:00:00 2001 From: watson1982 <112817572+watson1982@users.noreply.github.com> Date: Thu, 17 Aug 2023 15:03:16 +0800 Subject: [PATCH 2/5] DetailActivity.java+push --- .../tvbox/osc/ui/activity/DetailActivity.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/tvbox/osc/ui/activity/DetailActivity.java b/app/src/main/java/com/github/tvbox/osc/ui/activity/DetailActivity.java index 36098a37..26128711 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/activity/DetailActivity.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/activity/DetailActivity.java @@ -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; @@ -603,13 +604,18 @@ public class DetailActivity extends BaseActivity { 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 +717,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 +744,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); } } From c2561a10ab89993003ac5ec915e90ae0a034994a Mon Sep 17 00:00:00 2001 From: watson1982 <112817572+watson1982@users.noreply.github.com> Date: Thu, 17 Aug 2023 15:04:38 +0800 Subject: [PATCH 3/5] SourceViewModel.java+push --- .../tvbox/osc/viewmodel/SourceViewModel.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 90fcef2d..6f048b62 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 @@ -38,6 +38,7 @@ 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; @@ -427,7 +428,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) { From eaa3ddc9dda105ead9ec527df891b4ac5d7b7407 Mon Sep 17 00:00:00 2001 From: watson1982 <112817572+watson1982@users.noreply.github.com> Date: Thu, 17 Aug 2023 16:27:25 +0800 Subject: [PATCH 4/5] DetailActivity.java+history --- .../com/github/tvbox/osc/ui/activity/DetailActivity.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/tvbox/osc/ui/activity/DetailActivity.java b/app/src/main/java/com/github/tvbox/osc/ui/activity/DetailActivity.java index 26128711..f7a95d34 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/activity/DetailActivity.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/activity/DetailActivity.java @@ -460,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); @@ -601,6 +602,11 @@ 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; From 2b5166d91a88d63ff11920993d38cda0346e2001 Mon Sep 17 00:00:00 2001 From: watson1982 <112817572+watson1982@users.noreply.github.com> Date: Thu, 17 Aug 2023 21:45:44 +0800 Subject: [PATCH 5/5] SourceViewModel.java+secondary page push --- .../tvbox/osc/viewmodel/SourceViewModel.java | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) 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 6f048b62..bbfb5a3d 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 @@ -45,6 +45,7 @@ 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; @@ -875,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.get(sb.getApi()) + .tag("detail") + .params("ac","detail") + .params("ids", finalPushUrl) + .execute(new AbsCallback() { + @Override + public String convertResponse(okhttp3.Response response) throws Throwable { + if (response.body() != null) { + return response.body().string(); + } else { + return ""; + } + } + + @Override + public void onSuccess(Response response) { + String res = response.body(); + if (!TextUtils.isEmpty(res)) { + try { + AbsJson absJson = new Gson().fromJson(res, new TypeToken() { + }.getType()); + resData[0] = absJson.toAbsXml(); + absXml(resData[0], sb.getKey()); + } catch (Exception e) { + e.printStackTrace(); + } + } + countDownLatch.countDown(); + } + + @Override + public void onError(Response response) { + super.onError(response); + countDownLatch.countDown(); + } + }); + } else { + try { + Spider sp = ApiConfig.get().getCSP(sb); + // ApiConfig.get().setPlayJarKey(sb.getJar()); + List ids = new ArrayList<>(); + ids.add(finalPushUrl); + String res = sp.detailContent(ids); + if (!TextUtils.isEmpty(res)) { + try { + AbsJson absJson = new Gson().fromJson(res, new TypeToken() {}.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; @@ -960,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); @@ -1007,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);