Clean thunder code

pull/137/head
FongMi 3 years ago
parent 2345fe8c33
commit c8ed4ffe2e
  1. 28
      app/src/main/java/com/fongmi/android/tv/bean/Vod.java
  2. 24
      app/src/main/java/com/fongmi/android/tv/model/SiteViewModel.java
  3. 34
      app/src/main/java/com/fongmi/android/tv/player/extractor/Magnet.java
  4. 16
      thunder/src/main/java/com/xunlei/downloadlib/XLDownloadManager.java
  5. 10
      thunder/src/main/java/com/xunlei/downloadlib/XLTaskHelper.java
  6. 12
      thunder/src/main/java/com/xunlei/downloadlib/parameter/BtSubTaskDetail.java
  7. 2
      thunder/src/main/java/com/xunlei/downloadlib/parameter/GetDownloadLibVersion.java
  8. 6
      thunder/src/main/java/com/xunlei/downloadlib/parameter/GetFileName.java
  9. 9
      thunder/src/main/java/com/xunlei/downloadlib/parameter/GetTaskId.java
  10. 13
      thunder/src/main/java/com/xunlei/downloadlib/parameter/MagnetTaskParam.java
  11. 4
      thunder/src/main/java/com/xunlei/downloadlib/parameter/ThunderUrlInfo.java
  12. 24
      thunder/src/main/java/com/xunlei/downloadlib/parameter/TorrentFileInfo.java
  13. 28
      thunder/src/main/java/com/xunlei/downloadlib/parameter/TorrentInfo.java
  14. 96
      thunder/src/main/java/com/xunlei/downloadlib/parameter/XLTaskInfo.java
  15. 4
      thunder/src/main/java/com/xunlei/downloadlib/parameter/XLTaskLocalUrl.java

