#=================================================#
#   ██████╗ ██████╗ ███╗   ███╗███████╗████████╗  #
#  ██╔════╝██╔═══██╗████╗ ████║██╔════╝╚══██╔══╝  #
#  ██║     ██║   ██║██╔████╔██║█████╗     ██║     #
#  ██║     ██║   ██║██║╚██╔╝██║██╔══╝     ██║     #
#  ╚██████╗╚██████╔╝██║ ╚═╝ ██║███████╗   ██║     #
#   ╚═════╝ ╚═════╝ ╚═╝     ╚═╝╚══════╝   ╚═╝     #
#          Thank you for using Comet! 🚀          #
#=================================================#

# ============================== #
# Stremio Addon Configuration    #
# ============================== #
ADDON_ID=stremio.comet.fast
ADDON_NAME=Comet

# ============================== #
# FastAPI Server Configuration   #
# ============================== #
FASTAPI_HOST=0.0.0.0
FASTAPI_PORT=8000
FASTAPI_WORKERS=1 # set to -1 for auto-scaling (min((os.cpu_count() or 1) * 2 + 1, 12))
USE_GUNICORN=True # Will use uvicorn if False or if on Windows
GUNICORN_PRELOAD_APP=True # Set to False to start workers without preloading the app (reduces startup cost but requires schema to exist)

# ============================== #
# Dashboard Settings             #
# ============================== #
ADMIN_DASHBOARD_PASSWORD=CHANGE_ME # The password to access the dashboard
PUBLIC_METRICS_API=False # Set to True to allow public access to the metrics API (/admin/api/metrics)

# ============================== #
# Database Configuration         #
# ============================== #
# ⚠️  WARNING: SQLite has POOR CONCURRENCY support and should ONLY be used for development/testing!
# SQLite cannot handle multiple concurrent writers well, leading to:
#   - "database is locked" errors with multiple workers
#   - Performance issues with background scraper
#   - Data corruption risks under heavy load
# For production deployments, use PostgreSQL!
DATABASE_TYPE=postgresql # Options: sqlite, postgresql - Use postgresql for production, sqlite for development only
DATABASE_URL=comet:comet@postgres:5432/comet # For PostgreSQL (user:password@host:port/database)
DATABASE_PATH=data/comet.db # Only relevant for SQLite (development only)
DATABASE_BATCH_SIZE=20000 # The batch size for the database import and export operations
DATABASE_READ_REPLICA_URLS='' # Optional JSON array of PostgreSQL read-only URLs, e.g. '["user:pass@replica-1/db", "user:pass@replica-2/db"]'
DATABASE_STARTUP_CLEANUP_INTERVAL=3600 # Minimum seconds between heavy startup cleanup sweeps (0=every start, -1=disable)

# ============================== #
# Cache Settings (Seconds)       #
# ============================== #
METADATA_CACHE_TTL=2592000  # 30 days
TORRENT_CACHE_TTL=1296000  # 15 days - How long before torrents in DB start to be removed. -1 to disable.
LIVE_TORRENT_CACHE_TTL=1296000  # 15 days - How long before Live is re-queried for a search.
DEBRID_CACHE_TTL=86400  # 1 day
DEBRID_CACHE_CHECK_RATIO=0.05  # Minimum ratio (0.05 = 5%) of cached torrents/total torrents required to skip re-checking availability on the debrid service.
METRICS_CACHE_TTL=60  # 1 minute
SCRAPE_LOCK_TTL=300  # 5 minutes - Duration for distributed scraping locks
SCRAPE_WAIT_TIMEOUT=30  # 30 seconds - Max time to wait for other instance to complete scraping

# ======================================================= #
# Background Scraper                                      #
# Zilean and no-ratelimit indexers/scrapers recommended!  #
# PostgreSQL recommended for high worker count!           #
# ======================================================= #
BACKGROUND_SCRAPER_ENABLED=False
BACKGROUND_SCRAPER_CONCURRENT_WORKERS=1 # Number of concurrent workers for scraping (adjust depending on whether you are often ratelimited by scrapers)
BACKGROUND_SCRAPER_INTERVAL=3600 # Interval between scraping cycles in seconds
BACKGROUND_SCRAPER_MAX_MOVIES_PER_RUN=100 # Maximum number of movies to scrape per run
BACKGROUND_SCRAPER_MAX_SERIES_PER_RUN=100 # Maximum number of series to scrape per run
CATALOG_TIMEOUT=30 # Max time to fetch catalog pages (seconds)

# ============================== #
# Anime Mapping Configuration    #
# ============================== #
ANIME_MAPPING_SOURCE=remote # Options: remote, database - remote downloads on startup; database reads cached table
ANIME_MAPPING_REFRESH_INTERVAL=86400 # Seconds between background anime mapping refreshes when using database cache (<=0 disables)

# ============================== #
# Proxy Configuration            #
# ============================== #
BYPASS_PROXY_URL=http://warp:1080 # To bypass scraper IP blacklists

# ============================== #
# Jackett & Prowlarr Settings    #
# ============================== #

# Jackett Configuration
SCRAPE_JACKETT=False # Context mode: live, background, both, false
JACKETT_URL=http://127.0.0.1:9117
JACKETT_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
JACKETT_INDEXERS=[] # Leave empty to automatically use all configured/healthy indexers. Or specify a list of indexer IDs to use (e.g. '["oxtorrent", "torrent9"]').

# Prowlarr Configuration
SCRAPE_PROWLARR=False # Context mode: live, background, both, false
PROWLARR_URL=http://127.0.0.1:9696
PROWLARR_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
PROWLARR_INDEXERS=[] # Leave empty to automatically use all configured/healthy indexers. Or specify a list of indexer IDs.

# Shared Settings
INDEXER_MANAGER_TIMEOUT=30  # Max time to get search results (seconds) - Shared by both
INDEXER_MANAGER_WAIT_TIMEOUT=30 # Max time to wait for the indexer manager to initialize (seconds)
INDEXER_MANAGER_UPDATE_INTERVAL=900 # Time in seconds between indexer updates (default: 900s / 15m)

# ============================== #
# Torrent Settings               #
# ============================== #
GET_TORRENT_TIMEOUT=5 # Max time to download .torrent file (seconds)
DOWNLOAD_TORRENT_FILES=False # Enable torrent file retrieval from magnet link
MAGNET_RESOLVE_TIMEOUT=60 # Max time to resolve a magnet link (seconds)

# ============================== #
# Scraping Configuration         #
# ============================== #
# Multi-Instance Scraping Support:
# - Single URL: Use a simple string for one instance (default behavior)
# - Multiple URLs: Use JSON array format for multiple instances
# - Example single: COMET_URL=https://comet.elfhosted.com
# - Example multi: COMET_URL='["https://comet1.example.com", "https://comet2.example.com"]'
#
# Scraper Context Modes:
# Each SCRAPE_* setting can control when scrapers are used:
# - true/both: Used for live scraping AND background scraping (default)
# - live: Only used for live scraping (when users request content)
# - background: Only used for background scraping (automatic content pre-caching)
# - false: Completely disabled
#
# Examples:
# SCRAPE_COMET=both          # Used for both live and background scraping
# SCRAPE_TORRENTIO=live      # Fast live scraping only
# SCRAPE_ZILEAN=background   # Background cache building only
# SCRAPE_NYAA=false          # Completely disabled
# SCRAPE_JACKETT=live        # Jackett for live scraping only
# SCRAPE_PROWLARR=background # Prowlarr for background scraping only

SCRAPE_COMET=False
COMET_URL=https://comet.elfhosted.com
# Multi-instance example:
# COMET_URL='["https://comet1.example.com", "https://comet2.example.com"]'

SCRAPE_NYAA=False
NYAA_ANIME_ONLY=True # Only scrape Nyaa if the content is anime
NYAA_MAX_CONCURRENT_PAGES=5 # Maximum number of concurrent requests to Nyaa (consider reducing if you are often ratelimited by Nyaa)

SCRAPE_ZILEAN=False
ZILEAN_URL=https://zileanfortheweebs.midnightignite.me
# Multi-instance example:
# ZILEAN_URL='["https://zilean1.example.com", "https://zilean2.example.com"]'

SCRAPE_STREMTHRU=False
STREMTHRU_SCRAPE_URL=https://stremthru.13377001.xyz
# Multi-instance example:
# STREMTHRU_SCRAPE_URL='["https://stremthru1.example.com", "https://stremthru2.example.com"]'

