diff --git a/.env-sample b/.env-sample index fcff639..5d7a055 100644 --- a/.env-sample +++ b/.env-sample @@ -28,6 +28,11 @@ FASTAPI_WORKERS=1 # DO NOT change this if you don't know what you are doing. Set 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) +# ============================== # +# Playback Settings # +# ============================== # +PUBLIC_BASE_URL= # Optional: force playback URLs to use this public base (e.g. https://comet.example.com). Leave empty to use the request host. + # ============================== # # Dashboard Settings # # ============================== # diff --git a/comet/api/endpoints/stream.py b/comet/api/endpoints/stream.py index 64ae1f4..95cd5a1 100644 --- a/comet/api/endpoints/stream.py +++ b/comet/api/endpoints/stream.py @@ -509,6 +509,11 @@ async def stream( result_episode = episode if episode is not None else "n" torrents = torrent_manager.torrents + base_playback_host = ( + settings.PUBLIC_BASE_URL + if settings.PUBLIC_BASE_URL + else f"{request.url.scheme}://{request.url.netloc}" + ) for info_hash in torrent_manager.ranked_torrents: torrent = torrents[info_hash] rtn_data = torrent["parsed"] @@ -556,7 +561,7 @@ async def stream( the_stream["sources"] = torrent["sources"] else: the_stream["url"] = ( - f"{request.url.scheme}://{request.url.netloc}/{b64config}/playback/{info_hash}/{torrent['fileIndex'] if torrent['cached'] and torrent['fileIndex'] is not None else 'n'}/{result_season}/{result_episode}/{quote(torrent_title)}?name={quote(title)}" + f"{base_playback_host}/{b64config}/playback/{info_hash}/{torrent['fileIndex'] if torrent['cached'] and torrent['fileIndex'] is not None else 'n'}/{result_season}/{result_episode}/{quote(torrent_title)}?name={quote(title)}" ) if sort_mixed: diff --git a/comet/core/models.py b/comet/core/models.py index 58a8709..70492a3 100644 --- a/comet/core/models.py +++ b/comet/core/models.py @@ -116,6 +116,7 @@ class AppSettings(BaseSettings): "Direct torrent playback is disabled on this server." ) TORRENT_DISABLED_STREAM_URL: Optional[str] = "https://comet.fast" + PUBLIC_BASE_URL: Optional[str] = None REMOVE_ADULT_CONTENT: Optional[bool] = False BACKGROUND_SCRAPER_ENABLED: Optional[bool] = False BACKGROUND_SCRAPER_CONCURRENT_WORKERS: Optional[int] = 1 @@ -176,6 +177,7 @@ class AppSettings(BaseSettings): "JACKETTIO_URL", "JACKETT_URL", "PROWLARR_URL", + "PUBLIC_BASE_URL", ) def normalize_urls(cls, v): if isinstance(v, str):