修复一个数据升级导致的taskType列不存在问题,https://github.com/AriaLyy/Aria/issues/586
This commit is contained in:
laoyuyu
2020-01-09 20:44:01 +08:00
parent 7c4012c021
commit 90e55a0cee
25 changed files with 194 additions and 91 deletions

View File

@@ -258,9 +258,14 @@ final public class M3U8InfoTask implements IInfoTask {
m3U8Entity.method = param.split("=")[1];
} else if (param.startsWith("URI")) {
m3U8Entity.keyUrl = param.split("=")[1].replaceAll("\"", "");
m3U8Entity.keyPath =
new File(mEntity.getFilePath()).getParent() + "/" + CommonUtil.getStrMd5(
m3U8Entity.keyUrl) + ".key";
String keyPath;
if (((M3U8TaskOption) mTaskWrapper.getM3u8Option()).getKeyPath() == null) {
keyPath = new File(mEntity.getFilePath()).getParent() + "/"
+ CommonUtil.getStrMd5(m3U8Entity.keyUrl) + ".key";
} else {
keyPath = ((M3U8TaskOption) mTaskWrapper.getM3u8Option()).getKeyPath();
}
m3U8Entity.keyPath = keyPath;
} else if (param.startsWith("IV")) {
m3U8Entity.iv = param.split("=")[1];
} else if (param.startsWith("KEYFORMAT")) {

View File

@@ -115,6 +115,15 @@ public final class M3U8TaskOption implements ITaskOption {
*/
private boolean ignoreFailureTs = false;
/**
* 密钥文件保存路径
*/
private String keyPath;
public String getKeyPath() {
return keyPath;
}
public boolean isIgnoreFailureTs() {
return ignoreFailureTs;
}

View File

@@ -15,6 +15,8 @@
*/
package com.arialyy.aria.m3u8;
import android.net.Uri;
import android.text.TextUtils;
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.common.SubThreadConfig;
import com.arialyy.aria.core.download.DownloadEntity;
@@ -24,6 +26,7 @@ import com.arialyy.aria.exception.TaskException;
import com.arialyy.aria.http.ConnectionHelp;
import com.arialyy.aria.http.HttpTaskOption;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -46,6 +49,7 @@ import java.util.Set;
public final class M3U8ThreadTaskAdapter extends AbsThreadTaskAdapter {
private final String TAG = "M3U8ThreadTask";
private HttpTaskOption mHttpTaskOption;
private BufferedInputStream is = null;
public M3U8ThreadTaskAdapter(SubThreadConfig config) {
super(config);
@@ -58,19 +62,15 @@ public final class M3U8ThreadTaskAdapter extends AbsThreadTaskAdapter {
return;
}
HttpURLConnection conn = null;
BufferedInputStream is = null;
try {
URL url = ConnectionHelp.handleUrl(getThreadConfig().url, mHttpTaskOption);
conn = ConnectionHelp.handleConnection(url, mHttpTaskOption);
ALog.d(TAG, String.format("分片【%s】开始下载", getThreadRecord().threadId));
ConnectionHelp.setConnectParam(mHttpTaskOption, conn);
conn.setConnectTimeout(getTaskConfig().getConnectTimeOut());
conn.setReadTimeout(getTaskConfig().getIOTimeOut()); //设置读取流的等待时间,必须设置该参数
if (mHttpTaskOption.isChunked()) {
conn.setDoInput(true);
conn.setChunkedStreamingMode(0);
}
conn.connect();
// 传递参数
if (mHttpTaskOption.getRequestEnum() == RequestEnum.POST) {
Map<String, String> params = mHttpTaskOption.getParams();
@@ -89,20 +89,7 @@ public final class M3U8ThreadTaskAdapter extends AbsThreadTaskAdapter {
}
}
int code = conn.getResponseCode();
if (code != HttpURLConnection.HTTP_OK) {
fail(new TaskException(TAG,
String.format("连接错误http错误码%surl%s", code, getThreadConfig().url)),
false);
return;
}
is = new BufferedInputStream(ConnectionHelp.convertInputStream(conn));
if (mHttpTaskOption.isChunked()) {
readChunked(is);
} else if (getThreadConfig().isBlock) {
readDynamicFile(is);
}
handleConn(conn);
} catch (MalformedURLException e) {
fail(new TaskException(TAG,
String.format("分片【%s】下载失败filePath: %s, url: %s", getThreadRecord().threadId,
@@ -129,6 +116,65 @@ public final class M3U8ThreadTaskAdapter extends AbsThreadTaskAdapter {
}
}
private void handleConn(HttpURLConnection conn) throws IOException {
ConnectionHelp.setConnectParam(mHttpTaskOption, conn);
conn.setConnectTimeout(getTaskConfig().getConnectTimeOut());
conn.setReadTimeout(getTaskConfig().getIOTimeOut()); //设置读取流的等待时间,必须设置该参数
conn.connect();
int code = conn.getResponseCode();
if (code == HttpURLConnection.HTTP_OK) {
is = new BufferedInputStream(ConnectionHelp.convertInputStream(conn));
if (mHttpTaskOption.isChunked()) {
readChunked(is);
} else if (getThreadConfig().isBlock) {
readDynamicFile(is);
}
} else if (code == HttpURLConnection.HTTP_MOVED_TEMP
|| code == HttpURLConnection.HTTP_MOVED_PERM
|| code == HttpURLConnection.HTTP_SEE_OTHER
|| code == HttpURLConnection.HTTP_CREATED // 201 跳转
|| code == 307) {
handleUrlReTurn(conn, conn.getHeaderField("Location"));
} else {
fail(new TaskException(TAG,
String.format("连接错误http错误码%surl%s", code, getThreadConfig().url)),
false);
}
conn.disconnect();
}
/**
* 处理30x跳转
*/
private void handleUrlReTurn(HttpURLConnection conn, String newUrl) throws IOException {
ALog.d(TAG, "30x跳转新url为【" + newUrl + "");
if (TextUtils.isEmpty(newUrl) || newUrl.equalsIgnoreCase("null")) {
fail(new AriaIOException(TAG, "下载失败重定向url为空"), false);
return;
}
if (newUrl.startsWith("/")) {
Uri uri = Uri.parse(getThreadConfig().url);
newUrl = uri.getHost() + newUrl;
}
if (!CheckUtil.checkUrl(newUrl)) {
fail(new AriaIOException(TAG, "下载失败重定向url错误"), false);
return;
}
String cookies = conn.getHeaderField("Set-Cookie");
conn.disconnect(); // 关闭上一个连接
URL url = ConnectionHelp.handleUrl(newUrl, mHttpTaskOption);
conn = ConnectionHelp.handleConnection(url, mHttpTaskOption);
conn.setRequestProperty("Cookie", cookies);
if (mHttpTaskOption.isChunked()) {
conn.setDoInput(true);
conn.setChunkedStreamingMode(0);
}
handleConn(conn);
}
/**
* 读取chunked数据
*/