[extractor, cleanup] Reduce direct use of `_downloader`

This commit is contained in:
pukkandan 2022-06-23 09:44:22 +05:30
parent f67baae17e
commit 9809740ba5
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39
16 changed files with 40 additions and 32 deletions

View File

@ -109,7 +109,7 @@ class AbemaLicenseHandler(compat_urllib_request.BaseHandler):
self.ie = ie
def _get_videokey_from_ticket(self, ticket):
to_show = self.ie._downloader.params.get('verbose', False)
to_show = self.ie.get_param('verbose', False)
media_token = self.ie._get_media_token(to_show=to_show)
license_response = self.ie._download_json(

View File

@ -1431,7 +1431,7 @@ class AdobePassIE(InfoExtractor):
guid = xml_text(resource, 'guid') if '<' in resource else resource
count = 0
while count < 2:
requestor_info = self._downloader.cache.load(self._MVPD_CACHE, requestor_id) or {}
requestor_info = self.cache.load(self._MVPD_CACHE, requestor_id) or {}
authn_token = requestor_info.get('authn_token')
if authn_token and is_expired(authn_token, 'simpleTokenExpires'):
authn_token = None
@ -1726,12 +1726,12 @@ class AdobePassIE(InfoExtractor):
raise_mvpd_required()
raise
if '<pendingLogout' in session:
self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
self.cache.store(self._MVPD_CACHE, requestor_id, {})
count += 1
continue
authn_token = unescapeHTML(xml_text(session, 'authnToken'))
requestor_info['authn_token'] = authn_token
self._downloader.cache.store(self._MVPD_CACHE, requestor_id, requestor_info)
self.cache.store(self._MVPD_CACHE, requestor_id, requestor_info)
authz_token = requestor_info.get(guid)
if authz_token and is_expired(authz_token, 'simpleTokenTTL'):
@ -1747,14 +1747,14 @@ class AdobePassIE(InfoExtractor):
'userMeta': '1',
}), headers=mvpd_headers)
if '<pendingLogout' in authorize:
self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
self.cache.store(self._MVPD_CACHE, requestor_id, {})
count += 1
continue
if '<error' in authorize:
raise ExtractorError(xml_text(authorize, 'details'), expected=True)
authz_token = unescapeHTML(xml_text(authorize, 'authzToken'))
requestor_info[guid] = authz_token
self._downloader.cache.store(self._MVPD_CACHE, requestor_id, requestor_info)
self.cache.store(self._MVPD_CACHE, requestor_id, requestor_info)
mvpd_headers.update({
'ap_19': xml_text(authn_token, 'simpleSamlNameID'),
@ -1770,7 +1770,7 @@ class AdobePassIE(InfoExtractor):
'hashed_guid': 'false',
}), headers=mvpd_headers)
if '<pendingLogout' in short_authorize:
self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})
self.cache.store(self._MVPD_CACHE, requestor_id, {})
count += 1
continue
return short_authorize

View File

@ -600,9 +600,9 @@ class BrightcoveNewIE(AdobePassIE):
account_id, player_id, embed, content_type, video_id = self._match_valid_url(url).groups()
policy_key_id = '%s_%s' % (account_id, player_id)
policy_key = self._downloader.cache.load('brightcove', policy_key_id)
policy_key = self.cache.load('brightcove', policy_key_id)
policy_key_extracted = False
store_pk = lambda x: self._downloader.cache.store('brightcove', policy_key_id, x)
store_pk = lambda x: self.cache.store('brightcove', policy_key_id, x)
def extract_policy_key():
base_url = 'http://players.brightcove.net/%s/%s_%s/' % (account_id, player_id, embed)

View File

@ -304,13 +304,13 @@ class CBCGemIE(InfoExtractor):
def _get_claims_token(self, email, password):
if not self.claims_token_valid():
self._claims_token = self._new_claims_token(email, password)
self._downloader.cache.store(self._NETRC_MACHINE, 'claims_token', self._claims_token)
self.cache.store(self._NETRC_MACHINE, 'claims_token', self._claims_token)
return self._claims_token
def _real_initialize(self):
if self.claims_token_valid():
return
self._claims_token = self._downloader.cache.load(self._NETRC_MACHINE, 'claims_token')
self._claims_token = self.cache.load(self._NETRC_MACHINE, 'claims_token')
def _find_secret_formats(self, formats, video_id):
""" Find a valid video url and convert it to the secret variant """

View File

@ -695,6 +695,14 @@ class InfoExtractor:
"""Sets a YoutubeDL instance as the downloader for this IE."""
self._downloader = downloader
@property
def cache(self):
return self._downloader.cache
@property
def cookiejar(self):
return self._downloader.cookiejar
def _initialize_pre_login(self):
""" Intialization before login. Redefine in subclasses."""
pass
@ -3593,7 +3601,7 @@ class InfoExtractor:
0, name, value, port, port is not None, domain, True,
domain.startswith('.'), path, True, secure, expire_time,
discard, None, None, rest)
self._downloader.cookiejar.set_cookie(cookie)
self.cookiejar.set_cookie(cookie)
def _get_cookies(self, url):
""" Return a compat_cookies_SimpleCookie with the cookies for the url """

View File

@ -78,7 +78,7 @@ class FC2IE(InfoExtractor):
webpage = None
if not url.startswith('fc2:'):
webpage = self._download_webpage(url, video_id)
self._downloader.cookiejar.clear_session_cookies() # must clear
self.cookiejar.clear_session_cookies() # must clear
self._login()
title, thumbnail, description = None, None, None

View File

@ -31,7 +31,7 @@ class FoxgayIE(InfoExtractor):
description = get_element_by_id('inf_tit', webpage)
# The default user-agent with foxgay cookies leads to pages without videos
self._downloader.cookiejar.clear('.foxgay.com')
self.cookiejar.clear('.foxgay.com')
# Find the URL for the iFrame which contains the actual video.
iframe_url = self._html_search_regex(
r'<iframe[^>]+src=([\'"])(?P<url>[^\'"]+)\1', webpage,

View File

@ -264,7 +264,7 @@ class GoogleDriveIE(InfoExtractor):
subtitles_id = ttsurl.encode('utf-8').decode(
'unicode_escape').split('=')[-1]
self._downloader.cookiejar.clear(domain='.google.com', path='/', name='NID')
self.cookiejar.clear(domain='.google.com', path='/', name='NID')
return {
'id': video_id,

View File

@ -521,7 +521,7 @@ class IqIE(InfoExtractor):
'''
def _extract_vms_player_js(self, webpage, video_id):
player_js_cache = self._downloader.cache.load('iq', 'player_js')
player_js_cache = self.cache.load('iq', 'player_js')
if player_js_cache:
return player_js_cache
webpack_js_url = self._proto_relative_url(self._search_regex(
@ -534,7 +534,7 @@ class IqIE(InfoExtractor):
f'https://stc.iqiyipic.com/_next/static/chunks/{webpack_map1.get(module_index, module_index)}.{webpack_map2[module_index]}.js',
video_id, note=f'Downloading #{module_index} module JS', errnote='Unable to download module JS', fatal=False) or ''
if 'vms request' in module_js:
self._downloader.cache.store('iq', 'player_js', module_js)
self.cache.store('iq', 'player_js', module_js)
return module_js
raise ExtractorError('Unable to extract player JS')

View File

@ -131,7 +131,7 @@ class PhantomJSwrapper:
os.remove(self._TMP_FILES[name].name)
def _save_cookies(self, url):
cookies = cookie_jar_to_list(self.extractor._downloader.cookiejar)
cookies = cookie_jar_to_list(self.extractor.cookiejar)
for cookie in cookies:
if 'path' not in cookie:
cookie['path'] = '/'

View File

@ -43,7 +43,7 @@ class RadikoBaseIE(InfoExtractor):
}).split(',')[0]
auth_data = (auth_token, area_id)
self._downloader.cache.store('radiko', 'auth_data', auth_data)
self.cache.store('radiko', 'auth_data', auth_data)
return auth_data
def _extract_full_key(self):
@ -150,7 +150,7 @@ class RadikoIE(RadikoBaseIE):
vid_int = unified_timestamp(video_id, False)
prog, station_program, ft, radio_begin, radio_end = self._find_program(video_id, station, vid_int)
auth_cache = self._downloader.cache.load('radiko', 'auth_data')
auth_cache = self.cache.load('radiko', 'auth_data')
for attempt in range(2):
auth_token, area_id = (not attempt and auth_cache) or self._auth_client()
formats = self._extract_formats(

View File

@ -360,7 +360,7 @@ class RokfinSearchIE(SearchInfoExtractor):
_db_access_key = None
def _real_initialize(self):
self._db_url, self._db_access_key = self._downloader.cache.load(self.ie_key(), 'auth', default=(None, None))
self._db_url, self._db_access_key = self.cache.load(self.ie_key(), 'auth', default=(None, None))
if not self._db_url:
self._get_db_access_credentials()
@ -405,6 +405,6 @@ class RokfinSearchIE(SearchInfoExtractor):
self._db_url = url_or_none(f'{auth_data["ENDPOINT_BASE"]}/api/as/v1/engines/rokfin-search/search.json')
self._db_access_key = f'Bearer {auth_data["SEARCH_KEY"]}'
self._downloader.cache.store(self.ie_key(), 'auth', (self._db_url, self._db_access_key))
self.cache.store(self.ie_key(), 'auth', (self._db_url, self._db_access_key))
return
raise ExtractorError('Unable to extract access credentials')

View File

@ -67,7 +67,7 @@ class SoundcloudBaseIE(InfoExtractor):
_HEADERS = {}
def _store_client_id(self, client_id):
self._downloader.cache.store('soundcloud', 'client_id', client_id)
self.cache.store('soundcloud', 'client_id', client_id)
def _update_client_id(self):
webpage = self._download_webpage('https://soundcloud.com/', None)
@ -104,7 +104,7 @@ class SoundcloudBaseIE(InfoExtractor):
raise
def _initialize_pre_login(self):
self._CLIENT_ID = self._downloader.cache.load('soundcloud', 'client_id') or 'a3e059563d7fd3372b49b37f00a00bcf'
self._CLIENT_ID = self.cache.load('soundcloud', 'client_id') or 'a3e059563d7fd3372b49b37f00a00bcf'
def _perform_login(self, username, password):
if username != 'oauth':

View File

@ -148,7 +148,7 @@ class UdemyIE(InfoExtractor):
'X-Udemy-Snail-Case': 'true',
'X-Requested-With': 'XMLHttpRequest',
}
for cookie in self._downloader.cookiejar:
for cookie in self.cookiejar:
if cookie.name == 'client_id':
headers['X-Udemy-Client-Id'] = cookie.value
elif cookie.name == 'access_token':

View File

@ -20,7 +20,7 @@ class WPPilotBaseIE(InfoExtractor):
def _get_channel_list(self, cache=True):
if cache is True:
cache_res = self._downloader.cache.load('wppilot', 'channel-list')
cache_res = self.cache.load('wppilot', 'channel-list')
if cache_res:
return cache_res, True
webpage = self._download_webpage('https://pilot.wp.pl/tv/', None, 'Downloading webpage')
@ -35,7 +35,7 @@ class WPPilotBaseIE(InfoExtractor):
channel_list = try_get(qhash_content, lambda x: x['data']['allChannels']['nodes'])
if channel_list is None:
continue
self._downloader.cache.store('wppilot', 'channel-list', channel_list)
self.cache.store('wppilot', 'channel-list', channel_list)
return channel_list, False
raise ExtractorError('Unable to find the channel list')
@ -101,7 +101,7 @@ class WPPilotIE(WPPilotBaseIE):
channel = self._get_channel(video_id)
video_id = str(channel['id'])
is_authorized = next((c for c in self._downloader.cookiejar if c.name == 'netviapisessid'), None)
is_authorized = next((c for c in self.cookiejar if c.name == 'netviapisessid'), None)
# cookies starting with "g:" are assigned to guests
is_authorized = True if is_authorized is not None and not is_authorized.value.startswith('g:') else False

View File

@ -2475,7 +2475,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
func_id = f'js_{player_id}_{self._signature_cache_id(example_sig)}'
assert os.path.basename(func_id) == func_id
cache_spec = self._downloader.cache.load('youtube-sigfuncs', func_id)
cache_spec = self.cache.load('youtube-sigfuncs', func_id)
if cache_spec is not None:
return lambda s: ''.join(s[i] for i in cache_spec)
@ -2487,7 +2487,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
cache_res = res(test_string)
cache_spec = [ord(c) for c in cache_res]
self._downloader.cache.store('youtube-sigfuncs', func_id, cache_spec)
self.cache.store('youtube-sigfuncs', func_id, cache_spec)
return res
def _print_sig_code(self, func, example_sig):
@ -2602,7 +2602,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
def _extract_n_function(self, video_id, player_url):
player_id = self._extract_player_info(player_url)
func_code = self._downloader.cache.load('youtube-nsig', player_id)
func_code = self.cache.load('youtube-nsig', player_id)
if func_code:
jsi = JSInterpreter(func_code)
@ -2611,7 +2611,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
funcname = self._extract_n_function_name(jscode)
jsi = JSInterpreter(jscode)
func_code = jsi.extract_function_code(funcname)
self._downloader.cache.store('youtube-nsig', player_id, func_code)
self.cache.store('youtube-nsig', player_id, func_code)
if self.get_param('youtube_print_sig_code'):
self.to_screen(f'Extracted nsig function from {player_id}:\n{func_code[1]}\n')