Support parse magnet and thunder

pull/137/head
FongMi 3 years ago
parent 0a75c6e60e
commit 9aff6b1e00
  1. 4
      app/src/main/java/com/fongmi/android/tv/bean/Vod.java
  2. 26
      app/src/main/java/com/fongmi/android/tv/model/SiteViewModel.java
  3. 6
      app/src/main/java/com/fongmi/android/tv/utils/Sniffer.java
  4. 5
      thunder/src/main/java/com/xunlei/downloadlib/XLTaskHelper.java
  5. 41
      thunder/src/main/java/com/xunlei/downloadlib/parameter/TorrentFileInfo.java

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

@ -18,11 +18,15 @@ import com.fongmi.android.tv.player.Source;
import com.fongmi.android.tv.utils.ResUtil;
import com.fongmi.android.tv.utils.Sniffer;
import com.fongmi.android.tv.utils.Trans;
import com.fongmi.android.tv.utils.Utils;
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.TorrentFileInfo;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -92,7 +96,7 @@ public class SiteViewModel extends ViewModel {
} else {
ArrayMap<String, String> params = new ArrayMap<>();
if (site.getType() == 1 && !extend.isEmpty()) params.put("f", App.gson().toJson(extend));
else if (site.getType() == 4) params.put("ext", Utils.getBase64(App.gson().toJson(extend)));
else if (site.getType() == 4) params.put("ext", Util.base64(App.gson().toJson(extend)));
params.put("ac", site.getType() == 0 ? "videolist" : "detail");
params.put("t", tid);
params.put("pg", page);
@ -113,6 +117,7 @@ public class SiteViewModel extends ViewModel {
ApiConfig.get().setRecent(site);
Result result = Result.fromJson(detailContent);
if (!result.getList().isEmpty()) result.getList().get(0).setVodFlags();
if (!result.getList().isEmpty()) checkThunder(result);
return result;
} else if (key.equals("push_agent")) {
Vod vod = new Vod();
@ -129,6 +134,7 @@ public class SiteViewModel extends ViewModel {
SpiderDebug.log(body);
Result result = site.getType() == 0 ? Result.fromXml(body) : Result.fromJson(body);
if (!result.getList().isEmpty()) result.getList().get(0).setVodFlags();
if (!result.getList().isEmpty()) checkThunder(result);
return result;
}
});
@ -208,6 +214,22 @@ public class SiteViewModel extends ViewModel {
return result;
}
private void checkThunder(Result result) {
for (Vod.Flag flag : result.getList().get(0).getVodFlags()) {
List<Vod.Flag.Episode> items = new ArrayList<>();
for (Vod.Flag.Episode episode : flag.getEpisodes()) {
String scheme = Util.scheme(episode.getUrl());
if (!scheme.equals("magnet") && !scheme.equals("thunder")) continue;
File torrent = Path.thunder(XLTaskHelper.get().getFileName(episode.getUrl()));
long taskId = XLTaskHelper.get().addThunderTask(episode.getUrl(), Path.thunder().getAbsolutePath(), torrent.getName());
while (XLTaskHelper.get().getTaskInfo(taskId).getTaskStatus() == 2) XLTaskHelper.get().stopTask(taskId);
TorrentFileInfo[] infoArray = XLTaskHelper.get().getTorrentInfo(torrent).getSubFileInfo();
for (TorrentFileInfo info : infoArray) if (Sniffer.isMedia(info.getExt())) items.add(new Vod.Flag.Episode(info.getFileName(), info.getPlayUrl(torrent)));
if (items.size() > 0) flag.setEpisodes(items);
}
}
}
private void post(Site site, Result result) {
if (result.getList().isEmpty()) return;
for (Vod vod : result.getList()) vod.setSite(site);

@ -19,6 +19,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> VIDEO = Arrays.asList("avi", "flv", "mkv", "mov", "mp4", "mpeg", "mpe", "mpg", "wmv");
public static final List<String> AUDIO = Arrays.asList("aac", "ape", "flac", "mp3", "m4a", "ogg");
private static boolean matchOrContain(String url) {
for (String regex : getRegex(Uri.parse(url))) return Pattern.compile(regex).matcher(url).find() || url.contains(regex);
@ -30,6 +32,10 @@ public class Sniffer {
return false;
}
public static boolean isMedia(String ext) {
return VIDEO.contains(ext) || AUDIO.contains(ext);
}
public static boolean isVideoFormat(String url) {
return isVideoFormat(url, new HashMap<>());
}

@ -23,6 +23,7 @@ import com.xunlei.downloadlib.parameter.XLConstant;
import com.xunlei.downloadlib.parameter.XLTaskInfo;
import com.xunlei.downloadlib.parameter.XLTaskLocalUrl;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -156,9 +157,9 @@ public class XLTaskHelper {
return getFileName.getFileName();
}
public synchronized TorrentInfo getTorrentInfo(String torrentPath) {
public synchronized TorrentInfo getTorrentInfo(File file) {
TorrentInfo torrentInfo = new TorrentInfo();
downloadManager.getTorrentInfo(torrentPath, torrentInfo);
downloadManager.getTorrentInfo(file.getAbsolutePath(), torrentInfo);
return torrentInfo;
}

@ -2,52 +2,43 @@ package com.xunlei.downloadlib.parameter;
import android.text.TextUtils;
import java.io.File;
public class TorrentFileInfo {
public int mFileIndex;
public boolean isSelected;
public String mFileName;
public long mFileSize;
public int mRealIndex;
public String mSubPath;
public String playUrl;
public String hash;
public String torrentPath;
public boolean isSelected;
public int mFileIndex;
public int mRealIndex;
public long mFileSize;
public int getFileIndex() {
return mFileIndex;
public boolean isSelected() {
return isSelected;
}
public String getFileName() {
return TextUtils.isEmpty(mFileName) ? "" : mFileName;
}
public long getFileSize() {
return mFileSize;
}
public int getRealIndex() {
return mRealIndex;
}
public String getSubPath() {
return mSubPath;
}
public String getPlayUrl() {
return playUrl;
public int getFileIndex() {
return mFileIndex;
}
public String getHash() {
return hash;
public int getRealIndex() {
return mRealIndex;
}
public String getTorrentPath() {
return torrentPath;
public long getFileSize() {
return mFileSize;
}
public boolean isSelected() {
return isSelected;
public String getPlayUrl(File file) {
return "torrent://" + file.getAbsolutePath() + "/" + getFileIndex();
}
public String getExt() {

Loading…
Cancel
Save