Skip to content
Permalink
Browse files

fix bug #459

  • Loading branch information...
AriaLyy committed Sep 5, 2019
1 parent 22c8136 commit 1e2f52dacaa0f099e5bc8d4bfe2ceb96f68a166a
@@ -15,4 +15,5 @@
/cache
*.log
uml
*.swp
*.swp
py/.history
@@ -24,11 +24,11 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('androidx.test.espresso:espresso-core:3.1.0', {
api fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
testImplementation 'junit:junit:4.12'
api 'androidx.appcompat:appcompat:1.0.2'
api 'com.google.code.gson:gson:2.8.2'
api 'io.reactivex:rxandroid:1.2.0'
@@ -200,7 +200,7 @@ private void amendTaskState() {
Class[] clazzs = new Class[] {
DownloadEntity.class, UploadEntity.class, DownloadGroupEntity.class
};
String sql = "UPDATE %s SET state=2 WHERE state IN (3,4,5,6)";
String sql = "UPDATE %s SET state=2 WHERE state IN (4,5,6)";
for (Class clazz : clazzs) {
if (!mDbWrapper.tableExists(clazz)) {
continue;
@@ -5,6 +5,7 @@
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.AbsEntity;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IEntity;
@@ -104,7 +105,11 @@ private void addResumeEntity(AbsTaskWrapper te) {
*/
private void resumeWaitTask() {
int maxTaskNum = mQueue.getMaxTaskNum();
if (mWaitList == null || mWaitList.isEmpty()) return;
if (mWaitList == null || mWaitList.isEmpty()) {
return;
}
List<AbsEntity> resumeEntities = new ArrayList<>();

for (AbsTaskWrapper te : mWaitList) {
if (te instanceof DTaskWrapper) {
mQueue = DownloadTaskQueue.getInstance();
@@ -119,7 +124,11 @@ private void resumeWaitTask() {
te.getEntity().setState(IEntity.STATE_WAIT);
AbsTask task = createTask(te);
sendWaitState(task);
resumeEntities.add(te.getEntity());
}
}
if (!resumeEntities.isEmpty()) {
DbEntity.updateManyData(resumeEntities);
}
}
}
@@ -145,10 +145,10 @@ private synchronized void startTimer() {
|| mStateManager.isFail()
|| !isRunning()
|| isBreak()) {
ALog.d(TAG, "isComplete = " + mStateManager.isComplete()
+ "; isFail = " + mStateManager.isFail()
+ "; isRunning = " + isRunning()
+ "; isBreak = " + isBreak());
//ALog.d(TAG, "isComplete = " + mStateManager.isComplete()
// + "; isFail = " + mStateManager.isFail()
// + "; isRunning = " + isRunning()
// + "; isBreak = " + isBreak());
ThreadTaskManager.getInstance().removeTaskThread(mTaskWrapper.getKey());
closeTimer();
onDestroy();
@@ -28,14 +28,15 @@
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;

public abstract class BaseListener<ENTITY extends AbsEntity, TASK_WRAPPER extends AbsTaskWrapper<ENTITY>,
TASK extends AbsTask<TASK_WRAPPER>>
implements IEventListener {
protected static String TAG;
protected static final int RUN_SAVE_INTERVAL = 5 * 1000; //5s保存一次下载中的进度
protected WeakReference<Handler> outHandler;
protected SoftReference<Handler> outHandler;
private long mLastLen; //上一次发送长度
private boolean isFirst = true;
private TASK mTask;
@@ -46,7 +47,7 @@
private long mUpdateInterval;

protected BaseListener(TASK task, Handler outHandler) {
this.outHandler = new WeakReference<>(outHandler);
this.outHandler = new SoftReference<>(outHandler);
mTask = new WeakReference<>(task).get();
mEntity = mTask.getTaskWrapper().getEntity();
mTaskWrapper = mTask.getTaskWrapper();
@@ -18,7 +18,7 @@
import aria.apache.commons.net.ftp.FTPClientConfig;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.inf.ITaskConfig;
import java.lang.ref.WeakReference;
import java.lang.ref.SoftReference;
import java.net.Proxy;

/**
@@ -41,7 +41,7 @@
/**
* 上传拦截器
*/
private WeakReference<IFtpUploadInterceptor> uploadInterceptor;
private SoftReference<IFtpUploadInterceptor> uploadInterceptor;

/**
* 上传到服务器文件的新文件名{@link FtpInterceptHandler#getNewFileName()}
@@ -74,7 +74,7 @@ public IFtpUploadInterceptor getUploadInterceptor() {
}

public void setUploadInterceptor(IFtpUploadInterceptor uploadInterceptor) {
this.uploadInterceptor = new WeakReference<>(uploadInterceptor);
this.uploadInterceptor = new SoftReference<>(uploadInterceptor);
}

public FtpUrlEntity getUrlEntity() {
@@ -19,7 +19,7 @@
import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.inf.IHttpFileLenAdapter;
import com.arialyy.aria.core.inf.ITaskConfig;
import java.lang.ref.WeakReference;
import java.lang.ref.SoftReference;
import java.net.CookieManager;
import java.net.Proxy;
import java.util.HashMap;
@@ -78,7 +78,7 @@
*/
private Map<String, String> formFields = new HashMap<>();

private WeakReference<IHttpFileLenAdapter> fileLenAdapter;
private SoftReference<IHttpFileLenAdapter> fileLenAdapter;

public IHttpFileLenAdapter getFileLenAdapter() {
return fileLenAdapter == null ? null : fileLenAdapter.get();
@@ -88,7 +88,7 @@ public IHttpFileLenAdapter getFileLenAdapter() {
* 如果是匿名内部类,完成后需要将adapter设置为空,否则会出现内存泄漏
*/
public void setFileLenAdapter(IHttpFileLenAdapter fileLenAdapter) {
this.fileLenAdapter = new WeakReference<>(fileLenAdapter);
this.fileLenAdapter = new SoftReference<>(fileLenAdapter);
}

public Map<String, String> getFormFields() {
@@ -133,7 +133,7 @@ private void handleConnect(HttpURLConnection conn) throws IOException {
if (line.startsWith("#EXT-X-ENDLIST")) {
break;
}
//ALog.d(TAG, line);
ALog.d(TAG, line);
if (line.startsWith("#EXTINF")) {
String info = reader.readLine();
mInfos.add(info);
@@ -16,7 +16,6 @@
package com.arialyy.aria.core.download.m3u8;

import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.List;

/**
@@ -67,7 +66,7 @@
/**
* 码率url转换器
*/
private WeakReference<IBandWidthUrlConverter> bandWidthUrlConverter;
private SoftReference<IBandWidthUrlConverter> bandWidthUrlConverter;

/**
* 码率地址
@@ -77,7 +76,7 @@
/**
* 直播下载,ts url转换器
*/
private WeakReference<ILiveTsUrlConverter> liveTsUrlConverter;
private SoftReference<ILiveTsUrlConverter> liveTsUrlConverter;

/**
* 直播的m3u8文件更新间隔
@@ -136,7 +135,7 @@ public ILiveTsUrlConverter getLiveTsUrlConverter() {
}

public void setLiveTsUrlConverter(ILiveTsUrlConverter liveTsUrlConverter) {
this.liveTsUrlConverter = new WeakReference<>(liveTsUrlConverter);
this.liveTsUrlConverter = new SoftReference<>(liveTsUrlConverter);
}

public String getBandWidthUrl() {
@@ -152,7 +151,7 @@ public IBandWidthUrlConverter getBandWidthUrlConverter() {
}

public void setBandWidthUrlConverter(IBandWidthUrlConverter bandWidthUrlConverter) {
this.bandWidthUrlConverter = new WeakReference<>(bandWidthUrlConverter);
this.bandWidthUrlConverter = new SoftReference<>(bandWidthUrlConverter);
}

public int getBandWidth() {
@@ -3,6 +3,8 @@
- fix bug https://github.com/AriaLyy/Aria/issues/450
- fix bug https://github.com/AriaLyy/Aria/issues/466
- fix bug https://github.com/AriaLyy/Aria/issues/454
- fix bug https://github.com/AriaLyy/Aria/issues/467
- fix bug https://github.com/AriaLyy/Aria/issues/459
- 移除隐藏api的反射 https://github.com/AriaLyy/Aria/issues/456
- 新增ftp免证书登陆功能h ttps://github.com/AriaLyy/Aria/issues/455
- 适配androidX
@@ -12,7 +12,7 @@ Aria有以下特点:
- 支持下载FTP文件夹
- 支持HTTP表单上传
- 支持文件FTP断点续传上传
- 支持FTPS/SFTP断点续传,[see](https://aria.laoyuyu.me/aria_doc/download/ftps.html)
- 支持FTPS断点续传,[see](https://aria.laoyuyu.me/aria_doc/download/ftps.html)
+ 支持https地址下载
- 在配置文件中很容易就可以设置CA证书的信息
+ 支持[多线程分块下载](https://aria.laoyuyu.me/aria_doc/start/config.html),能更有效的发挥机器IO性能
@@ -69,7 +69,7 @@ dependencies {
// annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.14'
api 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation project(':AppFrame')
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.pddstudio:highlightjs-android:1.5.0'
implementation 'org.greenrobot:eventbus:3.1.1'
@@ -23,6 +23,7 @@
import androidx.lifecycle.ViewModelProviders;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.ProtocolType;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
@@ -47,6 +48,7 @@
private String mUrl, mFilePath;
private FtpDownloadModule mModule;
private long mTaskId;
private String user = "tester", passw = "password";

@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
@@ -94,7 +96,8 @@ public void onClick(View view) {
mTaskId = Aria.download(this).loadFtp(mUrl)
.setFilePath(mFilePath, true)
.option()
.login("lao", "123456")
//.login("lao", "123456")
.login(user, passw)
.asFtps()
.controller(ControllerType.CREATE_CONTROLLER)
.create();
@@ -108,8 +111,9 @@ public void onClick(View view) {
Aria.download(this)
.loadFtp(mTaskId)
.option()
.login("lao", "123456")
.login(user, passw)
.asFtps()
.setProtocol(ProtocolType.SSL)
.controller(ControllerType.TASK_CONTROLLER)
.resume();
getBinding().setStateStr(getString(R.string.stop));
@@ -33,7 +33,7 @@
private final String FTP_URL_KEY = "FTP_URL_KEY";
private final String FTP_PATH_KEY = "FTP_PATH_KEY";

private final String ftpDefUrl = "ftp://9.9.9.50:2121/Cyberduck-6.9.4.30164.zip";
private final String ftpDefUrl = "ftp://9.9.9.50:22/Cyberduck-6.9.4.30164.zip";
private final String ftpDefPath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();

@@ -16,6 +16,7 @@

package com.arialyy.simple.core.download.m3u8;

import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
@@ -29,11 +30,10 @@
import com.arialyy.annotations.Download;
import com.arialyy.annotations.M3U8;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.common.controller.BuilderController;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.download.m3u8.IBandWidthUrlConverter;
import com.arialyy.aria.core.download.m3u8.ITsMergeHandler;
import com.arialyy.aria.core.download.m3u8.IVodTsUrlConverter;
import com.arialyy.aria.core.download.m3u8.M3U8Entity;
@@ -281,16 +281,17 @@ public void onClick(View view) {
Aria.download(this)
.load(mTaskId)
.asM3U8()
.setBandWidthUrlConverter(new IBandWidthUrlConverter() {
@Override public String convert(String bandWidthUrl) {
int index = mUrl.lastIndexOf("/");
return mUrl.substring(0, index + 1) + bandWidthUrl;
}
})
//.setBandWidthUrlConverter(new IBandWidthUrlConverter() {
// @Override public String convert(String bandWidthUrl) {
// int index = mUrl.lastIndexOf("/");
// return mUrl.substring(0, index + 1) + bandWidthUrl;
// }
//})
.setTsUrlConvert(new IVodTsUrlConverter() {
@Override public List<String> convert(String m3u8Url, List<String> tsUrls) {
int index = m3u8Url.lastIndexOf("/");
String parentUrl = m3u8Url.substring(0, index + 1);

Uri uri = Uri.parse(m3u8Url);
String parentUrl = uri.getAuthority() + "://" + uri.getHost();
List<String> newUrls = new ArrayList<>();
for (String url : tsUrls) {
newUrls.add(parentUrl + url);
@@ -316,16 +317,22 @@ private void startD() {
.useServerFileName(true)
.setFilePath(mFilePath, true)
.asM3U8()
.setBandWidthUrlConverter(new IBandWidthUrlConverter() {
@Override public String convert(String bandWidthUrl) {
int index = mUrl.lastIndexOf("/");
return mUrl.substring(0, index + 1) + bandWidthUrl;
}
})
//.setBandWidthUrlConverter(new IBandWidthUrlConverter() {
// @Override public String convert(String bandWidthUrl) {
// int index = mUrl.lastIndexOf("/");
// return mUrl.substring(0, index + 1) + bandWidthUrl;
// }
//})
.setTsUrlConvert(new IVodTsUrlConverter() {
@Override public List<String> convert(String m3u8Url, List<String> tsUrls) {
int index = m3u8Url.lastIndexOf("/");
String parentUrl = m3u8Url.substring(0, index + 1);
//int index = m3u8Url.lastIndexOf("/");
//String parentUrl = m3u8Url.substring(0, index + 1);
//List<String> newUrls = new ArrayList<>();
//for (String url : tsUrls) {
// newUrls.add(parentUrl + url);
//}
Uri uri = Uri.parse(m3u8Url);
String parentUrl = uri.getScheme() + "://" + uri.getHost();
List<String> newUrls = new ArrayList<>();
for (String url : tsUrls) {
newUrls.add(parentUrl + url);
@@ -34,10 +34,11 @@
// m3u8测试集合:http://www.voidcn.com/article/p-snaliarm-ct.html
//private final String defUrl = "https://www.gaoya123.cn/2019/1557993797897.m3u8";
// 多码率地址:
private final String defUrl = "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8";
//private final String defUrl = "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8";
private final String defUrl = "http://cn1.fa1244.cn/hls/20190516/6d271eaa73b2e4cb51d13831b0c1ab4c/1557976262/index.m3u8";
private final String filePath =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()
+ "/1557993797897.ts";
+ "/道士下山.ts";

private MutableLiveData<DownloadEntity> liveData = new MutableLiveData<>();
private DownloadEntity singDownloadInfo;
@@ -53,6 +53,10 @@
setTitle("下载列表");
List<AbsEntity> temps = Aria.download(this).getTotalTaskList();
if (temps != null && !temps.isEmpty()) {

for (AbsEntity temp : temps){
ALog.d(TAG, "state = " + temp.getState());
}
mData.addAll(temps);
}
mAdapter = new DownloadAdapter(this, mData);

0 comments on commit 1e2f52d

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