mirror of https://github.com/FongMi/TV.git
parent
3c1be92da3
commit
899fd1ff25
@ -1,34 +1,57 @@ |
||||
package com.fongmi.android.tv.player.extractor; |
||||
|
||||
import android.net.Uri; |
||||
import android.os.SystemClock; |
||||
|
||||
import com.fongmi.android.tv.player.Source; |
||||
import com.github.catvod.utils.Path; |
||||
import com.github.catvod.utils.Util; |
||||
import com.xunlei.downloadlib.XLTaskHelper; |
||||
import com.xunlei.downloadlib.parameter.GetTaskId; |
||||
|
||||
import java.io.File; |
||||
import java.util.Objects; |
||||
|
||||
public class Thunder implements Source.Extractor { |
||||
|
||||
public Thunder() { |
||||
} |
||||
private GetTaskId taskId; |
||||
|
||||
@Override |
||||
public boolean match(String scheme, String host) { |
||||
return scheme.equalsIgnoreCase("ed2k") || scheme.equalsIgnoreCase("ftp") || scheme.equalsIgnoreCase("thunder") || scheme.equalsIgnoreCase("magnet"); |
||||
return scheme.equals("ed2k") || scheme.equals("ftp") || scheme.equals("torrent"); |
||||
} |
||||
|
||||
@Override |
||||
public String fetch(String url) throws Exception { |
||||
return url; |
||||
Uri uri = Uri.parse(url); |
||||
boolean torrent = "torrent".equals(uri.getScheme()); |
||||
return torrent ? fetchTorrent(uri) : fetchThunder(url); |
||||
} |
||||
|
||||
@Override |
||||
public void stop() { |
||||
private String fetchTorrent(Uri uri) { |
||||
File torrent = new File(uri.getPath()); |
||||
String name = uri.getQueryParameter("name"); |
||||
int index = Integer.parseInt(uri.getQueryParameter("index")); |
||||
taskId = XLTaskHelper.get().addTorrentTask(torrent, Objects.requireNonNull(torrent.getParentFile()), index); |
||||
while (XLTaskHelper.get().getBtSubTaskInfo(taskId, index).mTaskInfo.mTaskStatus == 0) SystemClock.sleep(10); |
||||
return XLTaskHelper.get().getLocalUrl(new File(torrent.getParent(), name)); |
||||
} |
||||
|
||||
private String fetchThunder(String url) { |
||||
File folder = Path.thunder(Util.md5(url)); |
||||
taskId = XLTaskHelper.get().addThunderTask(url, folder); |
||||
return XLTaskHelper.get().getLocalUrl(taskId.getSaveFile()); |
||||
} |
||||
|
||||
@Override |
||||
public void destroy() { |
||||
|
||||
public void stop() { |
||||
if (taskId == null) return; |
||||
XLTaskHelper.get().deleteTask(taskId); |
||||
taskId = null; |
||||
} |
||||
|
||||
@Override |
||||
public void release() { |
||||
|
||||
public void exit() { |
||||
XLTaskHelper.get().release(); |
||||
} |
||||
} |
||||
|
||||
@ -1,19 +1,42 @@ |
||||
package com.xunlei.downloadlib.parameter; |
||||
|
||||
import java.io.File; |
||||
|
||||
public class GetTaskId { |
||||
|
||||
private long mTaskId; |
||||
private String mSavePath; |
||||
private File mSavePath; |
||||
private String mFileName; |
||||
|
||||
public long getTaskId() { |
||||
return this.mTaskId; |
||||
public GetTaskId() { |
||||
} |
||||
|
||||
public GetTaskId(File savePath) { |
||||
this.mSavePath = savePath; |
||||
} |
||||
|
||||
public void setSavePath(String savePath) { |
||||
public GetTaskId(File savePath, String fileName) { |
||||
this.mSavePath = savePath; |
||||
this.mFileName = fileName; |
||||
} |
||||
|
||||
public long getTaskId() { |
||||
return this.mTaskId; |
||||
} |
||||
|
||||
public String getSavePath() { |
||||
public File getSavePath() { |
||||
return mSavePath; |
||||
} |
||||
|
||||
public String getFileName() { |
||||
return mFileName; |
||||
} |
||||
|
||||
public void setFileName(String fileName) { |
||||
this.mFileName = fileName; |
||||
} |
||||
|
||||
public File getSaveFile() { |
||||
return new File(getSavePath(), getFileName()); |
||||
} |
||||
} |
||||
|
||||
Loading…
Reference in new issue