@@ -17,50 +17,52 @@ def parse_args() -> argparse.Namespace:
17
17
parser = argparse .ArgumentParser (description = "Bulk download stuff from Itch.io." )
18
18
parser .add_argument ("url_or_path" ,
19
19
help = "itch.io URL or path to a game jam entries.json file" )
20
- parser .add_argument ("--api-key" , metavar = "key" , default = None ,
21
- help = "itch.io API key - https://itch.io/user/settings/api-keys" )
22
20
parser .add_argument ("--profile" , metavar = "profile" , default = None ,
23
21
help = "configuration profile to load" )
22
+
23
+ # These args must match config.py -> Settings class. Make sure all defaults here
24
+ # evaluate to False, or apply_args_on_settings will override profile settings.
25
+ parser .add_argument ("--api-key" , metavar = "key" , default = None ,
26
+ help = "itch.io API key - https://itch.io/user/settings/api-keys" )
27
+ parser .add_argument ("--user-agent" , metavar = "agent" , default = None ,
28
+ help = "user agent to use when sending HTTP requests" )
29
+ parser .add_argument ("--download-to" , metavar = "path" , default = None ,
30
+ help = "directory to save results into (default: current working dir)" )
31
+ parser .add_argument ("--mirror-web" , action = "store_true" ,
32
+ help = "try to fetch assets on game sites" )
24
33
parser .add_argument ("--urls-only" , action = "store_true" ,
25
34
help = "print scraped game URLs without downloading them" )
26
- parser .add_argument ("--download-to" , metavar = "path" ,
27
- help = "directory to save results into (default: current dir)" )
28
- parser .add_argument ("--parallel" , metavar = "parallel" , type = int , default = 1 ,
35
+ parser .add_argument ("--parallel" , metavar = "parallel" , type = int , default = None ,
29
36
help = "how many threads to use for downloading games (default: 1)" )
30
- parser .add_argument ("--mirror-web" , action = "store_true" ,
31
- help = "try to fetch assets on game sites" )
32
37
parser .add_argument ("--filter-files-glob" , metavar = "glob" , default = None ,
33
38
help = "filter downloaded files with a shell-style glob/fnmatch (unmatched files are skipped)" )
34
39
parser .add_argument ("--filter-files-regex" , metavar = "regex" , default = None ,
35
40
help = "filter downloaded files with a Python regex (unmatched files are skipped)" )
36
41
parser .add_argument ("--verbose" , action = "store_true" ,
37
42
help = "print verbose logs" )
43
+
38
44
return parser .parse_args ()
39
45
# fmt: on
40
46
41
47
42
- def apply_args_on_settings (args : argparse .Namespace , settings : Settings ):
43
- """Apply settings overrides from provided command line arguments, if set."""
44
- for key in ("api_key" , "filter_files_glob" , "filter_files_regex" ):
45
- value = getattr (args , key )
46
- if value :
47
- setattr (settings , key , value )
48
-
49
-
50
48
def run () -> int :
51
49
args = parse_args ()
52
50
if args .verbose :
53
51
logging .getLogger ().setLevel (logging .DEBUG )
54
52
55
- settings = load_config (profile = args .profile )
56
- apply_args_on_settings (args , settings )
53
+ settings : Settings = load_config (args , profile = args .profile )
54
+ if settings .verbose :
55
+ logging .getLogger ().setLevel (logging .DEBUG )
57
56
58
57
if not settings .api_key :
59
58
exit (
60
59
"You did not provide an API key which itch-dl requires.\n "
61
60
"See https://github.com/DragoonAethis/itch-dl/wiki/API-Keys for more info."
62
61
)
63
62
63
+ url_or_path = args .url_or_path
64
+ del args # Do not use `args` beyond this point.
65
+
64
66
# Check API key validity:
65
67
client = ItchApiClient (settings .api_key , settings .user_agent )
66
68
profile_req = client .get ("/profile" )
@@ -70,25 +72,24 @@ def run() -> int:
70
72
"See https://github.com/DragoonAethis/itch-dl/wiki/API-Keys for more info."
71
73
)
72
74
73
- jobs = get_jobs_for_url_or_path (args . url_or_path , settings )
75
+ jobs = get_jobs_for_url_or_path (url_or_path , settings )
74
76
jobs = list (set (jobs )) # Deduplicate, just in case...
75
77
logging .info (f"Found { len (jobs )} URL(s)." )
76
78
77
79
if len (jobs ) == 0 :
78
80
exit ("No URLs to download." )
79
81
80
- if args .urls_only :
82
+ if settings .urls_only :
81
83
for job in jobs :
82
84
print (job )
83
85
84
86
return 0
85
87
86
- download_to = os .getcwd ()
87
- if args .download_to is not None :
88
- download_to = os .path .normpath (args .download_to )
89
- os .makedirs (download_to , exist_ok = True )
88
+ # If the download dir is not set, use the current working dir:
89
+ settings .download_to = os .path .normpath (settings .download_to or os .getcwd ())
90
+ os .makedirs (settings .download_to , exist_ok = True )
90
91
91
92
# Grab all the download keys (there's no way to fetch them per title...):
92
93
keys = get_download_keys (client )
93
94
94
- return drive_downloads (jobs , download_to , args . mirror_web , settings , keys , parallel = args . parallel )
95
+ return drive_downloads (jobs , settings , keys )
0 commit comments