Skip to content

Commit

Permalink
[InfoExtractor] Support some warning and ._downloader shortcut meth…
Browse files Browse the repository at this point in the history
…ods from yt-dlp
  • Loading branch information
dirkf committed Jan 15, 2024
1 parent be008e6 commit 5831eaa
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion youtube_dl/extractor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,14 @@ def set_downloader(self, downloader):
"""Sets 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 _real_initialize(self):
"""Real initialization process. Redefine in subclasses."""
pass
Expand Down Expand Up @@ -947,9 +955,38 @@ def report_warning(self, msg, video_id=None):
self._downloader.report_warning(
'[%s] %s%s' % (self.IE_NAME, idstr, msg))

def __ie_msg(self, msg):
return '[{0}] {1}'.format(self.IE_NAME, msg)

def to_screen(self, msg):
"""Print msg to screen, prefixing it with '[ie_name]'"""
self._downloader.to_screen('[%s] %s' % (self.IE_NAME, msg))
self._downloader.to_screen(self.__ie_msg(msg))

def write_debug(self, msg, only_once=False, _cache=[]):
'''Log debug message or Print message to stderr'''
if not self.get_param('verbose', False):
return
message = '[debug] ' + self.__ie_msg(msg)
logger = self.get_param('logger')
if logger:
logger.debug(message)
else:
if only_once and hash(message) in _cache:
return
self._downloader.to_stderr(message)
_cache.append(hash(message))

# name, default=None, *args, **kwargs
def get_param(self, name, *args, **kwargs):
default, args = (args[0], args[1:]) if len(args) > 0 else (kwargs.pop('default', None), args)
if self._downloader:
return self._downloader.params.get(name, default, *args, **kwargs)
return default

def report_drm(self, video_id, partial=NO_DEFAULT):
if partial is not NO_DEFAULT:
self._downloader.deprecation_warning('InfoExtractor.report_drm no longer accepts the argument partial')
self.raise_no_formats('This video is DRM protected', expected=True, video_id=video_id)

def report_extraction(self, id_or_name):
"""Report information extraction."""
Expand Down Expand Up @@ -977,6 +1014,15 @@ def raise_login_required(msg='This video is only available for registered users'
def raise_geo_restricted(msg='This video is not available from your location due to geo restriction', countries=None):
raise GeoRestrictedError(msg, countries=countries)

def raise_no_formats(self, msg, expected=False, video_id=None):
if expected and (
self.get_param('ignore_no_formats_error') or self.get_param('wait_for_video')):
self.report_warning(msg, video_id)
elif isinstance(msg, ExtractorError):
raise msg
else:
raise ExtractorError(msg, expected=expected, video_id=video_id)

# Methods for following #608
@staticmethod
def url_result(url, ie=None, video_id=None, video_title=None):
Expand Down

0 comments on commit 5831eaa

Please sign in to comment.