-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
44 lines (33 loc) · 1.62 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
import argparse
import logging
from pathlib import Path
from batodl import BatotoDownloader
def main():
'''Main function.'''
cwd: Path = Path.cwd()
dl_dir = Path.cwd() / "Manga"
dl_dir.mkdir(exist_ok=True)
log_path = cwd / "batodl.log"
main_logger: logging.Logger = logging.getLogger(__name__)
logging.basicConfig(filename=log_path.name,
level=logging.INFO,
format="%(asctime)s|%(levelname)8s|%(name)s|%(message)s")
try:
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--series", type=str, help="Bato.to Series URL. Downloads entire series.", required=False)
parser.add_argument("-c", "--chapter", type=str, help="Bato.to Chapter URL. Downloads only specified chapter.", required=False)
parser.add_argument("-d", "--daiz", action="store_true", help="Enforce daiz naming scheme.", required=False)
parser.add_argument("-e", "--extension", type=str, help="Image type extension. If not specified, the original will be used", required=False)
args = parser.parse_args()
manga_downloader = BatotoDownloader(dl_dir, args.daiz, args.extension)
if args.series is not None:
manga_downloader.download(series_url=args.series)
elif args.chapter is not None:
manga_downloader.download(chapter_url=args.chapter)
else:
print("Please provide at least one argument. Run `python main.py -h` if you need help.`")
except Exception as e:
main_logger.exception(e)
print("Error, please check the log.")
if __name__ == "__main__":
main()