0

Downloading file from Google Drive without problem. I need limit download speed like 512kbps, 1024kbps per second.

Tried to time.sleep(1) and change chunksize but it's not working perfectly. Maybe there is fuction to limit speed.

        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']
        fh = io.FileIO(yazilacakyer, 'wb')
        downloader = MediaIoBaseDownload(fh, request, chunksize=1024 * 1024)
        time1 = time.time()
        done = False

        while done is False:
            status, done = downloader.next_chunk()
            fark = float(time.time() - time1)
            time1 = time.time()
            print('Download Speed:')
            print(self.byteToKb_or_Mb(int(1024/fark)*1024))

1 Answers1

0

not sure what you are trying to achieve but maybe it would be best to pull this by parts using the range request header in http standard instead of playing with bandwidth. https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests

for example adding header Range: bytes=0-1023 will make the server return just that chunk of data.

later you can multi-thread that to pull multiple chunks at once in the future.

mpod
  • 89
  • 5
  • I can download file from google drive. I want to limit download speed (example maximum 1024kbps) . –  Aug 05 '19 at 15:24