Created
August 30, 2018 08:05
-
-
Save jbdemonte/dea5c9cd8433030bdd3a7a9d56c8639f to your computer and use it in GitHub Desktop.
Google Drive large file download script using curl
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
#!/bin/bash | |
# Based on http://blog.mclain.ca/download-large-files-from-google-drive-via-curl/ | |
# Usage: ./curl-download.sh file_id | |
file_id=$1 | |
if [[ -z "$file_id" ]]; then | |
echo "ERROR - file_id is missing" | |
echo " Usage: ./curl-download.sh file_id" | |
exit 1 | |
fi | |
echo "" > ./cookie.txt | |
echo "accessing ${file_id}" | |
filename=`curl -c ./cookie.txt -s -L "https://drive.google.com/uc?export=download&id=${file_id}" \ | |
| perl -nE'say/uc-name-size.*? href=".*?\">(.*?)</' \ | |
| sed -e 's/amp;//g' | sed -n 2p` | |
if [[ -z "$filename" ]]; then | |
echo "ERROR - filename is missing" | |
exit 2 | |
fi | |
query=`curl -c ./cookie.txt -s -L "https://drive.google.com/uc?export=download&id=${file_id}" \ | |
| perl -nE'say/uc-download-link.*? href="(.*?)\">/' \ | |
| sed -e 's/amp;//g' | sed -n 2p` | |
url="https://drive.google.com$query" | |
echo "Downloading ${filename}" | |
curl -b ./cookie.txt -L -o "${filename}" $url && echo "${filename} downloaded" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment