Skip to content

Commit

Permalink
[brightcove] invalidate policy key cache on failing requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Remita Amine committed Dec 31, 2019
1 parent 0164cd5 commit 2d30b92
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion youtube_dl/extractor/brightcove.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ def _real_extract(self, url):
policy_key_id = '%s_%s' % (account_id, player_id)
policy_key = self._downloader.cache.load('brightcove', policy_key_id)
policy_key_extracted = False
store_pk = lambda x: self._downloader.cache.store('brightcove', policy_key_id, x)

def extract_policy_key():
webpage = self._download_webpage(
Expand All @@ -610,7 +611,7 @@ def extract_policy_key():
r'policyKey\s*:\s*(["\'])(?P<pk>.+?)\1',
webpage, 'policy key', group='pk')

self._downloader.cache.store('brightcove', policy_key_id, policy_key)
store_pk(policy_key)
return policy_key

api_url = 'https://edge.api.brightcove.com/playback/v1/accounts/%s/%ss/%s' % (account_id, content_type, video_id)
Expand Down Expand Up @@ -638,6 +639,7 @@ def extract_policy_key():
self.raise_geo_restricted(msg=message)
elif json_data.get('error_code') == 'INVALID_POLICY_KEY' and not policy_key_extracted:
policy_key = None
store_pk(None)
continue
raise ExtractorError(message, expected=True)
raise
Expand Down

0 comments on commit 2d30b92

Please sign in to comment.