-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (49 loc) · 1.9 KB
/
main.py
File metadata and controls
68 lines (49 loc) · 1.9 KB
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
"""Main module of the project.
This module provides functionality for reading URLs from a file, processing
them to download anime content, and clearing the file after the process is
complete.
Usage:
Ensure that a file named 'URLs.txt' is present in the same directory as
this script. The file should contain a list of URLs, one per line. When
executed, the script will:
1. Read the URLs from 'URLs.txt'.
2. Process each URL for downloading anime content.
3. Clear the contents of 'URLs.txt' after all URLs have been processed.
"""
from __future__ import annotations
import sys
from pathlib import Path
from typing import TYPE_CHECKING
from downloader import handle_download_process
from src.config import SESSION_LOG, URLS_FILE, parse_arguments
from src.file_utils import read_file, write_file
from src.general_utils import clear_terminal
from src.managers.live_manager import initialize_managers
if TYPE_CHECKING:
from argparse import Namespace
URLS_FILE_PATH = Path.cwd() / URLS_FILE
SESSION_FILE_PATH = Path.cwd() / SESSION_LOG
def process_urls(urls: list[str], args: Namespace | None = None) -> None:
"""Validate and downloads items for a list of URLs."""
live_manager = initialize_managers()
try:
with live_manager.live:
for url in urls:
handle_download_process(url, live_manager, args=args)
live_manager.stop()
except KeyboardInterrupt:
sys.exit(1)
def main() -> None:
"""Run the script."""
# Clear the terminal and session log file
clear_terminal()
write_file(SESSION_FILE_PATH)
# Parse arguments
args = parse_arguments(common_only=True)
# Read and process URLs, ignoring empty lines
urls = [url.strip() for url in read_file(URLS_FILE_PATH) if url.strip()]
process_urls(urls, args)
# Clear URLs file
write_file(URLS_FILE_PATH)
if __name__ == "__main__":
main()