summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2021-03-22 10:16:51 -0400
committermorpheus65535 <[email protected]>2021-03-22 10:16:51 -0400
commit762cd61b215e9f6aa8f0dfee9855f80bc7753f04 (patch)
tree479cdbfa7a59744b7d4f489866f2ce990a65fe47
parent854c46529f79fe015335afb88594ca390e548416 (diff)
downloadbazarr-762cd61b215e9f6aa8f0dfee9855f80bc7753f04.tar.gz
bazarr-762cd61b215e9f6aa8f0dfee9855f80bc7753f04.zip
Fixed OpenSubtitles.com token expiration
-rw-r--r--libs/subliminal_patch/providers/opensubtitlescom.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/libs/subliminal_patch/providers/opensubtitlescom.py b/libs/subliminal_patch/providers/opensubtitlescom.py
index c3d6a5b8d..716eef6e1 100644
--- a/libs/subliminal_patch/providers/opensubtitlescom.py
+++ b/libs/subliminal_patch/providers/opensubtitlescom.py
@@ -24,6 +24,7 @@ from guessit import guessit
logger = logging.getLogger(__name__)
SHOW_EXPIRATION_TIME = datetime.timedelta(weeks=1).total_seconds()
+TOKEN_EXPIRATION_TIME = datetime.timedelta(hours=12).total_seconds()
def fix_tv_naming(title):
@@ -143,16 +144,13 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
self.use_hash = use_hash
def initialize(self):
+ self.login()
self.token = region.get("oscom_token")
- if self.token:
- self.session.headers.update({'Authorization': 'Beaker ' + self.token})
- return True
- else:
- self.login()
def terminate(self):
self.session.close()
+ @region.cache_on_arguments(expiration_time=TOKEN_EXPIRATION_TIME)
def login(self):
try:
r = self.session.post(self.server_url + 'login',
@@ -168,7 +166,6 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
except ValueError:
raise ProviderError('Invalid JSON returned by provider')
else:
- self.session.headers.update({'Authorization': 'Beaker ' + self.token})
region.set("oscom_token", self.token)
return True
elif r.status_code == 401:
@@ -324,7 +321,8 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
def download_subtitle(self, subtitle):
logger.info('Downloading subtitle %r', subtitle)
- headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
+ headers = {'Accept': 'application/json', 'Content-Type': 'application/json',
+ 'Authorization': 'Beaker ' + self.token}
res = self.session.post(self.server_url + 'download',
json={'file_id': subtitle.file_id, 'sub_format': 'srt'},
headers=headers,