-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
46 lines (35 loc) · 1.28 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
import os
from dotenv import load_dotenv
from pydantic import BaseModel, Field
from audiobookmarks.utils import generate_arg_parser
load_dotenv(override=True)
from audiobookmarks.main_hoopla import main as hoopla_main
from audiobookmarks.main_libby import main as libby_main
# If running in debug mode, first run the following command in the terminal:
# google-chrome --remote-debugging-port=9222
class Args(BaseModel):
'''
Args for the main audiobookmarks function.
'''
platform: str = Field(..., description="The platform hosting the book and bookmarks.")
book: str = Field(..., description="The name of the audiobook.")
debug: bool = Field(False, description="Run browser in debug mode (not headless).")
class Config:
description = "Get bookmarks for an audiobook"
def main(args: Args):
'''
Get bookmarks for an audiobook.
'''
if args.debug:
os.environ["DEBUG_MODE"] = "true"
else:
os.environ["DEBUG_MODE"] = "false"
if args.platform == "libby":
libby_main(args.book, args.debug)
elif args.platform == "hoopla":
hoopla_main(args.book, args.debug)
if __name__ == "__main__":
parser = generate_arg_parser(Args)
args = parser.parse_args()
args_obj = Args(**vars(args))
main(args_obj)