-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiadownloader.py
56 lines (48 loc) · 1.86 KB
/
iadownloader.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
49
50
51
52
53
54
55
56
# Import needed modules for script to work
import argparse
import os
import time
# The following will see if internetarchive is installed and prompt if not.
try:
from internetarchive import download
except ImportError:
print("The internet archive module is not installed")
print("run pip install internetarchive to install it.")
exit()
# Construct an argument parser
all_args = argparse.ArgumentParser()
# Add arguments to the parser
all_args.add_argument('-u', '--url', type=str, required=True, help="Input URL (the bit after archive.org/download/THISSTUFFHERE)")
all_args.add_argument('-o', '--output', type=str, required=False, help="Output directory, if not specified it will download here")
all_args.add_argument('-g', '--glob_pattern', type=str, required=False, help="Glob Pattern if you only want certian files (ie. *7z, *mkv, *png)")
all_args.add_argument('-v', '--verbose', type=str, required=False, help="Verbose, whether you want to see the output")
args = all_args.parse_args()
# Do the stuff
# Check to see if a path was provided and set the script to use it if so.
if args.output:
path = args.output
f_path = os.chdir(path)
f = os.getcwd()
else:
path = './'
f_path = os.chdir(path)
f = os.getcwd()
# Create the downloader function and have it select the right method based on provided args
def downloader():
try:
if args.glob_pattern and args.verbose:
download (args.url, verbose=True, glob_pattern=args.glob_pattern)
elif args.glob_pattern:
download (args.url, glob_pattern=args.glob_pattern)
elif args.verbose:
download (args.url, verbose=True)
else:
download (args.url)
except:
print("Ran into a problem downloading, waiting to restart")
time.sleep(20)
downloader()
# Run it
downloader()
# We're done here
exit()