Skip to content

Instantly share code, notes, and snippets.

@ppetraki
Created November 8, 2017 20:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ppetraki/258ea8240041e19ab258a736781f06db to your computer and use it in GitHub Desktop.
Save ppetraki/258ea8240041e19ab258a736781f06db to your computer and use it in GitHub Desktop.
allows you do non-interactively download large public files from gdrive
#!/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)
wget --load-cookies $COOKIES "https://docs.google.com/uc?export=download&confirm=${CODE}&id=${FILEID}" -O $DEST
rm -f $COOKIES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment