-
Notifications
You must be signed in to change notification settings - Fork 4
/
gda.py
48 lines (39 loc) · 1.6 KB
/
gda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
gda.py - Python script for Google Drive download (large files) with the help of aria2
Copyright @raspiduino 2020
Date created 25/12/2020 - Christmas
'''
import requests
import os
import sys
helpstring = '''
gda.py - Python script for Google Drive download (large files) with the help of aria2
Copyright @raspiduino 2020
Date created 25/12/2020 - Christmas
Usage:
gda.py file/help fileid
fileid : Paste in the file/folder id, for example if the link is https://drive.google.com/file/d/abc
please type in abc
Note: + By default this python script will download at max speed using aria2 '-x16 -s16 -j5' option. You
can remove it if you don't want to.
+ You can add more command line to aria2 if you want
'''
if sys.argv != [""]:
# Download a single file
if sys.argv[1] != "":
# Get the cookies
session = requests.Session()
session.get("https://drive.google.com/uc?export=download&id=" + sys.argv[1])
cookiename = list(session.cookies.get_dict().keys())[0]
cookieval = list(session.cookies.get_dict().values())
# Execute the aria2c command
errorcode = -1
while errorcode != 0:
# Run until there is no error
# Restart if error occur
errorcode = os.system('aria2c -x16 -s16 -j5 --header="Cookie: ' + cookiename + '=' + cookieval[0] + '" --header="Cookie: NID=' + cookieval[1].replace("=", "%22") + '" "https://drive.google.com/uc?export=download&confirm=' + cookieval[0] + '&id=' + sys.argv[1] + '"')
elif sys.argv[1] == "help":
print(helpstring)
else:
print("Please enter a file id!")
print(helpstring)