Change Plex fallback url if run in docker
MODIFY
Dockerfile
Dockerfile
@@ -11,7 +11,8 @@ RUN pipenv install --system --deploy
ENV \
PTS_CONFIG_DIR=/app/config \
PTS_CACHE_DIR=/app/config \
- PTS_LOG_DIR=/app/config
+ PTS_LOG_DIR=/app/config \
+ PTS_IN_DOCKER=1
VOLUME /app/config

MODIFY
plex_trakt_sync/commands/plex_login.py
plex_trakt_sync/commands/plex_login.py
from functools import partial
from os import environ
from typing import List
+from subprocess import check_output
+import socket
import click
from click import Choice
@@ -171,6 +173,16 @@ def plex_login(username, password):
CONFIG["PLEX_USERNAME"] = user
CONFIG["PLEX_TOKEN"] = token
CONFIG["PLEX_BASEURL"] = plex._baseurl
+ if environ.get("PTS_IN_DOCKER"):
+ try:
+ host_ip = socket.gethostbyname("host.docker.internal")
+ except socket.gaierror:
+ try:
+ host_ip = check_output("ip -4 route show default | awk '{ print $3 }'", shell=True).decode().rstrip()
+ except:
+ host_ip = "172.17.0.1"
+ CONFIG["PLEX_FALLBACKURL"] = f"http://{host_ip}:32400"
+ else:
CONFIG["PLEX_FALLBACKURL"] = "http://localhost:32400"
CONFIG.save()

Change Plex fallback url if run in docker