修闪退bug;修磁力bug;修图片bug

pull/97/head
于俊 3 years ago
parent 3e6c42200a
commit 2f044d8dee
  1. 3
      app/src/main/java/com/github/tvbox/osc/picasso/MyOkhttpDownLoader.java
  2. 91
      app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java
  3. 34
      app/src/main/java/com/github/tvbox/osc/util/FileUtils.java
  4. 164
      app/src/main/java/com/github/tvbox/osc/util/thunder/Thunder.java
  5. 133
      app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java

@ -103,9 +103,6 @@ public final class MyOkhttpDownLoader implements Downloader {
mRequestBuilder.addHeader("Referer", referer); mRequestBuilder.addHeader("Referer", referer);
} }
} }
URL imgUrl = new URL(url);
String host = imgUrl.getHost();
mRequestBuilder.addHeader("Host", host);
return client.newCall(mRequestBuilder.build()).execute(); return client.newCall(mRequestBuilder.build()).execute();
} }

@ -119,7 +119,7 @@ public class PlayFragment extends BaseLazyFragment {
private SourceViewModel sourceViewModel; private SourceViewModel sourceViewModel;
private Handler mHandler; private Handler mHandler;
private long videoDuration = -1; private final long videoDuration = -1;
@Override @Override
protected int getLayoutResID() { protected int getLayoutResID() {
@ -147,14 +147,24 @@ public class PlayFragment extends BaseLazyFragment {
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
long skip = st * 1000; long skip = st * 1000L;
if (CacheManager.getCache(MD5.string2MD5(url)) == null) { Object theCache=CacheManager.getCache(MD5.string2MD5(url));
if (theCache == null) {
return skip; return skip;
} }
long rec = (long) CacheManager.getCache(MD5.string2MD5(url)); long rec = 0;
if (rec < skip) if (theCache instanceof Long) {
return skip; rec = (Long) theCache;
return rec; } else if (theCache instanceof String) {
try {
rec = Long.parseLong((String) theCache);
} catch (NumberFormatException e) {
System.out.println("String value is not a valid long.");
}
} else {
System.out.println("Value cannot be converted to long.");
}
return Math.max(rec, skip);
} }
private void initView() { private void initView() {
@ -182,7 +192,6 @@ public class PlayFragment extends BaseLazyFragment {
ProgressManager progressManager = new ProgressManager() { ProgressManager progressManager = new ProgressManager() {
@Override @Override
public void saveProgress(String url, long progress) { public void saveProgress(String url, long progress) {
if (videoDuration ==0) return;
CacheManager.save(MD5.string2MD5(url), progress); CacheManager.save(MD5.string2MD5(url), progress);
} }
@ -294,15 +303,14 @@ public class PlayFragment extends BaseLazyFragment {
searchSubtitleDialog.setSubtitleLoader(new SearchSubtitleDialog.SubtitleLoader() { searchSubtitleDialog.setSubtitleLoader(new SearchSubtitleDialog.SubtitleLoader() {
@Override @Override
public void loadSubtitle(Subtitle subtitle) { public void loadSubtitle(Subtitle subtitle) {
if (!isAdded()) return;
requireActivity().runOnUiThread(new Runnable() { requireActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
String zimuUrl = subtitle.getUrl(); String zimuUrl = subtitle.getUrl();
LOG.i("Remote Subtitle Url: " + zimuUrl); LOG.i("Remote Subtitle Url: " + zimuUrl);
setSubtitle(zimuUrl);//设置字幕 setSubtitle(zimuUrl);//设置字幕
if (searchSubtitleDialog != null) { searchSubtitleDialog.dismiss();
searchSubtitleDialog.dismiss();
}
} }
}); });
} }
@ -335,6 +343,7 @@ public class PlayFragment extends BaseLazyFragment {
subtitleDialog.show(); subtitleDialog.show();
} }
@SuppressLint("UseCompatLoadingForColorStateLists")
void setSubtitleViewTextStyle(int style) { void setSubtitleViewTextStyle(int style) {
if (style == 0) { if (style == 0) {
mController.mSubtitleView.setTextColor(getContext().getResources().getColorStateList(R.color.color_FFFFFF)); mController.mSubtitleView.setTextColor(getContext().getResources().getColorStateList(R.color.color_FFFFFF));
@ -349,9 +358,7 @@ public class PlayFragment extends BaseLazyFragment {
return; return;
} }
TrackInfo trackInfo = null; TrackInfo trackInfo = null;
if (mediaPlayer instanceof IjkMediaPlayer) { trackInfo = ((IjkMediaPlayer)mediaPlayer).getTrackInfo();
trackInfo = ((IjkMediaPlayer)mediaPlayer).getTrackInfo();
}
if (trackInfo == null) { if (trackInfo == null) {
Toast.makeText(mContext, "没有音轨", Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, "没有音轨", Toast.LENGTH_SHORT).show();
return; return;
@ -369,9 +376,7 @@ public class PlayFragment extends BaseLazyFragment {
} }
mediaPlayer.pause(); mediaPlayer.pause();
long progress = mediaPlayer.getCurrentPosition();//保存当前进度,ijk 切换轨道 会有快进几秒 long progress = mediaPlayer.getCurrentPosition();//保存当前进度,ijk 切换轨道 会有快进几秒
if (mediaPlayer instanceof IjkMediaPlayer) { ((IjkMediaPlayer)mediaPlayer).setTrack(value.index);
((IjkMediaPlayer)mediaPlayer).setTrack(value.index);
}
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -412,9 +417,7 @@ public class PlayFragment extends BaseLazyFragment {
return; return;
} }
TrackInfo trackInfo = null; TrackInfo trackInfo = null;
if (mediaPlayer instanceof IjkMediaPlayer) { trackInfo = ((IjkMediaPlayer)mediaPlayer).getTrackInfo();
trackInfo = ((IjkMediaPlayer)mediaPlayer).getTrackInfo();
}
if (trackInfo == null) { if (trackInfo == null) {
Toast.makeText(mContext, "没有内置字幕", Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, "没有内置字幕", Toast.LENGTH_SHORT).show();
return; return;
@ -432,19 +435,17 @@ public class PlayFragment extends BaseLazyFragment {
} }
mediaPlayer.pause(); mediaPlayer.pause();
long progress = mediaPlayer.getCurrentPosition();//保存当前进度,ijk 切换轨道 会有快进几秒 long progress = mediaPlayer.getCurrentPosition();//保存当前进度,ijk 切换轨道 会有快进几秒
if (mediaPlayer instanceof IjkMediaPlayer) { mController.mSubtitleView.destroy();
mController.mSubtitleView.destroy(); mController.mSubtitleView.clearSubtitleCache();
mController.mSubtitleView.clearSubtitleCache(); mController.mSubtitleView.isInternal = true;
mController.mSubtitleView.isInternal = true; ((IjkMediaPlayer)mediaPlayer).setTrack(value.index);
((IjkMediaPlayer)mediaPlayer).setTrack(value.index); new Handler().postDelayed(new Runnable() {
new Handler().postDelayed(new Runnable() { @Override
@Override public void run() {
public void run() { mediaPlayer.seekTo(progress);
mediaPlayer.seekTo(progress); mediaPlayer.start();
mediaPlayer.start(); }
} }, 800);
}, 800);
}
dialog.dismiss(); dialog.dismiss();
} catch (Exception e) { } catch (Exception e) {
LOG.e("切换内置字幕出错"); LOG.e("切换内置字幕出错");
@ -470,6 +471,7 @@ public class PlayFragment extends BaseLazyFragment {
} }
void setTip(String msg, boolean loading, boolean err) { void setTip(String msg, boolean loading, boolean err) {
if (!isAdded()) return;
requireActivity().runOnUiThread(new Runnable() { //影魔 requireActivity().runOnUiThread(new Runnable() { //影魔
@Override @Override
public void run() { public void run() {
@ -489,6 +491,7 @@ public class PlayFragment extends BaseLazyFragment {
void errorWithRetry(String err, boolean finish) { void errorWithRetry(String err, boolean finish) {
if (!autoRetry()) { if (!autoRetry()) {
if (!isAdded()) return;
requireActivity().runOnUiThread(new Runnable() { requireActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1100,6 +1103,7 @@ public class PlayFragment extends BaseLazyFragment {
} }
} }
if (rs.has("jxFrom")) { if (rs.has("jxFrom")) {
if(!isAdded())return;
requireActivity().runOnUiThread(new Runnable() { requireActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1145,6 +1149,7 @@ public class PlayFragment extends BaseLazyFragment {
if (rs.has("ua")) { if (rs.has("ua")) {
webUserAgent = rs.optString("ua").trim(); webUserAgent = rs.optString("ua").trim();
} }
if(!isAdded())return;
requireActivity().runOnUiThread(new Runnable() { requireActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1174,6 +1179,7 @@ public class PlayFragment extends BaseLazyFragment {
} }
} }
if (rs.has("jxFrom")) { if (rs.has("jxFrom")) {
if(!isAdded())return;
requireActivity().runOnUiThread(new Runnable() { requireActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1199,13 +1205,11 @@ public class PlayFragment extends BaseLazyFragment {
// webview // webview
private XWalkView mXwalkWebView; private XWalkView mXwalkWebView;
private XWalkWebClient mX5WebClient;
private WebView mSysWebView; private WebView mSysWebView;
private SysWebClient mSysWebClient; private final Map<String, Boolean> loadedUrls = new HashMap<>();
private Map<String, Boolean> loadedUrls = new HashMap<>();
private LinkedList<String> loadFoundVideoUrls = new LinkedList<>(); private LinkedList<String> loadFoundVideoUrls = new LinkedList<>();
private HashMap<String, HashMap<String, String>> loadFoundVideoUrlsHeader = new HashMap<>(); private HashMap<String, HashMap<String, String>> loadFoundVideoUrlsHeader = new HashMap<>();
private AtomicInteger loadFoundCount = new AtomicInteger(0); private final AtomicInteger loadFoundCount = new AtomicInteger(0);
void loadWebView(String url) { void loadWebView(String url) {
if (mSysWebView == null && mXwalkWebView == null) { if (mSysWebView == null && mXwalkWebView == null) {
@ -1252,6 +1256,7 @@ public class PlayFragment extends BaseLazyFragment {
} }
void loadUrl(String url) { void loadUrl(String url) {
if(!isAdded())return;
requireActivity().runOnUiThread(new Runnable() { requireActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1285,6 +1290,7 @@ public class PlayFragment extends BaseLazyFragment {
void stopLoadWebView(boolean destroy) { void stopLoadWebView(boolean destroy) {
if (mActivity == null) return; if (mActivity == null) return;
if(!isAdded())return;
requireActivity().runOnUiThread(new Runnable() { requireActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1378,6 +1384,7 @@ public class PlayFragment extends BaseLazyFragment {
webView.setFocusableInTouchMode(false); webView.setFocusableInTouchMode(false);
webView.clearFocus(); webView.clearFocus();
webView.setOverScrollMode(View.OVER_SCROLL_ALWAYS); webView.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
if(!isAdded())return;
requireActivity().addContentView(webView, layoutParams); requireActivity().addContentView(webView, layoutParams);
/* 添加webView配置 */ /* 添加webView配置 */
final WebSettings settings = webView.getSettings(); final WebSettings settings = webView.getSettings();
@ -1437,13 +1444,14 @@ public class PlayFragment extends BaseLazyFragment {
return true; return true;
} }
}); });
mSysWebClient = new SysWebClient(); SysWebClient mSysWebClient = new SysWebClient();
webView.setWebViewClient(mSysWebClient); webView.setWebViewClient(mSysWebClient);
webView.setBackgroundColor(Color.BLACK); webView.setBackgroundColor(Color.BLACK);
} }
private class SysWebClient extends WebViewClient { private class SysWebClient extends WebViewClient {
@SuppressLint("WebViewClientOnReceivedSslError")
@Override @Override
public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) { public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
sslErrorHandler.proceed(); sslErrorHandler.proceed();
@ -1503,7 +1511,7 @@ public class PlayFragment extends BaseLazyFragment {
ad = AdBlocker.isAd(url); ad = AdBlocker.isAd(url);
loadedUrls.put(url, ad); loadedUrls.put(url, ad);
} else { } else {
ad = loadedUrls.get(url); ad = Boolean.TRUE.equals(loadedUrls.get(url));
} }
if (!ad) { if (!ad) {
@ -1572,6 +1580,7 @@ public class PlayFragment extends BaseLazyFragment {
webView.setFocusableInTouchMode(false); webView.setFocusableInTouchMode(false);
webView.clearFocus(); webView.clearFocus();
webView.setOverScrollMode(View.OVER_SCROLL_ALWAYS); webView.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
if(!isAdded())return;
requireActivity().addContentView(webView, layoutParams); requireActivity().addContentView(webView, layoutParams);
/* 添加webView配置 */ /* 添加webView配置 */
final XWalkSettings settings = webView.getSettings(); final XWalkSettings settings = webView.getSettings();
@ -1625,7 +1634,7 @@ public class PlayFragment extends BaseLazyFragment {
return true; return true;
} }
}); });
mX5WebClient = new XWalkWebClient(webView); XWalkWebClient mX5WebClient = new XWalkWebClient(webView);
webView.setResourceClient(mX5WebClient); webView.setResourceClient(mX5WebClient);
} }
@ -1677,7 +1686,7 @@ public class PlayFragment extends BaseLazyFragment {
ad = AdBlocker.isAd(url); ad = AdBlocker.isAd(url);
loadedUrls.put(url, ad); loadedUrls.put(url, ad);
} else { } else {
ad = loadedUrls.get(url); ad = Boolean.TRUE.equals(loadedUrls.get(url));
} }
if (!ad ) { if (!ad ) {

@ -1,6 +1,7 @@
package com.github.tvbox.osc.util; package com.github.tvbox.osc.util;
import android.os.Environment; import android.os.Environment;
import android.text.TextUtils;
import com.github.tvbox.osc.base.App; import com.github.tvbox.osc.base.App;
@ -194,4 +195,37 @@ public class FileUtils {
return ""; return "";
} }
} }
public static String getFileName(String filePath){
if(TextUtils.isEmpty(filePath)) return "";
String fileName = filePath;
int p = fileName.lastIndexOf(File.separatorChar);
if(p != -1){
fileName = fileName.substring(p + 1);
}
return fileName;
}
public static String getFileNameWithoutExt(String filePath){
if(TextUtils.isEmpty(filePath)) return "";
String fileName = filePath;
int p = fileName.lastIndexOf(File.separatorChar);
if(p != -1){
fileName = fileName.substring(p + 1);
}
p = fileName.indexOf('.');
if(p != -1){
fileName = fileName.substring(0, p);
}
return fileName;
}
public static String getFileExt(String fileName){
if(TextUtils.isEmpty(fileName)) return "";
int p = fileName.lastIndexOf('.');
if(p != -1) {
return fileName.substring(p).toLowerCase();
}
return "";
}
} }

@ -6,6 +6,7 @@ import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.github.tvbox.osc.util.FileUtils;
import com.xunlei.downloadlib.XLDownloadManager; import com.xunlei.downloadlib.XLDownloadManager;
import com.xunlei.downloadlib.XLTaskHelper; import com.xunlei.downloadlib.XLTaskHelper;
import com.xunlei.downloadlib.android.XLUtil; import com.xunlei.downloadlib.android.XLUtil;
@ -90,16 +91,20 @@ public class Thunder {
void play(String url); void play(String url);
} }
private static ArrayList<String> playList = null;
private static ArrayList<String> ed2kList = null;
public static void parse(Context context, List<String> urlList, ThunderCallback callback) { public static void parse(Context context, List<String> urlList, ThunderCallback callback) {
init(context); init(context);
stop(true); stop(true);
threadPool = Executors.newSingleThreadExecutor(); threadPool = Executors.newSingleThreadExecutor();
ArrayList<String> playList = new ArrayList<>(); playList = new ArrayList<>();
torrentFileInfoArrayList=new ArrayList<>(); torrentFileInfoArrayList=new ArrayList<>();
ed2kList=new ArrayList<>();
threadPool.execute(new Runnable() { threadPool.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
for (String url : urlList) { for (String url : urlList) {
if(isThunder(url) )url=XLDownloadManager.getInstance().parserThunderUrl(url);
if (isMagnet(url) || isThunder(url) || isTorrent(url)) { if (isMagnet(url) || isThunder(url) || isTorrent(url)) {
String link = isThunder(url) ? XLDownloadManager.getInstance().parserThunderUrl(url) : url; String link = isThunder(url) ? XLDownloadManager.getInstance().parserThunderUrl(url) : url;
Uri p = Uri.parse(link); Uri p = Uri.parse(link);
@ -109,6 +114,10 @@ public class Thunder {
String fileName = XLTaskHelper.instance().getFileName(link); String fileName = XLTaskHelper.instance().getFileName(link);
File cache = new File(cacheRoot + File.separator + fileName); File cache = new File(cacheRoot + File.separator + fileName);
try { try {
if (currentTask > 0) {
XLTaskHelper.instance().stopTask(currentTask);
currentTask = 0L;
}
currentTask = isMagnet(url) ? currentTask = isMagnet(url) ?
XLTaskHelper.instance().addMagentTask(url, cacheRoot, fileName) : XLTaskHelper.instance().addMagentTask(url, cacheRoot, fileName) :
XLTaskHelper.instance().addThunderTask(url, cacheRoot, fileName); XLTaskHelper.instance().addThunderTask(url, cacheRoot, fileName);
@ -161,39 +170,25 @@ public class Thunder {
} }
} }
} }
for (String url : urlList) {
if(isThunder(url))url=XLDownloadManager.getInstance().parserThunderUrl(url);
if(isNetworkDownloadTask(url)){
task_url=url;
if(TextUtils.isEmpty(task_url)){
continue;
}
name = XLTaskHelper.instance().getFileName(task_url);
playList.add(name + "$tvbox-oth:" + ed2kList.size());
ed2kList.add(task_url);
}
}
if (playList.size() > 0) { if (playList.size() > 0) {
callback.list(TextUtils.join("#", playList)); callback.list(TextUtils.join("#", playList));
} else { } else {
callback.status(-1, "文件列表为空!"); callback.status(-1, "文件列表为空!");
} }
}}); }});
// if(isEd2k(url) || isFtp(url)){
// task_url= url;
// System.out.println("startTask:");
// threadPool.execute(new Runnable() {
// @Override
// public void run() {
// System.out.println("task_url: "+task_url);
// if(TextUtils.isEmpty(task_url) || currentTask != 0L){
// return;
// }
// if(isNetworkDownloadTask(task_url)){
// name = XLTaskHelper.instance().getFileName(task_url);
// localPath = (new File(cacheRoot+File.separator+"temp",getFileNameWithoutExt(name)))+"/";
// currentTask = XLTaskHelper.instance().addThunderTask(task_url, localPath, null);
// callback.list(name+"$"+task_url);
// System.out.println("init name:"+name);
// } else {
// currentTask = 0L;
// }
// System.out.println("name: "+name);
// Log.d("TAG", "startTask(" +task_url + "), taskId = " + currentTask);
// }
// });
// }
} }
@ -244,7 +239,13 @@ public class Thunder {
}); });
return true; return true;
} }
if (isEd2k(url) || isFtp(url)) { if (url.startsWith("tvbox-oth:")) {
int idx = Integer.parseInt(url.substring(10));
task_url=ed2kList.get(idx);
name = XLTaskHelper.instance().getFileName(task_url);
localPath = (new File(cacheRoot+File.separator+"temp",FileUtils.getFileNameWithoutExt(name)))+"/";
currentTask = XLTaskHelper.instance().addThunderTask(task_url, localPath, null);
threadPool.execute(new Runnable() { threadPool.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -261,26 +262,45 @@ public class Thunder {
callback.play(playUrl); callback.play(playUrl);
return; return;
} }
// XLTaskInfo taskInfo = getTaskInfo(); try {
// switch (taskInfo.mTaskStatus) { Thread.sleep(1000);
// case 3: { } catch (InterruptedException e) {
// callback.status(-1, errorInfo(taskInfo.mErrorCode)); e.printStackTrace();
// return; }
// } }
// case 1:{ }
// if(taskInfo.mDownloadSize>0){ });
// String playUrl=getPlayUrl(); return true;
// callback.play(playUrl); }
// return; if (isEd2k(url) || isFtp(url)) {
// } if (currentTask > 0) {
// } XLTaskHelper.instance().stopTask(currentTask);
// case 4: // 下载中 currentTask = 0L;
// case 2: { // 下载完成 }
// String playUrl=getPlayUrl(); if(threadPool==null){
// callback.play(playUrl); threadPool = Executors.newSingleThreadExecutor();
// return; }
// } task_url=url;
// } name = XLTaskHelper.instance().getFileName(task_url);
localPath = (new File(cacheRoot+File.separator+"temp",FileUtils.getFileNameWithoutExt(name)))+"/";
currentTask = XLTaskHelper.instance().addThunderTask(task_url, localPath, null);
threadPool.execute(new Runnable() {
@Override
public void run() {
int count = 20;
while (true) {
count--;
if (count <= 0) {
callback.status(-1, "解析下载超时");
break;
}
String playUrl=getPlayUrl();
if(!TextUtils.isEmpty(playUrl)){
callback.play(playUrl);
return;
}
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -294,6 +314,7 @@ public class Thunder {
return false; return false;
} }
private static String errorInfo(int code) { private static String errorInfo(int code) {
switch (code) { switch (code) {
case 9125: case 9125:
@ -416,37 +437,6 @@ public class Thunder {
} }
} }
public static void startTask(Context context, String url, ThunderCallback callback){
init(context);
stop(true);
task_url= url;
System.out.println("checkThunder: "+task_url);
System.out.println("startTask:");
threadPool = Executors.newSingleThreadExecutor();
threadPool.execute(new Runnable() {
@Override
public void run() {
if (isEd2k(task_url) || isFtp(task_url)) {
System.out.println("task_url: "+task_url);
if(TextUtils.isEmpty(task_url) || currentTask != 0L){
return;
}
if(isNetworkDownloadTask(task_url)){
name = XLTaskHelper.instance().getFileName(task_url);
localPath = (new File(cacheRoot+File.separator+"temp",getFileNameWithoutExt(name)))+"/";
currentTask = XLTaskHelper.instance().addThunderTask(task_url, localPath, null);
callback.list(name+"$"+task_url);
System.out.println("init name:"+name);
} else {
currentTask = 0L;
}
System.out.println("name: "+name);
Log.d("TAG", "startTask(" +task_url + "), taskId = " + currentTask);
}
}
});
}
public static void stopTask(){ public static void stopTask(){
if(currentTask != 0L){ if(currentTask != 0L){
XLTaskHelper.instance().deleteTask(currentTask, task_url.isEmpty()?cacheRoot:localPath); XLTaskHelper.instance().deleteTask(currentTask, task_url.isEmpty()?cacheRoot:localPath);
@ -466,18 +456,6 @@ public class Thunder {
return null; return null;
} }
public static String getFileNameWithoutExt(String filePath){
if(TextUtils.isEmpty(filePath)) return "";
String fileName = filePath;
int p = fileName.lastIndexOf(File.separatorChar);
if(p != -1){
fileName = fileName.substring(p + 1);
}
p = fileName.indexOf('.');
if(p != -1){
fileName = fileName.substring(0, p);
}
return fileName;
}
} }

@ -839,101 +839,64 @@ public class SourceViewModel extends ViewModel {
} }
} }
private void checkThunder(AbsXml data) { public void checkThunder(AbsXml data, int index) {
boolean thunderParse = false; boolean thunderParse = false;
if (data.movie != null && data.movie.videoList != null && data.movie.videoList.size() == 1) { if (data.movie != null && data.movie.videoList != null && data.movie.videoList.size() == 1) {
Movie.Video video = data.movie.videoList.get(0); Movie.Video video = data.movie.videoList.get(0);
if (video != null && video.urlBean != null && video.urlBean.infoList != null && video.urlBean.infoList.size() == 1) { if (video != null && video.urlBean != null && video.urlBean.infoList != null) {
Movie.Video.UrlBean.UrlInfo urlInfo = video.urlBean.infoList.get(0); for (int idx=0;idx<video.urlBean.infoList.size();idx++) {
if (urlInfo != null && Thunder.isSupportUrl(urlInfo.beanList.get(0).url)) { Movie.Video.UrlBean.UrlInfo urlInfo=video.urlBean.infoList.get(idx);
thunderParse = true; if(urlInfo != null){
List<String> urlList = new ArrayList<>(); List<String> urlList = new ArrayList<>();
for (Movie.Video.UrlBean.UrlInfo.InfoBean infoBean : urlInfo.beanList) { for (Movie.Video.UrlBean.UrlInfo.InfoBean infoBean : urlInfo.beanList) {
urlList.add(infoBean.url); urlList.add(infoBean.url);
} }
Thunder.parse(App.getInstance(), urlList, new Thunder.ThunderCallback() { if (Thunder.isSupportUrl(urlInfo.beanList.get(0).url)) {
@Override thunderParse = true;
public void status(int code, String info) { Thunder.parse(App.getInstance(), urlList, new Thunder.ThunderCallback() {
if (code >= 0) { @Override
LOG.i(info); public void status(int code, String info) {
} else { if (code >= 0) {
urlInfo.beanList.get(0).name = info; LOG.i(info);
detailResult.postValue(data); } else {
} urlInfo.beanList.get(0).name = info;
} detailResult.postValue(data);
@Override
public void list(String playList) {
urlInfo.urls = playList;
String[] str = playList.split("#");
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]));
// }
if (ss.length > 0) {
if (ss.length >= 2) {
infoBeanList.add(new Movie.Video.UrlBean.UrlInfo.InfoBean(ss[0], ss[1]));
} else {
infoBeanList.add(new Movie.Video.UrlBean.UrlInfo.InfoBean((infoBeanList.size() + 1) + "", ss[0]));
}
} }
} }
}
urlInfo.beanList = infoBeanList;
detailResult.postValue(data);
}
@Override
public void play(String url) {
} @Override
}); public void list(String playList) {
} urlInfo.urls = playList;
if (urlInfo != null && urlInfo.beanList.size() == 1 && Thunder.isNetworkDownloadTask(urlInfo.beanList.get(0).url)) { String[] str = playList.split("#");
Thunder.startTask(App.getInstance(), urlInfo.beanList.get(0).url, new Thunder.ThunderCallback() { List<Movie.Video.UrlBean.UrlInfo.InfoBean> infoBeanList = new ArrayList<>();
@Override for (String s : str) {
public void status(int code, String info) { if (s.contains("$")) {
if (code >= 0) { String[] ss = s.split("\\$");
LOG.i(info);
} else { if (ss.length > 0) {
urlInfo.beanList.get(0).name = info; if (ss.length >= 2) {
detailResult.postValue(data); infoBeanList.add(new Movie.Video.UrlBean.UrlInfo.InfoBean(ss[0], ss[1]));
} } else {
} infoBeanList.add(new Movie.Video.UrlBean.UrlInfo.InfoBean((infoBeanList.size() + 1) + "", ss[0]));
}
@Override }
public void list(String playList) {
urlInfo.urls = playList;
String[] str = playList.split("#");
List<Movie.Video.UrlBean.UrlInfo.InfoBean> infoBeanList = new ArrayList<>();
for (String s : str) {
if (s.contains("$")) {
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 {
infoBeanList.add(new Movie.Video.UrlBean.UrlInfo.InfoBean((infoBeanList.size() + 1) + "", ss[0]));
} }
} }
urlInfo.beanList = infoBeanList;
detailResult.postValue(data);
} }
}
urlInfo.beanList = infoBeanList;
detailResult.postValue(data);
}
@Override @Override
public void play(String url) { public void play(String url) {
}
});
} }
}); }
} }
} }
} }
if (!thunderParse) { if (!thunderParse && index==0) {
detailResult.postValue(data); detailResult.postValue(data);
} }
} }
@ -958,8 +921,8 @@ public class SourceViewModel extends ViewModel {
EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_QUICK_SEARCH_RESULT, data)); EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_QUICK_SEARCH_RESULT, data));
} else if (result != null) { } else if (result != null) {
if (result == detailResult) { if (result == detailResult) {
checkThunder(data); checkThunder(data,0);
} else { }else {
result.postValue(data); result.postValue(data);
} }
} }
@ -983,7 +946,7 @@ public class SourceViewModel extends ViewModel {
"\t\"list\": [{\n" + "\t\"list\": [{\n" +
"\t\t\"vod_id\": \"137133\",\n" + "\t\t\"vod_id\": \"137133\",\n" +
"\t\t\"vod_name\": \"磁力测试\",\n" + "\t\t\"vod_name\": \"磁力测试\",\n" +
"\t\t\"vod_pic\": \"https:/img9.doubanio.com/view/photo/s_ratio_poster/public/p2656327176.webp\",\n" + "\t\t\"vod_pic\": \"https:/img9.doubanio.com/view/photo/s_ratio_poster/public/p2656327176.webp@User-Agent=com.douban.frodo\",\n" +
"\t\t\"type_name\": \"剧情 / 爱情 / 古装\",\n" + "\t\t\"type_name\": \"剧情 / 爱情 / 古装\",\n" +
"\t\t\"vod_year\": \"2022\",\n" + "\t\t\"vod_year\": \"2022\",\n" +
"\t\t\"vod_area\": \"中国大陆\",\n" + "\t\t\"vod_area\": \"中国大陆\",\n" +
@ -1005,8 +968,8 @@ public class SourceViewModel extends ViewModel {
EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_QUICK_SEARCH_RESULT, data)); EventBus.getDefault().post(new RefreshEvent(RefreshEvent.TYPE_QUICK_SEARCH_RESULT, data));
} else if (result != null) { } else if (result != null) {
if (result == detailResult) { if (result == detailResult) {
checkThunder(data); checkThunder(data,0);
} else { }else {
result.postValue(data); result.postValue(data);
} }
} }

Loading…
Cancel
Save