Convert special constants to their respective values
MODIFY
plextraktsync/config/HttpCacheConfig.py
plextraktsync/config/HttpCacheConfig.py
from datetime import timedelta
from typing import TYPE_CHECKING
-from requests_cache import DO_NOT_CACHE
+from requests_cache import DO_NOT_CACHE, EXPIRE_IMMEDIATELY, NEVER_EXPIRE
from plextraktsync.util.parse_date import parse_date
@@ -23,6 +23,13 @@ class HttpCacheConfig:
policy: ExpirationPatterns
+ # Special values for expiry patterns
+ expire_constants = {
+ "DO_NOT_CACHE": DO_NOT_CACHE,
+ "EXPIRE_IMMEDIATELY": EXPIRE_IMMEDIATELY,
+ "NEVER_EXPIRE": NEVER_EXPIRE,
+ }
+
default_policy = {
# Requests matching these patterns will not be cached
"*.trakt.tv/shows/*/seasons": DO_NOT_CACHE,
@@ -100,9 +107,13 @@ def urls_expire_after(self) -> ExpirationPatterns:
# This will keep the order if user overwrote the item
policy.update(self.policy)
+ for (k, v) in ((k, v) for k, v in policy.items() if isinstance(v, str)):
+ # Special constants
+ if v in self.expire_constants:
+ policy[k] = self.expire_constants[v]
+ continue
# Parse string values with units to datetime
- for k in (k for k, v in policy.items() if isinstance(v, str)):
- policy[k] = parse_date(policy[k])
+ policy[k] = parse_date(v)
return policy

Convert special constants to their respective values