d
This commit is contained in:
@@ -182,6 +182,20 @@ class Soulseek(SearchProvider):
|
||||
DOWNLOAD_DIR = "./downloads"
|
||||
MAX_WAIT_TRANSFER = 1200
|
||||
|
||||
def __init__(self, config: Optional[Dict[str, Any]] = None):
|
||||
super().__init__(config)
|
||||
try:
|
||||
from config import get_soulseek_username, get_soulseek_password
|
||||
|
||||
user = get_soulseek_username(self.config)
|
||||
pwd = get_soulseek_password(self.config)
|
||||
if user:
|
||||
Soulseek.USERNAME = user
|
||||
if pwd:
|
||||
Soulseek.PASSWORD = pwd
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def download(self, result: SearchResult, output_dir: Path) -> Optional[Path]:
|
||||
"""Download file from Soulseek."""
|
||||
|
||||
@@ -433,8 +447,16 @@ class Soulseek(SearchProvider):
|
||||
def validate(self) -> bool:
|
||||
try:
|
||||
from aioslsk.client import SoulSeekClient # noqa: F401
|
||||
# Require configured credentials.
|
||||
try:
|
||||
from config import get_soulseek_username, get_soulseek_password
|
||||
|
||||
return True
|
||||
user = get_soulseek_username(self.config)
|
||||
pwd = get_soulseek_password(self.config)
|
||||
return bool(user and pwd)
|
||||
except Exception:
|
||||
# Fall back to legacy class defaults if config helpers aren't available.
|
||||
return bool(Soulseek.USERNAME and Soulseek.PASSWORD)
|
||||
except ImportError:
|
||||
return False
|
||||
|
||||
@@ -444,6 +466,9 @@ async def download_soulseek_file(
|
||||
filename: str,
|
||||
output_dir: Path = Path("./downloads"),
|
||||
timeout: int = 1200,
|
||||
*,
|
||||
client_username: Optional[str] = None,
|
||||
client_password: Optional[str] = None,
|
||||
) -> Optional[Path]:
|
||||
"""Download a file from a Soulseek peer."""
|
||||
|
||||
@@ -471,14 +496,19 @@ async def download_soulseek_file(
|
||||
|
||||
output_path = output_path.resolve()
|
||||
|
||||
settings = Settings(credentials=CredentialsSettings(username=Soulseek.USERNAME, password=Soulseek.PASSWORD))
|
||||
login_user = (client_username or Soulseek.USERNAME or "").strip()
|
||||
login_pass = (client_password or Soulseek.PASSWORD or "").strip()
|
||||
if not login_user or not login_pass:
|
||||
raise RuntimeError("Soulseek credentials not configured (set provider=soulseek username/password)")
|
||||
|
||||
settings = Settings(credentials=CredentialsSettings(username=login_user, password=login_pass))
|
||||
client = SoulSeekClient(settings)
|
||||
|
||||
with _suppress_aioslsk_noise():
|
||||
try:
|
||||
await client.start()
|
||||
await client.login()
|
||||
debug(f"[soulseek] Logged in as {Soulseek.USERNAME}")
|
||||
debug(f"[soulseek] Logged in as {login_user}")
|
||||
|
||||
debug(f"[soulseek] Requesting download from {username}: {filename}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user