forked from Witness-senpai/fakku-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
144 lines (133 loc) · 4.13 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
import argparse
from pathlib import Path
from downloader import (
FDownloader,
program_exit,
TIMEOUT,
WAIT,
URLS_FILE,
DONE_FILE,
COOKIES_FILE,
ROOT_MANGA_DIR,
MAX,
)
def main():
argparser = argparse.ArgumentParser()
argparser.add_argument(
"-z",
"--collection_url",
type=str,
default=None,
help=f"Give a collection URL that will be parsed and loaded into urls.txt \
The normal operations of downloading manga images will not happen while this \
parameter is set. \
By default -- None, process the urls.txt instead",
)
argparser.add_argument(
"-f",
"--file_urls",
type=str,
default=URLS_FILE,
help=f".txt file that contains list of urls for download \
By default -- {URLS_FILE}",
)
argparser.add_argument(
"-d",
"--done_file",
type=str,
default=DONE_FILE,
help=f".txt file that contains list of urls that have been downloaded. \
This is used to resume in the event that the process stops midway. \
By default -- {DONE_FILE}",
)
argparser.add_argument(
"-c",
"--cookies_file",
type=str,
default=COOKIES_FILE,
help=f"Binary file that contains saved cookies for authentication. \
By default -- {COOKIES_FILE}",
)
argparser.add_argument(
"-o",
"--output_dir",
type=str,
default=ROOT_MANGA_DIR,
help=f"The directory that will be used as the root of the output \
By default -- {ROOT_MANGA_DIR}",
)
argparser.add_argument(
"-l",
"--login",
type=str,
default=None,
help="Login or email for authentication",
)
argparser.add_argument(
"-p", "--password", type=str, default=None, help="Password for authentication"
)
argparser.add_argument(
"-t",
"--timeout",
type=float,
default=TIMEOUT,
help=f"Timeout in seconds for loading first manga page. \
Increase this argument if quality of pages is bad. By default -- {TIMEOUT} sec",
)
argparser.add_argument(
"-w",
"--wait",
type=float,
default=WAIT,
help=f"Wait time in seconds for pauses beetween downloading pages \
Increase this argument if you become blocked. By default -- {WAIT} sec",
)
argparser.add_argument(
"-m",
"--max",
type=int,
default=MAX,
help=f"Max number of volumes to download at once \
Set this argument if you become blocked. By default -- No limit",
)
args = argparser.parse_args()
file_urls = Path(args.file_urls)
if args.collection_url:
Path(args.file_urls).touch()
elif not file_urls.is_file() or file_urls.stat().st_size == 0:
print(
f"File {args.file_urls} does not exist or empty.\n"
+ "Create it and write the list of manga urls first.\n"
+ "Or run this again with the -z parameter with a collection_url to download urls first."
)
program_exit()
# Create empty done.text if it not exists
if not Path(args.done_file).is_file():
Path(args.done_file).touch()
loader = FDownloader(
urls_file=args.file_urls,
done_file=args.done_file,
cookies_file=args.cookies_file,
root_manga_dir=args.output_dir,
login=args.login,
password=args.password,
timeout=args.timeout,
wait=args.wait,
_max=args.max,
)
if not Path(args.cookies_file).is_file():
print(
f"Cookies file({args.cookies_file}) are not detected. Please, "
+ "login in next step for generate cookie for next runs."
)
loader.init_browser(headless=False)
else:
print(f"Using cookies file: {args.cookies_file}")
loader.init_browser(headless=True)
if args.collection_url:
loader.load_urls_from_collection(args.collection_url)
else:
loader.load_all()
if __name__ == "__main__":
main()