@ -20,7 +20,6 @@ import org.simpleframework.xml.Text;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@ -87,7 +86,8 @@ public class Vod {
private Site site;
public static List<Vod> arrayFrom(String str) {
Type listType = new TypeToken<List<Vod>>() {}.getType();
Type listType = new TypeToken<List<Vod>>() {
}.getType();
List<Vod> items = new Gson().fromJson(str, listType);
return items == null ? Collections.emptyList() : items;
}
@ -286,10 +286,6 @@ public class Vod {
return episodes;
}
public void setEpisodes(List<Episode> episodes) {
this.episodes = episodes;
}
public boolean isActivated() {
return activated;
}
@ -312,7 +308,7 @@ public class Vod {
for (int i = 0; i < urls.length; i++) {
String[] split = urls[i].split("\\$");
String number = String.format(Locale.getDefault(), "%02d", i + 1);
Episode episode = split.length > 1 ? new Vod.Flag.Episode(split[0].isEmpty() ? number : split[0].trim(), split[1]) : new Vod.Flag.Episode(number, urls[i]);
Episode episode = split.length > 1 ? Episode.create(split[0].isEmpty() ? number : split[0].trim(), split[1]) : Episode.create(number, urls[i]);
if (!getEpisodes().contains(episode)) getEpisodes().add(episode);
}
}
@ -330,17 +326,17 @@ public class Vod {
public Episode find(String remarks) {
int number = Utils.digit(remarks);
if (getEpisodes().size() == 1) return getEpisodes().get(0);
for (Vod.Flag.Episode item : getEpisodes()) if (item.rule1(remarks)) return item;
for (Vod.Flag.Episode item : getEpisodes()) if (item.rule2(number)) return item;
for (Vod.Flag.Episode item : getEpisodes()) if (item.rule3(remarks)) return item;
for (Vod.Flag.Episode item : getEpisodes()) if (item.rule4(remarks)) return item;
for (Episode item : getEpisodes()) if (item.rule1(remarks)) return item;
for (Episode item : getEpisodes()) if (item.rule2(number)) return item;
for (Episode item : getEpisodes()) if (item.rule3(remarks)) return item;
for (Episode item : getEpisodes()) if (item.rule4(remarks)) return item;
return getPosition() != -1 ? getEpisodes().get(getPosition()) : null;
}
public static List<Flag> create(String flag, String name, String url) {
Vod.Flag item = new Vod.Flag(flag);
item.getEpisodes().add(new Vod.Flag.Episode(name, url));
return Arrays.asList(item);
item.getEpisodes().add(Episode.create(name, url));
return List.of(item);
}
@Override
@ -363,11 +359,13 @@ public class Vod {
private final String name;
@SerializedName("url")
private final String url;
private final int number;
private boolean activated;
public static Episode create(String name, String url) {
return new Episode(name, url);
}
public static Episode objectFrom(String str) {
return new Gson().fromJson(str, Episode.class);
}

@ -1,7 +1,6 @@
package com.fongmi.android.tv.model;
import android.net.Uri;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.ArrayMap;
@ -16,19 +15,16 @@ import com.fongmi.android.tv.bean.Result;
import com.fongmi.android.tv.bean.Site;
import com.fongmi.android.tv.bean.Vod;
import com.fongmi.android.tv.player.Source;
import com.fongmi.android.tv.player.extractor.Magnet;
import com.fongmi.android.tv.utils.ResUtil;
import com.fongmi.android.tv.utils.Sniffer;
import com.fongmi.android.tv.utils.Trans;
import com.github.catvod.crawler.Spider;
import com.github.catvod.crawler.SpiderDebug;
import com.github.catvod.net.OkHttp;
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.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -36,6 +32,7 @@ import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
public class SiteViewModel extends ViewModel {
@ -217,19 +214,18 @@ public class SiteViewModel extends ViewModel {
return result;
}
private void checkThunder(List<Vod.Flag> flags) {
private void checkThunder(List<Vod.Flag> flags) throws Exception {
for (Vod.Flag flag : flags) {
List<Vod.Flag.Episode> items = new ArrayList<>();
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;
File folder = Path.thunder(Util.md5(episode.getUrl()));
GetTaskId taskId = XLTaskHelper.get().addThunderTask(episode.getUrl(), folder);
while (XLTaskHelper.get().getTaskInfo(taskId).getTaskStatus() != 2) SystemClock.sleep(10);
List<TorrentFileInfo> medias = XLTaskHelper.get().getTorrentInfo(taskId.getSaveFile()).getMedias();
for (TorrentFileInfo media : medias) items.add(new Vod.Flag.Episode(media.getFileName(), media.getPlayUrl(taskId.getSaveFile())));
if (items.size() > 0) flag.setEpisodes(items);
XLTaskHelper.get().stopTask(taskId);
magnets.add(Magnet.get(episode.getUrl()));
}
for (Future<List<TorrentFileInfo>> future : Executors.newCachedThreadPool().invokeAll(magnets, 3000, 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()));
}
}
}

@ -0,0 +1,34 @@
package com.fongmi.android.tv.player.extractor;
import android.os.SystemClock;
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.List;
import java.util.concurrent.Callable;
public class Magnet implements Callable<List<TorrentFileInfo>> {
private final String url;
public static Magnet get(String url) {
return new Magnet(url);
}
public Magnet(String url) {
this.url = url;
}
@Override
public List<TorrentFileInfo> call() {
GetTaskId taskId = XLTaskHelper.get().addThunderTask(url, Path.thunder(Util.md5(url)));
while (XLTaskHelper.get().getTaskInfo(taskId).getTaskStatus() != 2) SystemClock.sleep(10);
List<TorrentFileInfo> medias = XLTaskHelper.get().getTorrentInfo(taskId.getSaveFile()).getMedias();
XLTaskHelper.get().stopTask(taskId);
return medias;
}
}

@ -136,10 +136,6 @@ public class XLDownloadManager {
loader.setMiUiVersion(str);
}
public void setHttpHeaderProperty(long taskId, String key, String value) {
loader.setHttpHeaderProperty(taskId, key, value);
}
public void getDownloadLibVersion(GetDownloadLibVersion version) {
loader.getDownloadLibVersion(version);
}
@ -168,18 +164,14 @@ public class XLDownloadManager {
return loader.createBtTask(param.mTorrentPath, param.mFilePath, param.mMaxConcurrent, param.mCreateMode, param.mSeqId, taskId);
}
public void getTorrentInfo(String path, TorrentInfo info) {
loader.getTorrentInfo(path, info);
public void getTorrentInfo(TorrentInfo info) {
loader.getTorrentInfo(info.getFile().getAbsolutePath(), info);
}
public void getBtSubTaskInfo(long taskId, int index, BtSubTaskDetail detail) {
loader.getBtSubTaskInfo(taskId, index, detail);
}
public void selectBtSubTask(long taskId, BtIndexSet btIndexSet) {
loader.selectBtSubTask(taskId, btIndexSet);
}
public void deselectBtSubTask(long taskId, BtIndexSet btIndexSet) {
loader.deselectBtSubTask(taskId, btIndexSet);
}
@ -190,8 +182,8 @@ public class XLDownloadManager {
return thunderUrlInfo.mUrl;
}
public int getFileNameFromUrl(String url, GetFileName name) {
return loader.getFileNameFromUrl(url, name);
public void getFileNameFromUrl(String url, GetFileName name) {
loader.getFileNameFromUrl(url, name);
}
public void setSpeedLimit(long min, long max) {

@ -53,7 +53,7 @@ public class XLTaskHelper {
if (TextUtils.isEmpty(fileName)) {
GetFileName getFileName = new GetFileName();
getManager().getFileNameFromUrl(url, getFileName);
fileName = getFileName.getFileName();
fileName = getFileName.mFileName;
taskId.setFileName(fileName);
}
if (url.startsWith("magnet:?")) {
@ -94,8 +94,7 @@ public class XLTaskHelper {
}
public synchronized GetTaskId addTorrentTask(File torrent, File savePath, int index) {
TorrentInfo torrentInfo = new TorrentInfo();
getManager().getTorrentInfo(torrent.getAbsolutePath(), torrentInfo);
TorrentInfo torrentInfo = getTorrentInfo(torrent);
TorrentFileInfo[] fileInfos = torrentInfo.mSubFileInfo;
BtTaskParam taskParam = new BtTaskParam();
taskParam.setCreateMode(1);
@ -122,10 +121,9 @@ public class XLTaskHelper {
return taskId;
}
public synchronized TorrentInfo getTorrentInfo(File file) {
TorrentInfo torrentInfo = new TorrentInfo();
getManager().getTorrentInfo(file.getAbsolutePath(), torrentInfo);
TorrentInfo torrentInfo = new TorrentInfo(file);
getManager().getTorrentInfo(torrentInfo);
return torrentInfo;
}

@ -5,16 +5,4 @@ public class BtSubTaskDetail {
public int mFileIndex;
public boolean mIsSelect;
public XLTaskInfo mTaskInfo = new XLTaskInfo();
public int getFileIndex() {
return mFileIndex;
}
public boolean isSelect() {
return mIsSelect;
}
public XLTaskInfo getTaskInfo() {
return mTaskInfo;
}
}

@ -2,5 +2,5 @@ package com.xunlei.downloadlib.parameter;
public class GetDownloadLibVersion {
public String mVersion = null;
public String mVersion;
}

@ -2,9 +2,5 @@ package com.xunlei.downloadlib.parameter;
public class GetFileName {
private String mFileName;
public String getFileName() {
return this.mFileName;
}
public String mFileName;
}

@ -4,12 +4,9 @@ import java.io.File;
public class GetTaskId {
private long mTaskId;
private File mSavePath;
private String mFileName;
public GetTaskId() {
}
public long mTaskId;
public File mSavePath;
public String mFileName;
public GetTaskId(File savePath) {
this.mSavePath = savePath;

@ -6,15 +6,6 @@ public class MagnetTaskParam {
public String mFilePath;
public String mUrl;
public MagnetTaskParam(String str, String str2, String str3) {
this.mFileName = str;
this.mFilePath = str2;
this.mUrl = str3;
}
public MagnetTaskParam() {
}
public void setUrl(String str) {
this.mUrl = str;
}
@ -26,8 +17,4 @@ public class MagnetTaskParam {
public void setFilePath(String str) {
this.mFilePath = str;
}
public boolean checkMemberVar() {
return this.mFileName != null && this.mFilePath != null && this.mUrl != null;
}
}

@ -3,8 +3,4 @@ package com.xunlei.downloadlib.parameter;
public class ThunderUrlInfo {
public String mUrl;
public String getUrl() {
return mUrl;
}
}

@ -9,36 +9,30 @@ public class TorrentFileInfo {
public boolean isSelected;
public String mFileName;
public String mSubPath;
public long mFileSize;
public int mFileIndex;
public int mRealIndex;
public long mFileSize;
public boolean isSelected() {
return isSelected;
}
public File mFile;
public String getFileName() {
return TextUtils.isEmpty(mFileName) ? "" : mFileName;
}
public String getSubPath() {
return mSubPath;
}
public int getFileIndex() {
return mFileIndex;
}
public int getRealIndex() {
return mRealIndex;
public File getFile() {
return mFile;
}
public long getFileSize() {
return mFileSize;
public TorrentFileInfo file(File file) {
this.mFile = file;
return this;
}
public String getPlayUrl(File file) {
return "torrent://" + file.getAbsolutePath() + "?name=" + getFileName() + "&index=" + getFileIndex();
public String getPlayUrl() {
return "torrent://" + getFile().getAbsolutePath() + "?name=" + getFileName() + "&index=" + getFileIndex();
}
public String getExt() {

@ -2,31 +2,25 @@ package com.xunlei.downloadlib.parameter;
import com.xunlei.downloadlib.Util;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class TorrentInfo {
public int mFileCount;
public String mInfoHash;
public boolean mIsMultiFiles;
public String mMultiFileBaseFolder;
public TorrentFileInfo[] mSubFileInfo;
public String mMultiFileBaseFolder;
public boolean mIsMultiFiles;
public String mInfoHash;
public int mFileCount;
public File mFile;
public int getFileCount() {
return mFileCount;
}
public String getInfoHash() {
return mInfoHash;
}
public boolean isMultiFiles() {
return mIsMultiFiles;
public TorrentInfo(File file) {
this.mFile = file;
}
public String getMultiFileBaseFolder() {
return mMultiFileBaseFolder;
public File getFile() {
return mFile;
}
private TorrentFileInfo[] getSubFileInfo() {
@ -35,7 +29,7 @@ public class TorrentInfo {
public List<TorrentFileInfo> getMedias() {
List<TorrentFileInfo> items = new ArrayList<>();
for (TorrentFileInfo item : getSubFileInfo()) if (Util.isMedia(item.getExt())) items.add(item);
for (TorrentFileInfo item : getSubFileInfo()) if (Util.isMedia(item.getExt())) items.add(item.file(getFile()));
return items;
}
}

@ -74,102 +74,6 @@ public class XLTaskInfo implements Parcelable {
this.mScdnRecvBytes = parcel.readLong();
}
public int getAdditionalResCount() {
return mAdditionalResCount;
}
public long getAdditionalResPeerBytes() {
return mAdditionalResPeerBytes;
}
public long getAdditionalResPeerSpeed() {
return mAdditionalResPeerSpeed;
}
public int getAdditionalResType() {
return mAdditionalResType;
}
public long getAdditionalResVipRecvBytes() {
return mAdditionalResVipRecvBytes;
}
public long getAdditionalResVipSpeed() {
return mAdditionalResVipSpeed;
}
public String getCid() {
return mCid;
}
public long getDownloadSize() {
return mDownloadSize;
}
public long getDownloadSpeed() {
return mDownloadSpeed;
}
public int getErrorCode() {
return mErrorCode;
}
public String getFileName() {
return mFileName;
}
public long getFileSize() {
return mFileSize;
}
public String getGcid() {
return mGcid;
}
public int getInfoLen() {
return mInfoLen;
}
public long getOriginRecvBytes() {
return mOriginRecvBytes;
}
public long getOriginSpeed() {
return mOriginSpeed;
}
public long getP2PRecvBytes() {
return mP2PRecvBytes;
}
public long getP2PSpeed() {
return mP2PSpeed;
}
public long getP2SRecvBytes() {
return mP2SRecvBytes;
}
public long getP2SSpeed() {
return mP2SSpeed;
}
public int getQueryIndexStatus() {
return mQueryIndexStatus;
}
public long getScdnRecvBytes() {
return mScdnRecvBytes;
}
public long getScdnSpeed() {
return mScdnSpeed;
}
public long getTaskId() {
return mTaskId;
}
public int getTaskStatus() {
return mTaskStatus;
}

@ -3,8 +3,4 @@ package com.xunlei.downloadlib.parameter;
public class XLTaskLocalUrl {
public String mStrUrl;
public String getStrUrl() {
return mStrUrl;
}
}

Loading…
Cancel
Save