diff --git a/Aria/build.gradle b/Aria/build.gradle index 08cb9b35..0c8ad2ce 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -28,7 +28,7 @@ dependencies { api project(':AriaAnnotations') 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') // 打包时用这个 // compile project(':AriaFtpPlug') diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java index 0a4e505b..110c18f0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsNormalTarget.java @@ -36,14 +36,18 @@ public abstract class AbsNormalTarget extends Ab * * @return {@code true} 任务正在执行 */ - public abstract boolean isRunning(); + public boolean isRunning() { + return false; + } /** * 任务是否存在 * * @return {@code true} 任务存在 */ - public abstract boolean taskExists(); + public boolean taskExists() { + return false; + } private NormalController mNormalController; diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/BaseOption.java b/Aria/src/main/java/com/arialyy/aria/core/common/BaseOption.java deleted file mode 100644 index c3858bfa..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/common/BaseOption.java +++ /dev/null @@ -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 { - 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 controller(@ControllerType Class clazz) { - return FeatureController.newInstance(clazz, getTaskWrapper()); - } -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/FTPSDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/FTPSDelegate.java deleted file mode 100644 index 6660f84c..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/common/FTPSDelegate.java +++ /dev/null @@ -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 extends BaseOption { - - 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 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 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 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 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 setImplicit(boolean isImplicit) { - mUrlEntity.isImplicit = isImplicit; - return this; - } -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/FtpDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/FtpDelegate.java deleted file mode 100644 index 11c181ed..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/common/FtpDelegate.java +++ /dev/null @@ -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 extends BaseOption { - private static final String TAG = "FtpDelegate"; - - public FtpDelegate(TARGET target, AbsTaskWrapper wrapper) { - super(target, wrapper); - } - - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public FtpDelegate 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 login(String userName, String password) { - return login(userName, password, null); - } - - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public FtpDelegate 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 asFtps() { - return new FTPSDelegate<>(mTarget, mWrapper); - } - - /** - * 配置ftp客户端信息 - */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public FtpDelegate setFtpClentConfig(FTPClientConfig config) { - getTaskWrapper().getOptionParams().setParams(IOptionConstant.clientConfig, config); - return this; - } - - //@Override public TARGET setProxy(Proxy proxy) { - // mTarget.getTaskWrapper().asFtp().setProxy(proxy); - // return mTarget; - //} -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/FtpOption.java b/Aria/src/main/java/com/arialyy/aria/core/common/FtpOption.java new file mode 100644 index 00000000..ff5c1b52 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/common/FtpOption.java @@ -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; + } + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/HttpDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/HttpOption.java similarity index 62% rename from Aria/src/main/java/com/arialyy/aria/core/common/HttpDelegate.java rename to Aria/src/main/java/com/arialyy/aria/core/common/HttpOption.java index a9288aa0..0eb46613 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/HttpDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/HttpOption.java @@ -18,10 +18,7 @@ package com.arialyy.aria.core.common; import android.text.TextUtils; import androidx.annotation.CheckResult; 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.wrapper.AbsTaskWrapper; import com.arialyy.aria.util.ALog; import java.net.Proxy; import java.util.HashMap; @@ -30,13 +27,16 @@ import java.util.Map; /** * HTTP任务设置 */ -public class HttpDelegate extends BaseOption { +public class HttpOption extends BaseOption { private Map params; private Map headers; + private RequestEnum requestEnum = RequestEnum.GET; + private Map formFields; + private Proxy proxy; - public HttpDelegate(TARGET target, AbsTaskWrapper wrapper) { - super(target, wrapper); + public HttpOption() { + super(); } /** @@ -45,29 +45,26 @@ public class HttpDelegate extends BaseOption { * @param requestEnum {@link RequestEnum} */ @CheckResult(suggest = Suggest.TO_CONTROLLER) - public HttpDelegate setRequestType(RequestEnum requestEnum) { - getTaskWrapper().getOptionParams().setParams(IOptionConstant.requestEnum, requestEnum); + public HttpOption setRequestType(RequestEnum requestEnum) { + this.requestEnum = requestEnum; return this; } /** * 设置http请求参数 */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public HttpDelegate setParams(Map params) { + public HttpOption setParams(Map params) { if (this.params == null) { this.params = new HashMap<>(); } this.params.putAll(params); - getTaskWrapper().getOptionParams().setParams(IOptionConstant.params, this.params); return this; } /** * 设置http请求参数 */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public HttpDelegate setParam(String key, String value) { + public HttpOption setParam(String key, String value) { if (TextUtils.isEmpty(key) || TextUtils.isEmpty(value)) { ALog.d(TAG, "key 或value 为空"); return this; @@ -76,16 +73,14 @@ public class HttpDelegate extends BaseOption { params = new HashMap<>(); } params.put(key, value); - getTaskWrapper().getOptionParams().setParams(IOptionConstant.params, params); return this; } /** * 设置http表单字段 */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public HttpDelegate setFormFields(Map params) { - getTaskWrapper().getOptionParams().setParams(IOptionConstant.formFields, params); + public HttpOption setFormFields(Map formFields) { + this.formFields = formFields; return this; } @@ -96,8 +91,7 @@ public class HttpDelegate extends BaseOption { * @param key header对应的key * @param value header对应的value */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public HttpDelegate addHeader(@NonNull String key, @NonNull String value) { + public HttpOption addHeader(@NonNull String key, @NonNull String value) { if (TextUtils.isEmpty(key)) { ALog.w(TAG, "设置header失败,header对应的key不能为null"); return this; @@ -109,7 +103,6 @@ public class HttpDelegate extends BaseOption { this.headers = new HashMap<>(); } this.headers.put(key, value); - getTaskWrapper().getOptionParams().setParams(IOptionConstant.headers, this.headers); return this; } @@ -119,8 +112,7 @@ public class HttpDelegate extends BaseOption { * * @param headers 一组http header数据 */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public HttpDelegate addHeaders(@NonNull Map headers) { + public HttpOption addHeaders(@NonNull Map headers) { if (headers.size() == 0) { ALog.w(TAG, "设置header失败,map没有header数据"); return this; @@ -129,16 +121,14 @@ public class HttpDelegate extends BaseOption { this.headers = new HashMap<>(); } this.headers.putAll(headers); - getTaskWrapper().getOptionParams().setParams(IOptionConstant.headers, this.headers); return this; } /** * 设置代理 */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public HttpDelegate setUrlProxy(Proxy proxy) { - getTaskWrapper().getOptionParams().setParams(IOptionConstant.proxy, proxy); + public HttpOption setUrlProxy(Proxy proxy) { + this.proxy = proxy; return this; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java deleted file mode 100644 index 7693ea16..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java +++ /dev/null @@ -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 extends BaseOption { - 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 generateIndexFile() { - mTaskWrapper.getM3U8Params().setParams(IOptionConstant.generateIndexFileTemp, true); - return this; - } - - /** - * 是否合并ts文件,默认合并ts - * - * @param merge {@code true}合并所有ts文件为一个 - */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public M3U8Delegate 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 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 setTsUrlConvert(IVodTsUrlConverter converter) { - CheckUtil.checkMemberClass(converter.getClass()); - mTaskWrapper.getM3U8Params().setObjs(IOptionConstant.vodUrlConverter, converter); - return this; - } - - /** - * 选择需要下载的码率,默认下载的码率 - * - * @param bandWidth 指定的码率 - */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public M3U8Delegate 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 setBandWidthUrlConverter(IBandWidthUrlConverter converter) { - CheckUtil.checkMemberClass(converter.getClass()); - mTaskWrapper.getM3U8Params().setObjs(IOptionConstant.bandWidthUrlConverter, converter); - return this; - } - - /** - * 处理点播文件的下载参数 - */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public M3U8VodDelegate asVod() { - return new M3U8VodDelegate<>(mTarget, mTaskWrapper); - } - - /** - * 处理直播类的下载 - */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public M3U8LiveDelegate asLive() { - return new M3U8LiveDelegate<>(mTarget, mTaskWrapper); - } -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveOption.java similarity index 50% rename from Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveDelegate.java rename to Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveOption.java index a8417898..6d5d000a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveOption.java @@ -15,54 +15,46 @@ */ 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.wrapper.AbsTaskWrapper; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; /** * m3u8直播参数设置 */ -public class M3U8LiveDelegate extends BaseOption { +public class M3U8LiveOption extends M3U8Option { - M3U8LiveDelegate(TARGET target, AbsTaskWrapper wrapper) { - super(target, wrapper); - getTaskWrapper().setRequestType(AbsTaskWrapper.M3U8_LIVE); + private ILiveTsUrlConverter liveTsUrlConverter; + private long liveUpdateInterval; + + public M3U8LiveOption() { + super(); } /** * M3U8 ts 文件url转换器,对于某些服务器,返回的ts地址可以是相对地址,也可能是处理过的 * 对于这种情况,你需要使用url转换器将地址转换为可正常访问的http地址 * - * @param converter {@link ILiveTsUrlConverter} + * @param liveTsUrlConverter {@link ILiveTsUrlConverter} */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public M3U8LiveDelegate setLiveTsUrlConvert(ILiveTsUrlConverter converter) { - CheckUtil.checkMemberClass(converter.getClass()); - ((DTaskWrapper) getTaskWrapper()).getM3U8Params() - .setObjs(IOptionConstant.liveTsUrlConverter, converter); + public M3U8LiveOption setLiveTsUrlConvert(ILiveTsUrlConverter liveTsUrlConverter) { + CheckUtil.checkMemberClass(liveTsUrlConverter.getClass()); + this.liveTsUrlConverter = liveTsUrlConverter; return this; } /** * 设置直播的m3u8文件更新间隔,默认10000微秒。 * - * @param interval 更新间隔,单位微秒 + * @param liveUpdateInterval 更新间隔,单位微秒 */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public M3U8LiveDelegate setM3U8FileUpdateInterval(long interval) { - if (interval <= 1) { + public M3U8LiveOption setM3U8FileUpdateInterval(long liveUpdateInterval) { + if (liveUpdateInterval <= 1) { ALog.e(TAG, "间隔时间错误"); return this; } - ((DTaskWrapper) getTaskWrapper()).getM3U8Params() - .setParams(IOptionConstant.liveUpdateInterval, interval); + + this.liveUpdateInterval = liveUpdateInterval; return this; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Option.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Option.java new file mode 100644 index 00000000..fcd1b8b7 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Option.java @@ -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; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDelegate.java deleted file mode 100644 index b1fca565..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDelegate.java +++ /dev/null @@ -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 extends BaseOption { - 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 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 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 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)); - } -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodOption.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodOption.java new file mode 100644 index 00000000..039009e6 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodOption.java @@ -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; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java index f0ed90dc..b622dd56 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java @@ -18,10 +18,9 @@ package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; import com.arialyy.aria.core.common.AbsBuilderTarget; -import com.arialyy.aria.core.inf.Suggest; -import com.arialyy.aria.core.common.FtpDelegate; +import com.arialyy.aria.core.common.FtpOption; 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.util.CommonUtil; @@ -34,8 +33,6 @@ public class FtpBuilderTarget extends AbsBuilderTarget { FtpBuilderTarget(String url) { mConfigHandler = new DNormalConfigHandler<>(this, -1); mConfigHandler.setUrl(url); - getTaskWrapper().getOptionParams() - .setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(url)); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP); } @@ -43,8 +40,13 @@ public class FtpBuilderTarget extends AbsBuilderTarget { * 设置登陆、字符串编码、ftps等参数 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public FtpDelegate option() { - return new FtpDelegate<>(this, getTaskWrapper()); + public FtpBuilderTarget option(FtpOption option) { + if (option == null) { + throw new NullPointerException("ftp 任务配置为空"); + } + option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(mConfigHandler.getUrl())); + getTaskWrapper().getOptionParams().setParams(option); + return this; } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java index 421756f7..95ec9264 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java @@ -17,10 +17,9 @@ package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsBuilderTarget; -import com.arialyy.aria.core.inf.Suggest; -import com.arialyy.aria.core.common.FtpDelegate; +import com.arialyy.aria.core.common.FtpOption; 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.util.CommonUtil; @@ -30,12 +29,12 @@ import com.arialyy.aria.util.CommonUtil; */ public class FtpDirBuilderTarget extends AbsBuilderTarget { private FtpDirConfigHandler mConfigHandler; + private String url; FtpDirBuilderTarget(String url) { + this.url = url; mConfigHandler = new FtpDirConfigHandler<>(this, -1); getEntity().setGroupHash(url); - getTaskWrapper().getOptionParams() - .setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(url)); } /** @@ -75,8 +74,13 @@ public class FtpDirBuilderTarget extends AbsBuilderTarget { * 设置登陆、字符串编码、ftps等参数 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public FtpDelegate option() { - return new FtpDelegate<>(this, getTaskWrapper()); + public FtpDirBuilderTarget option(FtpOption option) { + if (option == null) { + throw new NullPointerException("ftp 任务配置为空"); + } + option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(url)); + getTaskWrapper().getOptionParams().setParams(option); + return this; } @Override public DownloadGroupEntity getEntity() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java index baff2e01..e657475c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java @@ -17,10 +17,9 @@ package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; -import com.arialyy.aria.core.inf.Suggest; -import com.arialyy.aria.core.common.FtpDelegate; +import com.arialyy.aria.core.common.FtpOption; 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.util.CommonUtil; @@ -33,8 +32,6 @@ public class FtpDirNormalTarget extends AbsNormalTarget { FtpDirNormalTarget(long taskId) { mConfigHandler = new FtpDirConfigHandler<>(this, taskId); - getTaskWrapper().getOptionParams() - .setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(getEntity().getKey())); } @Override public boolean isRunning() { @@ -73,8 +70,13 @@ public class FtpDirNormalTarget extends AbsNormalTarget { * 设置登陆、字符串编码、ftps等参数 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public FtpDelegate option() { - return new FtpDelegate<>(this, getTaskWrapper()); + public FtpDirNormalTarget option(FtpOption option) { + if (option == null) { + throw new NullPointerException("ftp 任务配置为空"); + } + option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getKey())); + getTaskWrapper().getOptionParams().setParams(option); + return this; } @Override public DownloadGroupEntity getEntity() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java index c7e48d0d..aec82b9e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java @@ -18,10 +18,9 @@ package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; import com.arialyy.aria.core.common.AbsNormalTarget; -import com.arialyy.aria.core.inf.Suggest; -import com.arialyy.aria.core.common.FtpDelegate; +import com.arialyy.aria.core.common.FtpOption; 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.util.CommonUtil; @@ -34,8 +33,6 @@ public class FtpNormalTarget extends AbsNormalTarget { FtpNormalTarget(long taskId) { mConfigHandler = new DNormalConfigHandler<>(this, taskId); - getTaskWrapper().getOptionParams() - .setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(getEntity().getUrl())); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP); } @@ -43,8 +40,13 @@ public class FtpNormalTarget extends AbsNormalTarget { * 设置登陆、字符串编码、ftps等参数 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public FtpDelegate option() { - return new FtpDelegate<>(this, getTaskWrapper()); + public FtpNormalTarget option(FtpOption option) { + if (option == null) { + throw new NullPointerException("ftp 任务配置为空"); + } + option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getUrl())); + getTaskWrapper().getOptionParams().setParams(option); + return this; } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java index 0bd189ca..c0e3e100 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java @@ -17,7 +17,7 @@ package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; 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.inf.IOptionConstant; import com.arialyy.aria.core.inf.Suggest; @@ -45,8 +45,12 @@ public class GroupBuilderTarget extends AbsBuilderTarget { * 设置http请求参数,header等信息 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public HttpDelegate option() { - return new HttpDelegate<>(this, getTaskWrapper()); + public GroupBuilderTarget option(HttpOption option) { + if (option == null) { + throw new NullPointerException("任务配置为空"); + } + getTaskWrapper().getOptionParams().setParams(option); + return this; } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java index e70d2143..5c3be712 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java @@ -17,10 +17,10 @@ package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; 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.common.HttpDelegate; -import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.core.manager.SubTaskManager; +import com.arialyy.aria.core.wrapper.ITaskWrapper; import java.util.List; /** @@ -39,8 +39,12 @@ public class GroupNormalTarget extends AbsNormalTarget { * 设置http请求参数,header等信息 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public HttpDelegate option() { - return new HttpDelegate<>(this, getTaskWrapper()); + public GroupNormalTarget option(HttpOption option) { + if (option == null) { + throw new NullPointerException("任务配置为空"); + } + getTaskWrapper().getOptionParams().setParams(option); + return this; } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java index ff3a81ef..213a8886 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java @@ -18,11 +18,14 @@ package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; import com.arialyy.aria.core.common.AbsBuilderTarget; -import com.arialyy.aria.core.common.HttpDelegate; -import com.arialyy.aria.core.download.m3u8.M3U8Delegate; -import com.arialyy.aria.core.processor.IHttpFileLenAdapter; +import com.arialyy.aria.core.common.HttpOption; +import com.arialyy.aria.core.download.DTaskWrapper; +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.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.util.CheckUtil; @@ -36,16 +39,37 @@ public class HttpBuilderTarget extends AbsBuilderTarget { mConfigHandler.setUrl(url); } - @CheckResult(suggest = Suggest.TASK_CONTROLLER) public M3U8Delegate asM3U8() { - return new M3U8Delegate<>(this, getTaskWrapper()); + @CheckResult(suggest = Suggest.TASK_CONTROLLER) + 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等信息 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public HttpDelegate option() { - return new HttpDelegate<>(this, getTaskWrapper()); + public HttpBuilderTarget option(HttpOption option) { + if (option == null) { + throw new NullPointerException("任务配置为空"); + } + getTaskWrapper().getOptionParams().setParams(option); + return this; } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java index aed1f7ba..d17e9b3a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java @@ -17,10 +17,13 @@ package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; -import com.arialyy.aria.core.inf.Suggest; -import com.arialyy.aria.core.common.HttpDelegate; +import com.arialyy.aria.core.common.HttpOption; +import com.arialyy.aria.core.download.DTaskWrapper; 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. @@ -35,16 +38,41 @@ public class HttpNormalTarget extends AbsNormalTarget { } @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public M3U8Delegate asM3U8() { - return new M3U8Delegate<>(this, getTaskWrapper()); + public M3U8NormalTarget 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 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等信息 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public HttpDelegate option() { - return new HttpDelegate<>(this, getTaskWrapper()); + public HttpNormalTarget option(HttpOption option) { + if (option == null) { + throw new NullPointerException("任务配置为空"); + } + getTaskWrapper().getOptionParams().setParams(option); + return this; } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/M3U8NormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/M3U8NormalTarget.java new file mode 100644 index 00000000..2b530b85 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/M3U8NormalTarget.java @@ -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(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)); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java index bd2918fe..4b492cb0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java @@ -34,14 +34,14 @@ public class TcpBuilderTarget extends AbsBuilderTarget { mConfigHandler = new DNormalConfigHandler<>(this, -1); getTaskWrapper().setRequestType(ITaskWrapper.D_TCP); } - - /** - * 设置tcp相应信息 - */ - @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public TcpDelegate option() { - return new TcpDelegate<>(this, getTaskWrapper()); - } + // + ///** + // * 设置tcp相应信息 + // */ + //@CheckResult(suggest = Suggest.TASK_CONTROLLER) + //public TcpBuilderTarget option(T) { + // return new TcpDelegate<>(this, getTaskWrapper()); + //} /** * 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java index f77632ef..14e689ca 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java @@ -16,11 +16,7 @@ package com.arialyy.aria.core.download.tcp; import android.text.TextUtils; -import androidx.annotation.CheckResult; 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 java.nio.charset.Charset; @@ -28,26 +24,26 @@ import java.nio.charset.Charset; * @Author aria * @Date 2019-09-06 */ -public class TcpDelegate extends BaseOption { +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) { - super(target, wrapper); - - mTcpConfig = (TcpTaskConfig) wrapper.getTaskOption(); + public TcpDelegate() { + super(); } /** * 上传给tcp服务的初始数据,一般是文件名、文件路径等信息 */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public TcpDelegate setParam(String params) { + public TcpDelegate setParam(String params) { if (TextUtils.isEmpty(params)) { ALog.w(TAG, "tcp传输的数据不能为空"); return this; } - mTcpConfig.setParams(params); + this.params = params; return this; } @@ -56,41 +52,39 @@ public class TcpDelegate extends BaseOption { * * @param heartbeatInfo 心跳包数据 */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public TcpDelegate setHeartbeatInfo(String heartbeatInfo) { + public TcpDelegate setHeartbeatInfo(String heartbeatInfo) { if (TextUtils.isEmpty(heartbeatInfo)) { ALog.w(TAG, "心跳包传输的数据不能为空"); return this; } - mTcpConfig.setHeartbeat(heartbeatInfo); + this.heartbeatInfo = heartbeatInfo; return this; } /** * 心跳间隔,默认1s * - * @param interval 单位毫秒 + * @param heartbeat 单位毫秒 */ - @CheckResult(suggest = Suggest.TO_CONTROLLER) - public TcpDelegate setHeartbeatInterval(long interval) { - if (interval <= 0) { + public TcpDelegate setHeartbeatInterval(long heartbeat) { + if (heartbeat <= 0) { ALog.w(TAG, "心跳间隔不能小于1毫秒"); return this; } - mTcpConfig.setHeartbeatInterval(interval); + this.heartbeat = heartbeat; return this; } /** * 数据传输编码,默认"utf-8" */ - public TcpDelegate setCharset(String charset) { + public TcpDelegate setCharset(String charset) { if (!Charset.isSupported(charset)) { ALog.w(TAG, "不支持的编码"); return this; } - mTcpConfig.setCharset(charset); + this.charset = charset; return this; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java index e9c1119e..1f7d3f91 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java @@ -17,12 +17,13 @@ package com.arialyy.aria.core.upload.target; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; -import com.arialyy.aria.core.processor.IFtpUploadInterceptor; 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.processor.IFtpUploadInterceptor; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.util.CheckUtil; +import com.arialyy.aria.util.CommonUtil; /** * Created by Aria.Lao on 2017/7/27. @@ -30,6 +31,7 @@ import com.arialyy.aria.util.CheckUtil; */ public class FtpBuilderTarget extends AbsBuilderTarget { private UNormalConfigHandler mConfigHandler; + private String url; FtpBuilderTarget(String filePath) { mConfigHandler = new UNormalConfigHandler<>(this, -1); @@ -44,6 +46,7 @@ public class FtpBuilderTarget extends AbsBuilderTarget { */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) public FtpBuilderTarget setUploadUrl(String tempUrl) { + url = tempUrl; mConfigHandler.setTempUrl(tempUrl); return this; } @@ -61,7 +64,12 @@ public class FtpBuilderTarget extends AbsBuilderTarget { * 设置登陆、字符串编码、ftps等参数 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public FtpDelegate option() { - return new FtpDelegate<>(this, getTaskWrapper()); + public FtpBuilderTarget option(FtpOption option) { + if (option == null) { + throw new NullPointerException("ftp 任务配置为空"); + } + option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(url)); + getTaskWrapper().getOptionParams().setParams(option); + return this; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java index 994b3004..15a5e88e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java @@ -17,11 +17,10 @@ package com.arialyy.aria.core.upload.target; import androidx.annotation.CheckResult; 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.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.wrapper.AbsTaskWrapper; import com.arialyy.aria.util.CommonUtil; /** @@ -33,9 +32,6 @@ public class FtpNormalTarget extends AbsNormalTarget { FtpNormalTarget(long taskId) { mConfigHandler = new UNormalConfigHandler<>(this, taskId); - getTaskWrapper().getOptionParams() - .setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(getEntity().getUrl())); - getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP); } @@ -43,8 +39,13 @@ public class FtpNormalTarget extends AbsNormalTarget { * 设置登陆、字符串编码、ftps等参数 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public FtpDelegate option() { - return new FtpDelegate<>(this, getTaskWrapper()); + public FtpNormalTarget option(FtpOption option) { + if (option == null) { + throw new NullPointerException("ftp 任务配置为空"); + } + option.setFtpUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getUrl())); + getTaskWrapper().getOptionParams().setParams(option); + return this; } @Override public UploadEntity getEntity() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java index 89ede1dd..b8b7ea5f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java @@ -17,8 +17,8 @@ package com.arialyy.aria.core.upload.target; import androidx.annotation.CheckResult; 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.common.HttpDelegate; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; /** @@ -52,7 +52,12 @@ public class HttpBuilderTarget extends AbsBuilderTarget { * 设置http请求参数,header等信息 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public HttpDelegate option() { - return new HttpDelegate<>(this, getTaskWrapper()); + public HttpBuilderTarget option(HttpOption option) { + + if (option == null) { + throw new NullPointerException("任务配置为空"); + } + getTaskWrapper().getOptionParams().setParams(option); + return this; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java index 8edf5eb5..2b7a3d5d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java @@ -17,8 +17,8 @@ package com.arialyy.aria.core.upload.target; import androidx.annotation.CheckResult; 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.common.HttpDelegate; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; /** @@ -49,8 +49,12 @@ public class HttpNormalTarget extends AbsNormalTarget { * 设置http请求参数,header等信息 */ @CheckResult(suggest = Suggest.TASK_CONTROLLER) - public HttpDelegate option() { - return new HttpDelegate<>(this, getTaskWrapper()); + public HttpNormalTarget option(HttpOption option) { + if (option == null) { + throw new NullPointerException("任务配置为空"); + } + getTaskWrapper().getOptionParams().setParams(option); + return this; } @Override public boolean isRunning() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/target/UNormalConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/UNormalConfigHandler.java index 251e628c..b24c172d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/target/UNormalConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/UNormalConfigHandler.java @@ -86,8 +86,6 @@ class UNormalConfigHandler implements IConfigHandler { void setTempUrl(String tempUrl) { getTaskWrapper().setTempUrl(tempUrl); - getTaskWrapper().getOptionParams() - .setParams(IOptionConstant.ftpUrlEntity, CommonUtil.getFtpUrlInfo(tempUrl)); } private UTaskWrapper getTaskWrapper() { diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/TaskOptionParams.java b/PublicComponent/src/main/java/com/arialyy/aria/core/TaskOptionParams.java index baa2fa5d..e82ec1e7 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/TaskOptionParams.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/TaskOptionParams.java @@ -15,8 +15,11 @@ */ 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.IOptionConstant; +import com.arialyy.aria.util.CommonUtil; +import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; @@ -38,6 +41,34 @@ public class TaskOptionParams { */ private Map 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; } - public Object getParam(String key){ + public Object getParam(String key) { return params.get(key); } - public IEventHandler getHandler(String key){ + public IEventHandler getHandler(String key) { return handler.get(key); } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/common/BaseOption.java b/PublicComponent/src/main/java/com/arialyy/aria/core/common/BaseOption.java new file mode 100644 index 00000000..68955305 --- /dev/null +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/common/BaseOption.java @@ -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()); + } +} diff --git a/PublicComponent/src/main/java/com/arialyy/aria/util/CommonUtil.java b/PublicComponent/src/main/java/com/arialyy/aria/util/CommonUtil.java index d2713dc6..cbf97a57 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -21,17 +21,10 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Environment; -import android.os.Handler; import android.text.TextUtils; import android.util.Base64; import com.arialyy.aria.core.AriaConfig; 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 java.io.File; import java.io.FileFilter; @@ -41,7 +34,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; -import java.lang.ref.SoftReference; import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -69,7 +61,6 @@ public class CommonUtil { public static final String SERVER_CHARSET = "ISO-8859-1"; private static long lastClickTime; - /** * 检查sql的expression是否合法 * diff --git a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java index 5e9f8acd..c33235a0 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java @@ -23,8 +23,7 @@ import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProviders; import com.arialyy.annotations.Download; import com.arialyy.aria.core.Aria; -import com.arialyy.aria.core.ProtocolType; -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.inf.IEntity; import com.arialyy.aria.core.task.DownloadTask; @@ -89,16 +88,14 @@ public class FtpDownloadActivity extends BaseActivity { } private void startD() { + HttpOption option = new HttpOption(); + option.addHeader("1", "@"); mTaskId = Aria.download(SingleTaskActivity.this) .load(mUrl) .useServerFileName(true) .setFilePath(mFilePath, true) .setFileLenAdapter(new FileLenAdapter()) - .option() - .addHeader("1", "@") - .controller(ControllerType.CREATE_CONTROLLER) + .option(option) .create(); } diff --git a/app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java index b8077dbb..8f8c0c1c 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/group/FTPDirDownloadActivity.java @@ -20,7 +20,7 @@ import android.os.Environment; import android.view.View; import com.arialyy.annotations.DownloadGroup; 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.inf.IEntity; import com.arialyy.aria.core.task.DownloadGroupTask; @@ -78,9 +78,7 @@ public class FTPDirDownloadActivity extends BaseActivity switch (view.getId()) { case R.id.start: startD(); - //if (!AppUtil.chekEntityValid(mEntity)) { - // startD(); - // break; - //} - //if (Aria.download(this).load(mEntity.getId()).isRunning()) { - // Aria.download(this).load(mEntity.getId()).stop(); - //} else { - // Aria.download(this).load(mEntity.getId()) - // .asM3U8() - // .asLive() - // .setLiveTsUrlConvert(new ILiveTsUrlConverter() { - // @Override public String convert(String m3u8Url, String tsUrl) { - // int index = m3u8Url.lastIndexOf("/"); - // String parentUrl = m3u8Url.substring(0, index + 1); - // return parentUrl + tsUrl; - // } - // }) - // .controller(ControllerType.TASK_CONTROLLER) - // .resume(); - //} - //break; + if (!AppUtil.chekEntityValid(mEntity)) { + startD(); + break; + } + if (Aria.download(this).load(mEntity.getId()).isRunning()) { + Aria.download(this).load(mEntity.getId()).stop(); + } else { + Aria.download(this).load(mEntity.getId()) + .m3u8LiveOption(getLiveoption()) + .resume(); + } + break; case R.id.cancel: if (AppUtil.chekEntityValid(mEntity)) { Aria.download(this).load(mEntity.getId()).cancel(true); @@ -247,31 +239,18 @@ public class M3U8LiveDLoadActivity extends BaseActivity .load(mUrl) .useServerFileName(true) .setFilePath(mFilePath, true) - .asM3U8() - //.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 convert(String m3u8Url, List tsUrls) { - // int peerIndex = m3u8Url.lastIndexOf("/"); - // String parentUrl = m3u8Url.substring(0, peerIndex + 1); - // List newUrls = new ArrayList<>(); - // for (String url : tsUrls) { - // newUrls.add(parentUrl + url); - // } - // - // return newUrls; - // } - //}) + .m3u8LiveOption(getLiveoption()) .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) { super.dataCallback(result, data); if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) { @@ -288,4 +267,17 @@ public class M3U8LiveDLoadActivity extends BaseActivity 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; + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java index a42d1a1a..23c93312 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java @@ -31,10 +31,11 @@ import com.arialyy.annotations.Download; import com.arialyy.annotations.M3U8; import com.arialyy.aria.core.Aria; 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.M3U8Entity; +import com.arialyy.aria.core.download.m3u8.M3U8VodOption; 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.IVodTsUrlConverter; import com.arialyy.aria.core.task.DownloadTask; @@ -122,7 +123,7 @@ public class M3U8VodDLoadActivity extends BaseActivity { @Subscribe(threadMode = ThreadMode.MAIN) 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 @@ -280,27 +281,7 @@ public class M3U8VodDLoadActivity extends BaseActivity { } else { 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; - // } - //}) - .setTsUrlConvert(new IVodTsUrlConverter() { - @Override public List convert(String m3u8Url, List tsUrls) { - - Uri uri = Uri.parse(m3u8Url); - String parentUrl = "http://" + uri.getHost(); - List newUrls = new ArrayList<>(); - for (String url : tsUrls) { - newUrls.add(parentUrl + url); - } - - return newUrls; - } - }) - .controller(ControllerType.TASK_CONTROLLER) + .m3u8VodOption(getM3U8Option()) .resume(); } break; @@ -316,36 +297,20 @@ public class M3U8VodDLoadActivity extends BaseActivity { .load(mUrl) .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; - // } - //}) - .setTsUrlConvert(new IVodTsUrlConverter() { - @Override public List convert(String m3u8Url, List tsUrls) { - Uri uri = Uri.parse(m3u8Url); - String parentUrl = uri.getScheme() + "://" + uri.getHost(); - List newUrls = new ArrayList<>(); - for (String url : tsUrls) { - newUrls.add(parentUrl + url); - } - - return newUrls; - } - }) - .setMergeHandler(new ITsMergeHandler() { - public boolean merge(@Nullable M3U8Entity m3U8Entity, List tsPath) { - ALog.d(TAG, "合并TS...."); - return false; - } - }) - .generateIndexFile() - .controller(ControllerType.CREATE_CONTROLLER) + .m3u8VodOption(getM3U8Option()) .create(); } + private M3U8VodOption getM3U8Option() { + M3U8VodOption option = new M3U8VodOption(); + option + .generateIndexFile() + .setTsUrlConvert(new VodTsUrlConverter()) + .setMergeHandler(new TsMergeHandler()); + //.setBandWidthUrlConverter(new BandWidthUrlConverter(mUrl)); + return option; + } + private Class c = BuilderController.class; @Override protected void dataCallback(int result, Object data) { @@ -356,4 +321,38 @@ public class M3U8VodDLoadActivity extends BaseActivity { mModule.updateFilePath(this, String.valueOf(data)); } } + + static class VodTsUrlConverter implements IVodTsUrlConverter { + @Override public List convert(String m3u8Url, List tsUrls) { + Uri uri = Uri.parse(m3u8Url); + String parentUrl = "http://" + uri.getHost(); + List newUrls = new ArrayList<>(); + for (String url : tsUrls) { + newUrls.add(parentUrl + url); + } + + return newUrls; + } + } + + static class TsMergeHandler implements ITsMergeHandler { + public boolean merge(@Nullable M3U8Entity m3U8Entity, List tsPath) { + ALog.d("TsMergeHandler", "合并TS...."); + return false; + } + } + + static class BandWidthUrlConverter implements IBandWidthUrlConverter { + + private String url; + + BandWidthUrlConverter(String url) { + this.url = url; + } + + @Override public String convert(String bandWidthUrl) { + int index = url.lastIndexOf("/"); + return url.substring(0, index + 1) + bandWidthUrl; + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java b/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java index 988df6f2..07bf5126 100644 --- a/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java @@ -25,10 +25,8 @@ import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProviders; import com.arialyy.annotations.Upload; 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.processor.FtpInterceptHandler; -import com.arialyy.aria.core.processor.IFtpUploadInterceptor; import com.arialyy.aria.core.task.UploadTask; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.util.ALog; @@ -42,7 +40,6 @@ import com.arialyy.simple.databinding.ActivityFtpUploadBinding; import com.arialyy.simple.util.AppUtil; import java.io.File; import java.io.IOException; -import java.util.List; /** * Created by lyy on 2017/7/28. Ftp 文件上传demo @@ -118,9 +115,7 @@ public class FtpUploadActivity extends BaseActivity { mTaskId = Aria.upload(this) .loadFtp(mFilePath) .setUploadUrl(mUrl) - .option() - .login(user, pwd) - .controller(ControllerType.CREATE_CONTROLLER) + .option(getOption()) .create(); getBinding().setStateStr(getString(R.string.stop)); break; @@ -131,9 +126,7 @@ public class FtpUploadActivity extends BaseActivity { } else { Aria.upload(this) .loadFtp(mTaskId) - .option() - .login(user, pwd) - .controller(ControllerType.TASK_CONTROLLER) + .option(getOption()) .resume(); getBinding().setStateStr(getString(R.string.stop)); } @@ -147,6 +140,12 @@ public class FtpUploadActivity extends BaseActivity { } } + private FtpOption getOption() { + FtpOption option = new FtpOption(); + option.login(user, pwd); + return option; + } + @Upload.onWait void onWait(UploadTask task) { Log.d(TAG, task.getTaskName() + "_wait"); } diff --git a/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java b/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java index a4bd69bb..4f6082a9 100644 --- a/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java @@ -21,8 +21,8 @@ import android.os.Environment; import android.view.View; import com.arialyy.annotations.Upload; 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.controller.ControllerType; import com.arialyy.aria.core.task.UploadTask; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.frame.util.FileUtil; @@ -76,15 +76,15 @@ public class HttpUploadActivity extends BaseActivity { } void upload() { + HttpOption option = new HttpOption(); + option.setRequestType(RequestEnum.POST) + .setParam("params", "bbbbbbbb"); Aria.upload(HttpUploadActivity.this).load(FILE_PATH) //.setUploadUrl("http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".apk\"}") .setUploadUrl("http://9.9.9.205:5000/upload/") //.setTempUrl("http://192.168.1.6:8080/upload/sign_file/").setAttachment("file") //.addHeader("iplanetdirectorypro", "11a09102fb934ad0bc206f9c611d7933") - .option() - .setRequestType(RequestEnum.POST) - .setParam("params", "bbbbbbbb") - .controller(ControllerType.CREATE_CONTROLLER) + .option(option) .create(); } diff --git a/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java b/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java index 9bd6459f..4ce216c8 100644 --- a/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java +++ b/app/src/main/java/com/arialyy/simple/modlue/AnyRunnModule.java @@ -20,7 +20,7 @@ import android.os.Environment; import android.util.Log; import com.arialyy.annotations.Download; 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.task.DownloadTask; import com.arialyy.aria.util.CommonUtil; @@ -108,18 +108,21 @@ public class AnyRunnModule { Aria.download(this) .loadFtp(url) .setFilePath(Environment.getExternalStorageDirectory().getPath() + "/Download/") - .option() - .asFtps() - .setStorePath("/mnt/sdcard/Download/server.crt") - .setAlias("www.laoyuyu.me") - .setStorePass("123456") - .controller(ControllerType.CREATE_CONTROLLER) + .option(getFtpOption()) .create(); } else { 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) { if (AppUtil.chekEntityValid(mEntity)) { Aria.download(this).load(mEntity.getId()).stop();