Skip to content

Instantly share code, notes, and snippets.

@nobodyzxc
Forked from afunTW/download_from_gdrive.bash
Last active May 15, 2020 08:56
Show Gist options
  • Save nobodyzxc/7d256760a5be9095f6805beef3479d55 to your computer and use it in GitHub Desktop.
Save nobodyzxc/7d256760a5be9095f6805beef3479d55 to your computer and use it in GitHub Desktop.
download the file on google drive (both small and large file)
download_from_gdrive() {
file_id=$1
file_name=$2 # first stage to get the warning html
curl -L -o $file_name -c /tmp/cookies \
"https://drive.google.com/uc?export=download&id=$file_id"
if grep "Virus scan warning" $file_name > /dev/null;then
# second stage to extract the download link from html above
download_link=$(cat $file_name | \
grep -Eo 'uc-download-link" [^>]* href="[^\"]*' | sed 's/\&/\&/g' | sed 's/.*href="\(.*\)/\1/')
#grep -Po 'uc-download-link" [^>]* href="\K[^"]*' | \
#sed 's/\&/\&/g')
if [ ! -z "$download_link" ];then
curl -L -b /tmp/cookies \
"https://drive.google.com$download_link" > $file_name
fi
fi
}
# download_from_gdrive <FILE_ID> <OUTPUT_FILENAME>
# ex.
# download_from_gdrive 1Eveuc2Yd12ehBmM-pmNde4ij1IUXDRMF 60w_tokey.txt # small
# download_from_gdrive 1VwjLCVfByaO5ywBFg_nmjp9RlJBRevCk 60w_token.txt # large
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment