From 75f86b2a66023d2901259ae85fe7435532d6c410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Thu, 17 Mar 2016 14:15:49 +0100 Subject: [PATCH] extractors: don't access directly params from the downloader --- youtube_dl/extractor/brightcove.py | 2 +- youtube_dl/extractor/ccc.py | 2 +- youtube_dl/extractor/common.py | 29 +++++++++++++------------- youtube_dl/extractor/commonmistakes.py | 2 +- youtube_dl/extractor/daum.py | 2 +- youtube_dl/extractor/deezer.py | 2 +- youtube_dl/extractor/generic.py | 6 +++--- youtube_dl/extractor/leeco.py | 2 +- youtube_dl/extractor/nba.py | 2 +- youtube_dl/extractor/neteasemusic.py | 2 +- youtube_dl/extractor/pluralsight.py | 6 +++--- youtube_dl/extractor/smotri.py | 4 ++-- youtube_dl/extractor/sohu.py | 2 +- youtube_dl/extractor/vimeo.py | 6 +++--- youtube_dl/extractor/youku.py | 4 ++-- youtube_dl/extractor/youtube.py | 18 ++++++++-------- 16 files changed, 46 insertions(+), 45 deletions(-) diff --git a/youtube_dl/extractor/brightcove.py b/youtube_dl/extractor/brightcove.py index 0d162d337..70d44cb63 100644 --- a/youtube_dl/extractor/brightcove.py +++ b/youtube_dl/extractor/brightcove.py @@ -343,7 +343,7 @@ class BrightcoveLegacyIE(InfoExtractor): 'url': video_info['FLVFullLengthURL'], }) - if self._downloader.params.get('include_ads', False): + if self.params.get('include_ads', False): adServerURL = video_info.get('_youtubedl_adServerURL') if adServerURL: ad_info = { diff --git a/youtube_dl/extractor/ccc.py b/youtube_dl/extractor/ccc.py index dda2c0959..9341876ac 100644 --- a/youtube_dl/extractor/ccc.py +++ b/youtube_dl/extractor/ccc.py @@ -37,7 +37,7 @@ class CCCIE(InfoExtractor): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) - if self._downloader.params.get('prefer_free_formats'): + if self.params.get('prefer_free_formats'): preference = qualities(['mp3', 'opus', 'mp4-lq', 'webm-lq', 'h264-sd', 'mp4-sd', 'webm-sd', 'mp4', 'webm', 'mp4-hd', 'h264-hd', 'webm-hd']) else: preference = qualities(['opus', 'mp3', 'webm-lq', 'mp4-lq', 'webm-sd', 'h264-sd', 'mp4-sd', 'webm', 'mp4', 'webm-hd', 'mp4-hd', 'h264-hd']) diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index 85ac0400c..d0bb8d4fe 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -331,6 +331,7 @@ class InfoExtractor(object): def set_downloader(self, downloader): """Sets the downloader for this IE.""" self._downloader = downloader + self.params = downloader.params if downloader else {} def _real_initialize(self): """Real initialization process. Redefine in subclasses.""" @@ -419,7 +420,7 @@ class InfoExtractor(object): webpage_bytes = prefix + webpage_bytes if not encoding: encoding = self._guess_encoding_from_content(content_type, webpage_bytes) - if self._downloader.params.get('dump_intermediate_pages', False): + if self.params.get('dump_intermediate_pages', False): try: url = url_or_request.get_full_url() except AttributeError: @@ -427,7 +428,7 @@ class InfoExtractor(object): self.to_screen('Dumping request to ' + url) dump = base64.b64encode(webpage_bytes).decode('ascii') self._downloader.to_screen(dump) - if self._downloader.params.get('write_pages', False): + if self.params.get('write_pages', False): try: url = url_or_request.get_full_url() except AttributeError: @@ -610,7 +611,7 @@ class InfoExtractor(object): if mobj: break - if not self._downloader.params.get('no_color') and compat_os_name != 'nt' and sys.stderr.isatty(): + if not self.params.get('no_color') and compat_os_name != 'nt' and sys.stderr.isatty(): _name = '\033[0;34m%s\033[0m' % name else: _name = name @@ -650,7 +651,7 @@ class InfoExtractor(object): username = None password = None - downloader_params = self._downloader.params + downloader_params = self.params # Attempt to use provided username and password or .netrc data if downloader_params.get('username') is not None: @@ -678,7 +679,7 @@ class InfoExtractor(object): """ if self._downloader is None: return None - downloader_params = self._downloader.params + downloader_params = self.params if downloader_params.get('twofactor') is not None: return downloader_params['twofactor'] @@ -869,7 +870,7 @@ class InfoExtractor(object): if f.get('vcodec') == 'none': # audio only preference -= 50 - if self._downloader.params.get('prefer_free_formats'): + if self.params.get('prefer_free_formats'): ORDER = ['aac', 'mp3', 'm4a', 'webm', 'ogg', 'opus'] else: ORDER = ['webm', 'opus', 'ogg', 'mp3', 'aac', 'm4a'] @@ -881,7 +882,7 @@ class InfoExtractor(object): else: if f.get('acodec') == 'none': # video only preference -= 40 - if self._downloader.params.get('prefer_free_formats'): + if self.params.get('prefer_free_formats'): ORDER = ['flv', 'mp4', 'webm'] else: ORDER = ['webm', 'flv', 'mp4'] @@ -948,7 +949,7 @@ class InfoExtractor(object): """ Either "http:" or "https:", depending on the user's preferences """ return ( 'http:' - if self._downloader.params.get('prefer_insecure', False) + if self.params.get('prefer_insecure', False) else 'https:') def _proto_relative_url(self, url, scheme=None): @@ -1614,8 +1615,8 @@ class InfoExtractor(object): return not any_restricted def extract_subtitles(self, *args, **kwargs): - if (self._downloader.params.get('writesubtitles', False) or - self._downloader.params.get('listsubtitles')): + if (self.params.get('writesubtitles', False) or + self.params.get('listsubtitles')): return self._get_subtitles(*args, **kwargs) return {} @@ -1640,8 +1641,8 @@ class InfoExtractor(object): return ret def extract_automatic_captions(self, *args, **kwargs): - if (self._downloader.params.get('writeautomaticsub', False) or - self._downloader.params.get('listsubtitles')): + if (self.params.get('writeautomaticsub', False) or + self.params.get('listsubtitles')): return self._get_automatic_captions(*args, **kwargs) return {} @@ -1649,9 +1650,9 @@ class InfoExtractor(object): raise NotImplementedError('This method must be implemented by subclasses') def mark_watched(self, *args, **kwargs): - if (self._downloader.params.get('mark_watched', False) and + if (self.params.get('mark_watched', False) and (self._get_login_info()[0] is not None or - self._downloader.params.get('cookiefile') is not None)): + self.params.get('cookiefile') is not None)): self._mark_watched(*args, **kwargs) def _mark_watched(self, *args, **kwargs): diff --git a/youtube_dl/extractor/commonmistakes.py b/youtube_dl/extractor/commonmistakes.py index 2f86e2381..998e340f5 100644 --- a/youtube_dl/extractor/commonmistakes.py +++ b/youtube_dl/extractor/commonmistakes.py @@ -24,7 +24,7 @@ class CommonMistakesIE(InfoExtractor): 'That doesn\'t make any sense. ' 'Simply remove the parameter in your command or configuration.' ) % url - if not self._downloader.params.get('verbose'): + if not self.params.get('verbose'): msg += ' Add -v to the command line to see what arguments and configuration youtube-dl got.' raise ExtractorError(msg, expected=True) diff --git a/youtube_dl/extractor/daum.py b/youtube_dl/extractor/daum.py index 86024a745..6a6b98f14 100644 --- a/youtube_dl/extractor/daum.py +++ b/youtube_dl/extractor/daum.py @@ -190,7 +190,7 @@ class DaumListIE(InfoExtractor): query_dict = compat_parse_qs(compat_urlparse.urlparse(url).query) if 'clipid' in query_dict: clip_id = query_dict['clipid'][0] - if self._downloader.params.get('noplaylist'): + if self.params.get('noplaylist'): self.to_screen('Downloading just video %s because of --no-playlist' % clip_id) return self.url_result(DaumClipIE._URL_TEMPLATE % clip_id, 'DaumClip') else: diff --git a/youtube_dl/extractor/deezer.py b/youtube_dl/extractor/deezer.py index c3205ff5f..9a151b587 100644 --- a/youtube_dl/extractor/deezer.py +++ b/youtube_dl/extractor/deezer.py @@ -26,7 +26,7 @@ class DeezerPlaylistIE(InfoExtractor): } def _real_extract(self, url): - if 'test' not in self._downloader.params: + if 'test' not in self.params: self._downloader.report_warning('For now, this extractor only supports the 30 second previews. Patches welcome!') mobj = re.match(self._VALID_URL, url) diff --git a/youtube_dl/extractor/generic.py b/youtube_dl/extractor/generic.py index 589d1e152..605df716e 100644 --- a/youtube_dl/extractor/generic.py +++ b/youtube_dl/extractor/generic.py @@ -1212,7 +1212,7 @@ class GenericIE(InfoExtractor): parsed_url = compat_urlparse.urlparse(url) if not parsed_url.scheme: - default_search = self._downloader.params.get('default_search') + default_search = self.params.get('default_search') if default_search is None: default_search = 'fixup_error' @@ -1301,8 +1301,8 @@ class GenericIE(InfoExtractor): info_dict['formats'] = formats return info_dict - if not self._downloader.params.get('test', False) and not is_intentional: - force = self._downloader.params.get('force_generic_extractor', False) + if not self.params.get('test', False) and not is_intentional: + force = self.params.get('force_generic_extractor', False) self._downloader.report_warning( '%s on generic information extractor.' % ('Forcing' if force else 'Falling back')) diff --git a/youtube_dl/extractor/leeco.py b/youtube_dl/extractor/leeco.py index 375fdaed1..58df591fb 100644 --- a/youtube_dl/extractor/leeco.py +++ b/youtube_dl/extractor/leeco.py @@ -124,7 +124,7 @@ class LeIE(InfoExtractor): play_json_req = sanitized_Request( 'http://api.le.com/mms/out/video/playJson?' + compat_urllib_parse_urlencode(params) ) - cn_verification_proxy = self._downloader.params.get('cn_verification_proxy') + cn_verification_proxy = self.params.get('cn_verification_proxy') if cn_verification_proxy: play_json_req.add_header('Ytdl-request-proxy', cn_verification_proxy) diff --git a/youtube_dl/extractor/nba.py b/youtube_dl/extractor/nba.py index d896b0d04..e6ae1e4d8 100644 --- a/youtube_dl/extractor/nba.py +++ b/youtube_dl/extractor/nba.py @@ -113,7 +113,7 @@ class NBAIE(InfoExtractor): def _extract_playlist(self, orig_path, video_id, webpage): team = orig_path.split('/')[0] - if self._downloader.params.get('noplaylist'): + if self.params.get('noplaylist'): self.to_screen('Downloading just video because of --no-playlist') video_path = self._search_regex( r'nbaVideoCore\.firstVideo\s*=\s*\'([^\']+)\';', webpage, 'video path') diff --git a/youtube_dl/extractor/neteasemusic.py b/youtube_dl/extractor/neteasemusic.py index 0d36474fa..a3adf97a7 100644 --- a/youtube_dl/extractor/neteasemusic.py +++ b/youtube_dl/extractor/neteasemusic.py @@ -392,7 +392,7 @@ class NetEaseMusicProgramIE(NetEaseMusicBaseIE): name = info['name'] description = info['description'] - if not info['songs'] or self._downloader.params.get('noplaylist'): + if not info['songs'] or self.params.get('noplaylist'): if info['songs']: self.to_screen( 'Downloading just the main audio %s because of --no-playlist' diff --git a/youtube_dl/extractor/pluralsight.py b/youtube_dl/extractor/pluralsight.py index df03dd419..9e32ed10b 100644 --- a/youtube_dl/extractor/pluralsight.py +++ b/youtube_dl/extractor/pluralsight.py @@ -167,18 +167,18 @@ class PluralsightIE(PluralsightBaseIE): # In order to minimize the number of calls to ViewClip API and reduce # the probability of being throttled or banned by Pluralsight we will request # only single format until formats listing was explicitly requested. - if self._downloader.params.get('listformats', False): + if self.params.get('listformats', False): allowed_qualities = ALLOWED_QUALITIES else: def guess_allowed_qualities(): - req_format = self._downloader.params.get('format') or 'best' + req_format = self.params.get('format') or 'best' req_format_split = req_format.split('-', 1) if len(req_format_split) > 1: req_ext, req_quality = req_format_split for allowed_quality in ALLOWED_QUALITIES: if req_ext == allowed_quality.ext and req_quality in allowed_quality.qualities: return (AllowedQuality(req_ext, (req_quality, )), ) - req_ext = 'webm' if self._downloader.params.get('prefer_free_formats') else 'mp4' + req_ext = 'webm' if self.params.get('prefer_free_formats') else 'mp4' return (AllowedQuality(req_ext, (best_quality, )), ) allowed_qualities = guess_allowed_qualities() diff --git a/youtube_dl/extractor/smotri.py b/youtube_dl/extractor/smotri.py index 5c3fd0fec..d7c6b3266 100644 --- a/youtube_dl/extractor/smotri.py +++ b/youtube_dl/extractor/smotri.py @@ -170,7 +170,7 @@ class SmotriIE(InfoExtractor): 'getvideoinfo': '1', } - video_password = self._downloader.params.get('videopassword') + video_password = self.params.get('videopassword') if video_password: video_form['pass'] = hashlib.md5(video_password.encode('utf-8')).hexdigest() @@ -356,7 +356,7 @@ class SmotriBroadcastIE(InfoExtractor): url = 'http://smotri.com/broadcast/view/url/?ticket=%s' % ticket - broadcast_password = self._downloader.params.get('videopassword') + broadcast_password = self.params.get('videopassword') if broadcast_password: url += '&pass=%s' % hashlib.md5(broadcast_password.encode('utf-8')).hexdigest() diff --git a/youtube_dl/extractor/sohu.py b/youtube_dl/extractor/sohu.py index 49e5d09ae..f587503aa 100644 --- a/youtube_dl/extractor/sohu.py +++ b/youtube_dl/extractor/sohu.py @@ -98,7 +98,7 @@ class SohuIE(InfoExtractor): req = sanitized_Request(base_data_url + vid_id) - cn_verification_proxy = self._downloader.params.get('cn_verification_proxy') + cn_verification_proxy = self.params.get('cn_verification_proxy') if cn_verification_proxy: req.add_header('Ytdl-request-proxy', cn_verification_proxy) diff --git a/youtube_dl/extractor/vimeo.py b/youtube_dl/extractor/vimeo.py index 707a5735a..fbce4e3db 100644 --- a/youtube_dl/extractor/vimeo.py +++ b/youtube_dl/extractor/vimeo.py @@ -250,7 +250,7 @@ class VimeoIE(VimeoBaseInfoExtractor): return mobj.group(1) def _verify_video_password(self, url, video_id, webpage): - password = self._downloader.params.get('videopassword') + password = self.params.get('videopassword') if password is None: raise ExtractorError('This video is protected by a password, use the --video-password option', expected=True) token, vuid = self._extract_xsrft_and_vuid(webpage) @@ -270,7 +270,7 @@ class VimeoIE(VimeoBaseInfoExtractor): 'Verifying the password', 'Wrong password') def _verify_player_video_password(self, url, video_id): - password = self._downloader.params.get('videopassword') + password = self.params.get('videopassword') if password is None: raise ExtractorError('This video is protected by a password, use the --video-password option') data = urlencode_postdata({'password': password}) @@ -567,7 +567,7 @@ class VimeoChannelIE(VimeoBaseInfoExtractor): if not login_form: return webpage - password = self._downloader.params.get('videopassword') + password = self.params.get('videopassword') if password is None: raise ExtractorError('This album is protected by a password, use the --video-password option', expected=True) fields = self._hidden_inputs(login_form) diff --git a/youtube_dl/extractor/youku.py b/youtube_dl/extractor/youku.py index fd7eb5a6d..8a5b5fb3a 100644 --- a/youtube_dl/extractor/youku.py +++ b/youtube_dl/extractor/youku.py @@ -206,7 +206,7 @@ class YoukuIE(InfoExtractor): self._set_cookie('youku.com', 'xreferrer', 'http://www.youku.com') req = sanitized_Request(req_url, headers=headers) - cn_verification_proxy = self._downloader.params.get('cn_verification_proxy') + cn_verification_proxy = self.params.get('cn_verification_proxy') if cn_verification_proxy: req.add_header('Ytdl-request-proxy', cn_verification_proxy) @@ -214,7 +214,7 @@ class YoukuIE(InfoExtractor): return raw_data['data'] - video_password = self._downloader.params.get('videopassword') + video_password = self.params.get('videopassword') # request basic data basic_data_url = 'http://play.youku.com/play/get.json?vid=%s&ct=12' % video_id diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 28355bf46..28f00d08f 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -888,7 +888,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): download_note = ( 'Downloading player %s' % player_url - if self._downloader.params.get('verbose') else + if self.params.get('verbose') else 'Downloading %s player %s' % (player_type, player_id) ) if player_type == 'js': @@ -985,7 +985,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): ) self._player_cache[player_id] = func func = self._player_cache[player_id] - if self._downloader.params.get('youtube_print_sig_code'): + if self.params.get('youtube_print_sig_code'): self._print_sig_code(func, s) return func(s) except Exception as e: @@ -1179,7 +1179,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): url, smuggled_data = unsmuggle_url(url, {}) proto = ( - 'http' if self._downloader.params.get('prefer_insecure', False) + 'http' if self.params.get('prefer_insecure', False) else 'https') start_time = None @@ -1253,7 +1253,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): add_dash_mpd(video_info) if args.get('livestream') == '1' or args.get('live_playback') == 1: is_live = True - if not video_info or self._downloader.params.get('youtube_include_dash_manifest', True): + if not video_info or self.params.get('youtube_include_dash_manifest', True): # We also try looking in get_video_info since it may contain different dashmpd # URL that points to a DASH manifest with possibly different itag set (some itags # are missing from DASH manifest pointed by webpage's dashmpd, some - from DASH @@ -1331,7 +1331,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): video_description = '' if 'multifeed_metadata_list' in video_info and not smuggled_data.get('force_singlefeed', False): - if not self._downloader.params.get('noplaylist'): + if not self.params.get('noplaylist'): entries = [] feed_ids = [] multifeed_metadata_list = video_info['multifeed_metadata_list'][0] @@ -1457,7 +1457,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): # annotations video_annotations = None - if self._downloader.params.get('writeannotations', False): + if self.params.get('writeannotations', False): video_annotations = self._extract_annotations(video_id) def _map_to_format_list(urlmap): @@ -1532,7 +1532,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): video_webpage, 'age gate player URL') player_url = json.loads(player_url_json) - if self._downloader.params.get('verbose'): + if self.params.get('verbose'): if player_url is None: player_version = 'unknown' player_desc = 'unknown' @@ -1627,7 +1627,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor): raise ExtractorError('no conn, hlsvp or url_encoded_fmt_stream_map information found in video info') # Look for the DASH manifest - if self._downloader.params.get('youtube_include_dash_manifest', True): + if self.params.get('youtube_include_dash_manifest', True): dash_mpd_fatal = True for mpd_url in dash_mpds: dash_formats = {} @@ -1862,7 +1862,7 @@ class YoutubePlaylistIE(YoutubePlaylistBaseInfoExtractor): query_dict = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query) if 'v' in query_dict: video_id = query_dict['v'][0] - if self._downloader.params.get('noplaylist'): + if self.params.get('noplaylist'): self.to_screen('Downloading just video %s because of --no-playlist' % video_id) return self.url_result(video_id, 'Youtube', video_id=video_id) else: