From c4cc804c67cfe37108b1eef32d37c2329eb79939 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Wed, 27 Nov 2019 21:38:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AB=8B=E5=8D=B3=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E4=BB=BB=E5=8A=A1=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E6=9D=A5=E8=AF=B4=EF=BC=8C=E5=BD=93=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=98=9F=E5=88=97=E6=BB=A1=E6=97=B6=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=81=A2=E5=A4=8D=E4=BB=BB=E5=8A=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E8=83=BD=E5=B0=86=E4=BB=BB=E5=8A=A1=E6=94=BE?= =?UTF-8?q?=E5=88=B0=E7=BC=93=E5=AD=98=E9=98=9F=E5=88=97=E4=B8=AD=E3=80=82?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E5=B8=8C=E6=9C=9B=E8=B0=83=E7=94=A8=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=8E=A5=E5=8F=A3=EF=BC=8C=E9=A9=AC=E4=B8=8A=E8=BF=9B?= =?UTF-8?q?=E5=85=A5=E6=89=A7=E8=A1=8C=E9=98=9F=E5=88=97=EF=BC=8C=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E8=B0=83=E7=94=A8`resume(true)`=E8=BF=99=E4=B8=AA?= =?UTF-8?q?=E9=87=8D=E8=BD=BD=E6=96=B9=E6=B3=95=E3=80=82=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=B8=80=E4=B8=AA=E9=9D=9E=E5=88=86=E5=9D=97=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=EF=BC=8C=E6=97=A0=E6=B3=95=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=9A=84=E9=97=AE=E9=A2=98=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0M3U8=E5=8A=A0=E5=AF=86=E5=AF=86=E9=92=A5=E7=9A=84?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=9C=B0=E5=9D=80=E8=BD=AC=E6=8D=A2=E5=99=A8?= =?UTF-8?q?=20https://github.com/AriaLyy/Aria/issues/522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aria/core/command/AbsCmdFactory.java | 4 +-- .../aria/core/command/AbsNormalCmd.java | 8 ----- .../aria/core/command/NormalCmdFactory.java | 4 +-- .../arialyy/aria/core/command/StartCmd.java | 18 +++++++++-- .../aria/core/common/AbsNormalTarget.java | 12 ++++++- .../common/controller/INormalFeature.java | 8 +++++ .../common/controller/NormalController.java | 20 ++++++++++-- .../aria/core/download/m3u8/M3U8Option.java | 13 ++++++++ DEV_LOG.md | 7 +++- .../http/download/HttpDThreadTaskAdapter.java | 1 + .../com/arialyy/aria/m3u8/M3U8InfoThread.java | 12 +++++-- .../com/arialyy/aria/m3u8/M3U8TaskOption.java | 14 ++++++++ .../aria/core/common/RecordHelper.java | 3 +- .../aria/core/processor/IKeyUrlConverter.java | 32 +++++++++++++++++++ .../com/arialyy/aria/util/CommonUtil.java | 16 +++++----- app/src/main/assets/aria_config.xml | 2 +- .../core/download/HttpDownloadModule.java | 4 +-- .../core/download/SingleTaskActivity.java | 3 +- .../core/download/mutil/DownloadAdapter.java | 8 ++--- 19 files changed, 151 insertions(+), 38 deletions(-) create mode 100644 PublicComponent/src/main/java/com/arialyy/aria/core/processor/IKeyUrlConverter.java diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java index 2af0e2ff..1a7cbf34 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java @@ -15,6 +15,7 @@ */ package com.arialyy.aria.core.command; +import com.arialyy.aria.core.task.ITask; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; /** @@ -25,8 +26,7 @@ public abstract class AbsCmdFactory extends AbsCmd { mQueue.resumeTask(task); } - /** - * 启动指定任务 - * - * @param task 指定任务 - */ - void startTask(AbsTask task) { - mQueue.startTask(task); - } /** * 从队列中获取任务 diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/NormalCmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/NormalCmdFactory.java index 8ba64474..194b7c32 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/NormalCmdFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/NormalCmdFactory.java @@ -16,6 +16,7 @@ package com.arialyy.aria.core.command; +import com.arialyy.aria.core.task.ITask; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; /** @@ -83,8 +84,7 @@ public class NormalCmdFactory extends AbsCmdFactory extends AbsNormalCmd { +final public class StartCmd extends AbsNormalCmd { + + private boolean newStart = false; StartCmd(T entity, int taskType) { super(entity, taskType); } + /** + * 立即执行任务 + * @param newStart true 立即执行任务,无论执行队列是否满了 + */ + public void setNewStart(boolean newStart) { + this.newStart = newStart; + } + @Override public void executeCmd() { if (!canExeCmd) return; if (!NetUtils.isConnected(AriaManager.getInstance().getAPP())) { @@ -71,7 +81,11 @@ final class StartCmd extends AbsNormalCmd { startTask(); } } else { - sendWaitState(task); + if (newStart){ + startTask(); + }else { + sendWaitState(task); + } } } } else { 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 110c18f0..b8572a54 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 @@ -150,7 +150,17 @@ public abstract class AbsNormalTarget extends Ab */ @Override public void resume() { - getController().resume(); + resume(false); + } + + /** + * 正常来说,当执行队列满时,调用恢复任务接口,只能将任务放到缓存队列中。 + * 如果希望调用恢复接口,马上进入执行队列,需要使用该方法 + * + * @param newStart true 立即将任务恢复到执行队列中 + */ + @Override public void resume(boolean newStart) { + getController().resume(newStart); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/controller/INormalFeature.java b/Aria/src/main/java/com/arialyy/aria/core/common/controller/INormalFeature.java index 550e5a50..968098fd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/controller/INormalFeature.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/controller/INormalFeature.java @@ -30,6 +30,14 @@ public interface INormalFeature { */ void resume(); + /** + * 正常来说,当执行队列满时,调用恢复任务接口,只能将任务放到缓存队列中。 + * 如果希望调用恢复接口,马上进入执行队列,需要使用该方法 + * + * @param newStart true 立即将任务恢复到执行队列中 + */ + void resume(boolean newStart); + /** * 删除任务 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/controller/NormalController.java b/Aria/src/main/java/com/arialyy/aria/core/common/controller/NormalController.java index 9567d908..8d019d01 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/controller/NormalController.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/controller/NormalController.java @@ -16,11 +16,12 @@ package com.arialyy.aria.core.common.controller; import com.arialyy.aria.core.command.CancelCmd; +import com.arialyy.aria.core.command.CmdHelper; import com.arialyy.aria.core.command.NormalCmdFactory; +import com.arialyy.aria.core.command.StartCmd; import com.arialyy.aria.core.event.EventMsgUtil; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.util.ALog; -import com.arialyy.aria.core.command.CmdHelper; /** * 启动控制器 @@ -49,10 +50,23 @@ public final class NormalController extends FeatureController implements INormal */ @Override public void resume() { + resume(false); + } + + /** + * 正常来说,当执行队列满时,调用恢复任务接口,只能将任务放到缓存队列中。 + * 如果希望调用恢复接口,马上进入执行队列,需要使用该方法 + * + * @param newStart true 立即将任务恢复到执行队列中 + */ + @Override public void resume(boolean newStart) { if (checkConfig()) { + StartCmd cmd = + (StartCmd) CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_START, + checkTaskType()); + cmd.setNewStart(newStart); EventMsgUtil.getDefault() - .post(CmdHelper.createNormalCmd(getTaskWrapper(), NormalCmdFactory.TASK_START, - checkTaskType())); + .post(cmd); } } 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 index d9b56734..eb921c8a 100644 --- 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 @@ -17,6 +17,7 @@ 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.IKeyUrlConverter; import com.arialyy.aria.core.processor.ITsMergeHandler; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.ComponentUtil; @@ -31,6 +32,7 @@ public class M3U8Option extends BaseOption { private int bandWidth; private ITsMergeHandler mergeHandler; private IBandWidthUrlConverter bandWidthUrlConverter; + private IKeyUrlConverter keyUrlConverter; M3U8Option() { super(); @@ -88,4 +90,15 @@ public class M3U8Option extends BaseOption { this.bandWidthUrlConverter = bandWidthUrlConverter; return (OP) this; } + + /** + * M3U8 密钥url转换器,对于某些服务器,密钥的下载地址是被加密的,因此需要使用该方法将被加密的密钥解密成可被识别的http地址 + * + * @param keyUrlConverter {@link IKeyUrlConverter} + */ + public OP setKeyUrlConverter(IKeyUrlConverter keyUrlConverter) { + CheckUtil.checkMemberClass(keyUrlConverter.getClass()); + this.keyUrlConverter = keyUrlConverter; + return (OP) this; + } } diff --git a/DEV_LOG.md b/DEV_LOG.md index 6d99e34d..550522d4 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,6 +1,11 @@ ## 开发日志 - + v_3.7.8-pre-1(2019/11/20) + + v_3.7.8 - fix bug https://github.com/AriaLyy/Aria/issues/526 + - fix bug https://github.com/AriaLyy/Aria/issues/533 + - fix bug https://github.com/AriaLyy/Aria/issues/535 + - 修复ftp无法完成下载的问题 + - 增加立即恢复任务的接口,正常来说,当执行队列满时,调用恢复任务接口,只能将任务放到缓存队列中。如果希望调用恢复接口,马上进入执行队列,需要调用`resume(true)`这个重载方法。 + - 增加M3U8加密密钥的下载地址转换器 https://github.com/AriaLyy/Aria/issues/522 + v_3.7.7 (2019/11/20) - 修复ftp无法完成下载的问题 - 修复一个http下载崩溃的问题 diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java index b9cfe3ea..3f5ca877 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java @@ -24,6 +24,7 @@ import com.arialyy.aria.http.BaseHttpThreadTaskAdapter; import com.arialyy.aria.http.ConnectionHelp; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.BufferedRandomAccessFile; +import com.arialyy.aria.util.FileUtil; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; diff --git a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8InfoThread.java b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8InfoThread.java index 9725c860..d92589b8 100644 --- a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8InfoThread.java +++ b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8InfoThread.java @@ -26,6 +26,7 @@ import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.M3U8Entity; import com.arialyy.aria.core.inf.OnFileInfoCallback; import com.arialyy.aria.core.processor.IBandWidthUrlConverter; +import com.arialyy.aria.core.processor.IKeyUrlConverter; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.core.wrapper.ITaskWrapper; import com.arialyy.aria.exception.M3U8Exception; @@ -127,7 +128,7 @@ final public class M3U8InfoThread implements Runnable { File indexFile = new File(indexPath); if (!indexFile.exists()) { FileUtil.createFile(indexPath); - }else { + } else { //FileUtil.deleteFile(indexPath); } fos = new FileOutputStream(indexFile); @@ -353,7 +354,14 @@ final public class M3U8InfoThread implements Runnable { } else { return; } - URL url = ConnectionHelp.handleUrl(info.keyUrl, mHttpOption); + + IKeyUrlConverter keyUrlConverter = mM3U8Option.getKeyUrlConverter(); + String keyUrl = info.keyUrl; + if (keyUrlConverter != null) { + keyUrl = keyUrlConverter.convert(keyUrl); + } + + URL url = ConnectionHelp.handleUrl(keyUrl, mHttpOption); conn = ConnectionHelp.handleConnection(url, mHttpOption); ConnectionHelp.setConnectParam(mHttpOption, conn); conn.setConnectTimeout(mConnectTimeOut); diff --git a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8TaskOption.java b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8TaskOption.java index cd1c663d..5e9df9fe 100644 --- a/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8TaskOption.java +++ b/M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8TaskOption.java @@ -17,6 +17,7 @@ package com.arialyy.aria.m3u8; import com.arialyy.aria.core.inf.ITaskOption; import com.arialyy.aria.core.processor.IBandWidthUrlConverter; +import com.arialyy.aria.core.processor.IKeyUrlConverter; import com.arialyy.aria.core.processor.ILiveTsUrlConverter; import com.arialyy.aria.core.processor.ITsMergeHandler; import com.arialyy.aria.core.processor.IVodTsUrlConverter; @@ -103,6 +104,19 @@ public class M3U8TaskOption implements ITaskOption { */ private boolean generateIndexFile = false; + /** + * 加密密钥的解密处理器 + */ + private SoftReference keyUrlConverter; + + public IKeyUrlConverter getKeyUrlConverter() { + return keyUrlConverter == null ? null : keyUrlConverter.get(); + } + + public void setKeyUrlConverter(IKeyUrlConverter keyUrlConverter) { + this.keyUrlConverter = new SoftReference<>(keyUrlConverter); + } + public boolean isGenerateIndexFile() { return generateIndexFile; } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java b/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java index f6fc6f97..12c2dd3d 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/common/RecordHelper.java @@ -63,7 +63,8 @@ public class RecordHelper { fileExists = true; } // 处理文件被删除的情况 - if (fileExists) { + if (!fileExists) { + ALog.w(TAG, String.format("文件【%s】被删除,重新分配线程区间", mTaskRecord.filePath)); for (int i = 0; i < mTaskRecord.threadNum; i++) { long startL = i * blockSize, endL = (i + 1) * blockSize; ThreadRecord tr = mTaskRecord.threadRecords.get(i); diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/processor/IKeyUrlConverter.java b/PublicComponent/src/main/java/com/arialyy/aria/core/processor/IKeyUrlConverter.java new file mode 100644 index 00000000..fd544746 --- /dev/null +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/processor/IKeyUrlConverter.java @@ -0,0 +1,32 @@ +/* + * 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.processor; + +import com.arialyy.aria.core.inf.IEventHandler; + +/** + * M3U8 密钥下载地址处理器,可用于解密被加密的密钥的下载地址 + */ +public interface IKeyUrlConverter extends IEventHandler { + + /** + * 将被加密的密钥下载地址转换为可使用的http下载地址 + * + * @param keyUrl 加密的url地址 + * @return 可正常访问的http地址 + */ + String convert(String keyUrl); +} 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 07eb8088..c046381f 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -71,15 +71,15 @@ public class CommonUtil { ALog.e(TAG, "sql语句表达式不能为null"); return false; } - if (expression.length == 1) { - ALog.e(TAG, String.format("表达式需要写入参数,参数信息:%s", Arrays.toString(expression))); - return false; - } + //if (expression.length == 1) { + // ALog.e(TAG, String.format("表达式需要写入参数,参数信息:%s", Arrays.toString(expression))); + // return false; + //} String where = expression[0]; - if (!where.contains("?")) { - ALog.e(TAG, String.format("请在where语句的'='后编写?,参数信息:%s", Arrays.toString(expression))); - return false; - } + //if (!where.contains("?")) { + // ALog.e(TAG, String.format("请在where语句的'='后编写?,参数信息:%s", Arrays.toString(expression))); + // return false; + //} Pattern pattern = Pattern.compile("\\?"); Matcher matcher = pattern.matcher(where); int count = 0; diff --git a/app/src/main/assets/aria_config.xml b/app/src/main/assets/aria_config.xml index cb8d1c24..e4ea2d42 100644 --- a/app/src/main/assets/aria_config.xml +++ b/app/src/main/assets/aria_config.xml @@ -32,7 +32,7 @@ 3、只对新的多线程下载任务有效 4、只对多线程的任务有效 --> - +