SCRAPE_BITMAGNET=False
BITMAGNET_URL=https://bitmagnetfortheweebs.midnightignite.me
BITMAGNET_MAX_CONCURRENT_PAGES=5
BITMAGNET_MAX_OFFSET=15000 # Maximum number of entries to scrape
# Multi-instance example:
# BITMAGNET_URL='["https://bitmagnet1.example.com", "https://bitmagnet2.example.com"]'

SCRAPE_TORRENTIO=False
TORRENTIO_URL=https://torrentio.strem.fun
# Multi-instance example:
# TORRENTIO_URL='["https://torrentio.strem.fun", "https://custom-torrentio.example.com"]'

SCRAPE_MEDIAFUSION=False
MEDIAFUSION_URL=https://mediafusion.elfhosted.com
MEDIAFUSION_API_PASSWORD= # API password for MediaFusion instances that require authentication
MEDIAFUSION_LIVE_SEARCH=True
# Multi-instance MediaFusion examples:
# MEDIAFUSION_URL='["https://mediafusion1.example.com", "https://mediafusion2.example.com"]'
# MEDIAFUSION_API_PASSWORD='["password1", "password2"]' # One password per URL in same order
# MEDIAFUSION_API_PASSWORD=single_password # Same password for all instances
# MEDIAFUSION_API_PASSWORD= # No password for any instance

SCRAPE_AIOSTREAMS=False
AIOSTREAMS_URL=https://aio.example.com
AIOSTREAMS_USER_UUID_AND_PASSWORD=user_uuid:password
# Multi-instance AIOStreams examples:
# AIOSTREAMS_URL='["https://aio1.example.com", "https://aio2.example.com"]'
# AIOSTREAMS_USER_UUID_AND_PASSWORD='["uuid1:password1", "uuid2:password2"]' # One credential per URL in same order
# AIOSTREAMS_USER_UUID_AND_PASSWORD=single_uuid:single_password # Same credentials for all instances

SCRAPE_JACKETTIO=False
JACKETTIO_URL=https://jackettio.example.com # Full manifest URL without /manifest.json at the end
# Multi-instance example:
# JACKETTIO_URL='["https://jackettio1.example.com", "https://jackettio2.example.com"]'

SCRAPE_DEBRIDIO=False
DEBRIDIO_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
DEBRIDIO_PROVIDER=realdebrid # alldebrid, debrider, debridlink, easydebrid, premiumize, realdebrid, torbox
DEBRIDIO_PROVIDER_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

SCRAPE_TORBOX=False
TORBOX_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

SCRAPE_YGGTORRENT=False
YGGTORRENT_USERNAME=username
YGGTORRENT_PASSWORD=password
YGGTORRENT_PASSKEY=passkey
YGGTORRENT_MAX_CONCURRENT_PAGES=5

# ============================== #
# Debrid Stream Proxy Settings   #
# ============================== #
PROXY_DEBRID_STREAM=False
PROXY_DEBRID_STREAM_PASSWORD=CHANGE_ME
PROXY_DEBRID_STREAM_MAX_CONNECTIONS=-1 # -1 to disable connection limits
PROXY_DEBRID_STREAM_DEBRID_DEFAULT_SERVICE=realdebrid
PROXY_DEBRID_STREAM_DEBRID_DEFAULT_APIKEY=CHANGE_ME

# ============================== #
# Torrent Stream Policy          #
# ============================== #
DISABLE_TORRENT_STREAMS=False # When true, torrent-only requests return a friendly message instead of magnets
TORRENT_DISABLED_STREAM_NAME=[INFO] Comet # Stremio stream name shown when torrents are disabled
TORRENT_DISABLED_STREAM_DESCRIPTION=Direct torrent playback is disabled on this server. Please configure a debrid provider. # Description shown to users in Stremio
TORRENT_DISABLED_STREAM_URL=https://comet.fast # Optional URL included in the placeholder stream response

# ============================== #
# Content Filtering              #
# ============================== #
REMOVE_ADULT_CONTENT=False
DIGITAL_RELEASE_FILTER=False # Filter unreleased content
TMDB_READ_ACCESS_TOKEN= # Optional: Provide your own TMDB Read Access Token to avoid using the shared default key

# ============================== #
# UI Customization               #
# ============================== #
CUSTOM_HEADER_HTML=None

# ============================== #
# StremThru Integration          #
# ============================== #
STREMTHRU_URL=https://stremthru.13377001.xyz # needed to use debrid services
