Extract local_url to own function
MODIFY
plextraktsync/commands/plex_login.py
plextraktsync/commands/plex_login.py
-import socket
from datetime import datetime, timedelta
from functools import partial
from os import environ
-from subprocess import check_output
from typing import List
import click
from plextraktsync.factory import factory
from plextraktsync.style import (comment, disabled, error, highlight, prompt,
success, title)
+from plextraktsync.util.local_url import local_url
PROMPT_PLEX_PASSWORD = prompt("Please enter your Plex password")
PROMPT_PLEX_USERNAME = prompt("Please enter your Plex username or e-mail")
@@ -215,23 +214,7 @@ def login(username: str, password: str):
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 Exception:
- host_ip = "172.17.0.1"
- CONFIG["PLEX_LOCALURL"] = f"http://{host_ip}:32400"
- else:
- CONFIG["PLEX_LOCALURL"] = "http://localhost:32400"
+ CONFIG["PLEX_LOCALURL"] = local_url()
CONFIG.save()
click.echo(SUCCESS_MESSAGE)

ADD
plextraktsync/util/local_url.py
+def local_url():
+ """
+ Find url for local plex access.
+ """
+
+ from os import environ
+
+ if not environ.get("PTS_IN_DOCKER"):
+ return "http://localhost:32400"
+
+ import socket
+ try:
+ host_ip = socket.gethostbyname("host.docker.internal")
+ except socket.gaierror:
+ try:
+ from subprocess import check_output
+ host_ip = check_output(
+ "ip -4 route show default | awk '{ print $3 }'", shell=True
+ ).decode().rstrip()
+ except Exception:
+ host_ip = "172.17.0.1"
+
+ return f"http://{host_ip}:32400"

Extract local_url to own function