From 9809740ba5cc5daf53e690d104a37aa6545e53f9 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 23 Jun 2022 09:44:22 +0530 Subject: [PATCH] [extractor, cleanup] Reduce direct use of `_downloader` --- yt_dlp/extractor/abematv.py | 2 +- yt_dlp/extractor/adobepass.py | 12 ++++++------ yt_dlp/extractor/brightcove.py | 4 ++-- yt_dlp/extractor/cbc.py | 4 ++-- yt_dlp/extractor/common.py | 10 +++++++++- yt_dlp/extractor/fc2.py | 2 +- yt_dlp/extractor/foxgay.py | 2 +- yt_dlp/extractor/googledrive.py | 2 +- yt_dlp/extractor/iqiyi.py | 4 ++-- yt_dlp/extractor/openload.py | 2 +- yt_dlp/extractor/radiko.py | 4 ++-- yt_dlp/extractor/rokfin.py | 4 ++-- yt_dlp/extractor/soundcloud.py | 4 ++-- yt_dlp/extractor/udemy.py | 2 +- yt_dlp/extractor/wppilot.py | 6 +++--- yt_dlp/extractor/youtube.py | 8 ++++---- 16 files changed, 40 insertions(+), 32 deletions(-) diff --git a/yt_dlp/extractor/abematv.py b/yt_dlp/extractor/abematv.py index 81a6542c3..6b8e6e31b 100644 --- a/yt_dlp/extractor/abematv.py +++ b/yt_dlp/extractor/abematv.py @@ -109,7 +109,7 @@ def __init__(self, ie: 'AbemaTVIE'): 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( diff --git a/yt_dlp/extractor/adobepass.py b/yt_dlp/extractor/adobepass.py index a8e6c4363..66e46832d 100644 --- a/yt_dlp/extractor/adobepass.py +++ b/yt_dlp/extractor/adobepass.py @@ -1431,7 +1431,7 @@ def extract_redirect_url(html, url=None, fatal=False): 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 @@ def extract_redirect_url(html, url=None, fatal=False): raise_mvpd_required() raise if ']+src=([\'"])(?P[^\'"]+)\1', webpage, diff --git a/yt_dlp/extractor/googledrive.py b/yt_dlp/extractor/googledrive.py index b4f483298..d7475b6da 100644 --- a/yt_dlp/extractor/googledrive.py +++ b/yt_dlp/extractor/googledrive.py @@ -264,7 +264,7 @@ def add_source_format(urlh): 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.py index 059b62e2a..35691ec20 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_cache webpack_js_url = self._proto_relative_url(self._search_regex( @@ -534,7 +534,7 @@ def _extract_vms_player_js(self, webpage, video_id): 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') diff --git a/yt_dlp/extractor/openload.py b/yt_dlp/extractor/openload.py index 22d7e1a84..79dad09e3 100644 --- a/yt_dlp/extractor/openload.py +++ b/yt_dlp/extractor/openload.py @@ -131,7 +131,7 @@ def __del__(self): 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.py index dbb748715..498cc6be9 100644 --- a/yt_dlp/extractor/radiko.py +++ b/yt_dlp/extractor/radiko.py @@ -43,7 +43,7 @@ def _auth_client(self): }).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 @@ def _real_extract(self, url): 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.py index 1ba11bd51..119c5ea3c 100644 --- a/yt_dlp/extractor/rokfin.py +++ b/yt_dlp/extractor/rokfin.py @@ -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 @@ def _get_db_access_credentials(self, video_id=None): 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') diff --git a/yt_dlp/extractor/soundcloud.py b/yt_dlp/extractor/soundcloud.py index 6dfa50c60..9e4c8cf25 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 @@ def _download_json(self, *args, **kwargs): 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': diff --git a/yt_dlp/extractor/udemy.py b/yt_dlp/extractor/udemy.py index d35cd0d43..94ea2fe59 100644 --- a/yt_dlp/extractor/udemy.py +++ b/yt_dlp/extractor/udemy.py @@ -148,7 +148,7 @@ def _download_json(self, url_or_request, *args, **kwargs): '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': diff --git a/yt_dlp/extractor/wppilot.py b/yt_dlp/extractor/wppilot.py index 6349e5326..e1062b9b5 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, True webpage = self._download_webpage('https://pilot.wp.pl/tv/', None, 'Downloading webpage') @@ -35,7 +35,7 @@ def _get_channel_list(self, cache=True): 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 @@ def _real_extract(self, url): 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 diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index ccb41cb2e..dee051d05 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -2475,7 +2475,7 @@ def _extract_signature_function(self, video_id, player_url, example_sig): 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 @@ def _extract_signature_function(self, video_id, player_url, example_sig): 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 @@ def _extract_n_function_name(self, jscode): 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 @@ def _extract_n_function(self, video_id, player_url): 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')