用于从服务器下载文件,只要总带宽不超过ISP上限,这些服务器就不会限制每个连接的带宽。
mfd的Python项目详细描述
多线程文件下载器
对于从不限制每个连接的带宽的服务器下载文件非常有用,只要总带宽不超过ISP上限。
<;u>;不支持cookie或会话。<;/u>
Example:
ISP cap: 2MBps
File server bandwidth per connection: 2MBps
Number of connections: 8
Expected download speed per connection: 256KBps
Expected download speed of the file: 2MBps
Download speed is capped by ISP
ISP cap: 10MBps
File server bandwidth per connection: 1MBps
Number of connections: 8
Expected download speed per connection: 1MBps
Expected download speed of the file: 8MBps
Download speed is capped by file server, can be enhanced by using more connections (which may be limited by the file server)
等级制度
^{pr2}$示例
Python
<;u>;MFD()不是线程安全的。
不要在线程中使用相同的MFD()实例。<;/u>
frommfdimportMFDmfd=MFD(# file saving directorysave_dir="I:\\test",# piece size of each download connection# adjust with hard disk speed and Internet bandwidth# size in bytespiece_size=1024*1024*(2**4),# number of retry when a piece is failed to downloadretry=2)info=mfd.download(# file urlurl="direct download url",# number of download connectionsconnections=2**3,# whether to calculate SHA1 after downloadingcal_hash=False)print(info)# {"file_path": "I:\\test\\file"}# {"file_path": "I:\\test\\file", "sha1": "checksum"}# if it is failed to download after the specified retries,# an exception is raised# additional retry can be like thistry:mfd.download(...)except:mfd.retry_download(# number of download connectionsconnections=2**3)# necessary to stop the downloader after downloadingmfd.stop()
- 项目
标签: