Skip to content

Instantly share code, notes, and snippets.

@ben8p
Created December 6, 2018 14:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben8p/e1655c723ccf5fc05414d185496d40c4 to your computer and use it in GitHub Desktop.
Save ben8p/e1655c723ccf5fc05414d185496d40c4 to your computer and use it in GitHub Desktop.
Get GoogleDrive direct download link, even for large files
/*
replace XXX by the id of the file you want to download. You can add as many as you want
to get the ID, first get the share URL :
https://drive.google.com/file/d/1LHsdf3leinq1wCertnwFVGertertHrfB/view?usp=sharing
the id in this example is :
1LHsdf3leinq1wCertnwFVGertertHrfB
*/
const https = require('https');
[
'XXX',
].forEach((id) => {
https.get(`https://docs.google.com/uc?export=download&id=${id}`, (response) => {
var confirmToken = '';
var cookieValue = '';
const foundDownloadWarning = (response.headers['set-cookie'] || []).some((cookie) => {
if (cookie.indexOf('download_warning') !== -1) {
confirmToken = cookie.split(';')[0].split('=')[1];
cookieValue = cookie;
}
return cookie.indexOf('download_warning') !== -1;
});
if (foundDownloadWarning) {
https.get(`https://docs.google.com/uc?export=download&id=${id}&confirm=${confirmToken}`, {
headers: {
Cookie: cookieValue
}
}, (newResponse) => {
if (newResponse.statusCode == 302 || newResponse.statusCode == 301) {
console.log(newResponse.headers.location)
}
});
}
});
});
@neutrixs
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment