Add save_new_url trickery
MODIFY
plextraktsync/plex_server.py
plextraktsync/plex_server.py
@@ -15,7 +15,11 @@ def __init__(self, factory: Factory):
@property
def timeout(self):
- return self.factory.config()["plex"]["timeout"]
+ return self.config["plex"]["timeout"]
+
+ @property
+ def config(self):
+ return self.factory.config()
@property
def session(self):
@@ -52,8 +56,10 @@ def connect(self, urls: List[str], token: str):
if "doesn't match '*." in message and ".plex.direct" in url:
url = self.extract_plex_direct(url, message)
logger.warning(f"Trying with url: {url}")
+ self.save_new_url(url, urls[-1])
urls.append(url)
continue
+
logger.error(e)
except Exception as e:
@@ -80,6 +86,15 @@ def extract_plex_direct(url: str, message: str):
return url[: end_pos - 32] + hash_value + url[end_pos:]
+ def save_new_url(self, base_url: str, local_url: str):
+ config = self.config
+
+ # save new url to .env
+ config["PLEX_BASEURL"] = base_url
+ config["PLEX_LOCALURL"] = local_url
+ config.save()
+ logger.info("Plex server url changed to {}".format(base_url))
+
def get_plex_server():
from plextraktsync.factory import factory

Add save_new_url trickery