Giter Site home page Giter Site logo

okdownload's Introduction

OkDownload

A Reliable, Flexible, Fast and Powerful download engine.

codecov Download

中文文档


P.S. If you ask me, which version is the most stability, I will tell you it's not the version of 1.0.0 or 2.0.0, the most stability version must be the latest version because it is developed with github-flow, not production-flow. So please follow the latest release version and show me your PR. Here is the changelog for each version, it may help you.

I. WHY CHOOSE

In fact OkDownload is FileDownloader2, which extends all benefits from FileDownloader and beyond. More detail please move to here

II. HOW TO IMPORT

We publish okdownload on jcenter, mavenCentral and Sonatype's snapshots repository, more detail about import OkDownload please move to here

III. HOW TO USE

  • The simple use case such as start and cancel, download queue or get state or task info, please more to here
  • The advanced use case such as set max parallel running count, set remit database delay milliseconds or injection components, please move to here

IV. SAMPLE

Debug

How to Debug

Screenshot

V. LICENSE

Copyright (c) 2017 LingoChamp Inc.

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.

okdownload's People

Contributors

devdengchao avatar ernest-su avatar fkorotkov avatar jacksgong avatar moomoon avatar oksep avatar rantianhua avatar zhch0633 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

okdownload's Issues

暂停和取消的区分

你好!

之前用过FileDownloader,这两天研究了一下OkDownload,但是从说明文档和Sample中没有看到Pause和Cancel的明确区分,请问在这个版本中已经不需要明确区分Pause和Cancel了吗?还是有什么我没注意到的?

因为实际使用中,某些需求上还是需要这两者都有的。
感谢!

no available gradle version

没有可用的gradle版本,看来这个repository是新创建的,请问作者计划什么时候发布一个release呢?

内存泄漏&&取消监听

退出页面时如果没有cancel,那么监听Listener不会释放,这样会导致Listener所在的页面无法释放造成内存泄漏。
请问可否增加取消监听的api?
谢谢!

下载文件失败.

当我用demo下载文件时,下载连接里面带有参数的时候(exp: url = xxxxx/thunt/get?t=f&id=c ),能够正常连接到服务器,文件读取成功,但是在调用MultiPointOutputStream类的inspectComplete() 方法时会抛出一个IO 异常(exp: The current offset on block-info isn't update correct, 225508 != 0 on 0 ).如果我用 FileDownloader 下载此文件能够正常下载的.

目标存储路径是文件,而不是文件夹情况下的异常处理设计不太合理

DownloadTask.java

try {
    ...
    if (file.exists() && file.isFile()) {
    // it have already provided file for it.
	throw new IllegalArgumentException("If you want filename from "
					+ "response please make sure you provide path is directory " + file.getPath());
    }
    ...
} finally {
    this.id = OkDownload.with().breakpointStore().findOrCreateId(this);
}

此处判断file.exists() && file.isFile()抛出IllegalArgumentException异常,
当此判断条件成立时,因为加了finally,所以代码还会执行
this.id = OkDownload.with().breakpointStore().findOrCreateId(this);
而此时会抛出

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.xxx.sample.webdownloader, PID: 16251
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.liulishuo.okdownload.core.download.DownloadStrategy$FilenameHolder.get()' on a null object reference
        at com.liulishuo.okdownload.DownloadTask.getFilename(DownloadTask.java:230)
        at com.liulishuo.okdownload.core.breakpoint.KeyToIdMap.generateKey(KeyToIdMap.java:63)
        at com.liulishuo.okdownload.core.breakpoint.KeyToIdMap.get(KeyToIdMap.java:43)
        at com.liulishuo.okdownload.core.breakpoint.BreakpointStoreOnCache.findOrCreateId(BreakpointStoreOnCache.java:146)
        at com.liulishuo.okdownload.core.breakpoint.BreakpointStoreOnSQLite.findOrCreateId(BreakpointStoreOnSQLite.java:100)
        at com.liulishuo.okdownload.DownloadTask.<init>(DownloadTask.java:190)
        at com.liulishuo.okdownload.DownloadTask$Builder.build(DownloadTask.java:838)

从而掩盖了
throw new IllegalArgumentException("If you want filename from " + "response please make sure you provide path is directory " + file.getPath());
的异常信息。

导致追查问题时不方便。

download

how to download batch tasks as a queue and download with different priority.

FileDownloader.startForeground() equivalent function

What is the equivalent function for FileDownloader.startForeground() function, i could not find any method equivalent to it in javadoc.

Moreover a lot of people are using FileDownloader, it will be a very good step to maintain a porting guide with equivalent functions.

sample crash

In sample project, when I click 'start' button on Single Download page, it does't work, and then I click 'cancel' button, but the project crash.

01-09 11:14:13.819 12251-12251/com.liulishuo.okdownload.sample E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.liulishuo.okdownload.sample, PID: 12251
java.lang.NullPointerException: Attempt to read from field 'com.liulishuo.okdownload.core.breakpoint.BreakpointInfo com.liulishuo.okdownload.core.listener.assist.Listener4Assist$Listener4Model.info' on a null object reference
at com.liulishuo.okdownload.core.listener.assist.Listener4Assist.taskEnd(Listener4Assist.java:127)
at com.liulishuo.okdownload.core.listener.DownloadListener4.taskEnd(DownloadListener4.java:87)
at com.liulishuo.okdownload.core.dispatcher.CallbackDispatcher$1$10.run(CallbackDispatcher.java:191)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5290)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:911)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)

OkDownload与FileDownloader的对比

之前一直在使用FileDownloader的库,但是最近升级后发现一些问题,而且无法降级,想了解下,后续okdownload会替代之前的FileDownloader么,还有就是OkDownload会保持维护么

如果现在想在项目里引用新的OkDownload,是否可以与之前的FileDownloader可以共存?或者说,是否可以正常升级到OkDownload里

Is it possible to cancel a task using task id?

As in the title. I can only see methods like

OkDownload.with().downloadDispatcher().cancel(task)

or
task.cancel()

or maybe there is possibility to get running task by id so I could use above methods?

Thanks

RxJava支持

OkDownload Version

v1.0.2

Problem Describe

在介绍看到了支持RxJava,但是关于使用文档没有提到RxJava

设置跳过已下载资源时,如何能够关联到上一次的下载链接,而非仅仅只通过文件路径来配对

你好,当我设置setPassIfAlreadyCompleted(true)的时候,按照逻辑应该是同一url 然后下载的路径以及文件名一致则当做同一个任务不再继续下载,
但是我查看了下StatusUtil#isCompletedOrUnknown方法,发现里面并没有判断url,只是当路径以及文件名一致的时候当做同一任务。这样就导致了如果url变了,但是目标位置存在同名文件,则不会继续下载了

首先使用A地址下载到一个位置,然后将A改为B,不会继续下载。版本1.0.1

获取状态信息的疑问

每次查询都要新建一个下载任务,是不是没有必要。

public static Status getStatus(@NonNull String url, @NonNull String parentPath,
                                   @Nullable String filename) {
        return getStatus(createFinder(url, parentPath, filename));
    }
@NonNull static DownloadTask createFinder(@NonNull String url,
                                              @NonNull String parentPath,
                                              @Nullable String filename) {
        return new DownloadTask.Builder(url, parentPath, filename)
                .build();
    }

断点续传进度有误

在demo的SingleDownload中,我下载了百分之五六十,然后点击取消,关掉app,刷掉进程。然后重新进去,个别时候没有进度需要重新下载,个别时候进度只有百分之二三十左右,但是我退出之前显示的进度确实百分之五六十。不知道这个问题是出在哪里。

Download resource which response dynamic but valid instance-length for each-block

我之前浏览了历史issues,发现也有相关的问题:#17 (comment) 我不知道跟我遇到的问题是否相似?我尝试使用最新的1.0.1的SNAPSHOT还是会遇到这个问题,

taskEnd cause:ERROR realCause:The current offset on block-info isn't update correct, 4447894 != 4535848 on 2

这是我创建task的代码(kotlin)的
image

我使用的是下面这些下载链接,而且还有很多。
https://play.podtrac.com/npr-510318/npr.mc.tritondigital.com/NPR_510318/media/anon.npr-mp3/npr/upfirst/2018/04/20180406_upfirst_upfirstfacebookspecial.mp3?orgId=1&d=893&p=510318&story=600081084&t=podcast&e=600081084&ft=pod&f=510318

https://play.podtrac.com/npr-510318/npr.mc.tritondigital.com/NPR_510318/media/anon.npr-mp3/npr/upfirst/2018/03/20180329_upfirst_180329upfirst.mp3?orgId=1&d=803&p=510318&story=597870311&t=podcast&e=597870311&ft=pod&f=510318

我们做的是一款播客类的APP,会遇到各国的播客源,而且各个播客类的APP都是相同的源,所以如果别的APP是可以下载的,不应该我们这边的不能下,其实到也不是不能下,主要就是会很容易出现下面的错误

taskEnd cause:ERROR realCause:The current offset on block-info isn't update correct, 4944990 != 4949823 on 2

而且我发现,我之前使用FileDownloader-1.4.X的版本是不会遇到这类问题的,直到升到最新的FileDownloader后发现该问题出现非常多lingochamp/FileDownloader#974 ,而且在FileDownloader的ISSUES列表里也有很多用户遇到这个问题,我也照着FileDownloader的方法进行设置了:

使用单连接下载方案一

  1. 在filedownloader.properties中配置不使用独立进程: 实现FileDownloadHelper.ConnectionCountAdapter,并在里面配置需要单连接的连接缓存,当下载出现类似错误的时候,将连接加入缓存,然后重新下载。
  2. 通过FileDownloder.setupOnApplicationOnCreate注册该ConnectionCountAdapter

使用单连接下载方案二

  1. 实现FileDownloadHelper.ConnectionCountAdapter全局都该用单线程下载。

但针对上面的进行设置后,FileDownloader-1.5.+版本还是会有问题!!!

后来我看到lingochamp/FileDownloader#990 (comment) 你说在OkDownload中解决了该问题.

然后尝试使用OkDownload,但是问题好像还是存在。

我截了个LOG:

image

刚才用Charles截了一段HTTP的数据,不知道可以不可以给你一些线索

image

是一个302的地址转移,但是我用的是OKHTTP,应该当是可以自己处理302的问题的

之后我又在FileDownloader-1.4.3的版本中我又尝试下了同一个链接,正常的,试了10来次都是正常的,但是1.4.3的版本好像对okcat支持的不是很好,所以没有捉到什么有用的LOG:

之前我已经了解过你写的 TCP 窗口的文章

@Jacksgong

不支持Partial Content的服务器会导致Crash

如果服务器没有返回Content-Range字段,并且以200而非206状态返回,同时返回了Transfer-Encoding: chunked,会导致BreakpointRemoteCheck中的instanceLength为-1,并抛出异常无法下载

Re-attachListener for UnifiedListenerManager no process callback for DownloadListener1 DownloadListener4 DownloadListener4WithSpeed case

场景:12个页面,每个页面有50个左右下载任务。在进入每个页面时都重新build task并attach listerner,退出当前页面时detachListerer,但是不会cancle下载。
这样在几个页面进出几次之后,停留在一个页面观察下载,一段时间后不再返回Listerner信息。这时退出页面再次进入也不会再返回Listener信息。

DownloadTask task = new DownloadTask.Builder(
                                    entity.getDownloadRecordTable().getMp4_url(),
                                    entity.getDownloadRecordTable().getParent_path(),
                                    entity.getDownloadRecordTable().getFilename())
                                    .setPriority(DOWNLOAD_PRIORITY_VIDEO)
                                    .setPassIfAlreadyCompleted(true)
                                    .build();

mUnifiedListenerManager.attachListener(task, taskDownloadListener);
mUnifiedListenerManager.detachListener(taskDownloadListener);

Downloading stuck for long time

I am downloading bunch of video files ( almost 60 of them). But most of the time after downloading 30 to 40 files, downloading is totally stuck and never call retry or taskEnd.

Is there any minimum waiting time API available?

can

5.0以下版本会报错,高版本可以正常下载
Could not find method android.system.Os.ftruncate, referenced from method com.liulishuo.okdownload.core.file.DownloadUriOutputStream.setLength

在OkDownload中有没有类似FileDownloader的FileDownloadNetworkPolicyException

FileDownloader中,当网络断开或是从WIFI切到3G/4G的时候(设定下载为wifiOnly)会有一个FileDownloadNetworkPolicyException 的错误上报。

现在用OkDownload断开网络的时候会有一个ERROREndCause和一个UnknownHostExecptionrealCause通过taskEnd上报上来,请问我是否可以通过这两个条件来判断是发生了断开网络的情况。还有就是如果我的task设定wifiRequired为true的情况下,当下载的过程中切换到3G/4G的时候,它会以什么形式来上报?还是说现在OkDownload只能自己来判断这一系列的操作?因为我看到这个问题 #15 ,你说FileDownloader这是一个伪需求,所以我不知道在OkDownload中是否有比较官方一些的方法来判断网络切换的情况?
@Jacksgong

Facing an issue with speed

Hi, I guess im missing some configuration here. I've been using this library to download files around 80 to 100mb but my problem is, the download speed starts at maximum speed "which is roughly around 5mb/s given my network speed" but then after 3 to 5 seconds the speed drops to around 250 to 500kb/s.

What am I doing wrong? Or is this a limitation of some sort on android?

java.lang.IllegalArgumentException: Info not on store!

Hi!
Thank you for the library!
I couldn't understand couple things because it is not well documented. Could you please help me?

  1. What is the difference between RemitStore and BreakpointStore.
    I tried to initialize OkDownload like following:
OkDownload.setSingletonInstance(OkDownload.Builder(appContext)
                                .downloadStore(BreakpointStoreOnSQLite(appContext).createRemitSelf())
                               // .downloadStore(BreakpointStoreOnSQLite(appContext)) // and like this
                                .build())

But data is not written to the database.
I have added implementation "com.liulishuo.okdownload:sqlite:1.0.1-SNAPSHOT" in build.gradle but couldn't use it. How can I add sqlite support?

  1. How can I cancel a task (delete completely all information about task)?
    Right now I am doing like this:
tasks[task].cancel() 
OkDownload.with().breakpointStore().remove(task.id)

But I am getting the FATAL Exception:
java.lang.IllegalArgumentException: Info not on store!

Hope to hear from u soon.

下载失败

当我用demo下载文件时,下载连接里面带有参数的时候(exp: url = xxxxx/thunt/get?t=f&id=c ),通过get 方法请求网络啊 ,能够正常连接上,但是下载回调里的文件总大小为0.结束时会跑抛出异常(exp: The current offset on block-info isn't update correct, 225508 != 0 on 0 )。

想要通过taskId来clear或pause某个task的方法

在原来FileDownloader里有一个操作就是clear,之前clear的操作从源码上看应该是先pause然后在去清除对应文件 ,现在OkDownload中好像并没有看到相应的clear操作,不知道有没有比较好的方法?从1.0.0的版本上要想自己清除下载文件,我是需要这样么?
OkDownload.with().breakpointStore().remove(taskId)
但是上面这个方法好像并没有暂停的功能吧?

我要是暂停的话是不是还需要:
OkDownload.with().downloadDispatcher().cancel(task)
但是问题来了,如果下载后,我只想通过taskId来进行 暂停清除的功能,好像并不如之前FileDownloader里方便,如果只能通过task来暂停某个任务,在项目里还需要单独维护一个保存task的collection..
要么就是每次使用 StatusUtils.createFinder() 的方法再重新创建这个task,然后进行cancel,我看了下task的构造函数,还是有一些开销的

How To Set Network Thread Count??

  1. How to set network thread count
  2. How to set My Own task id Generation Function?
  3. task.pause Callback is missing?
  4. from task object how to get download size and total size?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.