折腾:
【未解决】其他下载文件速度更快的Python的库
期间,不过都推荐了:aria2c
aria2c -x 16 [url]
其中16是16个线程,用于加速下载。
去试试
brew install aria2c Updating Homebrew... ==> Auto-updated Homebrew! ==> Searching taps on GitHub... Error: No formulae found in taps.
结果没有
去安装
aria2
安装后:
~ which aria2c /usr/local/aria2/bin/aria2c
看看help:
~/Downloads aria2c --help Usage: aria2c [OPTIONS] [URI | MAGNET | TORRENT_FILE | METALINK_FILE]... Printing options tagged with '#basic'. See 'aria2c -h#help' to know all available tags. Options: -v, --version Print the version number and exit. Tags: #basic -h, --help[=TAG|KEYWORD] Print usage and exit. The help messages are classified with tags. A tag starts with "#". For example, type "--help=#http" to get the usage for the options tagged with "#http". If non-tag word is given, print the usage for the options whose name includes that word. Possible Values: #basic, #advanced, #http, #https, #ftp, #metalink, #bittorrent, #cookie, #hook, #file, #rpc, #checksum, #experimental, #deprecated, #help, #all Default: #basic Tags: #basic, #help -l, --log=LOG The file name of the log file. If '-' is specified, log is written to stdout. Possible Values: /path/to/file, - Tags: #basic -d, --dir=DIR The directory to store the downloaded file. Possible Values: /path/to/directory Default: /Users/xxx/Downloads Tags: #basic, #file -o, --out=FILE The file name of the downloaded file. It is always relative to the directory given in -d option. When the -Z option is used, this option will be ignored. Possible Values: /path/to/file Tags: #basic, #http, #ftp, #file -s, --split=N Download a file using N connections. If more than N URIs are given, first N URIs are used and remaining URLs are used for backup. If less than N URIs are given, those URLs are used more than once so that N connections total are made simultaneously. The number of connections to the same host is restricted by the --max-connection-per-server option. See also the --min-split-size option. Possible Values: 1-* Default: 5 Tags: #basic, #http, #ftp --file-allocation=METHOD Specify file allocation method. 'none' doesn't pre-allocate file space. 'prealloc' pre-allocates file space before download begins. This may take some time depending on the size of the file. If you are using newer file systems such as ext4 (with extents support), btrfs, xfs or NTFS (MinGW build only), 'falloc' is your best choice. It allocates large(few GiB) files almost instantly. Don't use 'falloc' with legacy file systems such as ext3 and FAT32 because it takes almost same time as 'prealloc' and it blocks aria2 entirely until allocation finishes. 'falloc' may not be available if your system doesn't have posix_fallocate() function. 'trunc' uses ftruncate() system call or platform-specific counterpart to truncate a file to a specified length. Possible Values: none, prealloc, trunc, falloc Default: prealloc Tags: #basic, #file -V, --check-integrity[=true|false] Check file integrity by validating piece hashes or a hash of entire file. This option has effect only in BitTorrent, Metalink downloads with checksums or HTTP(S)/FTP downloads with --checksum option. If piece hashes are provided, this option can detect damaged portions of a file and re-download them. If a hash of entire file is provided, hash check is only done when file has been already download. This is determined by file length. If hash check fails, file is re-downloaded from scratch. If both piece hashes and a hash of entire file are provided, only piece hashes are used. Possible Values: true, false Default: false Tags: #basic, #metalink, #bittorrent, #file, #checksum -c, --continue[=true|false] Continue downloading a partially downloaded file. Use this option to resume a download started by a web browser or another program which downloads files sequentially from the beginning. Currently this option is only applicable to http(s)/ftp downloads. Possible Values: true, false Default: false Tags: #basic, #http, #ftp -i, --input-file=FILE Downloads URIs found in FILE. You can specify multiple URIs for a single entity: separate URIs on a single line using the TAB character. Reads input from stdin when '-' is specified. Additionally, options can be specified after each line of URI. This optional line must start with one or more white spaces and have one option per single line. See INPUT FILE section of man page for details. See also --deferred-input option. Possible Values: /path/to/file, - Tags: #basic -j, --max-concurrent-downloads=N Set maximum number of parallel downloads for every static (HTTP/FTP) URL, torrent and metalink. See also --split and --optimize-concurrent-downloads options. Possible Values: 1-* Default: 5 Tags: #basic -Z, --force-sequential[=true|false] Fetch URIs in the command-line sequentially and download each URI in a separate session, like the usual command-line download utilities. Possible Values: true, false Default: false Tags: #basic -x, --max-connection-per-server=NUM The maximum number of connections to one server for each download. Possible Values: 1-16 Default: 1 Tags: #basic, #http, #ftp -k, --min-split-size=SIZE aria2 does not split less than 2*SIZE byte range. For example, let's consider downloading 20MiB file. If SIZE is 10M, aria2 can split file into 2 range [0-10MiB) and [10MiB-20MiB) and download it using 2 sources(if --split >= 2, of course). If SIZE is 15M, since 2*15M > 20MiB, aria2 does not split file and download it using 1 source. You can append K or M(1K = 1024, 1M = 1024K). Possible Values: 1048576-1073741824 Default: 20M Tags: #basic, #http, #ftp --ftp-user=USER Set FTP user. This affects all URLs. Tags: #basic, #ftp --ftp-passwd=PASSWD Set FTP password. This affects all URLs. Tags: #basic, #ftp --http-user=USER Set HTTP user. This affects all URLs. Tags: #basic, #http --http-passwd=PASSWD Set HTTP password. This affects all URLs. Tags: #basic, #http --load-cookies=FILE Load Cookies from FILE using the Firefox3 format and Mozilla/Firefox(1.x/2.x)/Netscape format. Possible Values: /path/to/file Tags: #basic, #http, #cookie -S, --show-files[=true|false] Print file listing of .torrent, .meta4 and .metalink file and exit. More detailed information will be listed in case of torrent file. Possible Values: true, false Default: false Tags: #basic, #metalink, #bittorrent --max-overall-upload-limit=SPEED Set max overall upload speed in bytes/sec. 0 means unrestricted. You can append K or M(1K = 1024, 1M = 1024K). To limit the upload speed per torrent, use --max-upload-limit option. Possible Values: 0-* Default: 0 Tags: #basic, #bittorrent -u, --max-upload-limit=SPEED Set max upload speed per each torrent in bytes/sec. 0 means unrestricted. You can append K or M(1K = 1024, 1M = 1024K). To limit the overall upload speed, use --max-overall-upload-limit option. Possible Values: 0-* Default: 0 Tags: #basic, #bittorrent -T, --torrent-file=TORRENT_FILE The path to the .torrent file. Possible Values: /path/to/file Tags: #basic, #bittorrent --listen-port=PORT... Set TCP port number for BitTorrent downloads. Multiple ports can be specified by using ',', for example: "6881,6885". You can also use '-' to specify a range: "6881-6999". ',' and '-' can be used together. Possible Values: 1024-65535 Default: 6881-6999 Tags: #basic, #bittorrent --enable-dht[=true|false] Enable IPv4 DHT functionality. It also enables UDP tracker support. If a private flag is set in a torrent, aria2 doesn't use DHT for that download even if ``true`` is given. Possible Values: true, false Default: true Tags: #basic, #bittorrent --dht-listen-port=PORT... Set UDP listening port used by DHT(IPv4, IPv6) and UDP tracker. Multiple ports can be specified by using ',', for example: "6881,6885". You can also use '-' to specify a range: "6881-6999". ',' and '-' can be used together. Possible Values: 1024-65535 Default: 6881-6999 Tags: #basic, #bittorrent --enable-dht6[=true|false] Enable IPv6 DHT functionality. Use --dht-listen-port option to specify port number to listen on. See also --dht-listen-addr6 option. Possible Values: true, false Default: false Tags: #basic, #bittorrent --dht-listen-addr6=ADDR Specify address to bind socket for IPv6 DHT. It should be a global unicast IPv6 address of the host. Tags: #basic, #bittorrent -M, --metalink-file=METALINK_FILE The file path to the .meta4 and .metalink file. Reads input from stdin when '-' is specified. Possible Values: /path/to/file, - Tags: #basic, #metalink URI, MAGNET, TORRENT_FILE, METALINK_FILE: You can specify multiple HTTP(S)/FTP URIs. Unless you specify -Z option, all URIs must point to the same file or downloading will fail. You can also specify arbitrary number of BitTorrent Magnet URIs, torrent/ metalink files stored in a local drive. Please note that they are always treated as a separate download. You can specify both torrent file with -T option and URIs. By doing this, download a file from both torrent swarm and HTTP/FTP server at the same time, while the data from HTTP/FTP are uploaded to the torrent swarm. For single file torrents, URI can be a complete URI pointing to the resource or if URI ends with '/', 'name' in torrent file is added. For multi-file torrents, 'name' and 'path' in torrent are added to form a URI for each file. Make sure that URI is quoted with single(') or double(") quotation if it contains "&" or any characters that have special meaning in shell. About the number of connections Since 1.10.0 release, aria2 uses 1 connection per host by default and has 20MiB segment size restriction. So whatever value you specify using -s option, it uses 1 connection per host. To make it behave like 1.9.x, use --max-connection-per-server=4 --min-split-size=1M. Refer to man page for more information.
其中关键参数:
- -s, –split=N
- Download a file using N connections. If more than N URIs are given, first N URIs are used and remaining URLs are used for backup. If less than N URIs are given, those URLs are used more than once so that N connections total are made simultaneously. The number of connections to the same host is restricted by the –max-connection-per-server option. See also the –min-split-size option. Possible Values: 1-* Default: 5 Tags: #basic, #http, #ftp
- -x, –max-connection-per-server=NUM
- The maximum number of connections to one server for each download. Possible Values: 1-16 Default: 1 Tags: #basic, #http, #ftp
然后去试试
aria2c -x 16 -s 16 https://gameapktxdl.vivo.com.cn/appstore/developer/soft/20200222/202002221737396781531.apk 11/30 09:36:36 [NOTICE] Downloading 1 item(s) 11/30 09:36:36 [NOTICE] Allocating disk space. Use --file-allocation=none to disable it. See --file-allocation option in man page for more details. [#368441 60MiB/126MiB(47%) CN:4 DL:1.7MiB ETA:38s]

没有显示下载速度啊
去看看是否有参数可以显示下载速度
看到有另外并行下载的参数:j
- -j, –max-concurrent-downloads=N
- Set maximum number of parallel downloads for every static (HTTP/FTP) URL, torrent and metalink. See also –split and –optimize-concurrent-downloads options. Possible Values: 1-* Default: 5 Tags: #basic
此处已下载完毕了:
11/30 09:37:49 [NOTICE] Download complete: /Users/xxx/Downloads/202002221737396781531.apk Download Results: gid |stat|avg speed |path/URI ======+====+===========+======================================================= 368441|OK | 1.7MiB/s|/Users/xxx/Downloads/202002221737396781531.apk Status Legend: (OK):download completed.
平均下载速度是:1.7MB/s
和之前python的requests一样,没区别
-》并没有提高下载速度
再试试-j
aria2c -j 10 https://gameapktxdl.vivo.com.cn/appstore/developer/soft/20200222/202002221737396781531.apk 11/30 09:40:19 [NOTICE] Downloading 1 item(s) 11/30 09:40:19 [NOTICE] Allocating disk space. Use --file-allocation=none to disable it. See --file-allocation option in man page for more details. [#6d9025 16MiB/126MiB(13%) CN:1 DL:1.5MiB ETA:1m10s]
最后:
*** Download Progress Summary as of Mon Nov 30 09:41:19 2020 *** ====================================================================================================================================== [#6d9025 99MiB/126MiB(79%) CN:1 DL:1.7MiB ETA:14s] FILE: /Users/xxx/Downloads/202002221737396781531.apk -------------------------------------------------------------------------------------------------------------------------------------- [#6d9025 124MiB/126MiB(98%) CN:1 DL:1.7MiB] 11/30 09:41:34 [NOTICE] Download complete: /Users/xxx/Downloads/202002221737396781531.apk Download Results: gid |stat|avg speed |path/URI ======+====+===========+======================================================= 6d9025|OK | 1.6MiB/s|/Users/xxx/Downloads/202002221737396781531.apk Status Legend: (OK):download completed.
平均速度:1.6MB/s
还是没有希望的更快的速度。
放弃。
那是不是此处测试100多MB的文件太小了,还没看出加速就结束了?
不至于吧
不过还是去找个别的下载试试
aria2c -x 16 -s 16 https://gameapktxdl.vivo.com.cn/appstore/developer/soft/20201119/202011191831229j3il.apk
另外看到
About the number of connections Since 1.10.0 release, aria2 uses 1 connection per host by default and has 20MiB segment size restriction. So whatever value you specify using -s option, it uses 1 connection per host. To make it behave like 1.9.x, use --max-connection-per-server=4 --min-split-size=1M.
不过此处同时制定了-s和-x,所以应该没问题
不过也没指定split size = chunk size
- -k, –min-split-size=SIZE
- aria2 does not split less than 2*SIZE byte range. For example, let’s consider downloading 20MiB file. If SIZE is 10M, aria2 can split file into 2 range [0-10MiB) and [10MiB-20MiB) and download it using 2 sources(if –split >= 2, of course). If SIZE is 15M, since 2*15M > 20MiB, aria2 does not split file and download it using 1 source. You can append K or M(1K = 1024, 1M = 1024K). Possible Values: 1048576-1073741824 Default: 20M Tags: #basic, #http, #ftp
所以感觉应该去指定不同的split size?
之前下载100多MB,按默认的20M,其实也可以有6,7个并行加速
-》按道理也应该加速6,7倍才对,但是实际上速度也没变化啊
所以感觉和此处split size,关系不是很大
下载完毕了:
aria2c -x 16 -s 16 https://gameapktxdl.vivo.com.cn/appstore/developer/soft/20201119/202011191831229j3il.apk 11/30 09:48:58 [NOTICE] Downloading 1 item(s) 11/30 09:48:58 [NOTICE] Allocating disk space. Use --file-allocation=none to disable it. See --file-allocation option in man page for more details. *** Download Progress Summary as of Mon Nov 30 09:49:59 2020 *** ====================================================================================================================================== [#6f5298 103MiB/670MiB(15%) CN:16 DL:1.8MiB ETA:5m11s] FILE: /Users/xxx/Downloads/202011191831229j3il.apk -------------------------------------------------------------------------------------------------------------------------------------- *** Download Progress Summary as of Mon Nov 30 09:50:59 2020 *** ====================================================================================================================================== [#6f5298 207MiB/670MiB(31%) CN:16 DL:1.7MiB ETA:4m20s] FILE: /Users/xxx/Downloads/202011191831229j3il.apk -------------------------------------------------------------------------------------------------------------------------------------- *** Download Progress Summary as of Mon Nov 30 09:52:00 2020 *** ====================================================================================================================================== [#6f5298 315MiB/670MiB(47%) CN:16 DL:1.7MiB ETA:3m22s] FILE: /Users/xxx/Downloads/202011191831229j3il.apk -------------------------------------------------------------------------------------------------------------------------------------- *** Download Progress Summary as of Mon Nov 30 09:53:00 2020 *** ====================================================================================================================================== [#6f5298 421MiB/670MiB(62%) CN:16 DL:1.7MiB ETA:2m21s] FILE: /Users/xxx/Downloads/202011191831229j3il.apk -------------------------------------------------------------------------------------------------------------------------------------- *** Download Progress Summary as of Mon Nov 30 09:54:01 2020 *** ====================================================================================================================================== [#6f5298 528MiB/670MiB(78%) CN:14 DL:1.7MiB ETA:1m19s] FILE: /Users/xxx/Downloads/202011191831229j3il.apk -------------------------------------------------------------------------------------------------------------------------------------- *** Download Progress Summary as of Mon Nov 30 09:55:01 2020 *** ====================================================================================================================================== [#6f5298 633MiB/670MiB(94%) CN:7 DL:1.7MiB ETA:20s] FILE: /Users/xxx/Downloads/202011191831229j3il.apk -------------------------------------------------------------------------------------------------------------------------------------- [#6f5298 668MiB/670MiB(99%) CN:1 DL:1.7MiB] 11/30 09:55:22 [NOTICE] Download complete: /Users/xxx/Downloads/202011191831229j3il.apk Download Results: gid |stat|avg speed |path/URI ======+====+===========+======================================================= 6f5298|OK | 1.7MiB/s|/Users/xxx/Downloads/202011191831229j3il.apk Status Legend: (OK):download completed.
速度还只是 1.7MB/s
并没有提高下载速度。
放弃。
【后记20201204】
其实后来发现是:
公司的WiFi被网管限速导致此处下载慢
实际上速度可以很快,比如5MB/s,甚至9MB/s的。
对应的此处的aria2c的加速,则实际上应该是有效的了。
最终:
aria2c -x 16 -s 16 your_url
可以实现加速下载。
转载请注明:在路上 » 【已解决】Mac中尝试用aria2c提高文件下载速度