Created
March 19, 2021 10:11
-
-
Save josemarcosrf/b750520b78bfe476bdf24d27c5765783 to your computer and use it in GitHub Desktop.
Download Google Drive file with wget
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
#!/usr/bin/env bash | |
set -e | |
set -o pipefail | |
say() { | |
echo "$@" | sed \ | |
-e "s/\(\(@\(red\|green\|yellow\|blue\|magenta\|cyan\|white\|reset\|b\|u\)\)\+\)[[]\{2\}\(.*\)[]]\{2\}/\1\4@reset/g" \ | |
-e "s/@red/$(tput setaf 1)/g" \ | |
-e "s/@green/$(tput setaf 2)/g" \ | |
-e "s/@yellow/$(tput setaf 3)/g" \ | |
-e "s/@blue/$(tput setaf 4)/g" \ | |
-e "s/@magenta/$(tput setaf 5)/g" \ | |
-e "s/@cyan/$(tput setaf 6)/g" \ | |
-e "s/@white/$(tput setaf 7)/g" \ | |
-e "s/@reset/$(tput sgr0)/g" \ | |
-e "s/@b/$(tput bold)/g" \ | |
-e "s/@u/$(tput sgr 0 1)/g" | |
} | |
if [ -z "$1" ]; then | |
say @red[["Please set the first parameter as the source file ID to download"]] | |
exit | |
else | |
FILE_ID=$1 | |
fi | |
if [ -z "$2" ]; then | |
say @red[["Please set the second parameter as the file NAME to save as"]] | |
exit | |
else | |
FILE_NAME=$2 | |
fi | |
wget --load-cookies /tmp/cookies.txt \ | |
"https://docs.google.com/uc?export=download&confirm=$( \ | |
wget --quiet --save-cookies /tmp/cookies.txt \ | |
--keep-session-cookies \ | |
--no-check-certificate \ | |
"https://docs.google.com/uc?export=download&id=$FILE_ID" -O- | \ | |
sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p' \ | |
)&id=$FILE_ID" \ | |
-O $FILE_NAME && rm -rf /tmp/cookies.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run as:
The
<FILE-NAME>
is any name of your choice to save the file locally.To get the
FILE_ID
:You’ll need the part after
https://drive.google.com/file/d/
and before/view?usp=sharing
for later. This is what we will callFILE_ID