Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plextraktsync/config/HttpCacheConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class HttpCacheConfig:
# system_account
"*/accounts": DO_NOT_CACHE,
# version, updated_at
# "*/": DO_NOT_CACHE,
"*.plex.direct:*/": DO_NOT_CACHE,
}

@property
Expand Down
9 changes: 9 additions & 0 deletions plextraktsync/config/PlexServerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ class PlexServerConfig:
id: str = None
config: dict = None

@property
def base_urls(self):
"""
Returns unique host:port of all urls
"""
from urllib.parse import urlparse

return {urlparse(url).netloc for url in self.urls}

def asdict(self):
data = asdict(self)
del data["name"]
Expand Down
2 changes: 0 additions & 2 deletions plextraktsync/plex/PlexServerConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from requests.exceptions import ConnectionError, SSLError

from plextraktsync.config import PLEX_PLATFORM
from plextraktsync.decorators.nocache import nocache
from plextraktsync.factory import Factory, logging


Expand All @@ -29,7 +28,6 @@ def config(self):
def session(self):
return self.factory.session

@nocache
def connect(self, urls: list[str], token: str):
plexapi.X_PLEX_PLATFORM = PLEX_PLATFORM
plexapi.TIMEOUT = self.timeout
Expand Down
22 changes: 21 additions & 1 deletion plextraktsync/util/Factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,27 @@ def urls_expire_after(self):
"*": DO_NOT_CACHE,
}

return self.config.http_cache.urls_expire_after
def patch_plex_urls(patterns, base_urls, glob="*.plex.direct:*"):
"""
Replace plex.direct urls from patterns to current server urls
"""
from fnmatch import filter

for pattern, expire in patterns.items():
# add original pattern
yield pattern, expire

# replaced patterns
for url in filter(base_urls, glob):
url = pattern.replace(glob, url)
yield url, expire

urls_expire_after = dict(patch_plex_urls(
self.config.http_cache.urls_expire_after,
self.server_config.base_urls,
))

return urls_expire_after

@cached_property
def session(self):
Expand Down