def get_report(self): return { 'size': self.meta['size'], 'size_readable': self.meta['size_readable'], 'num': self.meta['num'], 'start_time': self.start_time, 'end_time': self.end_time, 'elapsed_time': self.elapsed_time, 'speed': '%s/s' % util.readable_size(self.meta['size'] / self.elapsed_time) }
def init(self): if not path.exists(self.temp_dir) and not path.isdir(self.temp_dir): os.mkdir(self.temp_dir) if not path.exists(self.data_path) and not path.isdir(self.data_path): os.mkdir(self.data_path) size = util.get_source_size(self.url, 3) if size and size > 0: self.meta['size'] = size self.meta['size_readable'] = util.readable_size(size) if size > 1024 * 128: self.meta['num'] = size / 1024 / 128 else: self.meta['num'] = 1 self.meta['chunk_size'] = size / self.meta['num'] else: raise Exception("Can't get content-length of %s" % self.url)