任务设置修改

pull/617/head
laoyuyu 5 years ago
parent df310b7fbe
commit 550455084f
  1. 2
      Aria/build.gradle
  2. 8
      Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java
  3. 52
      Aria/src/main/java/com/arialyy/aria/core/common/BaseOption.java
  4. 114
      Aria/src/main/java/com/arialyy/aria/core/common/FTPSDelegate.java
  5. 99
      Aria/src/main/java/com/arialyy/aria/core/common/FtpDelegate.java
  6. 146
      Aria/src/main/java/com/arialyy/aria/core/common/FtpOption.java
  7. 42
      Aria/src/main/java/com/arialyy/aria/core/common/HttpOption.java
  8. 128
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java
  9. 38
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveOption.java
  10. 104
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Option.java
  11. 116
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDelegate.java
  12. 87
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodOption.java
  13. 16
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java
  14. 18
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java
  15. 16
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java
  16. 16
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java
  17. 10
      Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java
  18. 12
      Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java
  19. 38
      Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java
  20. 42
      Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java
  21. 56
      Aria/src/main/java/com/arialyy/aria/core/download/target/M3U8NormalTarget.java
  22. 16
      Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java
  23. 40
      Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java
  24. 16
      Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java
  25. 17
      Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java
  26. 11
      Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java
  27. 10
      Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java
  28. 2
      Aria/src/main/java/com/arialyy/aria/core/upload/target/UNormalConfigHandler.java
  29. 35
      PublicComponent/src/main/java/com/arialyy/aria/core/TaskOptionParams.java
  30. 26
      PublicComponent/src/main/java/com/arialyy/aria/core/common/BaseOption.java
  31. 9
      PublicComponent/src/main/java/com/arialyy/aria/util/CommonUtil.java
  32. 21
      app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
  33. 7
      app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  34. 16
      app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java
  35. 80
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveDLoadActivity.java
  36. 91
      app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
  37. 19
      app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java
  38. 10
      app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java
  39. 17
      app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java

@ -28,7 +28,7 @@ dependencies {
api project(':AriaAnnotations') api project(':AriaAnnotations')
api project(path: ':PublicComponent') api project(path: ':PublicComponent')
api 'com.arialyy.aria:aria-ftp-plug:1.0.4' // api 'com.arialyy.aria:aria-ftp-plug:1.0.4'
implementation project(path: ':HttpComponent') // implementation project(path: ':HttpComponent') //
// compile project(':AriaFtpPlug') // compile project(':AriaFtpPlug')

@ -36,14 +36,18 @@ public abstract class AbsNormalTarget<TARGET extends AbsNormalTarget> extends Ab
* *
* @return {@code true} 任务正在执行 * @return {@code true} 任务正在执行
*/ */
public abstract boolean isRunning(); public boolean isRunning() {
return false;
}
/** /**
* 任务是否存在 * 任务是否存在
* *
* @return {@code true} 任务存在 * @return {@code true} 任务存在
*/ */
public abstract boolean taskExists(); public boolean taskExists() {
return false;
}
private NormalController mNormalController; private NormalController mNormalController;

@ -1,52 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.common;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.common.controller.FeatureController;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.CommonUtil;
public abstract class BaseOption<TARGET extends AbsTarget> {
protected final String TAG;
protected TARGET mTarget;
protected AbsTaskWrapper mWrapper;
public BaseOption(TARGET target, AbsTaskWrapper wrapper) {
TAG = CommonUtil.getClassName(getClass());
mTarget = target;
mWrapper = wrapper;
}
protected AbsTaskWrapper getTaskWrapper() {
return mWrapper;
}
/**
* 使用对应等控制器注意
* 1对于不存在的任务第一次下载只能使用{@link ControllerType#CREATE_CONTROLLER}
* 2对于已存在的任务只能使用{@link ControllerType#TASK_CONTROLLER}
*
* @param clazz {@link ControllerType#CREATE_CONTROLLER}{@link ControllerType#TASK_CONTROLLER}
*/
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public synchronized <T extends FeatureController> T controller(@ControllerType Class<T> clazz) {
return FeatureController.newInstance(clazz, getTaskWrapper());
}
}

@ -1,114 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.common;
import android.text.TextUtils;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.ProtocolType;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.util.ALog;
/**
* D_FTP SSL/TSL 参数委托
*/
public class FTPSDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
private FtpUrlEntity mUrlEntity;
public FTPSDelegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
mUrlEntity = (FtpUrlEntity) getTaskWrapper().getOptionParams()
.getParam(IOptionConstant.ftpUrlEntity);
if (mUrlEntity != null) {
mUrlEntity.isFtps = true;
}
}
/**
* 设置协议类型
*
* @param protocol {@link ProtocolType}
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> setProtocol(@ProtocolType String protocol) {
if (TextUtils.isEmpty(protocol)) {
ALog.e(TAG, "设置协议失败,协议信息为空");
return this;
}
mUrlEntity.protocol = protocol;
return this;
}
/**
* 设置证书别名
*
* @param keyAlias 别名
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> setAlias(String keyAlias) {
if (TextUtils.isEmpty(keyAlias)) {
ALog.e(TAG, "设置证书别名失败,证书别名为空");
return this;
}
mUrlEntity.keyAlias = keyAlias;
return this;
}
/**
* 设置证书密码
*
* @param storePass 私钥密码
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> setStorePass(String storePass) {
if (TextUtils.isEmpty(storePass)) {
ALog.e(TAG, "设置证书密码失败,证书密码为空");
return this;
}
mUrlEntity.storePass = storePass;
return this;
}
/**
* 设置证书路径
*
* @param storePath 证书路径
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> setStorePath(String storePath) {
if (TextUtils.isEmpty(storePath)) {
ALog.e(TAG, "设置证书路径失败,证书路径为空");
return this;
}
mUrlEntity.storePath = storePath;
return this;
}
/**
* 设置安全模式默认true
*
* @param isImplicit true 隐式false 显式
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> setImplicit(boolean isImplicit) {
mUrlEntity.isImplicit = isImplicit;
return this;
}
}

@ -1,99 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.common;
import android.text.TextUtils;
import androidx.annotation.CheckResult;
import aria.apache.commons.net.ftp.FTPClientConfig;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.util.ALog;
/**
* Created by laoyuyu on 2018/3/9.
*/
public class FtpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
private static final String TAG = "FtpDelegate";
public FtpDelegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
}
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FtpDelegate<TARGET> charSet(String charSet) {
if (TextUtils.isEmpty(charSet)) {
throw new NullPointerException("字符编码为空");
}
getTaskWrapper().getOptionParams().setParams(IOptionConstant.charSet, charSet);
return this;
}
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FtpDelegate<TARGET> login(String userName, String password) {
return login(userName, password, null);
}
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FtpDelegate<TARGET> login(String userName, String password, String account) {
if (TextUtils.isEmpty(userName)) {
ALog.e(TAG, "用户名不能为null");
return this;
} else if (TextUtils.isEmpty(password)) {
ALog.e(TAG, "密码不能为null");
return this;
}
// urlEntity 不能在构造函数中获取,因为ftp上传时url是后于构造函数的
FtpUrlEntity urlEntity =
(FtpUrlEntity) getTaskWrapper().getOptionParams()
.getParam(IOptionConstant.ftpUrlEntity);
if (urlEntity == null) {
ALog.e(TAG, "设置登陆信息失败,FtpUrlEntity为空");
return this;
}
urlEntity.needLogin = true;
urlEntity.user = userName;
urlEntity.password = password;
urlEntity.account = account;
return this;
}
/**
* 是否是FTPS协议
* 如果是FTPS协议需要使用{@link FTPSDelegate#setStorePath(String)} {@link FTPSDelegate#setAlias(String)}
* 设置证书信息
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FTPSDelegate<TARGET> asFtps() {
return new FTPSDelegate<>(mTarget, mWrapper);
}
/**
* 配置ftp客户端信息
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public FtpDelegate<TARGET> setFtpClentConfig(FTPClientConfig config) {
getTaskWrapper().getOptionParams().setParams(IOptionConstant.clientConfig, config);
return this;
}
//@Override public TARGET setProxy(Proxy proxy) {
// mTarget.getTaskWrapper().asFtp().setProxy(proxy);
// return mTarget;
//}
}

@ -0,0 +1,146 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.common;
import android.text.TextUtils;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.ProtocolType;
import com.arialyy.aria.util.ALog;
/**
* Created by laoyuyu on 2018/3/9.
*/
public class FtpOption extends BaseOption {
private String charSet, userName, password, account;
private boolean isNeedLogin = false;
private FtpUrlEntity ftpUrlEntity;
private String protocol, keyAlias, storePass, storePath;
private boolean isImplicit = true;
public FtpOption() {
super();
}
public FtpOption charSet(String charSet) {
if (TextUtils.isEmpty(charSet)) {
throw new NullPointerException("字符编码为空");
}
this.charSet = charSet;
return this;
}
public FtpOption login(String userName, String password) {
return login(userName, password, null);
}
public FtpOption login(String userName, String password, String account) {
if (TextUtils.isEmpty(userName)) {
ALog.e(TAG, "用户名不能为null");
return this;
} else if (TextUtils.isEmpty(password)) {
ALog.e(TAG, "密码不能为null");
return this;
}
this.userName = userName;
this.password = password;
this.account = account;
isNeedLogin = true;
return this;
}
/**
* 设置协议类型
*
* @param protocol {@link ProtocolType}
*/
public FtpOption setProtocol(@ProtocolType String protocol) {
if (TextUtils.isEmpty(protocol)) {
ALog.e(TAG, "设置协议失败,协议信息为空");
return this;
}
this.protocol = protocol;
return this;
}
/**
* 设置证书别名
*
* @param keyAlias 别名
*/
public FtpOption setAlias(String keyAlias) {
if (TextUtils.isEmpty(keyAlias)) {
ALog.e(TAG, "设置证书别名失败,证书别名为空");
return this;
}
this.keyAlias = keyAlias;
return this;
}
/**
* 设置证书密码
*
* @param storePass 私钥密码
*/
public FtpOption setStorePass(String storePass) {
if (TextUtils.isEmpty(storePass)) {
ALog.e(TAG, "设置证书密码失败,证书密码为空");
return this;
}
this.storePass = storePass;
return this;
}
/**
* 设置证书路径
*
* @param storePath 证书路径
*/
public FtpOption setStorePath(String storePath) {
if (TextUtils.isEmpty(storePath)) {
ALog.e(TAG, "设置证书路径失败,证书路径为空");
return this;
}
this.storePath = storePath;
return this;
}
/**
* 设置安全模式默认true
*
* @param isImplicit true 隐式false 显式
*/
public FtpOption setImplicit(boolean isImplicit) {
this.isImplicit = isImplicit;
return this;
}
public void setFtpUrlEntity(FtpUrlEntity ftpUrlEntity) {
this.ftpUrlEntity = ftpUrlEntity;
ftpUrlEntity.needLogin = isNeedLogin;
ftpUrlEntity.user = userName;
ftpUrlEntity.password = password;
ftpUrlEntity.account = account;
if (!TextUtils.isEmpty(storePath)) {
ftpUrlEntity.isFtps = true;
ftpUrlEntity.protocol = protocol;
ftpUrlEntity.keyAlias = keyAlias;
ftpUrlEntity.storePass = storePass;
ftpUrlEntity.storePath = storePath;
ftpUrlEntity.isImplicit = isImplicit;
}
}
}

@ -18,10 +18,7 @@ package com.arialyy.aria.core.common;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import java.net.Proxy; import java.net.Proxy;
import java.util.HashMap; import java.util.HashMap;
@ -30,13 +27,16 @@ import java.util.Map;
/** /**
* HTTP任务设置 * HTTP任务设置
*/ */
public class HttpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> { public class HttpOption extends BaseOption {
private Map<String, String> params; private Map<String, String> params;
private Map<String, String> headers; private Map<String, String> headers;
private RequestEnum requestEnum = RequestEnum.GET;
private Map<String, String> formFields;
private Proxy proxy;
public HttpDelegate(TARGET target, AbsTaskWrapper wrapper) { public HttpOption() {
super(target, wrapper); super();
} }
/** /**
@ -45,29 +45,26 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
* @param requestEnum {@link RequestEnum} * @param requestEnum {@link RequestEnum}
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) @CheckResult(suggest = Suggest.TO_CONTROLLER)
public HttpDelegate<TARGET> setRequestType(RequestEnum requestEnum) { public HttpOption setRequestType(RequestEnum requestEnum) {
getTaskWrapper().getOptionParams().setParams(IOptionConstant.requestEnum, requestEnum); this.requestEnum = requestEnum;
return this; return this;
} }
/** /**
* 设置http请求参数 * 设置http请求参数
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public HttpOption setParams(Map<String, String> params) {
public HttpDelegate<TARGET> setParams(Map<String, String> params) {
if (this.params == null) { if (this.params == null) {
this.params = new HashMap<>(); this.params = new HashMap<>();
} }
this.params.putAll(params); this.params.putAll(params);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.params, this.params);
return this; return this;
} }
/** /**
* 设置http请求参数 * 设置http请求参数
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public HttpOption setParam(String key, String value) {
public HttpDelegate<TARGET> setParam(String key, String value) {
if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) { if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) {
ALog.d(TAG, "key 或value 为空"); ALog.d(TAG, "key 或value 为空");
return this; return this;
@ -76,16 +73,14 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
params = new HashMap<>(); params = new HashMap<>();
} }
params.put(key, value); params.put(key, value);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.params, params);
return this; return this;
} }
/** /**
* 设置http表单字段 * 设置http表单字段
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public HttpOption setFormFields(Map<String, String> formFields) {
public HttpDelegate<TARGET> setFormFields(Map<String, String> params) { this.formFields = formFields;
getTaskWrapper().getOptionParams().setParams(IOptionConstant.formFields, params);
return this; return this;
} }
@ -96,8 +91,7 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
* @param key header对应的key * @param key header对应的key
* @param value header对应的value * @param value header对应的value
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public HttpOption addHeader(@NonNull String key, @NonNull String value) {
public HttpDelegate<TARGET> addHeader(@NonNull String key, @NonNull String value) {
if (TextUtils.isEmpty(key)) { if (TextUtils.isEmpty(key)) {
ALog.w(TAG, "设置header失败,header对应的key不能为null"); ALog.w(TAG, "设置header失败,header对应的key不能为null");
return this; return this;
@ -109,7 +103,6 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
this.headers = new HashMap<>(); this.headers = new HashMap<>();
} }
this.headers.put(key, value); this.headers.put(key, value);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.headers, this.headers);
return this; return this;
} }
@ -119,8 +112,7 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
* *
* @param headers 一组http header数据 * @param headers 一组http header数据
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public HttpOption addHeaders(@NonNull Map<String, String> headers) {
public HttpDelegate<TARGET> addHeaders(@NonNull Map<String, String> headers) {
if (headers.size() == 0) { if (headers.size() == 0) {
ALog.w(TAG, "设置header失败,map没有header数据"); ALog.w(TAG, "设置header失败,map没有header数据");
return this; return this;
@ -129,16 +121,14 @@ public class HttpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
this.headers = new HashMap<>(); this.headers = new HashMap<>();
} }
this.headers.putAll(headers); this.headers.putAll(headers);
getTaskWrapper().getOptionParams().setParams(IOptionConstant.headers, this.headers);
return this; return this;
} }
/** /**
* 设置代理 * 设置代理
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public HttpOption setUrlProxy(Proxy proxy) {
public HttpDelegate<TARGET> setUrlProxy(Proxy proxy) { this.proxy = proxy;
getTaskWrapper().getOptionParams().setParams(IOptionConstant.proxy, proxy);
return this; return this;
} }
} }

@ -1,128 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.m3u8;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
import com.arialyy.aria.core.processor.ITsMergeHandler;
import com.arialyy.aria.core.processor.IVodTsUrlConverter;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.ComponentUtil;
/**
* m3u8 委托
*/
public class M3U8Delegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
private DTaskWrapper mTaskWrapper;
public M3U8Delegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_M3U8);
mTaskWrapper = (DTaskWrapper) getTaskWrapper();
mTaskWrapper.setRequestType(AbsTaskWrapper.M3U8_VOD);
}
/**
* 生成m3u8索引文件
* 注意创建索引文件{@link #merge(boolean)}方法设置与否都不再合并文件
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> generateIndexFile() {
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.generateIndexFileTemp, true);
return this;
}
/**
* 是否合并ts文件默认合并ts
*
* @param merge {@code true}合并所有ts文件为一个
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> merge(boolean merge) {
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.mergeFile, merge);
return this;
}
/**
* 如果你希望使用自行处理ts文件的合并可以使用{@link ITsMergeHandler}处理ts文件的合并
* 需要注意的是只有{@link #merge(boolean)}设置合并ts文件该方法才会生效
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setMergeHandler(ITsMergeHandler handler) {
CheckUtil.checkMemberClass(handler.getClass());
mTaskWrapper.getM3U8Params().setObjs(IOptionConstant.mergeHandler, handler);
return this;
}
/**
* M3U8 ts 文件url转换器对于某些服务器返回的ts地址可以是相对地址也可能是处理过的
* 对于这种情况你需要使用url转换器将地址转换为可正常访问的http地址
*
* @param converter {@link IVodTsUrlConverter}
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setTsUrlConvert(IVodTsUrlConverter converter) {
CheckUtil.checkMemberClass(converter.getClass());
mTaskWrapper.getM3U8Params().setObjs(IOptionConstant.vodUrlConverter, converter);
return this;
}
/**
* 选择需要下载的码率默认下载的码率
*
* @param bandWidth 指定的码率
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setBandWidth(int bandWidth) {
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.bandWidth, bandWidth);
return this;
}
/**
* M3U8 bandWidth 码率url转换器对于某些服务器返回的ts地址可以是相对地址也可能是处理过的
* 对于这种情况你需要使用url转换器将地址转换为可正常访问的http地址
*
* @param converter {@link IBandWidthUrlConverter}
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8Delegate<TARGET> setBandWidthUrlConverter(IBandWidthUrlConverter converter) {
CheckUtil.checkMemberClass(converter.getClass());
mTaskWrapper.getM3U8Params().setObjs(IOptionConstant.bandWidthUrlConverter, converter);
return this;
}
/**
* 处理点播文件的下载参数
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8VodDelegate<TARGET> asVod() {
return new M3U8VodDelegate<>(mTarget, mTaskWrapper);
}
/**
* 处理直播类的下载
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8LiveDelegate<TARGET> asLive() {
return new M3U8LiveDelegate<>(mTarget, mTaskWrapper);
}
}

@ -15,54 +15,46 @@
*/ */
package com.arialyy.aria.core.download.m3u8; package com.arialyy.aria.core.download.m3u8;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.processor.ILiveTsUrlConverter; import com.arialyy.aria.core.processor.ILiveTsUrlConverter;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
/** /**
* m3u8直播参数设置 * m3u8直播参数设置
*/ */
public class M3U8LiveDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> { public class M3U8LiveOption extends M3U8Option {
M3U8LiveDelegate(TARGET target, AbsTaskWrapper wrapper) { private ILiveTsUrlConverter liveTsUrlConverter;
super(target, wrapper); private long liveUpdateInterval;
getTaskWrapper().setRequestType(AbsTaskWrapper.M3U8_LIVE);
public M3U8LiveOption() {
super();
} }
/** /**
* M3U8 ts 文件url转换器对于某些服务器返回的ts地址可以是相对地址也可能是处理过的 * M3U8 ts 文件url转换器对于某些服务器返回的ts地址可以是相对地址也可能是处理过的
* 对于这种情况你需要使用url转换器将地址转换为可正常访问的http地址 * 对于这种情况你需要使用url转换器将地址转换为可正常访问的http地址
* *
* @param converter {@link ILiveTsUrlConverter} * @param liveTsUrlConverter {@link ILiveTsUrlConverter}
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public M3U8LiveOption setLiveTsUrlConvert(ILiveTsUrlConverter liveTsUrlConverter) {
public M3U8LiveDelegate<TARGET> setLiveTsUrlConvert(ILiveTsUrlConverter converter) { CheckUtil.checkMemberClass(liveTsUrlConverter.getClass());
CheckUtil.checkMemberClass(converter.getClass()); this.liveTsUrlConverter = liveTsUrlConverter;
((DTaskWrapper) getTaskWrapper()).getM3U8Params()
.setObjs(IOptionConstant.liveTsUrlConverter, converter);
return this; return this;
} }
/** /**
* 设置直播的m3u8文件更新间隔默认10000微秒 * 设置直播的m3u8文件更新间隔默认10000微秒
* *
* @param interval 更新间隔单位微秒 * @param liveUpdateInterval 更新间隔单位微秒
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public M3U8LiveOption setM3U8FileUpdateInterval(long liveUpdateInterval) {
public M3U8LiveDelegate<TARGET> setM3U8FileUpdateInterval(long interval) { if (liveUpdateInterval <= 1) {
if (interval <= 1) {
ALog.e(TAG, "间隔时间错误"); ALog.e(TAG, "间隔时间错误");
return this; return this;
} }
((DTaskWrapper) getTaskWrapper()).getM3U8Params()
.setParams(IOptionConstant.liveUpdateInterval, interval); this.liveUpdateInterval = liveUpdateInterval;
return this; return this;
} }
} }

@ -0,0 +1,104 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.m3u8;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
import com.arialyy.aria.core.processor.ITsMergeHandler;
import com.arialyy.aria.core.processor.IVodTsUrlConverter;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.ComponentUtil;
/**
* m3u8任务设置
*/
public class M3U8Option extends BaseOption {
private boolean generateIndexFileTemp = false;
private boolean mergeFile = false;
private int bandWidth;
private ITsMergeHandler mergeHandler;
private IVodTsUrlConverter vodUrlConverter;
private IBandWidthUrlConverter bandWidthUrlConverter;
M3U8Option() {
super();
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_M3U8);
}
/**
* 生成m3u8索引文件
* 注意创建索引文件{@link #merge(boolean)}方法设置与否都不再合并文件
*/
public M3U8Option generateIndexFile() {
this.generateIndexFileTemp = true;
return this;
}
/**
* 是否合并ts文件默认合并ts
*
* @param mergeFile {@code true}合并所有ts文件为一个
*/
public M3U8Option merge(boolean mergeFile) {
this.mergeFile = mergeFile;
return this;
}
/**
* 如果你希望使用自行处理ts文件的合并可以使用{@link ITsMergeHandler}处理ts文件的合并
* 需要注意的是只有{@link #merge(boolean)}设置合并ts文件该方法才会生效
*/
public M3U8Option setMergeHandler(ITsMergeHandler mergeHandler) {
CheckUtil.checkMemberClass(mergeHandler.getClass());
this.mergeHandler = mergeHandler;
return this;
}
/**
* M3U8 ts 文件url转换器对于某些服务器返回的ts地址可以是相对地址也可能是处理过的
* 对于这种情况你需要使用url转换器将地址转换为可正常访问的http地址
*
* @param vodUrlConverter {@link IVodTsUrlConverter}
*/
public M3U8Option setTsUrlConvert(IVodTsUrlConverter vodUrlConverter) {
CheckUtil.checkMemberClass(vodUrlConverter.getClass());
this.vodUrlConverter = vodUrlConverter;
return this;
}
/**
* 选择需要下载的码率默认下载的码率
*
* @param bandWidth 指定的码率
*/
public M3U8Option setBandWidth(int bandWidth) {
this.bandWidth = bandWidth;
return this;
}
/**
* M3U8 bandWidth 码率url转换器对于某些服务器返回的ts地址可以是相对地址也可能是处理过的
* 对于这种情况你需要使用url转换器将地址转换为可正常访问的http地址
*
* @param bandWidthUrlConverter {@link IBandWidthUrlConverter}
*/
public M3U8Option setBandWidthUrlConverter(IBandWidthUrlConverter bandWidthUrlConverter) {
CheckUtil.checkMemberClass(bandWidthUrlConverter.getClass());
this.bandWidthUrlConverter = bandWidthUrlConverter;
return this;
}
}

@ -1,116 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.m3u8;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.event.PeerIndexEvent;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.util.ALog;
/**
* m3u8点播文件参数设置
*/
public class M3U8VodDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
private DTaskWrapper mTaskWrapper;
M3U8VodDelegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
mTaskWrapper = (DTaskWrapper) getTaskWrapper();
mTaskWrapper.setRequestType(AbsTaskWrapper.M3U8_VOD);
}
/**
* 由于m3u8协议的特殊性质无法有效快速获取到正确到文件长度如果你需要显示文件中长度你需要自行设置文件长度
*
* @param fileSize 文件长度
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8VodDelegate<TARGET> setFileSize(long fileSize) {
if (fileSize <= 0) {
ALog.e(TAG, "文件长度错误");
return this;
}
mTaskWrapper.getEntity().setFileSize(fileSize);
return this;
}
/**
* 默认情况下对于同一点播文件的下载最多同时下载4个ts分片如果你希望增加或减少同时下载的ts分片数量可以使用该方法设置同时下载的ts分片数量
*
* @param num 同时下载的ts分片数量
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8VodDelegate<TARGET> setMaxTsQueueNum(int num) {
if (num < 1) {
ALog.e(TAG, "同时下载的分片数量不能小于1");
return this;
}
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.maxTsQueueNum, num);
return this;
}
/**
* 启动任务时初始化索引位置
*
* 优先下载指定索引后的切片
* 如果指定的切片索引大于切片总数则此操作无效
* 如果指定的切片索引小于当前正在下载的切片索引并且指定索引和当前索引区间内有未下载的切片则优先下载该区间的切片否则此操作无效
* 如果指定索引后的切片已经全部下载完成但是索引前有未下载的切片间会自动下载未下载的切片
*
* @param index 指定的切片位置
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public M3U8VodDelegate<TARGET> setPeerIndex(int index) {
if (index < 1) {
ALog.e(TAG, "切片索引不能小于1");
return this;
}
mTaskWrapper.getM3U8Params().setParams(IOptionConstant.jumpIndex, index);
return this;
}
/**
* 任务执行中跳转索引位置
* 优先下载指定索引后的切片
* 如果指定的切片索引大于切片总数则此操作无效
* 如果指定的切片索引小于当前正在下载的切片索引并且指定索引和当前索引区间内有未下载的切片则优先下载该区间的切片否则此操作无效
* 如果指定索引后的切片已经全部下载完成但是索引前有未下载的切片间会自动下载未下载的切片
*
* @param index 指定的切片位置
*/
public void jumPeerIndex(int index) {
if (index < 1) {
ALog.e(TAG, "切片索引不能小于1");
return;
}
if (!DTaskQueue.getInstance().taskIsRunning(mTaskWrapper.getKey())) {
ALog.e(TAG,
String.format("任务【%s】没有运行,如果你希望在启动任务时初始化索引位置,请调用setPeerIndex(xxx)",
mTaskWrapper.getKey()));
return;
}
EventMsgUtil.getDefault().post(new PeerIndexEvent(mTaskWrapper.getKey(), index));
}
}

