77from __future__ import annotations
88
99from dataclasses import dataclass
10+ from enum import IntEnum
1011from typing import TYPE_CHECKING
1112
1213if TYPE_CHECKING :
1314 from argparse import Namespace
1415
15- STATUS_PAGE = "https://status.bunkr.ru/" # The URL of the status page for checking
16- # service availability.
17- BUNKR_API = "https://bunkr.cr/api/vs" # The API for retrieving encryption data.
1816
19- DOWNLOAD_FOLDER = "Downloads" # The folder where downloaded files will be
20- # stored.
21- URLS_FILE = "URLs.txt" # The name of the file containing the list
22- # of URLs to process.
23- SESSION_LOG = "session_log.txt" # The file used to log errors.
24- MIN_DISK_SPACE_GB = 3 # Minimum free disk space (in GB) required.
25-
26- MAX_FILENAME_LEN = 120 # The maximum length for a file name.
27- MAX_WORKERS = 3 # The maximum number of threads for
28- # concurrent downloads.
29-
30- # Maps URL type identifiers to a boolean indicating whether the URL points to an album
31- # (True) or a single file (False). For example, URLs containing '/a/' are considered
32- # albums, while '/f/' or '/v/' are single files.
17+ # ============================
18+ # Paths and Files
19+ # ============================
20+ DOWNLOAD_FOLDER = "Downloads" # The folder where downloaded files will be stored.
21+ URLS_FILE = "URLs.txt" # The name of the file containing the list of URLs to
22+ # process.
23+ SESSION_LOG = "session_log.txt" # The file used to log errors.
24+ MIN_DISK_SPACE_GB = 3 # Minimum free disk space (in GB) required.
25+
26+ # ============================
27+ # API / Status Endpoints
28+ # ============================
29+ STATUS_PAGE = "https://status.bunkr.ru/" # The URL of the status page for checking
30+ # service availability.
31+ BUNKR_API = "https://bunkr.cr/api/vs" # The API for retrieving encryption data.
32+
33+ # ============================
34+ # Regex
35+ # ============================
36+ MEDIA_SLUG_REGEX = r'const\s+slug\s*=\s*"([a-zA-Z0-9_-]+)"' # Extract media slug.
37+ VALID_SLUG_REGEX = r"^[a-zA-Z0-9_-]+$" # Validate media slug.
38+
39+ # ============================
40+ # Download Settings
41+ # ============================
42+ MAX_FILENAME_LEN = 120 # The maximum length for a file name.
43+ MAX_WORKERS = 3 # The maximum number of threads for concurrent downloads.
44+
45+ # Mapping of URL identifiers to a boolean for album (True) vs single file (False).
3346URL_TYPE_MAPPING = {"a" : True , "f" : False , "v" : False }
3447
35- # Regex used to extract and validate the media slug.
36- VALID_SLUG_REGEX = r"^[a-zA-Z0-9_-]+$"
37- MEDIA_SLUG_REGEX = r'const\s+slug\s*=\s*"([a-zA-Z0-9_-]+)"'
38-
3948# Constants for file sizes, expressed in bytes.
4049KB = 1024
4150MB = 1024 * KB
4251GB = 1024 * MB
4352
4453# Thresholds for file sizes and corresponding chunk sizes used during download.
45- # Each tuple represents: (file size threshold, chunk size to download in that range).
4654THRESHOLDS = [
4755 (1 * MB , 32 * KB ), # Less than 1 MB
4856 (10 * MB , 128 * KB ), # 1 MB to 10 MB
5664# Default chunk size for files larger than the largest threshold.
5765LARGE_FILE_CHUNK_SIZE = 16 * MB
5866
59- # HTTP status codes.
60- HTTP_STATUS_OK = 200
61- HTTP_STATUS_FORBIDDEN = 403
62- HTTP_STATUS_BAD_GATEWAY = 502
63- HTTP_STATUS_SERVER_DOWN = 521
67+ # ============================
68+ # HTTP / Network
69+ # ============================
70+ class HTTPStatus (IntEnum ):
71+ """Enumeration of common HTTP status codes used in the project."""
72+
73+ OK = 200
74+ FORBIDDEN = 403
75+ INTERNAL_ERROR = 500
76+ BAD_GATEWAY = 502
77+ SERVER_DOWN = 521
78+
79+ # Mapping of HTTP error codes to human-readable fetch error messages.
80+ FETCH_ERROR_MESSAGES : dict [HTTPStatus , str ] = {
81+ HTTPStatus .FORBIDDEN : "DDoSGuard blocked the request to {url}" ,
82+ HTTPStatus .INTERNAL_ERROR : "Internal server error when fetching {url}" ,
83+ HTTPStatus .BAD_GATEWAY : "Bad gateway for {url}, probably offline" ,
84+ }
6485
6586# Headers used for general HTTP requests.
6687HEADERS = {
7697 "Referer" : "https://get.bunkrr.su/" ,
7798}
7899
100+ # ============================
101+ # Data Classes
102+ # ============================
79103@dataclass
80104class DownloadInfo :
81105 """Represent the information related to a download task."""
@@ -94,7 +118,7 @@ class SessionInfo:
94118
95119@dataclass
96120class AlbumInfo :
97- """Store the informations about an album and its associated item pages."""
121+ """Store the information about an album and its associated item pages."""
98122
99123 album_id : str
100124 item_pages : list [str ]
0 commit comments