Moduł konfiguracji¶
config
¶
Configuration management for Weeb CLI.
This module provides a centralized configuration system that stores settings in a SQLite database with fallback to default values. Supports both interactive and headless (API) modes.
Configuration is stored persistently in the database and can be accessed
throughout the application using the global config instance.
Example
Basic usage::
from weeb_cli.config import config
# Get configuration value
download_dir = config.get("download_dir")
aria2_enabled = config.get("aria2_enabled", True)
# Set configuration value
config.set("language", "tr")
# Enable headless mode (no database access)
config.set_headless(True)
Attributes:
| Name | Type | Description |
|---|---|---|
APP_NAME |
str
|
Application name for directory naming. |
CONFIG_DIR |
Path
|
User configuration directory (~/.weeb-cli). |
DEFAULT_CONFIG |
dict
|
Default configuration values. |
config |
Config
|
Global configuration instance. |
Config
¶
Configuration manager with database persistence.
Provides a simple key-value interface for application settings with automatic persistence to SQLite database. Supports headless mode for API usage without database access.
Attributes:
| Name | Type | Description |
|---|---|---|
_db |
Optional[Database]
|
Lazy-loaded database instance. |
_headless |
bool
|
Whether running in headless mode (no database). |
Source code in weeb_cli/config.py
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
db
property
¶
Get database instance with lazy loading.
Returns:
| Type | Description |
|---|---|
Database
|
Database instance for configuration storage. |
__init__
¶
get
¶
Get configuration value by key.
Attempts to retrieve value from database first, then falls back to provided default or DEFAULT_CONFIG. Special handling for download_dir to generate localized default path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Configuration key name. |
required |
default
|
Optional[Any]
|
Default value if key not found in database. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Configuration value, default, or None. |
Example
config.get("language", "en") "tr" config.get("aria2_max_connections") 16
Source code in weeb_cli/config.py
set
¶
Set configuration value.
Persists the value to database for future retrieval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Configuration key name. |
required |
value
|
Any
|
Value to store (must be JSON-serializable). |
required |
Example
config.set("language", "tr") config.set("aria2_max_connections", 32)
Source code in weeb_cli/config.py
set_headless
¶
Enable or disable headless mode.
In headless mode, configuration is read from DEFAULT_CONFIG only, without database access. Useful for API commands and testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headless
|
bool
|
Whether to enable headless mode. |
True
|
Source code in weeb_cli/config.py
get_default_download_dir
¶
Get the default download directory path.
Uses localized folder name from i18n translations.
Returns:
| Type | Description |
|---|---|
str
|
Absolute path to default download directory in current working directory. |
Source code in weeb_cli/config.py
Przegląd¶
Moduł konfiguracji zapewnia scentralizowane zarządzanie ustawieniami dla Weeb CLI. Cała konfiguracja jest przechowywana w bazie danych SQLite z powrotem do rozsądnych wartości domyślnych.
Przykłady użycia¶
Pobieranie wartości konfiguracji¶
from weeb_cli.config import config
# Pobierz z domyślnym powrotem
language = config.get("language", "en")
download_dir = config.get("download_dir")
aria2_enabled = config.get("aria2_enabled", True)
Ustawianie wartości konfiguracji¶
from weeb_cli.config import config
# Ustaw język
config.set("language", "tr")
# Ustaw katalog pobierania
config.set("download_dir", "/ścieżka/do/pobierania")
# Włącz/wyłącz funkcje
config.set("discord_rpc_enabled", False)
Tryb bezgłowy¶
Do użycia API bez dostępu do bazy danych:
from weeb_cli.config import config
# Włącz tryb bezgłowy
config.set_headless(True)
# Teraz config.get() zwraca tylko wartości DEFAULT_CONFIG
language = config.get("language") # Zwraca None (domyślnie)
Konfiguracja domyślna¶
Następujące wartości domyślne są używane, gdy nie istnieje wartość w bazie danych:
| Klucz | Wartość domyślna | Opis |
|---|---|---|
language |
None |
Język UI (tr, en, de, pl) |
aria2_enabled |
True |
Włącz Aria2 do pobierania |
ytdlp_enabled |
True |
Włącz yt-dlp do pobierania |
aria2_max_connections |
16 |
Maks. połączenia na pobieranie |
max_concurrent_downloads |
3 |
Maks. równoczesne pobieranie |
download_dir |
None |
Ścieżka katalogu pobierania |
ytdlp_format |
"bestvideo+bestaudio/best" |
Ciąg formatu yt-dlp |
scraping_source |
None |
Domyślny dostawca |
show_description |
True |
Pokaż opisy anime |
debug_mode |
False |
Włącz logowanie debugowania |
download_max_retries |
3 |
Próby ponowienia pobierania |
download_retry_delay |
10 |
Opóźnienie między ponownymi próbami (sekundy) |
discord_rpc_enabled |
True |
Włącz Discord Rich Presence |
shortcuts_enabled |
False |
Włącz skróty klawiszowe |
Katalog konfiguracji¶
Konfiguracja i dane są przechowywane w:
~/.weeb-cli/
├── weeb.db # Baza danych SQLite
├── cache/ # Dane w pamięci podręcznej
├── bin/ # Pobrane zależności
└── logs/ # Logi debugowania
Dokumentacja API¶
Configuration manager with database persistence.
Provides a simple key-value interface for application settings with automatic persistence to SQLite database. Supports headless mode for API usage without database access.
Attributes:
| Name | Type | Description |
|---|---|---|
_db |
Optional[Database]
|
Lazy-loaded database instance. |
_headless |
bool
|
Whether running in headless mode (no database). |
Source code in weeb_cli/config.py
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
get
¶
Get configuration value by key.
Attempts to retrieve value from database first, then falls back to provided default or DEFAULT_CONFIG. Special handling for download_dir to generate localized default path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Configuration key name. |
required |
default
|
Optional[Any]
|
Default value if key not found in database. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Configuration value, default, or None. |
Example
config.get("language", "en") "tr" config.get("aria2_max_connections") 16
Source code in weeb_cli/config.py
set
¶
Set configuration value.
Persists the value to database for future retrieval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Configuration key name. |
required |
value
|
Any
|
Value to store (must be JSON-serializable). |
required |
Example
config.set("language", "tr") config.set("aria2_max_connections", 32)
Source code in weeb_cli/config.py
set_headless
¶
Enable or disable headless mode.
In headless mode, configuration is read from DEFAULT_CONFIG only, without database access. Useful for API commands and testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headless
|
bool
|
Whether to enable headless mode. |
True
|