Skip to content

Commit

Permalink
Extract urls_expire_after as separate factory
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Jan 14, 2024
1 parent 33837c3 commit 78a0f07
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions plextraktsync/util/Factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,16 @@ def server_config(self):
return server_config.get_server(server_name)

@cached_property
def session(self):
from requests_cache import CachedSession

def urls_expire_after(self):
from plextraktsync.decorators.flatten import flatten_dict

if not self.run_config.cache:
from requests_cache import DO_NOT_CACHE

return {
"*": DO_NOT_CACHE,
}

@flatten_dict
def patch_plex_urls(patterns, base_urls, glob="*.plex.direct:*"):
"""
Expand All @@ -138,20 +143,18 @@ def patch_plex_urls(patterns, base_urls, glob="*.plex.direct:*"):
url = pattern.replace(glob, url)
yield url, expire

if self.run_config.cache:
urls_expire_after = patch_plex_urls(
self.config.http_cache.urls_expire_after,
self.server_config.base_urls,
)
else:
from requests_cache import DO_NOT_CACHE
urls_expire_after = {
"*": DO_NOT_CACHE,
}
return patch_plex_urls(
self.config.http_cache.urls_expire_after,
self.server_config.base_urls,
)

@cached_property
def session(self):
from requests_cache import CachedSession

return CachedSession(
cache_name=self.config.cache_path,
urls_expire_after=urls_expire_after,
urls_expire_after=self.urls_expire_after,
)

@cached_property
Expand Down

0 comments on commit 78a0f07

Please sign in to comment.