-
-
Save allenyllee/ac42730e9c756e0aeb9b2f07424b68dd to your computer and use it in GitHub Desktop.
allows you do non-interactively download large public files from gdrive
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/bash | |
SOURCE="$1" | |
if [ "${SOURCE}" == "" ]; then | |
echo "Must specify a source url" | |
exit 1 | |
fi | |
DEST="$2" | |
#if [ "${DEST}" == "" ]; then | |
# echo "Must specify a destination filename" | |
# exit 1 | |
#fi | |
FILEID=$(echo $SOURCE | rev | cut -d= -f1 | rev) | |
COOKIES=$(mktemp) | |
CODE=$(wget --save-cookies $COOKIES --keep-session-cookies --no-check-certificate "https://docs.google.com/uc?export=download&id=${FILEID}" -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/Code: \1\n/p') | |
# cleanup the code, format is 'Code: XXXX' | |
CODE=$(echo $CODE | rev | cut -d: -f1 | rev | xargs) | |
# if no $DEST, auto fetch filename, otherwise use $DEST as filename | |
if [ -z "$DEST" ]; then | |
# option --content-disposition to auto fetch filename | |
wget --content-disposition --load-cookies $COOKIES "https://docs.google.com/uc?export=download&confirm=${CODE}&id=${FILEID}" | |
else | |
wget --load-cookies $COOKIES "https://docs.google.com/uc?export=download&confirm=${CODE}&id=${FILEID}" -O $DEST | |
fi | |
rm -f $COOKIES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment