修复m3u8、http上传记录重复的问题

pull/617/head
laoyuyu 5 years ago
parent 75ff995d81
commit 9f673503c1
  1. 7
      HttpComponent/src/main/java/com/arialyy/aria/http/HttpRecordAdapter.java
  2. 7
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/BaseM3U8Loader.java
  3. 11
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8RecordAdapter.java
  4. 9
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/M3U8LiveLoader.java
  5. 1
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/live/M3U8LiveUtil.java
  6. 3
      PublicComponent/src/main/java/com/arialyy/aria/core/common/AbsRecordHandlerAdapter.java
  7. 1
      PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHandler.java
  8. 5
      PublicComponent/src/main/java/com/arialyy/aria/core/inf/IRecordHandlerAdapter.java
  9. 29
      PublicComponent/src/main/java/com/arialyy/aria/util/RecordUtil.java
  10. 13
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveDLoadActivity.java

@ -36,6 +36,13 @@ public class HttpRecordAdapter extends AbsRecordHandlerAdapter {
super(wrapper);
}
@Override public void onPre() {
super.onPre();
if (getWrapper().getRequestType() == ITaskWrapper.U_HTTP){
RecordUtil.delTaskRecord(getEntity().getFilePath(), IRecordHandler.TYPE_UPLOAD);
}
}
@Override public void handlerTaskRecord(TaskRecord record) {
RecordHelper helper = new RecordHelper(getWrapper(), record);
if (record.isBlock) {

@ -15,6 +15,7 @@
*/
package com.arialyy.aria.m3u8;
import com.arialyy.aria.core.common.RecordHandler;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.M3U8Entity;
@ -127,8 +128,10 @@ public abstract class BaseM3U8Loader extends AbsLoader {
}
@Override protected IRecordHandler getRecordHandler(AbsTaskWrapper wrapper) {
return null;
RecordHandler handler = new RecordHandler(wrapper);
M3U8RecordAdapter adapter = new M3U8RecordAdapter((DTaskWrapper) wrapper);
handler.setAdapter(adapter);
return handler;
}
protected DownloadEntity getEntity() {

@ -21,8 +21,10 @@ import com.arialyy.aria.core.common.AbsRecordHandlerAdapter;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.M3U8Entity;
import com.arialyy.aria.core.inf.IRecordHandler;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.RecordUtil;
import java.io.File;
import java.util.ArrayList;
@ -33,11 +35,18 @@ import java.util.ArrayList;
public class M3U8RecordAdapter extends AbsRecordHandlerAdapter {
private M3U8TaskOption mOption;
public M3U8RecordAdapter(DTaskWrapper wrapper) {
M3U8RecordAdapter(DTaskWrapper wrapper) {
super(wrapper);
mOption = (M3U8TaskOption) wrapper.getM3u8Option();
}
@Override public void onPre() {
super.onPre();
if (getWrapper().getRequestType() == ITaskWrapper.M3U8_LIVE){
RecordUtil.delTaskRecord(getEntity().getFilePath(), IRecordHandler.TYPE_DOWNLOAD);
}
}
/**
* 不处理live的记录
*/

@ -52,19 +52,18 @@ public class M3U8LiveLoader extends BaseM3U8Loader {
private static final int EXEC_MAX_NUM = 4;
private Handler mStateHandler;
private ArrayBlockingQueue<Long> mFlagQueue = new ArrayBlockingQueue<>(EXEC_MAX_NUM);
private LiveStateManager mManager;
private ReentrantLock LOCK = new ReentrantLock();
private Condition mCondition = LOCK.newCondition();
private LinkedBlockingQueue<String> mPeerQueue = new LinkedBlockingQueue<>();
public M3U8LiveLoader(M3U8Listener listener, DTaskWrapper wrapper) {
M3U8LiveLoader(M3U8Listener listener, DTaskWrapper wrapper) {
super(listener, wrapper);
}
@Override protected IThreadState createStateManager(Looper looper) {
mManager = new LiveStateManager(looper, mListener);
mStateHandler = new Handler(looper, mManager);
return mManager;
LiveStateManager manager = new LiveStateManager(looper, mListener);
mStateHandler = new Handler(looper, manager);
return manager;
}
void offerPeer(String peerUrl) {

@ -154,6 +154,7 @@ public class M3U8LiveUtil extends AbsNormalLoaderUtil {
mInfoPool.execute(mInfoThread);
}
}, 0, mM3U8Option.getLiveUpdateInterval(), TimeUnit.MILLISECONDS);
getLoader().start();
}
private void closeTimer() {

@ -27,6 +27,9 @@ public abstract class AbsRecordHandlerAdapter implements IRecordHandlerAdapter {
private AbsTaskWrapper mWrapper;
protected String TAG = CommonUtil.getClassName(getClass());
@Override public void onPre() {
}
public AbsRecordHandlerAdapter(AbsTaskWrapper wrapper) {
mWrapper = wrapper;
}

@ -70,6 +70,7 @@ public class RecordHandler implements IRecordHandler {
if (mConfigFile.exists()) {
convertDb();
} else {
mAdapter.onPre();
mTaskRecord = DbDataHelper.getTaskRecord(getFilePath());
if (mTaskRecord == null) {
initRecord(true);

@ -26,6 +26,11 @@ import com.arialyy.aria.core.ThreadRecord;
*/
public interface IRecordHandlerAdapter {
/**
* 记录处理前的操作可用来删除任务记录
*/
void onPre();
/**
* 处理任务记录
*/

@ -16,16 +16,16 @@
package com.arialyy.aria.util;
import android.text.TextUtils;
import com.arialyy.aria.core.inf.IRecordHandler;
import com.arialyy.aria.core.wrapper.RecordWrapper;
import com.arialyy.aria.core.TaskRecord;
import com.arialyy.aria.core.ThreadRecord;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.common.AbsNormalEntity;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.download.M3U8Entity;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.common.AbsNormalEntity;
import com.arialyy.aria.core.inf.IRecordHandler;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.wrapper.RecordWrapper;
import com.arialyy.aria.orm.DbEntity;
import java.io.File;
import java.util.List;
@ -148,13 +148,13 @@ public class RecordUtil {
* 处理任务未完成的情况
*/
if (!entity.isComplete()) {
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件
if (recordIsM3U8(record.taskType)) { // 删除ts分片文件
removeTsCache(targetFile, record.bandWidth);
} else if (record.isBlock) { // 删除分块文件
removeBlockFile(record);
}
} else if (removeFile) { // 处理任务完成情况
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) {
if (recordIsM3U8(record.taskType)) {
removeTsCache(targetFile, record.bandWidth);
}
removeTargetFile(targetFile);
@ -164,6 +164,16 @@ public class RecordUtil {
removeRecord(filePath);
}
/**
* 任务记录是否是m3u8记录
*
* @param recordType 任务记录类型
* @return true 为m3u8任务
*/
private static boolean recordIsM3U8(int recordType) {
return recordType == TaskRecord.TYPE_M3U8_VOD || recordType == TaskRecord.TYPE_M3U8_LIVE;
}
/**
* 删除任务记录默认删除文件
*
@ -208,13 +218,13 @@ public class RecordUtil {
* 处理任务未完成的情况
*/
if (!entity.isComplete()) {
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) { // 删除ts分片文件
if (recordIsM3U8(record.taskType)) { // 删除ts分片文件
removeTsCache(targetFile, record.bandWidth);
} else if (record.isBlock) { // 删除分块文件
removeBlockFile(record);
}
} else if (removeFile) { // 处理任务完成情况
if (record.taskType == TaskRecord.TYPE_M3U8_VOD) {
if (recordIsM3U8(record.taskType)) {
removeTsCache(targetFile, record.bandWidth);
}
removeTargetFile(targetFile);
@ -357,7 +367,8 @@ public class RecordUtil {
tr.taskKey = newPath;
File blockFile = new File(String.format(IRecordHandler.SUB_PATH, oldPath, tr.threadId));
if (blockFile.exists()) {
blockFile.renameTo(new File(String.format(IRecordHandler.SUB_PATH, newPath, tr.threadId)));
blockFile.renameTo(
new File(String.format(IRecordHandler.SUB_PATH, newPath, tr.threadId)));
}
}
DbEntity.updateManyData(record.threadRecords);

@ -219,7 +219,18 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
if (Aria.download(this).load(mEntity.getId()).isRunning()) {
Aria.download(this).load(mEntity.getId()).stop();
} else {
Aria.download(this).load(mEntity.getId()).resume();
Aria.download(this).load(mEntity.getId())
.asM3U8()
.asLive()
.setLiveTsUrlConvert(new ILiveTsUrlConverter() {
@Override public String convert(String m3u8Url, String tsUrl) {
int index = m3u8Url.lastIndexOf("/");
String parentUrl = m3u8Url.substring(0, index + 1);
return parentUrl + tsUrl;
}
})
.controller(ControllerType.TASK_CONTROLLER)
.resume();
}
break;
case R.id.cancel:

Loading…
Cancel
Save