-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
109 lines (97 loc) · 4.05 KB
/
Copy pathconfig.py
File metadata and controls
109 lines (97 loc) · 4.05 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
from dataclasses import dataclass
from dotenv import load_dotenv
load_dotenv()
@dataclass(frozen=True)
class Config:
api_id: int
api_hash: str
bot_token: str
realdebrid_key: str | None
alldebrid_key: str | None
torbox_key: str | None
premiumize_key: str | None
debridlink_key: str | None
deepbrid_key: str | None
megadebrid_key: str | None
megadebrid_login: str | None
megadebrid_password: str | None
highway_login: str | None
highway_password: str | None
allowed_users: frozenset[int]
download_dir: str
debrid_proxy: str | None
link_proxy: bool
link_proxy_port: int
link_proxy_url: str | None
host_rules: tuple[tuple[str, str], ...]
failover: bool
ytdlp: bool
ytdlp_format: str
# re-codificar vídeos yt-dlp a H.264+AAC (QuickTime / Mac); por defecto activo
ytdlp_reencode_h264: bool
dripfiles: bool
# plantilla del mensaje/descripción en DripFiles; placeholders: {filename} {host} {size}
dripfiles_message: str
def _env(name: str) -> str | None:
value = os.getenv(name, "").strip()
return value or None
def load_config() -> Config:
missing = [
name
for name in ("TELEGRAM_API_ID", "TELEGRAM_API_HASH", "TELEGRAM_BOT_TOKEN")
if not _env(name)
]
if missing:
raise SystemExit(f"Faltan variables de entorno: {', '.join(missing)} (revisa .env.example)")
raw_users = _env("ALLOWED_USER_IDS") or ""
allowed = frozenset(int(uid) for uid in raw_users.replace(" ", "").split(",") if uid)
# HOST_RULES=rapidgator:torbox, 1fichier.com:alldebrid
rules = []
for part in (_env("HOST_RULES") or "").split(","):
host, sep, slug = part.strip().lower().partition(":")
if not sep:
if part.strip():
raise SystemExit(f"HOST_RULES: entrada inválida '{part.strip()}' (formato host:servicio)")
continue
rules.append((host.strip(), slug.strip()))
proxy = _env("DEBRID_PROXY")
if proxy and not proxy.startswith(("socks5://", "socks5h://", "socks4://", "http://")):
raise SystemExit(
"DEBRID_PROXY debe empezar por socks5://, socks5h://, socks4:// o http:// "
f"(recibido: {proxy.split('://')[0]}://...)"
)
return Config(
api_id=int(_env("TELEGRAM_API_ID")),
api_hash=_env("TELEGRAM_API_HASH"),
bot_token=_env("TELEGRAM_BOT_TOKEN"),
realdebrid_key=_env("REALDEBRID_API_KEY"),
alldebrid_key=_env("ALLDEBRID_API_KEY"),
torbox_key=_env("TORBOX_API_KEY"),
premiumize_key=_env("PREMIUMIZE_API_KEY"),
debridlink_key=_env("DEBRIDLINK_API_KEY"),
deepbrid_key=_env("DEEPBRID_API_KEY"),
megadebrid_key=_env("MEGADEBRID_API_KEY"),
megadebrid_login=_env("MEGADEBRID_LOGIN"),
megadebrid_password=_env("MEGADEBRID_PASSWORD"),
highway_login=_env("HIGHWAY_LOGIN"),
highway_password=_env("HIGHWAY_PASSWORD"),
allowed_users=allowed,
download_dir=_env("DOWNLOAD_DIR") or "downloads",
debrid_proxy=proxy,
link_proxy=(_env("LINK_PROXY") or "").lower() in ("1", "true", "yes", "si", "sí"),
link_proxy_port=int(_env("LINK_PROXY_PORT") or 8845),
link_proxy_url=_env("LINK_PROXY_URL"),
host_rules=tuple(rules),
failover=(_env("FAILOVER") or "true").lower() in ("1", "true", "yes", "si", "sí"),
# Opcional: fallback con yt-dlp para YouTube, Vimeo, etc. (pip install yt-dlp)
ytdlp=(_env("YTDLP") or "").lower() in ("1", "true", "yes", "si", "sí"),
ytdlp_format=_env("YTDLP_FORMAT") or "bv*+ba/b",
# Por defecto true: tras descargar, re-codifica a H.264+AAC si hace falta (ffmpeg).
ytdlp_reencode_h264=(_env("YTDLP_REENCODE_H264") or "true").lower()
in ("1", "true", "yes", "si", "sí"),
# Subir a DripFiles (API free, sin key). Por defecto activo.
dripfiles=(_env("DRIPFILES") or "true").lower() in ("1", "true", "yes", "si", "sí"),
dripfiles_message=_env("DRIPFILES_MESSAGE")
or "{filename}\nHost: {host}",
)