@ -0,0 +1,87 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.download.m3u8;
import com.arialyy.aria.util.ALog;
/**
* m3u8点播文件参数设置
*/
public class M3U8VodOption extends M3U8Option {
private long fileSize;
private int maxTsQueueNum;
private int jumpIndex;
public M3U8VodOption() {
super();
}
/**
* 由于m3u8协议的特殊性质无法有效快速获取到正确到文件长度如果你需要显示文件中长度你需要自行设置文件长度
*
* @param fileSize 文件长度
*/
public M3U8VodOption setFileSize(long fileSize) {
if (fileSize <= 0) {
ALog.e(TAG, "文件长度错误");
return this;
}
this.fileSize = fileSize;
return this;
}
/**
* 默认情况下对于同一点播文件的下载最多同时下载4个ts分片如果你希望增加或减少同时下载的ts分片数量可以使用该方法设置同时下载的ts分片数量
*
* @param maxTsQueueNum 同时下载的ts分片数量
*/
public M3U8VodOption setMaxTsQueueNum(int maxTsQueueNum) {
if (maxTsQueueNum < 1) {
ALog.e(TAG, "同时下载的分片数量不能小于1");
return this;
}
this.maxTsQueueNum = maxTsQueueNum;
return this;
}
/**
* 启动任务时初始化索引位置
*
* 优先下载指定索引后的切片
* 如果指定的切片索引大于切片总数则此操作无效
* 如果指定的切片索引小于当前正在下载的切片索引并且指定索引和当前索引区间内有未下载的切片则优先下载该区间的切片否则此操作无效
* 如果指定索引后的切片已经全部下载完成但是索引前有未下载的切片间会自动下载未下载的切片
*
* @param jumpIndex 指定的切片位置
*/
public M3U8VodOption setPeerIndex(int jumpIndex) {
if (jumpIndex < 1) {
ALog.e(TAG, "切片索引不能小于1");
return this;
}
this.jumpIndex = jumpIndex;
return this;
}
public long getFileSize() {
return fileSize;
}
public int getJumpIndex() {
return jumpIndex;
}
}

