diff --git a/backend/src/config/__init__.py b/backend/src/config/__init__.py index 6adda15..c4f0716 100644 --- a/backend/src/config/__init__.py +++ b/backend/src/config/__init__.py @@ -1,5 +1,4 @@ import os -from typing import Literal from pydantic import BaseModel @@ -16,16 +15,8 @@ class ProwlarrConfig(BaseModel): -class QbittorrentConfig(BaseModel): - host: str = os.getenv("QBITTORRENT_HOST") or "localhost" - port: int = os.getenv("QBITTORRENT_PORT") or 8080 - username: str = os.getenv("QBITTORRENT_USERNAME") or "admin" - password: str = os.getenv("QBITTORRENT_PASSWORD") or "adminadmin" -class DownloadClientConfig(BaseModel): - client: Literal['qbit'] = os.getenv("DOWNLOAD_CLIENT") or "qbit" - class MachineLearningConfig(BaseModel): model_name: str = os.getenv("OLLAMA_MODEL_NAME") or "qwen2.5:0.5b" \ No newline at end of file diff --git a/backend/src/dowloadClients/__init__.py b/backend/src/dowloadClients/__init__.py index e31891a..3220a4f 100644 --- a/backend/src/dowloadClients/__init__.py +++ b/backend/src/dowloadClients/__init__.py @@ -1,10 +1,10 @@ -from config import DownloadClientConfig +from dowloadClients.config import DownloadClientConfig from dowloadClients.qbittorrent import QbittorrentClient config = DownloadClientConfig() # TODO: add more elif when implementing more download clients -if config.client == "qbit": +if config.download_client == "qbit": client = QbittorrentClient() else: - client = QbittorrentClient() + raise ValueError("Unknown download client") diff --git a/backend/src/dowloadClients/config.py b/backend/src/dowloadClients/config.py new file mode 100644 index 0000000..b3f3a51 --- /dev/null +++ b/backend/src/dowloadClients/config.py @@ -0,0 +1,5 @@ +from pydantic_settings import BaseSettings + + +class DownloadClientConfig(BaseSettings): + download_client: str = "qbit" diff --git a/backend/src/dowloadClients/qbittorrent.py b/backend/src/dowloadClients/qbittorrent.py index e730264..5ad90ee 100644 --- a/backend/src/dowloadClients/qbittorrent.py +++ b/backend/src/dowloadClients/qbittorrent.py @@ -1,13 +1,21 @@ import logging import qbittorrentapi +from pydantic_settings import BaseSettings, SettingsConfigDict -from config import QbittorrentConfig from database.torrents import Torrent from dowloadClients.genericDownloadClient import GenericDownloadClient log = logging.getLogger(__name__) + +class QbittorrentConfig(BaseSettings): + model_config = SettingsConfigDict(env_prefix='QBITTORRENT_') + host: str = "localhost" + port: int = 8080 + username: str = "admin" + + class QbittorrentClient(GenericDownloadClient): DOWNLOADING_STATE = ("allocating", "downloading", "metaDL", "pausedDL", "queuedDL", "stalledDL", "checkingDL", "forcedDL", "moving")