从Google云端硬盘向下下载文件没有任何问题。我想设置最大下载速度(例如:256kbps)
我做了我想要的,但是在下lodlo开始之后不能更改chunksize。如果我在您的帮助下解决此问题,一切都会很好。 这是我的代码:
http = credentials.authorize(httplib2.Http())
drive_service = discovery.build('drive', 'v3', http=http, cache_discovery=False)
request = drive_service.files().get_media(fileId=link)
file = drive_service.files().get(fileId=link).execute()
dosyadi = file['name']
print(file['name'])
self.PATH_DRIVE = self.PATH_DRIVE.replace("\n", "")
yazilacakyer = self.PATH_DRIVE + '\\' + dosyadi
fh = io.FileIO(yazilacakyer, 'wb')
KB_PERSEC=1024 #default chunk size 1mb
if speedlimit!=0:
KB_PERSEC = speedlimit #if has speed limit on parameter, set chunksizes as speedlimit
downloader = MediaIoBaseDownload(fh, request, chunksize=1024*KB_PERSEC)
done = False
while done is False:
gecensure = time.time()
status, done = downloader.next_chunk()
gecensure=time.time()-gecensure #if downloading chunksize time lower than 1 second then wait 1 sec
while self.indirilecek_indexler[structakiIndex].indirilecek_indirmeDevamEdiyor==False:
time.sleep(5)
self.indirilecek_indexler[structakiIndex].thr_strIndirilenMbToplamMb=self.humanbytes(status.resumable_progress) + ' / ' + self.humanbytes(status.total_size)
self.indirilecek_indexler[structakiIndex].thr_yuzde=int(status.progress()*100)
if fark < 1.1 and speedlimit != 0:
self.indirilecek_indexler[structakiIndex].thr_lblDownloadSpeed = self.humanbytes(KB_PERSEC*1024)
else:
self.indirilecek_indexler[structakiIndex].thr_lblDownloadSpeed=self.humanbytes(int(KB_PERSEC/gecensure*KB_PERSEC))
if speedlimit!=0:
time.sleep(1)