-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
61 lines (49 loc) · 1.94 KB
/
config.py
File metadata and controls
61 lines (49 loc) · 1.94 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
import os
import tempfile
from typing import Optional, List
from pydantic import field_validator
try:
from pydantic_settings import BaseSettings
except ImportError:
try:
from pydantic import BaseSettings
except ImportError:
raise ImportError("Please install pydantic-settings package: pip install pydantic-settings")
class Settings(BaseSettings):
# Server settings
HOST: Optional[str] = "0.0.0.0"
PORT: int = 8000
# Cache settings
CACHE_DIR: str = os.path.join(tempfile.gettempdir(), "youtube_api_cache")
CACHE_LIMIT_GB: float = 1.0 # Maximum cache size in GB
CACHE_EXPIRY_DAYS: int = 7 # Number of days after which cache files expire
AUTO_CLEAN_CACHE: bool = True # Automatically clean expired cache files on startup
# Download settings
DEFAULT_QUALITY: str = "720p"
MAX_SEARCH_RESULTS: int = 50
# API settings
ENABLE_CORS: bool = True
CORS_ORIGINS: List[str] = ["*"]
# FFMPEG settings
FFMPEG_PATH: Optional[str] = None
# Rate limiting
ENABLE_RATE_LIMIT: bool = True
RATE_LIMIT_REQUESTS: int = 60 # Max requests per minute
RATE_LIMIT_WINDOW: int = 60 # Window size in seconds
# Security settings
ADMIN_API_KEY: str = "1234" # Key for admin operations like cache management
# Multi-server settings
MULTI_SERVER_ENABLED: bool = False # Enable multi-server mode
MULTI_SERVER_MAIN: bool = False # Is this the main server (load balancer)
MULTI_SERVER_URLS: List[str] = [] # List of worker server URLs (only used when MULTI_SERVER_MAIN is True)
@field_validator('HOST', mode='before')
@classmethod
def convert_none_string(cls, v):
"""Convert 'none' string to None for HOST"""
if isinstance(v, str) and v.lower() == 'none':
return None
return v
class Config:
env_file = ".env"
env_prefix = "YT_API_"
settings = Settings()