diff --git a/app/src/main/java/com/github/tvbox/osc/base/App.java b/app/src/main/java/com/github/tvbox/osc/base/App.java index cc133eef..c4280965 100644 --- a/app/src/main/java/com/github/tvbox/osc/base/App.java +++ b/app/src/main/java/com/github/tvbox/osc/base/App.java @@ -12,11 +12,13 @@ import com.github.tvbox.osc.util.AppManager; import com.github.tvbox.osc.util.EpgUtil; import com.github.tvbox.osc.util.FileUtils; import com.github.tvbox.osc.util.HawkConfig; +import com.github.tvbox.osc.util.LOG; import com.github.tvbox.osc.util.OkGoHelper; import com.github.tvbox.osc.util.PlayerHelper; import com.github.tvbox.osc.util.js.JSEngine; import com.kingja.loadsir.core.LoadSir; import com.orhanobut.hawk.Hawk; +import com.p2p.P2PClass; import me.jessyan.autosize.AutoSizeConfig; import me.jessyan.autosize.unit.Subunits; @@ -29,6 +31,9 @@ import me.jessyan.autosize.unit.Subunits; public class App extends MultiDexApplication { private static App instance; + private static P2PClass p; + public static String burl; + @Override public void onCreate() { super.onCreate(); @@ -82,6 +87,18 @@ public class App extends MultiDexApplication { return this.vodInfo; } + public static P2PClass getp2p() { + try { + if (p == null) { + p = new P2PClass(instance.getExternalCacheDir().getAbsolutePath()); + } + return p; + } catch (Exception e) { + LOG.e(e.toString()); + return null; + } + } + public Activity getCurrentActivity() { return AppManager.getInstance().currentActivity(); } diff --git a/app/src/main/java/com/github/tvbox/osc/picasso/MyOkhttpDownLoader.java b/app/src/main/java/com/github/tvbox/osc/picasso/MyOkhttpDownLoader.java index 177c0d41..10b204d1 100644 --- a/app/src/main/java/com/github/tvbox/osc/picasso/MyOkhttpDownLoader.java +++ b/app/src/main/java/com/github/tvbox/osc/picasso/MyOkhttpDownLoader.java @@ -25,6 +25,7 @@ import com.google.gson.JsonObject; import com.squareup.picasso.Downloader; import java.io.IOException; +import java.net.URLDecoder; import okhttp3.Cache; import okhttp3.Call; @@ -62,6 +63,7 @@ public final class MyOkhttpDownLoader implements Downloader { @Override public Response load(@NonNull Request request) throws IOException { String url = request.url().toString(); + url= URLDecoder.decode(url); String header = null; String cookie = null; String ua = null; diff --git a/app/src/main/java/com/github/tvbox/osc/player/IjkMediaPlayer.java b/app/src/main/java/com/github/tvbox/osc/player/IjkMediaPlayer.java index c9f9d3ea..885b5b20 100644 --- a/app/src/main/java/com/github/tvbox/osc/player/IjkMediaPlayer.java +++ b/app/src/main/java/com/github/tvbox/osc/player/IjkMediaPlayer.java @@ -40,6 +40,7 @@ public class IjkMediaPlayer extends IjkPlayer { int category = Integer.parseInt(opt[0].trim()); String name = opt[1].trim(); try { + assert value != null; long valLong = Long.parseLong(value); mMediaPlayer.setOption(category, name, valLong); } catch (Exception e) { diff --git a/app/src/main/java/com/github/tvbox/osc/ui/activity/PlayActivity.java b/app/src/main/java/com/github/tvbox/osc/ui/activity/PlayActivity.java index dabd1fa3..12c92d42 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/activity/PlayActivity.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/activity/PlayActivity.java @@ -67,6 +67,7 @@ import com.github.tvbox.osc.util.MD5; import com.github.tvbox.osc.util.PlayerHelper; import com.github.tvbox.osc.util.VideoParseRuler; import com.github.tvbox.osc.util.XWalkUtils; +import com.github.tvbox.osc.util.thunder.Jianpian; import com.github.tvbox.osc.util.thunder.Thunder; import com.github.tvbox.osc.viewmodel.SourceViewModel; import com.lzy.okgo.OkGo; @@ -732,6 +733,7 @@ public class PlayActivity extends BaseActivity { } stopLoadWebView(true); stopParse(); + Thunder.stop(false); } private VodInfo mVodInfo; @@ -821,6 +823,17 @@ public class PlayActivity extends BaseActivity { CacheManager.delete(MD5.string2MD5(progressKey), 0); CacheManager.delete(MD5.string2MD5(subtitleCacheKey), 0); } + if(vs.url.startsWith("tvbox-xg:") || (Thunder.isFtp(vs.url) && vs.url.contains("gbl.114s"))){//荐片地址特殊判断 + String jp_url= vs.url; + mController.showParse(false); + if(vs.url.startsWith("tvbox-xg:")){ + jp_url = jp_url.replace("tvbox-xg://","tvbox-xg:"); + playUrl(Jianpian.JPUrlDec(jp_url.substring(9)), null); + }else { + playUrl(Jianpian.JPUrlDec(jp_url), null); + } + return; + } if (Thunder.play(vs.url, new Thunder.ThunderCallback() { @Override public void status(int code, String info) { diff --git a/app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java b/app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java index 4eaac3d2..9d103c61 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java @@ -67,6 +67,7 @@ import com.github.tvbox.osc.util.MD5; import com.github.tvbox.osc.util.PlayerHelper; import com.github.tvbox.osc.util.VideoParseRuler; import com.github.tvbox.osc.util.XWalkUtils; +import com.github.tvbox.osc.util.thunder.Jianpian; import com.github.tvbox.osc.util.thunder.Thunder; import com.github.tvbox.osc.viewmodel.SourceViewModel; import com.lzy.okgo.OkGo; @@ -760,6 +761,7 @@ public class PlayFragment extends BaseLazyFragment { } stopLoadWebView(true); stopParse(); + Thunder.stop(true); } private VodInfo mVodInfo; @@ -845,6 +847,18 @@ public class PlayFragment extends BaseLazyFragment { CacheManager.delete(MD5.string2MD5(progressKey), 0); CacheManager.delete(MD5.string2MD5(subtitleCacheKey), 0); } + + if(vs.url.startsWith("tvbox-xg:") || (Thunder.isFtp(vs.url) && vs.url.contains("gbl.114s"))){//荐片地址特殊判断 + String jp_url= vs.url; + mController.showParse(false); + if(vs.url.startsWith("tvbox-xg:")){ + jp_url = jp_url.replace("tvbox-xg://","tvbox-xg:"); + playUrl(Jianpian.JPUrlDec(jp_url.substring(9)), null); + }else { + playUrl(Jianpian.JPUrlDec(jp_url), null); + } + return; + } if (Thunder.play(vs.url, new Thunder.ThunderCallback() { @Override public void status(int code, String info) { diff --git a/app/src/main/java/com/github/tvbox/osc/util/LocalIPAddress.java b/app/src/main/java/com/github/tvbox/osc/util/LocalIPAddress.java new file mode 100644 index 00000000..14283522 --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/util/LocalIPAddress.java @@ -0,0 +1,155 @@ +package com.github.tvbox.osc.util; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; + +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; +import java.util.regex.Pattern; + + +/** + * 作者:By hdy + * 日期:On 2018/11/1 + * 时间:At 19:17 + */ +public class LocalIPAddress { + @SuppressLint("DefaultLocale") + public static String getLocalIPAddress(Context context) { + WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); + int ipAddress = wifiManager.getConnectionInfo().getIpAddress(); + if (ipAddress == 0) { + try { + Enumeration enumerationNi = NetworkInterface.getNetworkInterfaces(); + while (enumerationNi.hasMoreElements()) { + NetworkInterface networkInterface = enumerationNi.nextElement(); + String interfaceName = networkInterface.getDisplayName(); + if (interfaceName.equals("eth0") || interfaceName.equals("wlan0")) { + Enumeration enumIpAddr = networkInterface.getInetAddresses(); + while (enumIpAddr.hasMoreElements()) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { + return inetAddress.getHostAddress(); + } + } + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + } else { + return String.format("%d.%d.%d.%d", (ipAddress & 0xff), (ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff)); + } + return "127.0.0.1"; + } + public static String getIP(Context context) { + try { + WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); + //判断wifi是否开启 + WifiInfo wifiInfo = null; + if (wifiManager != null) { + wifiInfo = wifiManager.getConnectionInfo(); + } + int ipAddress = 0; + if (wifiInfo != null) { + ipAddress = wifiInfo.getIpAddress(); + } + return intToIp(ipAddress); + } catch (Exception e) { + e.printStackTrace(); + try { + return getLocalIPAddress(); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + return "127.0.0.1"; + } + + public static String getLocalIPAddress() { + try { + for (Enumeration mEnumeration = NetworkInterface + .getNetworkInterfaces(); mEnumeration.hasMoreElements(); ) { + NetworkInterface intf = mEnumeration.nextElement(); + for (Enumeration enumIPAddr = intf + .getInetAddresses(); enumIPAddr.hasMoreElements(); ) { + InetAddress inetAddress = enumIPAddr.nextElement(); + // 如果不是回环地址 + if (!inetAddress.isLoopbackAddress()) { + // 直接返回本地IP地址 + return inetAddress.getHostAddress(); + } + } + } + } catch (SocketException ex) { + System.err.print("error"); + } + return "127.0.0.1"; + } + + + private static String intToIp(int i) { + return (i & 0xFF) + "." + + ((i >> 8) & 0xFF) + "." + + ((i >> 16) & 0xFF) + "." + + (i >> 24 & 0xFF); + } + + /** + * Ipv4 address check. + */ + private static final Pattern IPV4_PATTERN = Pattern.compile( + "^(" + "([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}" + + "([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"); + private static final Pattern IPV6_PATTERN = Pattern.compile("^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:)(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"); + + /** + * Check if valid IPV4 address. + * + * @param input the address string to check for validity. + * @return True if the input parameter is a valid IPv4 address. + */ + public static boolean isIPv4Address(String input) { + return IPV4_PATTERN.matcher(input).matches(); + } + + public static boolean isIPv6Address(String str) { + return str != null && IPV6_PATTERN.matcher(str).matches(); + } + + public static boolean isIPAddress(String str) { + return isIPv4Address(str) || isIPv6Address(str); + } + + public static boolean isNetworkAvailable(final Context context) { + boolean hasWifoCon = false; + boolean hasMobileCon = false; + + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE); + NetworkInfo[] netInfos = cm.getAllNetworkInfo(); + for (NetworkInfo net : netInfos) { + + String type = net.getTypeName(); + if (type.equalsIgnoreCase("WIFI")) { + if (net.isConnected()) { + hasWifoCon = true; + } + } + + if (type.equalsIgnoreCase("MOBILE")) { + if (net.isConnected()) { + hasMobileCon = true; + } + } + } + return hasWifoCon || hasMobileCon; + + } +} diff --git a/app/src/main/java/com/github/tvbox/osc/util/thunder/Jianpian.java b/app/src/main/java/com/github/tvbox/osc/util/thunder/Jianpian.java new file mode 100644 index 00000000..8a3b2787 --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/util/thunder/Jianpian.java @@ -0,0 +1,53 @@ +package com.github.tvbox.osc.util.thunder; + +import android.net.Uri; +import android.text.TextUtils; + +import com.github.tvbox.osc.base.App; +import com.github.tvbox.osc.util.LocalIPAddress; +import com.p2p.P2PClass; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; + + +public class Jianpian { + + public static String JPUrlDec(String url) { + if (App.getp2p() != null) { + try { + String decode = URLDecoder.decode(url, "UTF-8"); + String[] split = decode.split("\\|"); + String replace = split[0].replace("xg://", "ftp://"); + if (replace.contains("xgplay://")) { + replace = split[0].replace("xgplay://", "ftp://"); + } + if (!TextUtils.isEmpty(App.burl)) { + App.getp2p().P2Pdoxpause(App.burl.getBytes("GBK")); + App.getp2p().P2Pdoxdel(App.burl.getBytes("GBK")); + } + App.burl = replace; + App.getp2p().P2Pdoxstart(replace.getBytes("GBK")); + App.getp2p().P2Pdoxadd(replace.getBytes("GBK")); + return "http://" + LocalIPAddress.getIP(App.getInstance()) + ":" + P2PClass.port + "/" + URLEncoder.encode(Uri.parse(replace).getLastPathSegment(), "GBK"); + } catch (Exception e) { + return e.getLocalizedMessage(); + } + } else { + return ""; + } + } + + public static void finish() { + if (!TextUtils.isEmpty(App.burl) && App.getp2p() != null) { + try { + App.getp2p().P2Pdoxpause(App.burl.getBytes("GBK")); + App.getp2p().P2Pdoxdel(App.burl.getBytes("GBK")); + App.burl = ""; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + } +} diff --git a/app/src/main/java/com/github/tvbox/osc/util/thunder/Thunder.java b/app/src/main/java/com/github/tvbox/osc/util/thunder/Thunder.java index be0b8829..cd739c88 100644 --- a/app/src/main/java/com/github/tvbox/osc/util/thunder/Thunder.java +++ b/app/src/main/java/com/github/tvbox/osc/util/thunder/Thunder.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.net.Uri; import android.text.TextUtils; +import android.util.Log; import com.xunlei.downloadlib.XLDownloadManager; import com.xunlei.downloadlib.XLTaskHelper; @@ -21,6 +22,9 @@ import java.util.concurrent.Executors; public class Thunder { private static String cacheRoot = ""; + private static String localPath = ""; + private static String name = ""; + private static String task_url = ""; private static long currentTask = 0L; private static ArrayList torrentFileInfoArrayList = null; private static ExecutorService threadPool = null; @@ -53,23 +57,25 @@ public class Thunder { cacheRoot = context.getCacheDir().getAbsolutePath() + File.separator + "thunder"; } - public static void stop() { + public static void stop(Boolean bool) { if (currentTask > 0) { XLTaskHelper.instance().stopTask(currentTask); currentTask = 0L; } - torrentFileInfoArrayList = null; - // del cache file - File cache = new File(cacheRoot); - recursiveDelete(cache); - if (!cache.exists()) - cache.mkdirs(); - if (threadPool != null) { - try { - threadPool.shutdownNow(); - threadPool = null; - } catch (Throwable th) { + if(bool){ + torrentFileInfoArrayList = null; + // del cache file + File cache = new File(task_url.isEmpty()?cacheRoot:localPath); + recursiveDelete(cache); + if (!cache.exists()) + cache.mkdirs(); + if (threadPool != null) { + try { + threadPool.shutdownNow(); + threadPool = null; + } catch (Throwable th) { + } } } } @@ -85,7 +91,7 @@ public class Thunder { public static void parse(Context context, String url, ThunderCallback callback) { init(context); - stop(); + stop(true); threadPool = Executors.newSingleThreadExecutor(); if (isMagnet(url) || isThunder(url)) { String link = isThunder(url) ? XLDownloadManager.getInstance().parserThunderUrl(url) : url; @@ -170,6 +176,30 @@ public class Thunder { } }); } +// 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); +// } +// }); +// } } @@ -220,6 +250,53 @@ public class Thunder { }); return true; } + if (isEd2k(url) || isFtp(url)) { + 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(!playUrl.isEmpty()){ + callback.play(playUrl); + return; + } +// XLTaskInfo taskInfo = getTaskInfo(); +// switch (taskInfo.mTaskStatus) { +// case 3: { +// callback.status(-1, errorInfo(taskInfo.mErrorCode)); +// return; +// } +// case 1:{ +// if(taskInfo.mDownloadSize>0){ +// String playUrl=getPlayUrl(); +// callback.play(playUrl); +// return; +// } +// } +// case 4: // 下载中 +// case 2: { // 下载完成 +// String playUrl=getPlayUrl(); +// callback.play(playUrl); +// return; +// } +// } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }); + return true; + } return false; } @@ -255,7 +332,8 @@ public class Thunder { public static boolean isSupportUrl(String url) { - return isMagnet(url) || isThunder(url)/* || isTorrent(url) || isEd2k(url)*/; +// return isMagnet(url) || isThunder(url) || isEd2k(url) || isFtp(url); + return isMagnet(url) || isThunder(url); } private static boolean isMagnet(String url) { @@ -274,6 +352,10 @@ public class Thunder { return url.toLowerCase().startsWith("ed2k:"); } + public static boolean isFtp(String url) { + return url.toLowerCase().startsWith("ftp://"); + } + static void recursiveDelete(File file) { if (!file.exists()) return; @@ -330,4 +412,78 @@ public class Thunder { return sb.toString(); } + + public static boolean isNetworkDownloadTask(String url){ + if(TextUtils.isEmpty(url)) return false; + if(isThunder(url)|| isFtp(url) || isEd2k(url)){ + return true; + }else{ + return false; + } + } + + 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(){ + if(currentTask != 0L){ + XLTaskHelper.instance().deleteTask(currentTask, task_url.isEmpty()?cacheRoot:localPath); + currentTask = 0L; + } + } + public static XLTaskInfo getTaskInfo(){ + return XLTaskHelper.instance().getTaskInfo(currentTask); + } + + public static String getPlayUrl(){ + if(currentTask != 0L){ + if(isNetworkDownloadTask(task_url)){ + return XLTaskHelper.instance().getLoclUrl(localPath + name); + } + } + 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; + } + } 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 c5c3100f..e4cc2fda 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 @@ -883,6 +883,45 @@ public class SourceViewModel extends ViewModel { @Override public void play(String url) { + } + }); + } + if (urlInfo != null && urlInfo.beanList.size() == 1 && Thunder.isNetworkDownloadTask(urlInfo.beanList.get(0).url)) { + Thunder.startTask(App.getInstance(), urlInfo.beanList.get(0).url, new Thunder.ThunderCallback() { + @Override + public void status(int code, String info) { + if (code >= 0) { + LOG.i(info); + } else { + urlInfo.beanList.get(0).name = info; + detailResult.postValue(data); + } + } + + @Override + public void list(String playList) { + urlInfo.urls = playList; + String[] str = playList.split("#"); + List 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); + } + + @Override + public void play(String url) { + } }); } diff --git a/app/src/main/java/com/p2p/P2PClass.java b/app/src/main/java/com/p2p/P2PClass.java new file mode 100644 index 00000000..d7d47d88 --- /dev/null +++ b/app/src/main/java/com/p2p/P2PClass.java @@ -0,0 +1,204 @@ +package com.p2p; + +import java.io.File; +import java.util.concurrent.Executors; + + +public class P2PClass { + private static final String TAG = "P2PClass"; + + public static int port = 8087; + + public String path = null; + + class init extends Thread { + + final String CardPath; + + init(String str) { + this.CardPath = str; + } + + public void run() { + P2PClass p2PClass = P2PClass.this; + p2PClass.path = this.CardPath + "/jpali"; + File file = new File(P2PClass.this.path); + if (!file.exists()) { + file.mkdirs(); + } + P2PClass.port = P2PClass.this.doxstarthttpd("TEST3E63BAAECDAA79BEAA91853490A69F08".getBytes(), this.CardPath.getBytes()); + } + } + + static { + System.loadLibrary("p2p"); + } + + public P2PClass(String str) { + path = str + "/jpali"; + File file = new File(path); + if (!file.exists()) { + file.mkdirs(); + } + port = doxstarthttpd("TEST3E63BAAECDAA79BEAA91853490A69F08".getBytes(), str.getBytes()); + //Executors.newCachedThreadPool().execute(new init(str)); + } + + + private final native void XGFilmCloseFile(long j); + + private final native long XGFilmOpenFile(byte[] bArr); + + private final native int XGFilmReadFile(long j, long j2, int i, byte[] bArr); + + private final native int dosetupload(int i); + + private final native void doxSetP2PPauseUpdate(int i); + + private final native int doxadd(byte[] bArr); + + private final native int doxcheck(byte[] bArr); + + private final native int doxdel(byte[] bArr); + + private final native int doxdelall(); + + private final native int doxdownload(byte[] bArr); + + private final native int doxendhttpd(); + + private final native String doxgetVersion(); + + private final native String doxgethostbynamehook(String str); + + private final native String doxgetlocalAddress(); + + private final native String doxgettaskstat(int i); + + private final native int doxpause(byte[] bArr); + + private final native int doxsave(); + + private final native int doxsetduration(int i); + + private final native int doxstart(byte[] bArr); + + private final native int doxstarthttpd(byte[] bArr, byte[] bArr2); + + private final native int doxterminate(); + + private final native long getdownsize(int i); + + private final native long getfilesize(int i); + + private final native long getlocalfilesize(byte[] bArr); + + private final native int getpercent(); + + private final native long getspeed(int i); + + + public int P2Pdoxstart(byte[] bArr) { + return doxstart(bArr); + } + + public int P2Pdoxdownload(byte[] bArr) { + return doxdownload(bArr); + } + + public int P2Pdoxterminate() { + return doxterminate(); + } + + public int P2Pdosetupload(int i) { + return dosetupload(i); + } + + public int P2Pdoxcheck(byte[] bArr) { + return doxcheck(bArr); + } + + public int P2Pdoxadd(byte[] bArr) { + return doxadd(bArr); + } + + public int P2Pdoxpause(byte[] bArr) { + return doxpause(bArr); + } + + public int P2Pdoxdel(byte[] bArr) { + return doxdel(bArr); + } + + public int P2PdoxdelAll() { + return doxdelall(); + } + + public long P2Pgetspeed(int i) { + return getspeed(i); + } + + public long P2Pgetdownsize(int i) { + return getdownsize(i); + } + + public long P2Pgetfilesize(int i) { + return getfilesize(i); + } + + public int P2Pgetpercent() { + return getpercent(); + } + + public long P2Pgetlocalfilesize(byte[] bArr) { + return getlocalfilesize(bArr); + } + + public long P2Pdosetduration(int i) { + return doxsetduration(i); + } + + public String getServiceAddress() { + return doxgethostbynamehook("xx0.github.com"); + } + + public int P2Pdoxstarthttpd(byte[] bArr, byte[] bArr2) { + return doxstarthttpd(bArr, bArr2); + } + + public int P2Pdoxsave() { + return doxsave(); + } + + public int P2Pdoxendhttpd() { + return doxendhttpd(); + } + + public String getVersion() { + return doxgetVersion(); + } + + public long xGFilmOpenFile(byte[] bArr) { + return XGFilmOpenFile(bArr); + } + + public void xGFilmCloseFile(long j) { + XGFilmCloseFile(j); + } + + public int xGFilmReadFile(long j, long j2, int i, byte[] bArr) { + return XGFilmReadFile(j, j2, i, bArr); + } + + public void setP2PPauseUpdate(int i) { + doxSetP2PPauseUpdate(i); + } + + public String getTouPingUrl() { + return doxgetlocalAddress(); + } + + public String P2Pdoxgettaskstat(int i) { + return doxgettaskstat(i); + } +} \ No newline at end of file diff --git a/player/src/main/jniLibs/armeabi-v7a/libp2p.so b/player/src/main/jniLibs/armeabi-v7a/libp2p.so new file mode 100644 index 00000000..17024664 Binary files /dev/null and b/player/src/main/jniLibs/armeabi-v7a/libp2p.so differ