config.py•1.76 kB
"""
Configuration and constants for the MCP server.
"""
import logging
import os
from dotenv import load_dotenv
# Determine the directory where this script is located
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
# File paths
LOG_FILE_PATH = os.path.join(SCRIPT_DIR, "main.log")
ERROR_LOG_FILE_PATH = os.path.join(SCRIPT_DIR, "error.log")
PERSISTENT_INFO_PATH = os.path.join(SCRIPT_DIR, "persistent_info.json")
SCHEDULED_JOBS_PATH = os.path.join(SCRIPT_DIR, "scheduled_jobs.json")
JOB_EXECUTION_LOG_PATH = os.path.join(SCRIPT_DIR, "job_execution_log.json")
DOWNLOADS_BASE_PATH = os.path.join(SCRIPT_DIR, "downloads")
# Path to ffmpeg/ffprobe binaries for yt-dlp postprocessing.
# Make sure this points to the 'bin' directory containing ffmpeg.exe and ffprobe.exe.
FFMPEG_LOCATION = r"C:\Program Files\ffmpeg-master-latest-win64-gpl-shared\bin"
# Environment variables
dotenv_path = os.path.join(SCRIPT_DIR, ".env")
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)
TG_TOKEN = os.environ.get("TG_TOKEN")
ADMIN_ID = os.environ.get("ADMIN_ID")
# Logging configuration
def setup_logging():
"""Configure logging for the application."""
# Use only file logging to avoid conflicts with MCP stdio transport
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[logging.FileHandler(LOG_FILE_PATH, encoding="utf-8")],
)
# Set up a separate error log file for errors and above
error_handler = logging.FileHandler(ERROR_LOG_FILE_PATH, encoding="utf-8")
error_handler.setLevel(logging.ERROR)
error_handler.setFormatter(
logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
)
logging.getLogger().addHandler(error_handler)