Skip to content
Permalink
Browse files

fix bug fix bug #595

修复一个数据升级导致的taskType列不存在问题,#586
  • Loading branch information
AriaLyy committed Jan 9, 2020
1 parent 7c4012c commit 90e55a0ceec86681c0691474ba738a2001e7e0f2
Showing with 194 additions and 91 deletions.
  1. +17 −0 Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Option.java
  2. +2 −1 Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  3. +3 −2 Aria/src/main/java/com/arialyy/aria/core/queue/DGroupTaskQueue.java
  4. +2 −1 DEV_LOG.md
  5. +2 −1 FtpComponent/src/main/java/com/arialyy/aria/ftp/download/FtpDGLoader.java
  6. +3 −0 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java
  7. +1 −1 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoader.java
  8. +2 −2 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java
  9. +8 −3 M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8InfoTask.java
  10. +9 −0 M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8TaskOption.java
  11. +65 −19 M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8ThreadTaskAdapter.java
  12. +0 −3 PublicComponent/src/main/java/com/arialyy/aria/core/common/AbsNormalEntity.java
  13. +20 −16 PublicComponent/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  14. +7 −1 PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoader.java
  15. +1 −3 PublicComponent/src/main/java/com/arialyy/aria/core/group/AbsGroupLoaderUtil.java
  16. +1 −0 PublicComponent/src/main/java/com/arialyy/aria/core/inf/IThreadStateManager.java
  17. +1 −4 PublicComponent/src/main/java/com/arialyy/aria/core/loader/AbsNormalLoaderUtil.java
  18. +8 −6 PublicComponent/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
  19. +11 −9 PublicComponent/src/main/java/com/arialyy/aria/orm/SqlHelper.java
  20. +16 −14 README.md
  21. +4 −2 app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
  22. +3 −1 app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodModule.java
  23. +1 −0 app/src/main/java/com/arialyy/simple/core/download/mutil/DownloadAdapter.java
  24. +6 −1 app/src/main/java/com/arialyy/simple/core/download/mutil/MultiTaskActivity.java
  25. +1 −1 build.gradle
@@ -15,10 +15,12 @@
*/
package com.arialyy.aria.core.download.m3u8;

import android.text.TextUtils;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
import com.arialyy.aria.core.processor.IKeyUrlConverter;
import com.arialyy.aria.core.processor.ITsMergeHandler;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.ComponentUtil;

@@ -34,12 +36,27 @@
private IBandWidthUrlConverter bandWidthUrlConverter;
private IKeyUrlConverter keyUrlConverter;
private boolean ignoreFailureTs = false;
private String keyPath;

M3U8Option() {
super();
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_M3U8);
}

/**
* 设置密钥文件的保存路径
*
* @param keyPath 密钥文件的保存路径
*/
public OP setKeyPath(String keyPath) {
if (TextUtils.isEmpty(keyPath)) {
ALog.e(TAG, "密钥文件保存路径为空");
return (OP) this;
}
this.keyPath = keyPath;
return (OP) this;
}

/**
* 忽略下载失败的ts切片,即使有失败的切片,下载完成后也要合并所有切片,并进入complete回调
*/
@@ -33,6 +33,7 @@
import com.arialyy.aria.core.task.UploadTask;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;
import java.util.List;

@@ -45,7 +46,7 @@
final int TYPE_DG_QUEUE = 2;
final int TYPE_U_QUEUE = 3;

private final String TAG = "AbsTaskQueue";
private final String TAG = CommonUtil.getClassName(this);
BaseCachePool<TASK> mCachePool;
BaseExecutePool<TASK> mExecutePool;

@@ -24,6 +24,7 @@
import com.arialyy.aria.core.scheduler.TaskSchedulers;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;