@ -18,10 +18,9 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IOptionConstant; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -34,8 +33,6 @@ public class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
FtpBuilderTarget(String url) { FtpBuilderTarget(String url) {
mConfigHandler = new DNormalConfigHandler<>(this, -1); mConfigHandler = new DNormalConfigHandler<>(this, -1);
mConfigHandler.setUrl(url); mConfigHandler.setUrl(url);
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(url));
getTaskWrapper().setRequestType(ITaskWrapper.D_FTP); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP);
} }
@ -43,8 +40,13 @@ public class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
* 设置登陆字符串编码ftps等参数 * 设置登陆字符串编码ftps等参数
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDelegate<FtpBuilderTarget> option() { public FtpBuilderTarget option(FtpOption option) {
return new FtpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("ftp 任务配置为空");
}
option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(mConfigHandler.getUrl()));
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
/** /**

@ -17,10 +17,9 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.IOptionConstant; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -30,12 +29,12 @@ import com.arialyy.aria.util.CommonUtil;
*/ */
public class FtpDirBuilderTarget extends AbsBuilderTarget<FtpDirBuilderTarget> { public class FtpDirBuilderTarget extends AbsBuilderTarget<FtpDirBuilderTarget> {
private FtpDirConfigHandler<FtpDirBuilderTarget> mConfigHandler; private FtpDirConfigHandler<FtpDirBuilderTarget> mConfigHandler;
private String url;
FtpDirBuilderTarget(String url) { FtpDirBuilderTarget(String url) {
this.url = url;
mConfigHandler = new FtpDirConfigHandler<>(this, -1); mConfigHandler = new FtpDirConfigHandler<>(this, -1);
getEntity().setGroupHash(url); getEntity().setGroupHash(url);
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(url));
} }
/** /**
@ -75,8 +74,13 @@ public class FtpDirBuilderTarget extends AbsBuilderTarget<FtpDirBuilderTarget> {
* 设置登陆字符串编码ftps等参数 * 设置登陆字符串编码ftps等参数
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDelegate<FtpDirBuilderTarget> option() { public FtpDirBuilderTarget option(FtpOption option) {
return new FtpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("ftp 任务配置为空");
}
option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(url));
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
@Override public DownloadGroupEntity getEntity() { @Override public DownloadGroupEntity getEntity() {

@ -17,10 +17,9 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.IOptionConstant; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -33,8 +32,6 @@ public class FtpDirNormalTarget extends AbsNormalTarget<FtpDirNormalTarget> {
FtpDirNormalTarget(long taskId) { FtpDirNormalTarget(long taskId) {
mConfigHandler = new FtpDirConfigHandler<>(this, taskId); mConfigHandler = new FtpDirConfigHandler<>(this, taskId);
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(getEntity().getKey()));
} }
@Override public boolean isRunning() { @Override public boolean isRunning() {
@ -73,8 +70,13 @@ public class FtpDirNormalTarget extends AbsNormalTarget<FtpDirNormalTarget> {
* 设置登陆字符串编码ftps等参数 * 设置登陆字符串编码ftps等参数
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDelegate<FtpDirNormalTarget> option() { public FtpDirNormalTarget option(FtpOption option) {
return new FtpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("ftp 任务配置为空");
}
option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getKey()));
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
@Override public DownloadGroupEntity getEntity() { @Override public DownloadGroupEntity getEntity() {

@ -18,10 +18,9 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IOptionConstant; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -34,8 +33,6 @@ public class FtpNormalTarget extends AbsNormalTarget<FtpNormalTarget> {
FtpNormalTarget(long taskId) { FtpNormalTarget(long taskId) {
mConfigHandler = new DNormalConfigHandler<>(this, taskId); mConfigHandler = new DNormalConfigHandler<>(this, taskId);
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(getEntity().getUrl()));
getTaskWrapper().setRequestType(ITaskWrapper.D_FTP); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP);
} }
@ -43,8 +40,13 @@ public class FtpNormalTarget extends AbsNormalTarget<FtpNormalTarget> {
* 设置登陆字符串编码ftps等参数 * 设置登陆字符串编码ftps等参数
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDelegate<FtpNormalTarget> option() { public FtpNormalTarget option(FtpOption option) {
return new FtpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("ftp 任务配置为空");
}
option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getUrl()));
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
/** /**

@ -17,7 +17,7 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.HttpDelegate; import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.download.DGTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant; import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.inf.Suggest;
@ -45,8 +45,12 @@ public class GroupBuilderTarget extends AbsBuilderTarget<GroupBuilderTarget> {
* 设置http请求参数header等信息 * 设置http请求参数header等信息
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpDelegate<GroupBuilderTarget> option() { public GroupBuilderTarget option(HttpOption option) {
return new HttpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("任务配置为空");
}
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
/** /**

@ -17,10 +17,10 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.HttpDelegate;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.core.manager.SubTaskManager;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import java.util.List; import java.util.List;
/** /**
@ -39,8 +39,12 @@ public class GroupNormalTarget extends AbsNormalTarget<GroupNormalTarget> {
* 设置http请求参数header等信息 * 设置http请求参数header等信息
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpDelegate<GroupNormalTarget> option() { public GroupNormalTarget option(HttpOption option) {
return new HttpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("任务配置为空");
}
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
/** /**

@ -18,11 +18,14 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.HttpDelegate; import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.download.m3u8.M3U8Delegate; import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.processor.IHttpFileLenAdapter; import com.arialyy.aria.core.download.m3u8.M3U8LiveOption;
import com.arialyy.aria.core.download.m3u8.M3U8VodOption;
import com.arialyy.aria.core.inf.IOptionConstant; import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.processor.IHttpFileLenAdapter;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
@ -36,16 +39,37 @@ public class HttpBuilderTarget extends AbsBuilderTarget<HttpBuilderTarget> {
mConfigHandler.setUrl(url); mConfigHandler.setUrl(url);
} }
@CheckResult(suggest = Suggest.TASK_CONTROLLER) public M3U8Delegate<HttpBuilderTarget> asM3U8() { @CheckResult(suggest = Suggest.TASK_CONTROLLER)
return new M3U8Delegate<>(this, getTaskWrapper()); public HttpBuilderTarget m3u8VodOption(M3U8VodOption m3U8VodOption) {
if (m3U8VodOption == null){
throw new NullPointerException("m3u8任务设置为空");
}
getTaskWrapper().setRequestType(AbsTaskWrapper.M3U8_VOD);
getTaskWrapper().getEntity().setFileSize(m3U8VodOption.getFileSize());
((DTaskWrapper) getTaskWrapper()).getM3U8Params().setParams(m3U8VodOption);
return this;
}
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpBuilderTarget m3u8LiveOption(M3U8LiveOption m3U8LiveOption) {
if (m3U8LiveOption == null){
throw new NullPointerException("m3u8任务设置为空");
}
getTaskWrapper().setRequestType(AbsTaskWrapper.M3U8_LIVE);
((DTaskWrapper) getTaskWrapper()).getM3U8Params().setParams(m3U8LiveOption);
return this;
} }
/** /**
* 设置http请求参数header等信息 * 设置http请求参数header等信息
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpDelegate<HttpBuilderTarget> option() { public HttpBuilderTarget option(HttpOption option) {
return new HttpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("任务配置为空");
}
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
/** /**

@ -17,10 +17,13 @@ package com.arialyy.aria.core.download.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.common.HttpDelegate; import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.m3u8.M3U8Delegate; import com.arialyy.aria.core.download.m3u8.M3U8LiveOption;
import com.arialyy.aria.core.download.m3u8.M3U8VodOption;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/** /**
* Created by lyy on 2016/12/5. * Created by lyy on 2016/12/5.
@ -35,16 +38,41 @@ public class HttpNormalTarget extends AbsNormalTarget<HttpNormalTarget> {
} }
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public M3U8Delegate<HttpNormalTarget> asM3U8() { public M3U8NormalTarget m3u8VodOption(M3U8VodOption m3U8VodOption) {
return new M3U8Delegate<>(this, getTaskWrapper()); if (m3U8VodOption == null) {
throw new NullPointerException("m3u8任务设置为空");
}
getTaskWrapper().setRequestType(AbsTaskWrapper.M3U8_VOD);
getTaskWrapper().getEntity().setFileSize(m3U8VodOption.getFileSize());
((DTaskWrapper) getTaskWrapper()).getM3U8Params().setParams(m3U8VodOption);
return new M3U8NormalTarget((DTaskWrapper) getTaskWrapper());
}
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public M3U8NormalTarget m3u8VodOption() {
return new M3U8NormalTarget((DTaskWrapper) getTaskWrapper());
}
@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpNormalTarget m3u8LiveOption(M3U8LiveOption m3U8LiveOption) {
if (m3U8LiveOption == null) {
throw new NullPointerException("m3u8任务设置为空");
}
getTaskWrapper().setRequestType(AbsTaskWrapper.M3U8_LIVE);
((DTaskWrapper) getTaskWrapper()).getM3U8Params().setParams(m3U8LiveOption);
return this;
} }
/** /**
* 设置http请求参数header等信息 * 设置http请求参数header等信息
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpDelegate<HttpNormalTarget> option() { public HttpNormalTarget option(HttpOption option) {
return new HttpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("任务配置为空");
}
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
/** /**

@ -0,0 +1,56 @@
package com.arialyy.aria.core.download.target;
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.download.DTaskWrapper;
import com.arialyy.aria.core.event.EventMsgUtil;
import com.arialyy.aria.core.event.PeerIndexEvent;
import com.arialyy.aria.core.queue.DTaskQueue;
import com.arialyy.aria.util.ALog;
public class M3U8NormalTarget extends AbsNormalTarget<M3U8NormalTarget> {
M3U8NormalTarget(DTaskWrapper wrapper) {
setTaskWrapper(wrapper);
}
/**
* 任务执行中跳转索引位置
* 优先下载指定索引后的切片
* 如果指定的切片索引大于切片总数则此操作无效
* 如果指定的切片索引小于当前正在下载的切片索引并且指定索引和当前索引区间内有未下载的切片则优先下载该区间的切片否则此操作无效
* 如果指定索引后的切片已经全部下载完成但是索引前有未下载的切片间会自动下载未下载的切片
*
* @param index 指定的切片位置
*/
public void jumPeerIndex(int index) {
if (index < 1) {
ALog.e(TAG, "切片索引不能小于1");
return;
}
if (!DTaskQueue.getInstance().taskIsRunning(getTaskWrapper().getKey())) {
ALog.e(TAG,
String.format("任务【%s】没有运行,如果你希望在启动任务时初始化索引位置,请调用setPeerIndex(xxx)",
getTaskWrapper().getKey()));
return;
}
EventMsgUtil.getDefault().post(new PeerIndexEvent(getTaskWrapper().getKey(), index));
}
}

