def download(url,ofolder,sz=64,trimm=True,file=None): if file==None: file=location(url) res=file.response;readable=file.readable;fname=file.name file_id=file.ID; if not readable: return False totsize=file.size output=os.path.join(ofolder,fname) buf=int(sz*1024) if fname.endswith(".xci") and trimm==True: end=DriveTools.get_xci_rom_size(file) hd={"Range" : 'bytes=%s-%s' % (0,end)} file.sess.headers=hd file.response = file.sess.get(file.url, stream=True) totsize=end else: res = file.rewind() print("Downloading file to {}".format(output)) t = tqdm(total=totsize, unit='B', unit_scale=True, leave=False) with open(output,"wb") as o: for data in res.iter_content(chunk_size=buf): o.write(data) p=file.position t.update(len(data));file.position=p+len(data) if not data: break t.close()
def download(path, ofolder, TD=None, filter=None, trimm=True): if path == 'pick': account = token_picker() TD = TD_picker(account) return test = path.split(".+") if TD == 'pick': TD = TD_picker(path) if len(test) > 1 or path.endswith('/') or path.endswith('\\'): type = "folder" else: ID, name, type, size, md5, remote = get_Data(path, TD=TD, Print=False) output = os.path.join(ofolder, name) if type != 'file': # print('Path is a folder') folderpicker(path, ofolder, TD, filter) return else: if name.endswith(".xci") and trimm == True: end = DriveTools.get_xci_rom_size(remote) hd = get_html_header(remote.access_token, off1=0, off2=end) remote.get_session(hd) size = end else: remote.get_session() buf = int(64 * 1024) print("- Downloading file to {}".format(output)) t = tqdm(total=int(size), unit='B', unit_scale=True, leave=False) with open(output, "wb") as o: for data in remote.response.iter_content(chunk_size=buf): o.write(data) t.update(len(data)) if not data: break t.close() print(" *Finished*")