Download Files with zagoload - part 6

Other Parameters

  • If you do not use, you can set the parameter loadData to False to save memory resources.
  • You can set retries parameter to number of tries that the class should do before retirement and reporting that the download has failed ( FileRequest.valid is False and FileRequest.failed is True ). The default value is 2.
  • You can set contentType to the content type of the expected file (if downloaded via HTTP protocol). If the content type the is different than expected, the download will fail.
  • You can set maxCache - The time in seconds while the file which exist in cache folder is valid.

You can give a callback function to display the download progress via onDownloading parameter which should have the following signature:

onDownloading callback
 def onDownloading(fileSize,downSize, downSpeed):
   # the fileSize is the size of the source file in bytes
   # the downSize is the size of the target file which already downloaded in bytes
   # the downsize is the speed as bytes per second
 import zagoload
 def download(source):
   def info(ss):
     import sys ;sys.stdout.write(ss + u'\n')
   def onDownload(fileSize,downSize, downSpeed):
     info( u'{0:3}% - {1:8}/{2}, {3:4.0f}kb/s'.format(int(100*downSize/fileSize), downSize, fileSize, downSpeed/1024))
   ff = zagoload.load(source,onDownload=onDownload)
   if ff.valid:
     info( u'{0} => {1}'.format(ff.source, )
     info( 'Failed to download {0}'.format(ff.source) )
 download('') output
 # python
   6% -   339968/5242880,  332kb/s
  22% -  1163264/5242880,  768kb/s
  51% -  2674688/5242880, 1431kb/s
  94% -  4935680/5242880, 2208kb/s => Cache/CO/file_CO3FhQihPolP4gE0.bin