@ -34,14 +34,14 @@ public class TcpBuilderTarget extends AbsBuilderTarget<TcpBuilderTarget> {
mConfigHandler = new DNormalConfigHandler<>(this, -1); mConfigHandler = new DNormalConfigHandler<>(this, -1);
getTaskWrapper().setRequestType(ITaskWrapper.D_TCP); getTaskWrapper().setRequestType(ITaskWrapper.D_TCP);
} }
//
/** ///**
* 设置tcp相应信息 // * 设置tcp相应信息
*/ // */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) //@CheckResult(suggest = Suggest.TASK_CONTROLLER)
public TcpDelegate<TcpBuilderTarget> option() { //public TcpBuilderTarget option(T) {
return new TcpDelegate<>(this, getTaskWrapper()); // return new TcpDelegate<>(this, getTaskWrapper());
} //}
/** /**
* 设置文件存储路径如果需要修改新的文件名修改路径便可 * 设置文件存储路径如果需要修改新的文件名修改路径便可

@ -16,11 +16,7 @@
package com.arialyy.aria.core.download.tcp; package com.arialyy.aria.core.download.tcp;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.BaseOption; import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -28,26 +24,26 @@ import java.nio.charset.Charset;
* @Author aria * @Author aria
* @Date 2019-09-06 * @Date 2019-09-06
*/ */
public class TcpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> { public class TcpDelegate extends BaseOption {
private TcpTaskConfig mTcpConfig; private String params;
private String heartbeatInfo;
private long heartbeat;
private String charset;
public TcpDelegate(TARGET target, AbsTaskWrapper wrapper) { public TcpDelegate() {
super(target, wrapper); super();
mTcpConfig = (TcpTaskConfig) wrapper.getTaskOption();
} }
/** /**
* 上传给tcp服务的初始数据一般是文件名文件路径等信息 * 上传给tcp服务的初始数据一般是文件名文件路径等信息
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public TcpDelegate setParam(String params) {
public TcpDelegate<TARGET> setParam(String params) {
if (TextUtils.isEmpty(params)) { if (TextUtils.isEmpty(params)) {
ALog.w(TAG, "tcp传输的数据不能为空"); ALog.w(TAG, "tcp传输的数据不能为空");
return this; return this;
} }
mTcpConfig.setParams(params); this.params = params;
return this; return this;
} }
@ -56,41 +52,39 @@ public class TcpDelegate<TARGET extends AbsTarget> extends BaseOption<TARGET> {
* *
* @param heartbeatInfo 心跳包数据 * @param heartbeatInfo 心跳包数据
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public TcpDelegate setHeartbeatInfo(String heartbeatInfo) {
public TcpDelegate<TARGET> setHeartbeatInfo(String heartbeatInfo) {
if (TextUtils.isEmpty(heartbeatInfo)) { if (TextUtils.isEmpty(heartbeatInfo)) {
ALog.w(TAG, "心跳包传输的数据不能为空"); ALog.w(TAG, "心跳包传输的数据不能为空");
return this; return this;
} }
mTcpConfig.setHeartbeat(heartbeatInfo); this.heartbeatInfo = heartbeatInfo;
return this; return this;
} }
/** /**
* 心跳间隔默认1s * 心跳间隔默认1s
* *
* @param interval 单位毫秒 * @param heartbeat 单位毫秒
*/ */
@CheckResult(suggest = Suggest.TO_CONTROLLER) public TcpDelegate setHeartbeatInterval(long heartbeat) {
public TcpDelegate<TARGET> setHeartbeatInterval(long interval) { if (heartbeat <= 0) {
if (interval <= 0) {
ALog.w(TAG, "心跳间隔不能小于1毫秒"); ALog.w(TAG, "心跳间隔不能小于1毫秒");
return this; return this;
} }
mTcpConfig.setHeartbeatInterval(interval); this.heartbeat = heartbeat;
return this; return this;
} }
/** /**
* 数据传输编码默认"utf-8" * 数据传输编码默认"utf-8"
*/ */
public TcpDelegate<TARGET> setCharset(String charset) { public TcpDelegate setCharset(String charset) {
if (!Charset.isSupported(charset)) { if (!Charset.isSupported(charset)) {
ALog.w(TAG, "不支持的编码"); ALog.w(TAG, "不支持的编码");
return this; return this;
} }
mTcpConfig.setCharset(charset); this.charset = charset;
return this; return this;
} }
} }

@ -17,12 +17,13 @@ package com.arialyy.aria.core.upload.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.arialyy.aria.core.processor.IFtpUploadInterceptor;
import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.FtpDelegate; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.processor.IFtpUploadInterceptor;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
/** /**
* Created by Aria.Lao on 2017/7/27. * Created by Aria.Lao on 2017/7/27.
@ -30,6 +31,7 @@ import com.arialyy.aria.util.CheckUtil;
*/ */
public class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> { public class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
private UNormalConfigHandler<FtpBuilderTarget> mConfigHandler; private UNormalConfigHandler<FtpBuilderTarget> mConfigHandler;
private String url;
FtpBuilderTarget(String filePath) { FtpBuilderTarget(String filePath) {
mConfigHandler = new UNormalConfigHandler<>(this, -1); mConfigHandler = new UNormalConfigHandler<>(this, -1);
@ -44,6 +46,7 @@ public class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpBuilderTarget setUploadUrl(String tempUrl) { public FtpBuilderTarget setUploadUrl(String tempUrl) {
url = tempUrl;
mConfigHandler.setTempUrl(tempUrl); mConfigHandler.setTempUrl(tempUrl);
return this; return this;
} }
@ -61,7 +64,12 @@ public class FtpBuilderTarget extends AbsBuilderTarget<FtpBuilderTarget> {
* 设置登陆字符串编码ftps等参数 * 设置登陆字符串编码ftps等参数
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDelegate<FtpBuilderTarget> option() { public FtpBuilderTarget option(FtpOption option) {
return new FtpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("ftp 任务配置为空");
}
option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(url));
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
} }

@ -17,11 +17,10 @@ package com.arialyy.aria.core.upload.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.FtpDelegate;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
/** /**
@ -33,9 +32,6 @@ public class FtpNormalTarget extends AbsNormalTarget<FtpNormalTarget> {
FtpNormalTarget(long taskId) { FtpNormalTarget(long taskId) {
mConfigHandler = new UNormalConfigHandler<>(this, taskId); mConfigHandler = new UNormalConfigHandler<>(this, taskId);
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(getEntity().getUrl()));
getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP); getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP);
} }
@ -43,8 +39,13 @@ public class FtpNormalTarget extends AbsNormalTarget<FtpNormalTarget> {
* 设置登陆字符串编码ftps等参数 * 设置登陆字符串编码ftps等参数
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public FtpDelegate<FtpNormalTarget> option() { public FtpNormalTarget option(FtpOption option) {
return new FtpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("ftp 任务配置为空");
}
option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getUrl()));
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
@Override public UploadEntity getEntity() { @Override public UploadEntity getEntity() {

@ -17,8 +17,8 @@ package com.arialyy.aria.core.upload.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.AbsBuilderTarget;
import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.HttpDelegate;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/** /**
@ -52,7 +52,12 @@ public class HttpBuilderTarget extends AbsBuilderTarget<HttpBuilderTarget> {
* 设置http请求参数header等信息 * 设置http请求参数header等信息
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpDelegate<HttpBuilderTarget> option() { public HttpBuilderTarget option(HttpOption option) {
return new HttpDelegate<>(this, getTaskWrapper());
if (option == null) {
throw new NullPointerException("任务配置为空");
}
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
} }

@ -17,8 +17,8 @@ package com.arialyy.aria.core.upload.target;
import androidx.annotation.CheckResult; import androidx.annotation.CheckResult;
import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.AbsNormalTarget;
import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.inf.Suggest; import com.arialyy.aria.core.inf.Suggest;
import com.arialyy.aria.core.common.HttpDelegate;
import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
/** /**
@ -49,8 +49,12 @@ public class HttpNormalTarget extends AbsNormalTarget<HttpNormalTarget> {
* 设置http请求参数header等信息 * 设置http请求参数header等信息
*/ */
@CheckResult(suggest = Suggest.TASK_CONTROLLER) @CheckResult(suggest = Suggest.TASK_CONTROLLER)
public HttpDelegate<HttpNormalTarget> option() { public HttpNormalTarget option(HttpOption option) {
return new HttpDelegate<>(this, getTaskWrapper()); if (option == null) {
throw new NullPointerException("任务配置为空");
}
getTaskWrapper().getOptionParams().setParams(option);
return this;
} }
@Override public boolean isRunning() { @Override public boolean isRunning() {

@ -86,8 +86,6 @@ class UNormalConfigHandler<TARGET extends AbsTarget> implements IConfigHandler {
void setTempUrl(String tempUrl) { void setTempUrl(String tempUrl) {
getTaskWrapper().setTempUrl(tempUrl); getTaskWrapper().setTempUrl(tempUrl);
getTaskWrapper().getOptionParams()
.setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(tempUrl));
} }
private UTaskWrapper getTaskWrapper() { private UTaskWrapper getTaskWrapper() {

@ -15,8 +15,11 @@
*/ */
package com.arialyy.aria.core; package com.arialyy.aria.core;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.inf.IEventHandler; import com.arialyy.aria.core.inf.IEventHandler;
import com.arialyy.aria.core.inf.IOptionConstant; import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -38,6 +41,34 @@ public class TaskOptionParams {
*/ */
private Map<String, IEventHandler> handler = new HashMap<>(); private Map<String, IEventHandler> handler = new HashMap<>();
/**
* 设置任务参数
*
* @param option 任务配置
*/
public void setParams(BaseOption option) {
Field[] fields = CommonUtil.getFields(option.getClass());
for (Field field : fields) {
field.setAccessible(true);
try {
if (field.getType() == IEventHandler.class) {
Object eventHandler = field.get(option);
if (eventHandler != null) {
setObjs(field.getName(), (IEventHandler) eventHandler);
}
} else {
Object params = field.get(option);
if (params != null) {
setParams(field.getName(), params);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/** /**
* 设置普通参数 * 设置普通参数
* *
@ -60,11 +91,11 @@ public class TaskOptionParams {
return params; return params;
} }
public Object getParam(String key){ public Object getParam(String key) {
return params.get(key); return params.get(key);
} }
public IEventHandler getHandler(String key){ public IEventHandler getHandler(String key) {
return handler.get(key); return handler.get(key);
} }

@ -0,0 +1,26 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.core.common;
import com.arialyy.aria.util.CommonUtil;
public abstract class BaseOption {
protected final String TAG;
public BaseOption() {
TAG = CommonUtil.getClassName(getClass());
}
}

@ -21,17 +21,10 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Environment; import android.os.Environment;
import android.os.Handler;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Base64; import android.util.Base64;
import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.TaskOptionParams;
import com.arialyy.aria.core.inf.IEventHandler;
import com.arialyy.aria.core.inf.ITaskOption;
import com.arialyy.aria.core.listener.IEventListener;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import dalvik.system.DexFile; import dalvik.system.DexFile;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
@ -41,7 +34,6 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.ref.SoftReference;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -69,7 +61,6 @@ public class CommonUtil {
public static final String SERVER_CHARSET = "ISO-8859-1"; public static final String SERVER_CHARSET = "ISO-8859-1";
private static long lastClickTime; private static long lastClickTime;
/** /**
* 检查sql的expression是否合法 * 检查sql的expression是否合法
* *

@ -23,8 +23,7 @@ import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders; import androidx.lifecycle.ViewModelProviders;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.ProtocolType; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.DownloadTask;
@ -89,16 +88,14 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
} }
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
if (mTaskId == -1) { if (mTaskId == -1) {
mTaskId = Aria.download(this).loadFtp(mUrl) mTaskId = Aria.download(this).loadFtp(mUrl)
.setFilePath(mFilePath, true) .setFilePath(mFilePath, true)
.option() .option(getFtpOption())
.login(user, passw)
//.asFtps()
.controller(ControllerType.CREATE_CONTROLLER)
.create(); .create();
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
break; break;
@ -109,11 +106,7 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
} else { } else {
Aria.download(this) Aria.download(this)
.loadFtp(mTaskId) .loadFtp(mTaskId)
.option() .option(getFtpOption())
.login(user, passw)
//.asFtps()
//.setProtocol(ProtocolType.SSL)
.controller(ControllerType.TASK_CONTROLLER)
.resume(); .resume();
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
} }
@ -127,6 +120,12 @@ public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding
} }
} }
private FtpOption getFtpOption() {
FtpOption option = new FtpOption();
option.login(user, passw);
return option;
}
public void chooseUrl() { public void chooseUrl() {
ModifyUrlDialog dialog = ModifyUrlDialog dialog =
new ModifyUrlDialog(this, getString(R.string.modify_url_dialog_title), mUrl); new ModifyUrlDialog(this, getString(R.string.modify_url_dialog_title), mUrl);

@ -31,6 +31,7 @@ import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders; import androidx.lifecycle.ViewModelProviders;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.common.controller.ControllerType; import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
@ -287,14 +288,14 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
} }
private void startD() { private void startD() {
HttpOption option = new HttpOption();
option.addHeader("1", "@");
mTaskId = Aria.download(SingleTaskActivity.this) mTaskId = Aria.download(SingleTaskActivity.this)
.load(mUrl) .load(mUrl)
.useServerFileName(true) .useServerFileName(true)
.setFilePath(mFilePath, true) .setFilePath(mFilePath, true)
.setFileLenAdapter(new FileLenAdapter()) .setFileLenAdapter(new FileLenAdapter())
.option() .option(option)
.addHeader("1", "@")
.controller(ControllerType.CREATE_CONTROLLER)
.create(); .create();
} }

@ -20,7 +20,7 @@ import android.os.Environment;
import android.view.View; import android.view.View;
import com.arialyy.annotations.DownloadGroup; import com.arialyy.annotations.DownloadGroup;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.controller.ControllerType; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.task.DownloadGroupTask; import com.arialyy.aria.core.task.DownloadGroupTask;
@ -78,9 +78,7 @@ public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBi
.setDirPath( .setDirPath(
Environment.getExternalStorageDirectory().getPath() + "/Download/ftp_dir") Environment.getExternalStorageDirectory().getPath() + "/Download/ftp_dir")
.setGroupAlias("ftp文件夹下载") .setGroupAlias("ftp文件夹下载")
.option() .option(getFtpOption())
.login(user, pwd)
.controller(ControllerType.CREATE_CONTROLLER)
.create(); .create();
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
break; break;
@ -91,9 +89,7 @@ public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBi
} else { } else {
Aria.download(this) Aria.download(this)
.loadFtpDir(mTaskId) .loadFtpDir(mTaskId)
.option() .option(getFtpOption())
.login(user, pwd)
.controller(ControllerType.TASK_CONTROLLER)
.resume(); .resume();
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
} }
@ -105,6 +101,12 @@ public class FTPDirDownloadActivity extends BaseActivity<ActivityDownloadGroupBi
} }
} }
private FtpOption getFtpOption() {
FtpOption option = new FtpOption();
option.login(user, pwd);
return option;
}
@DownloadGroup.onPre() protected void onPre(DownloadGroupTask task) { @DownloadGroup.onPre() protected void onPre(DownloadGroupTask task) {
L.d(TAG, "group pre"); L.d(TAG, "group pre");
} }

@ -27,8 +27,9 @@ import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders; import androidx.lifecycle.ViewModelProviders;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.m3u8.M3U8LiveOption;
import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
import com.arialyy.aria.core.processor.ILiveTsUrlConverter; import com.arialyy.aria.core.processor.ILiveTsUrlConverter;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
@ -213,27 +214,18 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
startD(); startD();
//if (!AppUtil.chekEntityValid(mEntity)) { if (!AppUtil.chekEntityValid(mEntity)) {
// startD(); startD();
// break; break;
//} }
//if (Aria.download(this).load(mEntity.getId()).isRunning()) { if (Aria.download(this).load(mEntity.getId()).isRunning()) {
// Aria.download(this).load(mEntity.getId()).stop(); Aria.download(this).load(mEntity.getId()).stop();
//} else { } else {
// Aria.download(this).load(mEntity.getId()) Aria.download(this).load(mEntity.getId())
// .asM3U8() .m3u8LiveOption(getLiveoption())
// .asLive() .resume();
// .setLiveTsUrlConvert(new ILiveTsUrlConverter() { }
// @Override public String convert(String m3u8Url, String tsUrl) { break;
// int index = m3u8Url.lastIndexOf("/");
// String parentUrl = m3u8Url.substring(0, index + 1);
// return parentUrl + tsUrl;
// }
// })
// .controller(ControllerType.TASK_CONTROLLER)
// .resume();
//}
//break;
case R.id.cancel: case R.id.cancel:
if (AppUtil.chekEntityValid(mEntity)) { if (AppUtil.chekEntityValid(mEntity)) {
Aria.download(this).load(mEntity.getId()).cancel(true); Aria.download(this).load(mEntity.getId()).cancel(true);
@ -247,31 +239,18 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
.load(mUrl) .load(mUrl)
.useServerFileName(true) .useServerFileName(true)
.setFilePath(mFilePath, true) .setFilePath(mFilePath, true)
.asM3U8() .m3u8LiveOption(getLiveoption())
//.setBandWidthUrlConverter(new IBandWidthUrlConverter() {
// @Override public String convert(String bandWidthUrl) {
// int peerIndex = mUrl.lastIndexOf("/");
// return mUrl.substring(0, peerIndex + 1) + bandWidthUrl;
// }
//})
.asLive()
.setLiveTsUrlConvert(new LiveTsUrlConverter())
.controller(ControllerType.CREATE_CONTROLLER)
//.setLiveTsUrlConvert(new IVodTsUrlConverter() {
// @Override public List<String> convert(String m3u8Url, List<String> tsUrls) {
// int peerIndex = m3u8Url.lastIndexOf("/");
// String parentUrl = m3u8Url.substring(0, peerIndex + 1);
// List<String> newUrls = new ArrayList<>();
// for (String url : tsUrls) {
// newUrls.add(parentUrl + url);
// }
//
// return newUrls;
// }
//})
.create(); .create();
} }
private M3U8LiveOption getLiveoption() {
M3U8LiveOption option = new M3U8LiveOption();
option
.setLiveTsUrlConvert(new LiveTsUrlConverter());
//.setBandWidthUrlConverter(new BandWidthUrlConverter(mUrl));
return option;
}
@Override protected void dataCallback(int result, Object data) { @Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data); super.dataCallback(result, data);
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) { if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) {
@ -288,4 +267,17 @@ public class M3U8LiveDLoadActivity extends BaseActivity<ActivityM3u8LiveBinding>
return parentUrl + tsUrl; return parentUrl + tsUrl;
} }
} }
static class BandWidthUrlConverter implements IBandWidthUrlConverter {
String url;
BandWidthUrlConverter(String url) {
this.url = url;
}
@Override public String convert(String bandWidthUrl) {
int peerIndex = url.lastIndexOf("/");
return url.substring(0, peerIndex + 1) + bandWidthUrl;
}
}
} }

@ -31,10 +31,11 @@ import com.arialyy.annotations.Download;
import com.arialyy.annotations.M3U8; import com.arialyy.annotations.M3U8;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.controller.BuilderController; 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.DownloadEntity;
import com.arialyy.aria.core.download.M3U8Entity; import com.arialyy.aria.core.download.M3U8Entity;
import com.arialyy.aria.core.download.m3u8.M3U8VodOption;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
import com.arialyy.aria.core.processor.ITsMergeHandler; import com.arialyy.aria.core.processor.ITsMergeHandler;
import com.arialyy.aria.core.processor.IVodTsUrlConverter; import com.arialyy.aria.core.processor.IVodTsUrlConverter;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.DownloadTask;
@ -122,7 +123,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void jumpIndex(PeerIndex index) { public void jumpIndex(PeerIndex index) {
Aria.download(this).load(mUrl).asM3U8().asVod().jumPeerIndex(index.index); Aria.download(this).load(mTaskId).m3u8VodOption().jumPeerIndex(index.index);
} }
@Override @Override
@ -280,27 +281,7 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
} else { } else {
Aria.download(this) Aria.download(this)
.load(mTaskId) .load(mTaskId)
.asM3U8() .m3u8VodOption(getM3U8Option())
//.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) {
Uri uri = Uri.parse(m3u8Url);
String parentUrl = "http://" + uri.getHost();
List<String> newUrls = new ArrayList<>();
for (String url : tsUrls) {
newUrls.add(parentUrl + url);
}
return newUrls;
}
})
.controller(ControllerType.TASK_CONTROLLER)
.resume(); .resume();
} }
break; break;
@ -316,17 +297,35 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
.load(mUrl) .load(mUrl)
.useServerFileName(true) .useServerFileName(true)
.setFilePath(mFilePath, true) .setFilePath(mFilePath, true)
.asM3U8() .m3u8VodOption(getM3U8Option())
//.setBandWidthUrlConverter(new IBandWidthUrlConverter() { .create();
// @Override public String convert(String bandWidthUrl) { }
// int index = mUrl.lastIndexOf("/");
// return mUrl.substring(0, index + 1) + bandWidthUrl; private M3U8VodOption getM3U8Option() {
// } M3U8VodOption option = new M3U8VodOption();
//}) option
.setTsUrlConvert(new IVodTsUrlConverter() { .generateIndexFile()
.setTsUrlConvert(new VodTsUrlConverter())
.setMergeHandler(new TsMergeHandler());
//.setBandWidthUrlConverter(new BandWidthUrlConverter(mUrl));
return option;
}
private Class<BuilderController> c = BuilderController.class;
@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) {
mModule.uploadUrl(this, String.valueOf(data));
} else if (result == ModifyPathDialog.MODIFY_PATH_RESULT) {
mModule.updateFilePath(this, String.valueOf(data));
}
}
static class VodTsUrlConverter implements IVodTsUrlConverter {
@Override public List<String> convert(String m3u8Url, List<String> tsUrls) { @Override public List<String> convert(String m3u8Url, List<String> tsUrls) {
Uri uri = Uri.parse(m3u8Url); Uri uri = Uri.parse(m3u8Url);
String parentUrl = uri.getScheme() + "://" + uri.getHost(); String parentUrl = "http://" + uri.getHost();
List<String> newUrls = new ArrayList<>(); List<String> newUrls = new ArrayList<>();
for (String url : tsUrls) { for (String url : tsUrls) {
newUrls.add(parentUrl + url); newUrls.add(parentUrl + url);
@ -334,26 +333,26 @@ public class M3U8VodDLoadActivity extends BaseActivity<ActivityM3u8VodBinding> {
return newUrls; return newUrls;
} }
}) }
.setMergeHandler(new ITsMergeHandler() {
static class TsMergeHandler implements ITsMergeHandler {
public boolean merge(@Nullable M3U8Entity m3U8Entity, List<String> tsPath) { public boolean merge(@Nullable M3U8Entity m3U8Entity, List<String> tsPath) {
ALog.d(TAG, "合并TS...."); ALog.d("TsMergeHandler", "合并TS....");
return false; return false;
} }
})
.generateIndexFile()
.controller(ControllerType.CREATE_CONTROLLER)
.create();
} }
private Class<BuilderController> c = BuilderController.class; static class BandWidthUrlConverter implements IBandWidthUrlConverter {
@Override protected void dataCallback(int result, Object data) { private String url;
super.dataCallback(result, data);
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) { BandWidthUrlConverter(String url) {
mModule.uploadUrl(this, String.valueOf(data)); this.url = url;
} else if (result == ModifyPathDialog.MODIFY_PATH_RESULT) { }
mModule.updateFilePath(this, String.valueOf(data));
@Override public String convert(String bandWidthUrl) {
int index = url.lastIndexOf("/");
return url.substring(0, index + 1) + bandWidthUrl;
} }
} }
} }

@ -25,10 +25,8 @@ import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders; import androidx.lifecycle.ViewModelProviders;
import com.arialyy.annotations.Upload; import com.arialyy.annotations.Upload;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.controller.ControllerType; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.processor.FtpInterceptHandler;
import com.arialyy.aria.core.processor.IFtpUploadInterceptor;
import com.arialyy.aria.core.task.UploadTask; import com.arialyy.aria.core.task.UploadTask;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
@ -42,7 +40,6 @@ import com.arialyy.simple.databinding.ActivityFtpUploadBinding;
import com.arialyy.simple.util.AppUtil; import com.arialyy.simple.util.AppUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
/** /**
* Created by lyy on 2017/7/28. Ftp 文件上传demo * Created by lyy on 2017/7/28. Ftp 文件上传demo
@ -118,9 +115,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
mTaskId = Aria.upload(this) mTaskId = Aria.upload(this)
.loadFtp(mFilePath) .loadFtp(mFilePath)
.setUploadUrl(mUrl) .setUploadUrl(mUrl)
.option() .option(getOption())
.login(user, pwd)
.controller(ControllerType.CREATE_CONTROLLER)
.create(); .create();
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
break; break;
@ -131,9 +126,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
} else { } else {
Aria.upload(this) Aria.upload(this)
.loadFtp(mTaskId) .loadFtp(mTaskId)
.option() .option(getOption())
.login(user, pwd)
.controller(ControllerType.TASK_CONTROLLER)
.resume(); .resume();
getBinding().setStateStr(getString(R.string.stop)); getBinding().setStateStr(getString(R.string.stop));
} }
@ -147,6 +140,12 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
} }
} }
private FtpOption getOption() {
FtpOption option = new FtpOption();
option.login(user, pwd);
return option;
}
@Upload.onWait void onWait(UploadTask task) { @Upload.onWait void onWait(UploadTask task) {
Log.d(TAG, task.getTaskName() + "_wait"); Log.d(TAG, task.getTaskName() + "_wait");
} }

@ -21,8 +21,8 @@ import android.os.Environment;
import android.view.View; import android.view.View;
import com.arialyy.annotations.Upload; import com.arialyy.annotations.Upload;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.HttpOption;
import com.arialyy.aria.core.common.RequestEnum; import com.arialyy.aria.core.common.RequestEnum;
import com.arialyy.aria.core.common.controller.ControllerType;
import com.arialyy.aria.core.task.UploadTask; import com.arialyy.aria.core.task.UploadTask;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.frame.util.FileUtil; import com.arialyy.frame.util.FileUtil;
@ -76,15 +76,15 @@ public class HttpUploadActivity extends BaseActivity<ActivityUploadBinding> {
} }
void upload() { void upload() {
HttpOption option = new HttpOption();
option.setRequestType(RequestEnum.POST)
.setParam("params", "bbbbbbbb");
Aria.upload(HttpUploadActivity.this).load(FILE_PATH) Aria.upload(HttpUploadActivity.this).load(FILE_PATH)
//.setUploadUrl("http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".apk\"}") //.setUploadUrl("http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".apk\"}")
.setUploadUrl("http://9.9.9.205:5000/upload/") .setUploadUrl("http://9.9.9.205:5000/upload/")
//.setTempUrl("http://192.168.1.6:8080/upload/sign_file/").setAttachment("file") //.setTempUrl("http://192.168.1.6:8080/upload/sign_file/").setAttachment("file")
//.addHeader("iplanetdirectorypro", "11a09102fb934ad0bc206f9c611d7933") //.addHeader("iplanetdirectorypro", "11a09102fb934ad0bc206f9c611d7933")
.option() .option(option)
.setRequestType(RequestEnum.POST)
.setParam("params", "bbbbbbbb")
.controller(ControllerType.CREATE_CONTROLLER)
.create(); .create();
} }

@ -20,7 +20,7 @@ import android.os.Environment;
import android.util.Log; import android.util.Log;
import com.arialyy.annotations.Download; import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.controller.ControllerType; import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.task.DownloadTask; import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -108,18 +108,21 @@ public class AnyRunnModule {
Aria.download(this) Aria.download(this)
.loadFtp(url) .loadFtp(url)
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/Download/") .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/Download/")
.option() .option(getFtpOption())
.asFtps()
.setStorePath("/mnt/sdcard/Download/server.crt")
.setAlias("www.laoyuyu.me")
.setStorePass("123456")
.controller(ControllerType.CREATE_CONTROLLER)
.create(); .create();
} else { } else {
Aria.download(this).load(mEntity.getId()).resume(); Aria.download(this).load(mEntity.getId()).resume();
} }
} }
private FtpOption getFtpOption() {
FtpOption option = new FtpOption();
option.setStorePath("/mnt/sdcard/Download/server.crt")
.setAlias("www.laoyuyu.me")
.setStorePass("123456");
return option;
}
public void stop(String url) { public void stop(String url) {
if (AppUtil.chekEntityValid(mEntity)) { if (AppUtil.chekEntityValid(mEntity)) {
Aria.download(this).load(mEntity.getId()).stop(); Aria.download(this).load(mEntity.getId()).stop();

Loading…
Cancel
Save