/**
* Created by AriaL on 2017/6/29. 任务组下载队列
@@ -32,7 +33,7 @@
extends AbsTaskQueue<DownloadGroupTask, DGTaskWrapper> {
private static volatile DGroupTaskQueue INSTANCE = null;

private final String TAG = "DownloadGroupTaskQueue";
private final String TAG = CommonUtil.getClassName(this);

public static DGroupTaskQueue getInstance() {
if (INSTANCE == null) {
@@ -57,7 +58,7 @@ public void maxTaskNum(DGMaxNumEvent event) {
}

@Override public int getMaxTaskNum() {
return AriaConfig.getInstance().getDConfig().getMaxTaskNum();
return AriaConfig.getInstance().getDGConfig().getMaxTaskNum();
}

@Override public DownloadGroupTask createTask(DGTaskWrapper wrapper) {
@@ -1,12 +1,13 @@
## 开发日志
+ v_3.8.3
+ v_3.8.3 (2020/1/9)
- fix bug https://github.com/AriaLyy/Aria/issues/573
- android P适配 https://github.com/AriaLyy/Aria/issues/581
- 添加ftp服务器标志 https://github.com/AriaLyy/Aria/issues/580
- 重构loader模块,让loader模块的代码更加清晰,去除一些不必要的线程创建
- 修复ftp上传完成后,删除服务器端的文件,无法重新下载的问题
- 增加获取执行中的任务api,详情见:https://aria.laoyuyu.me/aria_doc/api/task_list.html
- 增加获取剩余时间的api,详情见:https://aria.laoyuyu.me/aria_doc/start/task_explain.html
- fix bug https://github.com/AriaLyy/Aria/issues/595
+ v_3.8.1 (2019/12/22)
- 修复一个表创建失败的问题 https://github.com/AriaLyy/Aria/issues/570
- 修复一个非分块模式下导致下载失败的问题 https://github.com/AriaLyy/Aria/issues/571
@@ -80,7 +80,8 @@ private void startSub() {
}

@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
getListener().onFail(needRetry, e);
//getListener().onFail(needRetry, e);
fail(e, needRetry);
}
});
}
@@ -89,6 +89,9 @@
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!mPool.isShutdown()){
mPool.shutdown();
}
} else {
for (DTaskWrapper wrapper : wrapper.getSubTaskWrapper()) {
cloneHeader(wrapper);
@@ -66,7 +66,7 @@ private void startSub() {
}

@Override public void onFail(AbsEntity entity, BaseException e, boolean needRetry) {
getListener().onFail(needRetry, e);
fail(e, needRetry);
}
});
}
@@ -24,7 +24,6 @@
import com.arialyy.aria.http.ConnectionHelp;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile;
import com.arialyy.aria.util.FileUtil;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -112,7 +111,7 @@
new BufferedRandomAccessFile(getThreadConfig().tempFile, "rwd",
getTaskConfig().getBuffSize());
//设置每条线程写入文件的位置
if (getThreadRecord().startLocation > 0){
if (getThreadRecord().startLocation > 0) {
file.seek(getThreadRecord().startLocation);
}
readNormal(is, file);
@@ -199,6 +198,7 @@ private void readDynamicFile(InputStream is) {
fos = new FileOutputStream(getThreadConfig().tempFile, true);
foc = fos.getChannel();
fic = Channels.newChannel(is);

ByteBuffer bf = ByteBuffer.allocate(getTaskConfig().getBuffSize());
//如果要通过 Future 的 cancel 方法取消正在运行的任务,那么该任务必定是可以 对线程中断做出响应 的任务。

@@ -258,9 +258,14 @@ private void getKeyInfo(String line) {
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")) {
@@ -115,6 +115,15 @@
*/
private boolean ignoreFailureTs = false;

/**
* 密钥文件保存路径
*/
private String keyPath;

public String getKeyPath() {
return keyPath;
}

public boolean isIgnoreFailureTs() {
return ignoreFailureTs;
}
@@ -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.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 @@
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 M3U8ThreadTaskAdapter(SubThreadConfig config) {
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 M3U8ThreadTaskAdapter(SubThreadConfig config) {
}
}

int code = conn.getResponseCode();
if (code != HttpURLConnection.HTTP_OK) {
fail(new TaskException(TAG,
String.format("连接错误,http错误码:%s,url:%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 M3U8ThreadTaskAdapter(SubThreadConfig config) {
}
}

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错误码:%s,url:%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数据
*/
@@ -51,9 +51,6 @@
*/
private int taskType;

@Override public int getTaskType() {
return taskType;
}

public void setTaskType(int taskType) {
this.taskType = taskType;
@@ -78,22 +78,26 @@ public M3U8Entity getM3U8Entity() {
return getUrl();
}

//@Override public int getTaskType() {
// int type;
// if (TextUtils.isEmpty(getUrl())) {
// type = ITaskWrapper.ERROR;
// } else if (getUrl().startsWith("ftp")) {
// type = ITaskWrapper.D_FTP;
// } else {
// M3U8Entity temp = getM3U8Entity();
// if (temp == null) {
// type = ITaskWrapper.D_HTTP;
// } else {
// type = temp.isLive() ? ITaskWrapper.M3U8_LIVE : ITaskWrapper.M3U8_VOD;
// }
// }
// return type;
//}
@Override public int getTaskType() {
int type;
if (TextUtils.isEmpty(getUrl())) {
type = ITaskWrapper.ERROR;
} else if (getUrl().startsWith("http")) {
type = ITaskWrapper.D_HTTP;
} else if (getUrl().startsWith("ftp")) {
type = ITaskWrapper.D_FTP;
} else if (getUrl().startsWith("sftp")) {
type = ITaskWrapper.D_SFTP;
} else {
M3U8Entity temp = getM3U8Entity();
if (temp == null) {
type = ITaskWrapper.D_HTTP;
} else {
type = temp.isLive() ? ITaskWrapper.M3U8_LIVE : ITaskWrapper.M3U8_VOD;
}
}
return type;
}

public DownloadEntity() {
}

0 comments on commit 90e55a0

Please sign in to comment.
You can’t perform that action at this time.