Created
December 6, 2018 14:36
-
-
Save ben8p/e1655c723ccf5fc05414d185496d40c4 to your computer and use it in GitHub Desktop.
Get GoogleDrive direct download link, even for large files
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
/* | |
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) | |
} | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice