Fix thunder bug

pull/137/head
FongMi 3 years ago
parent e4384a8553
commit 2d6b4e2643
  1. 4
      app/src/main/java/com/fongmi/android/tv/bean/Vod.java
  2. 17
      app/src/main/java/com/fongmi/android/tv/model/SiteViewModel.java
  3. 13
      app/src/main/java/com/fongmi/android/tv/player/extractor/Magnet.java
  4. 6
      app/src/main/java/com/fongmi/android/tv/player/extractor/Thunder.java
  5. 8
      app/src/main/java/com/fongmi/android/tv/utils/Sniffer.java
  6. 6
      thunder/src/main/java/com/xunlei/downloadlib/XLDownloadManager.java
  7. 50
      thunder/src/main/java/com/xunlei/downloadlib/XLTaskHelper.java
  8. 4
      thunder/src/main/java/com/xunlei/downloadlib/parameter/GetFileName.java
  9. 8
      thunder/src/main/java/com/xunlei/downloadlib/parameter/GetTaskId.java

@ -286,6 +286,10 @@ public class Vod {
return episodes;
}
public void setEpisodes(List<Episode> episodes) {
this.episodes = episodes;
}
public boolean isActivated() {
return activated;
}

@ -23,7 +23,6 @@ import com.github.catvod.crawler.Spider;
import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Util;
import com.xunlei.downloadlib.parameter.TorrentFileInfo;
import java.util.ArrayList;
import java.util.Arrays;
@ -217,16 +216,12 @@ public class SiteViewModel extends ViewModel {
private void checkThunder(List<Vod.Flag> flags) throws Exception {
for (Vod.Flag flag : flags) {
List<Magnet> magnets = new ArrayList<>();
for (Vod.Flag.Episode episode : flag.getEpisodes()) {
String scheme = Util.scheme(episode.getUrl());
if (!scheme.equals("magnet") && !scheme.equals("thunder")) continue;
magnets.add(Magnet.get(episode.getUrl()));
}
for (Future<List<TorrentFileInfo>> future : Executors.newCachedThreadPool().invokeAll(magnets, 5000, TimeUnit.MILLISECONDS)) {
List<TorrentFileInfo> files = future.get();
if (files.size() > 0) flag.getEpisodes().clear();
for (TorrentFileInfo file : files) flag.getEpisodes().add(Vod.Flag.Episode.create(file.getFileName(), file.getPlayUrl()));
}
List<Vod.Flag.Episode> items = new ArrayList<>();
for (Vod.Flag.Episode episode : flag.getEpisodes()) if (Sniffer.isThunder(episode.getUrl())) magnets.add(Magnet.get(episode.getUrl()));
ExecutorService executor = Executors.newCachedThreadPool();
for (Future<List<Vod.Flag.Episode>> future : executor.invokeAll(magnets, 15, TimeUnit.SECONDS)) items.addAll(future.get());
if (items.size() > 0) flag.setEpisodes(items);
executor.shutdownNow();
}
}

@ -2,16 +2,18 @@ package com.fongmi.android.tv.player.extractor;
import android.os.SystemClock;
import com.fongmi.android.tv.bean.Vod;
import com.github.catvod.utils.Path;
import com.github.catvod.utils.Util;
import com.xunlei.downloadlib.XLTaskHelper;
import com.xunlei.downloadlib.parameter.GetTaskId;
import com.xunlei.downloadlib.parameter.TorrentFileInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
public class Magnet implements Callable<List<TorrentFileInfo>> {
public class Magnet implements Callable<List<Vod.Flag.Episode>> {
private final String url;
@ -24,11 +26,14 @@ public class Magnet implements Callable<List<TorrentFileInfo>> {
}
@Override
public List<TorrentFileInfo> call() {
GetTaskId taskId = XLTaskHelper.get().addThunderTask(url, Path.thunder(Util.md5(url)));
public List<Vod.Flag.Episode> call() {
List<Vod.Flag.Episode> episodes = new ArrayList<>();
GetTaskId taskId = XLTaskHelper.get().parse(url, Path.thunder(Util.md5(url)));
if (!taskId.getRealUrl().startsWith("magnet")) return List.of(Vod.Flag.Episode.create(taskId.getFileName(), taskId.getRealUrl()));
while (XLTaskHelper.get().getTaskInfo(taskId).getTaskStatus() != 2) SystemClock.sleep(10);
List<TorrentFileInfo> medias = XLTaskHelper.get().getTorrentInfo(taskId.getSaveFile()).getMedias();
for (TorrentFileInfo media : medias) episodes.add(Vod.Flag.Episode.create(media.getFileName(), media.getPlayUrl()));
XLTaskHelper.get().stopTask(taskId);
return medias;
return episodes;
}
}

@ -30,14 +30,14 @@ public class Thunder implements Source.Extractor {
}
private String addTorrentTask(Uri uri) {
File file = new File(uri.getPath());
File torrent = new File(uri.getPath());
String name = uri.getQueryParameter("name");
int index = Integer.parseInt(uri.getQueryParameter("index"));
taskId = XLTaskHelper.get().addTorrentTask(file, Objects.requireNonNull(file.getParentFile()), index);
taskId = XLTaskHelper.get().addTorrentTask(torrent, Objects.requireNonNull(torrent.getParentFile()), index);
while (true) {
XLTaskInfo taskInfo = XLTaskHelper.get().getBtSubTaskInfo(taskId, index).mTaskInfo;
if (taskInfo.mTaskStatus == 3) App.post(() -> Notify.show(taskInfo.getErrorMsg()));
if (taskInfo.mTaskStatus != 0) return XLTaskHelper.get().getLocalUrl(new File(file.getParent(), name));
if (taskInfo.mTaskStatus != 0) return XLTaskHelper.get().getLocalUrl(new File(torrent.getParent(), name));
else SystemClock.sleep(50);
}
}

@ -6,6 +6,7 @@ import android.text.TextUtils;
import com.fongmi.android.tv.api.ApiConfig;
import com.fongmi.android.tv.bean.Rule;
import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.utils.Util;
import java.util.ArrayList;
import java.util.Arrays;
@ -19,7 +20,8 @@ public class Sniffer {
public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
public static final Pattern RULE = Pattern.compile("http((?!http).){12,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)\\?.*|http((?!http).){12,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)|http((?!http).)*?video/tos*");
public static final List<String> PUSH = Arrays.asList("http", "https", "smb", "ftp", "ed2k", "magnet", "thunder");
public static final List<String> PUSH = Arrays.asList("http", "https", "smb", "thunder", "magnet", "ed2k", "ftp");
public static final List<String> THUNDER = Arrays.asList("thunder", "magnet", "ed2k", "ftp");
private static boolean matchOrContain(String url) {
for (String regex : getRegex(Uri.parse(url))) return Pattern.compile(regex).matcher(url).find() || url.contains(regex);
@ -35,6 +37,10 @@ public class Sniffer {
return PUSH.contains(uri.getScheme());
}
public static boolean isThunder(String url) {
return THUNDER.contains(Util.scheme(url));
}
public static boolean isVideoFormat(String url) {
return isVideoFormat(url, new HashMap<>());
}

@ -182,8 +182,10 @@ public class XLDownloadManager {
return thunderUrlInfo.mUrl;
}
public void getFileNameFromUrl(String url, GetFileName name) {
loader.getFileNameFromUrl(url, name);
public String getFileNameFromUrl(String url) {
GetFileName getFileName = new GetFileName();
loader.getFileNameFromUrl(url, getFileName);
return getFileName.getFileName();
}
public void setSpeedLimit(long min, long max) {

@ -1,13 +1,10 @@
package com.xunlei.downloadlib;
import android.text.TextUtils;
import com.github.catvod.utils.Path;
import com.xunlei.downloadlib.parameter.BtIndexSet;
import com.xunlei.downloadlib.parameter.BtSubTaskDetail;
import com.xunlei.downloadlib.parameter.BtTaskParam;
import com.xunlei.downloadlib.parameter.EmuleTaskParam;
import com.xunlei.downloadlib.parameter.GetFileName;
import com.xunlei.downloadlib.parameter.GetTaskId;
import com.xunlei.downloadlib.parameter.MagnetTaskParam;
import com.xunlei.downloadlib.parameter.P2spTaskParam;
@ -43,27 +40,30 @@ public class XLTaskHelper {
return manager = manager == null ? new XLDownloadManager() : manager;
}
public synchronized GetTaskId addThunderTask(String url, File savePath) {
return addThunderTask(url, savePath, null);
private GetTaskId startTask(GetTaskId taskId, int index) {
getManager().startTask(taskId.getTaskId());
getManager().setTaskGsState(taskId.getTaskId(), index, 2);
return taskId;
}
public synchronized GetTaskId addThunderTask(String url, File savePath, String fileName) {
GetTaskId taskId = new GetTaskId(savePath, fileName);
public synchronized GetTaskId parse(String url, File savePath) {
if (url.startsWith("thunder://")) url = getManager().parserThunderUrl(url);
if (TextUtils.isEmpty(fileName)) {
GetFileName getFileName = new GetFileName();
getManager().getFileNameFromUrl(url, getFileName);
fileName = getFileName.mFileName;
taskId.setFileName(fileName);
}
if (url.startsWith("magnet:?")) {
MagnetTaskParam param = new MagnetTaskParam();
param.setFilePath(savePath.getAbsolutePath());
param.setFileName(fileName);
param.setUrl(url);
int code = getManager().createBtMagnetTask(param, taskId);
if (code != XLConstant.XLErrorCode.NO_ERROR) return taskId;
} else if (url.startsWith("ftp://")) {
String fileName = getManager().getFileNameFromUrl(url);
GetTaskId taskId = new GetTaskId(savePath, fileName, url);
if (!url.startsWith("magnet:?")) return taskId;
MagnetTaskParam param = new MagnetTaskParam();
param.setFilePath(savePath.getAbsolutePath());
param.setFileName(fileName);
param.setUrl(url);
int code = getManager().createBtMagnetTask(param, taskId);
if (code != XLConstant.XLErrorCode.NO_ERROR) return taskId;
return startTask(taskId, 0);
}
public synchronized GetTaskId addThunderTask(String url, File savePath) {
String fileName = getManager().getFileNameFromUrl(url);
GetTaskId taskId = new GetTaskId(savePath, fileName, url);
if (url.startsWith("ftp://")) {
P2spTaskParam param = new P2spTaskParam();
param.setFilePath(savePath.getAbsolutePath());
param.setSeqId(getSeq().incrementAndGet());
@ -88,9 +88,7 @@ public class XLTaskHelper {
int code = getManager().createEmuleTask(param, taskId);
if (code != XLConstant.XLErrorCode.NO_ERROR) return taskId;
}
getManager().startTask(taskId.getTaskId());
getManager().setTaskGsState(taskId.getTaskId(), 0, 2);
return taskId;
return startTask(taskId, 0);
}
public synchronized GetTaskId addTorrentTask(File torrent, File savePath, int index) {
@ -116,9 +114,7 @@ public class XLTaskHelper {
for (int i = 0; i < list.size(); i++) btIndexSet.mIndexSet[i] = list.get(i);
getManager().deselectBtSubTask(taskId.getTaskId(), btIndexSet);
}
getManager().startTask(taskId.getTaskId());
getManager().setTaskGsState(taskId.getTaskId(), index, 2);
return taskId;
return startTask(taskId, index);
}
public synchronized TorrentInfo getTorrentInfo(File file) {

@ -3,4 +3,8 @@ package com.xunlei.downloadlib.parameter;
public class GetFileName {
public String mFileName;
public String getFileName() {
return mFileName;
}
}

@ -7,14 +7,16 @@ public class GetTaskId {
public long mTaskId;
public File mSavePath;
public String mFileName;
public String mRealUrl;
public GetTaskId(File savePath) {
this.mSavePath = savePath;
}
public GetTaskId(File savePath, String fileName) {
public GetTaskId(File savePath, String fileName, String realUrl) {
this.mSavePath = savePath;
this.mFileName = fileName;
this.mRealUrl = realUrl;
}
public long getTaskId() {
@ -29,8 +31,8 @@ public class GetTaskId {
return mFileName;
}
public void setFileName(String fileName) {
this.mFileName = fileName;
public String getRealUrl() {
return mRealUrl;
}
public File getSaveFile() {

Loading…
Cancel
Save