diff --git a/app/src/main/java/com/github/catvod/spider/Market.java b/app/src/main/java/com/github/catvod/spider/Market.java index ce439fb0..6e29e2f6 100644 --- a/app/src/main/java/com/github/catvod/spider/Market.java +++ b/app/src/main/java/com/github/catvod/spider/Market.java @@ -61,20 +61,24 @@ public class Market extends Spider { Utils.notify("正在下載..."); Response response = OkHttp.newCall(url); File file = FileUtil.getCacheFile(Uri.parse(url).getLastPathSegment()); - download(file, response.body().byteStream()); + download(file, response.body().byteStream(), Double.parseDouble(response.header("Content-Length", "1"))); FileUtil.openFile(FileUtil.chmod(file)); } catch (Exception e) { Utils.notify(e.getMessage()); } } - private void download(File file, InputStream is) throws Exception { + private void download(File file, InputStream is, double length) throws Exception { FileOutputStream os = new FileOutputStream(file); try (BufferedInputStream input = new BufferedInputStream(is)) { byte[] buffer = new byte[4096]; int readBytes; + long totalBytes = 0; while ((readBytes = input.read(buffer)) != -1) { + totalBytes += readBytes; os.write(buffer, 0, readBytes); + int progress = (int) (totalBytes / length * 100.0); + if (progress % 10 < 5) Utils.notify("正在下載..." + progress + "%"); } } } diff --git a/jar/custom_spider.jar b/jar/custom_spider.jar index ab8d8c31..18f864ee 100644 Binary files a/jar/custom_spider.jar and b/jar/custom_spider.jar differ diff --git a/jar/custom_spider.jar.md5 b/jar/custom_spider.jar.md5 index e9c94d93..5461222c 100644 --- a/jar/custom_spider.jar.md5 +++ b/jar/custom_spider.jar.md5 @@ -1 +1 @@ -f78dde289126840ebdd4abaf0cb7841d +e387f38428b7c337475b2827c56949f5