how make python script for renewable downloads? -
i've been searching (without results) reanudable (i don't know if correct word, sorry) way download big files internet python, know how directly urllib2, if interrupt connection, need way reconnect , continue download if it's possible (like download manager).
for other people can answer, there's http protocol called chunked transfer encoding allow specifying 'range' header of request beginning , end bytes (separated dash), possible count how many bytes downloaded , send new beginning byte continue download. example requests module:
import requests os.path import getsize #get size of previous downloaded chunk file beg = getsize(path_to_file) #if want can size before download file (without download it) end = request.head(url).headers['content-length'] #continue download in next byte stopped headers = {'range': "bytes=%d-%s"%(beg+1,end)} download = requests.get(url, headers=headers)
Comments
Post a Comment