-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
71 lines (53 loc) · 1.86 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
"""Main module of the project.
This module facilitates the downloading of albums by processing profile URLs
and validating album URLs. It provides functionalities for reading and writing
URL lists, handling command-line arguments, and organizing the download
workflow.
Usage:
To run the application, execute the module from the command line, providing
optional arguments for profile or album URLs.
"""
from __future__ import annotations
from album_downloader import (
download_album,
extract_profile_name,
initialize_managers,
setup_parser,
validate_url,
)
from helpers.config import (
DUMP_FILE,
)
from helpers.config import (
FILE as DEFAULT_FILE,
)
from helpers.file_utils import read_file, write_file
from helpers.general_utils import clear_terminal
from helpers.profile_crawler import process_profile_url
def process_urls(urls: list[str], profile_name: str) -> None:
"""Validate and processes a list of URLs to download items."""
live_manager = initialize_managers()
with live_manager.live:
for url in urls:
validated_url = validate_url(url)
download_album(validated_url, live_manager, profile=profile_name)
live_manager.stop()
def handle_profile_processing(profile_url: str) -> str | None:
"""Process a profile URL and extracts the profile name."""
if profile_url:
process_profile_url(profile_url)
return extract_profile_name(profile_url)
return None
def main() -> None:
"""Run the script."""
clear_terminal()
write_file(DUMP_FILE)
parser = setup_parser()
args = parser.parse_args()
file_to_read = DUMP_FILE if args.profile else DEFAULT_FILE
profile_name = handle_profile_processing(args.profile)
urls = read_file(file_to_read)
process_urls(urls, profile_name)
write_file(DEFAULT_FILE)
if __name__ == "__main__":
main()