@@ -39,14 +39,12 @@ def load_media_dir() -> Path:
3939LOG_FILE = BASE_DIR / "logs" / "download-watchdog.log"
4040RADARR_CFG = BASE_DIR / "config" / "radarr" / "config.xml"
4141SONARR_CFG = BASE_DIR / "config" / "sonarr" / "config.xml"
42+ CREDENTIALS_FILE = BASE_DIR / "state" / "first-run-credentials.txt"
4243
4344RADARR_URL = os .getenv ("RADARR_URL" , "http://localhost:7878" )
4445SONARR_URL = os .getenv ("SONARR_URL" , "http://localhost:8989" )
4546QBIT_URL = os .getenv ("QBIT_URL" , "http://localhost:8080" )
4647
47- QBIT_USERNAME = os .getenv ("QBIT_USERNAME" , "admin" )
48- QBIT_PASSWORD = os .getenv ("QBIT_PASSWORD" , "" )
49-
5048STALL_SECONDS = int (os .getenv ("WATCHDOG_STALL_SECONDS" , "1800" ))
5149SLOW_SECONDS = int (os .getenv ("WATCHDOG_SLOW_SECONDS" , "1200" ))
5250MIN_SPEED_BPS = int (os .getenv ("WATCHDOG_MIN_SPEED_BPS" , str (300 * 1024 )))
@@ -77,6 +75,26 @@ def parse_api_key_xml(path):
7775 return text [start + 8 : end ].strip ()
7876
7977
78+ def load_qbit_credentials ():
79+ username = os .getenv ("QBIT_USERNAME" , "" ).strip ()
80+ password = os .getenv ("QBIT_PASSWORD" , "" ).strip ()
81+
82+ if username and password :
83+ return username , password
84+
85+ if CREDENTIALS_FILE .exists ():
86+ try :
87+ for line in CREDENTIALS_FILE .read_text (errors = "ignore" ).splitlines ():
88+ if line .startswith ("qBittorrent Username:" ) and not username :
89+ username = line .split (":" , 1 )[1 ].strip ()
90+ elif line .startswith ("qBittorrent Password:" ) and not password :
91+ password = line .split (":" , 1 )[1 ].strip ()
92+ except Exception :
93+ pass
94+
95+ return (username or "admin" ), password
96+
97+
8098def http_json (url , headers = None , timeout = 30 ):
8199 req = urllib .request .Request (url , headers = headers or {})
82100 with urllib .request .urlopen (req , timeout = timeout ) as resp :
@@ -168,8 +186,14 @@ def main():
168186 log ("[ERROR] No API keys found" )
169187 return 1
170188
189+ qbit_username , qbit_password = load_qbit_credentials ()
190+ globals ()["QBIT_USERNAME" ] = qbit_username
191+ globals ()["QBIT_PASSWORD" ] = qbit_password
192+
171193 if not QBIT_PASSWORD :
172- log ("[ERROR] QBIT_PASSWORD is not set. Check your environment or credentials file." )
194+ log (
195+ f"[ERROR] QBIT_PASSWORD is not set and no credentials found in { CREDENTIALS_FILE } "
196+ )
173197 return 1
174198
175199 try :
0 commit comments