A feature-rich command-line audio/video downloader
[extractor, cleanup] Reduce direct use of `_downloader`
pukkandan9809740ba5cc
diff --git a/yt_dlp/extractor/abematv.py b/yt_dlp/extractor/abematv.pyindex 81a6542c3a..6b8e6e31b6 100644--- a/yt_dlp/extractor/abematv.py+++ b/yt_dlp/extractor/abematv.py@@ -109,7 +109,7 @@ class AbemaLicenseHandler(compat_urllib_request.BaseHandler):self.ie = iedef _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(diff --git a/yt_dlp/extractor/adobepass.py b/yt_dlp/extractor/adobepass.pyindex a8e6c43632..66e46832de 100644--- a/yt_dlp/extractor/adobepass.py+++ b/yt_dlp/extractor/adobepass.py@@ -1431,7 +1431,7 @@ class AdobePassIE(InfoExtractor):guid = xml_text(resource, 'guid') if '<' in resource else resourcecount = 0while 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()raiseif '<pendingLogout' in session:- self._downloader.cache.store(self._MVPD_CACHE, requestor_id, {})+ self.cache.store(self._MVPD_CACHE, requestor_id, {})count += 1continueauthn_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 += 1continueif '<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 += 1continuereturn short_authorizediff --git a/yt_dlp/extractor/brightcove.py b/yt_dlp/extractor/brightcove.pyindex 936c34e158..a5412897d6 100644--- a/yt_dlp/extractor/brightcove.py+++ b/yt_dlp/extractor/brightcove.py@@ -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)diff --git a/yt_dlp/extractor/cbc.py b/yt_dlp/extractor/cbc.pyindex cac3f1e9d0..999b7bc53a 100644--- a/yt_dlp/extractor/cbc.py+++ b/yt_dlp/extractor/cbc.py@@ -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_tokendef _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 """diff --git a/yt_dlp/extractor/common.py b/yt_dlp/extractor/common.pyindex f4c34f43ce..fe43ff519c 100644--- a/yt_dlp/extractor/common.py+++ b/yt_dlp/extractor/common.py@@ -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 """diff --git a/yt_dlp/extractor/fc2.py b/yt_dlp/extractor/fc2.pyindex 8983a16fd4..3501c4cf6b 100644--- a/yt_dlp/extractor/fc2.py+++ b/yt_dlp/extractor/fc2.py@@ -78,7 +78,7 @@ class FC2IE(InfoExtractor):webpage = Noneif 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 clearself._login()title, thumbnail, description = None, None, Nonediff --git a/yt_dlp/extractor/foxgay.py b/yt_dlp/extractor/foxgay.pyindex 4abc2cfd02..b285464ec8 100644--- a/yt_dlp/extractor/foxgay.py+++ b/yt_dlp/extractor/foxgay.py@@ -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,diff --git a/yt_dlp/extractor/googledrive.py b/yt_dlp/extractor/googledrive.pyindex b4f4832982..d7475b6da7 100644--- a/yt_dlp/extractor/googledrive.py+++ b/yt_dlp/extractor/googledrive.py@@ -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,diff --git a/yt_dlp/extractor/iqiyi.py b/yt_dlp/extractor/iqiyi.pyindex 059b62e2ab..35691ec201 100644--- a/yt_dlp/extractor/iqiyi.py+++ b/yt_dlp/extractor/iqiyi.py@@ -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_cachewebpack_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_jsraise ExtractorError('Unable to extract player JS')diff --git a/yt_dlp/extractor/openload.py b/yt_dlp/extractor/openload.pyindex 22d7e1a84f..79dad09e35 100644--- a/yt_dlp/extractor/openload.py+++ b/yt_dlp/extractor/openload.py@@ -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'] = '/'diff --git a/yt_dlp/extractor/radiko.py b/yt_dlp/extractor/radiko.pyindex dbb7487150..498cc6be94 100644--- a/yt_dlp/extractor/radiko.py+++ b/yt_dlp/extractor/radiko.py@@ -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_datadef _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(diff --git a/yt_dlp/extractor/rokfin.py b/yt_dlp/extractor/rokfin.pyindex 1ba11bd514..119c5ea3c2 100644--- a/yt_dlp/extractor/rokfin.py+++ b/yt_dlp/extractor/rokfin.py@@ -360,7 +360,7 @@ class RokfinSearchIE(SearchInfoExtractor):_db_access_key = Nonedef _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))returnraise ExtractorError('Unable to extract access credentials')diff --git a/yt_dlp/extractor/soundcloud.py b/yt_dlp/extractor/soundcloud.pyindex 6dfa50c602..9e4c8cf256 100644--- a/yt_dlp/extractor/soundcloud.py+++ b/yt_dlp/extractor/soundcloud.py@@ -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):raisedef _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':diff --git a/yt_dlp/extractor/udemy.py b/yt_dlp/extractor/udemy.pyindex d35cd0d431..94ea2fe590 100644--- a/yt_dlp/extractor/udemy.py+++ b/yt_dlp/extractor/udemy.py@@ -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.valueelif cookie.name == 'access_token':diff --git a/yt_dlp/extractor/wppilot.py b/yt_dlp/extractor/wppilot.pyindex 6349e5326b..e1062b9b5b 100644--- a/yt_dlp/extractor/wppilot.py+++ b/yt_dlp/extractor/wppilot.py@@ -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, Truewebpage = 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, Falseraise 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 guestsis_authorized = True if is_authorized is not None and not is_authorized.value.startswith('g:') else Falsediff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.pyindex ccb41cb2e8..dee051d05a 100644--- a/yt_dlp/extractor/youtube.py+++ b/yt_dlp/extractor/youtube.py@@ -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 resdef _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')