-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
79 lines (64 loc) · 2.1 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
"""
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 helpers.profile_crawler import process_profile_url
from helpers.file_utils import read_file, write_file
from helpers.general_utils import clear_terminal
from helpers.config import (
FILE as DEFAULT_FILE,
DUMP_FILE
)
from album_downloader import (
extract_profile_name,
validate_url,
download_album,
setup_parser,
initialize_managers
)
def process_urls(urls, profile_name):
"""
Validates and processes a list of URLs to download items.
Args:
urls (list): A list of URLs to process.
profile_name (str): The name of the profile associated with the URLs.
"""
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):
"""
Processes a profile URL and extracts the profile name.
Args:
profile_url (str): The URL of the profile to process.
Returns:
str: The extracted profile name, or None if the profile URL is not
provided.
"""
if profile_url:
process_profile_url(profile_url)
return extract_profile_name(profile_url)
return None
def main():
"""
Main entry point for the album download processing application.
"""
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()