[extractor] Improve `url_result` and related

This commit is contained in:
pukkandan 2022-01-20 07:06:42 +05:30
parent 396a76f7bf
commit 311b6615d8
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698
1 changed files with 23 additions and 23 deletions

View File

@ -1120,39 +1120,39 @@ class InfoExtractor(object):
# Methods for following #608 # Methods for following #608
@staticmethod @staticmethod
def url_result(url, ie=None, video_id=None, video_title=None, **kwargs): def url_result(url, ie=None, video_id=None, video_title=None, *, url_transparent=False, **kwargs):
"""Returns a URL that points to a page that should be processed""" """Returns a URL that points to a page that should be processed"""
# TODO: ie should be the class used for getting the info if ie is not None:
video_info = {'_type': 'url', kwargs['ie_key'] = ie if isinstance(ie, str) else ie.ie_key()
'url': url,
'ie_key': ie}
video_info.update(kwargs)
if video_id is not None: if video_id is not None:
video_info['id'] = video_id kwargs['id'] = video_id
if video_title is not None: if video_title is not None:
video_info['title'] = video_title kwargs['title'] = video_title
return video_info return {
**kwargs,
'_type': 'url_transparent' if url_transparent else 'url',
'url': url,
}
def playlist_from_matches(self, matches, playlist_id=None, playlist_title=None, getter=None, ie=None): def playlist_from_matches(self, matches, playlist_id=None, playlist_title=None, getter=None, ie=None, **kwargs):
urls = orderedSet( urls = (self.url_result(self._proto_relative_url(m), ie)
self.url_result(self._proto_relative_url(getter(m) if getter else m), ie) for m in orderedSet(map(getter, matches) if getter else matches))
for m in matches) return self.playlist_result(urls, playlist_id, playlist_title, **kwargs)
return self.playlist_result(
urls, playlist_id=playlist_id, playlist_title=playlist_title)
@staticmethod @staticmethod
def playlist_result(entries, playlist_id=None, playlist_title=None, playlist_description=None, **kwargs): def playlist_result(entries, playlist_id=None, playlist_title=None, playlist_description=None, *, multi_video=False, **kwargs):
"""Returns a playlist""" """Returns a playlist"""
video_info = {'_type': 'playlist',
'entries': entries}
video_info.update(kwargs)
if playlist_id: if playlist_id:
video_info['id'] = playlist_id kwargs['id'] = playlist_id
if playlist_title: if playlist_title:
video_info['title'] = playlist_title kwargs['title'] = playlist_title
if playlist_description is not None: if playlist_description is not None:
video_info['description'] = playlist_description kwargs['description'] = playlist_description
return video_info return {
**kwargs,
'_type': 'multi_video' if multi_video else 'playlist',
'entries': entries,
}
def _search_regex(self, pattern, string, name, default=NO_DEFAULT, fatal=True, flags=0, group=None): def _search_regex(self, pattern, string, name, default=NO_DEFAULT, fatal=True, flags=0, group=None):
""" """