-
-
Save ricardodeazambuja/415cf5776d370eedf09df779778ceb0e to your computer and use it in GitHub Desktop.
How to download stuff directly from google drive into a jupyter notebook / colab
This file contains hidden or 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
#!/bin/sh | |
######Usage####### | |
# ./dgoogle_download.sh FILE_ID OUTPUT_NAME | |
## Remember to chomod +x dgoogle_download.sh | |
#This scrip is based on https://unix.stackexchange.com/questions/136371/how-to-download-a-folder-from-google-drive-using-terminal | |
LINK="https://drive.google.com/uc?export=download&id="$1 | |
CODE="$(wget -q --save-cookies $1.txt --keep-session-cookies --no-check-certificate $LINK -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1/p' )" | |
LINK="https://drive.google.com/uc?export=download&confirm=$CODE&id="$1 | |
wget --load-cookies cookies.txt $LINK -O $2 | |
rm -f $1.txt |
Extra notes:
Follow these steps and it is possible to open the shared link on incognito mode and press the ESC key as soon as you click on the download button. Then, you just need to add the address between quotation marks because bash gets confused with the & character: $ curl -L -o local_file_name 'link_to_google_drive_file_copied'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One-liner version (using -q, therefore no outputs from wget) to be used with Jupyter notebooks:
!FILENAME="<name_used_to_save_your_file>" && ID="<id_copied_from_link>" && LINK="https://drive.google.com/uc?export=download&id="$ID && CODE="$(wget -q --save-cookies $ID.txt --keep-session-cookies --no-check-certificate $LINK -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1/p' )" && LINK="https://drive.google.com/uc?export=download&confirm=$CODE&id="$ID && wget -q --load-cookies $ID.txt $LINK -O $FILENAME && rm -f $ID.txt && echo $FILENAME '...done!'