Skip to content

Instantly share code, notes, and snippets.

@korakot
Last active March 11, 2022 04:46
Show Gist options
  • Save korakot/6ccbdbac39e438dba576ac1423f03b38 to your computer and use it in GitHub Desktop.
Save korakot/6ccbdbac39e438dba576ac1423f03b38 to your computer and use it in GitHub Desktop.
Google Drive download in Colab, with wget and gdown
# already a few gists about this. But here seems to be a few easier methods
# from github.com/hzwer/LearningToPaint/blob/master/LearningToPaint.ipynb
# wget export=download
!wget "https://drive.google.com/uc?export=download&id=1-7dVdjCIZIxh8hHJnGTK-RA1-jL1tor4" -O renderer.pkl
!wget https://drive.google.com/uc?id=0B7EVK8r0v71pZjFTYXZWM3FlRnM --content-disposition
# gdown auto detect filename
!gdown https://drive.google.com/uc?id=0B7EVK8r0v71pZjFTYXZWM3FlRnM
!gdown --id 0B7EVK8r0v71pZjFTYXZWM3FlRnM
gdown.download('https://drive.google.com/uc?id=' + fid, None, True) # auto, quiet
# gdown rename
!gdown --id 1qDo_HqTAkx8W6HM5uIx25s0xOXLR2r3U -O out.pdf
# version 4.4+
!gdown 1l_5RK28JRL19wpT22B-DY9We3TVXnnQQ
!gdown https://drive.google.com/drive/folders/15uNXeRBIhVvZJIhL4yTw4IsStMhUaaxl -O /tmp/folder --folder
# for limited sharing only to your friends
def auth_drive():
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from oauth2client.client import GoogleCredentials as GC
from google.colab import auth
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GC.get_application_default()
return GoogleDrive(gauth)
def gdown(fid):
drive = auth_drive()
f = drive.CreateFile({'id':fid})
f.FetchMetadata(fetch_all=True)
f.GetContentFile(f.metadata['title'])
return f.metadata['title']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment