Last active
March 11, 2022 04:46
-
-
Save korakot/6ccbdbac39e438dba576ac1423f03b38 to your computer and use it in GitHub Desktop.
Google Drive download in Colab, with wget and gdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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