parent
df310b7fbe
commit
550455084f
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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); |
|
||||||
} |
|
||||||
} |
|
@ -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; |
||||||
|
} |
||||||
|
} |
@ -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)); |
||||||
|
} |
||||||
|
} |
@ -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()); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue