1%
1 words - 1 min read.

If you need to download a large (> 40 mB) file off of Google Drive via wget or curl you're going to have a bad time. Google Drive likes to scan files for viruses before allowing you to download them but it doesn't bother if the file is over 40 mB. Instead it will present you with a prompt that warns you that the file was too large to scan and may be a risk.

virus-scan

The download button contains a generated code that changes frequently (I have no idea how often) and that token must be provided as part of the query to download the file. I wrote a script that grabs the HTML of the warning page via curl, scrapes the code out via a perl regex (couldn't use sed because I needed lazy/reluctant matching and sed doesn't provide that), and constructs a valid url.

#!/bin/bash
filename="chain.zip"
file_id="1SubsQbGr48CAXFv2L3pPLDc1JlabcAnI"
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"
curl -b ./cookie.txt -L -o ${filename} $url

I've seen this code elsewhere, but it's usually a bit more complicated and required you to download other tools like pup for parsing the HTML.

© 2018. All Rights Reserved.

Proudly published with Ghost