Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --dump-regexps option to print the regular expressions used to match supported sites #52

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions youtube-dl
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ class FileDownloader(object):
"""

params = None
_ies = []
ies = []
_pps = []
_download_retcode = None
_num_downloads = None
_screen_file = None

def __init__(self, params):
"""Create a FileDownloader object with the given options."""
self._ies = []
self.ies = []
self._pps = []
self._download_retcode = 0
self._num_downloads = 0
Expand Down Expand Up @@ -309,7 +309,7 @@ class FileDownloader(object):

def add_info_extractor(self, ie):
"""Add an InfoExtractor object to the end of the list."""
self._ies.append(ie)
self.ies.append(ie)
ie.set_downloader(self)

def add_post_processor(self, pp):
Expand Down Expand Up @@ -470,7 +470,7 @@ class FileDownloader(object):

for url in url_list:
suitable_found = False
for ie in self._ies:
for ie in self.ies:
# Go to next InfoExtractor if not suitable
if not ie.suitable(url):
continue
Expand Down Expand Up @@ -715,6 +715,10 @@ class InfoExtractor(object):
def set_downloader(self, downloader):
"""Sets the downloader for this IE."""
self._downloader = downloader

def url_regex(self):
"""Returns the regular expression used by this info extractor to match a URL."""
return getattr(self, '_VALID_URL', None)

def _real_initialize(self):
"""Real initialization process. Redefine in subclasses."""
Expand Down Expand Up @@ -2259,6 +2263,8 @@ if __name__ == '__main__':
dest='playlistend', metavar='NUMBER', help='playlist video to end at (default is last)', default=-1)
parser.add_option('--dump-user-agent',
action='store_true', dest='dump_user_agent', help='display the current browser identification', default=False)
parser.add_option('--dump-regexps',
action='store_true', dest='dump_regexps', help='display the regular expressions used to match supported sites', default=False)

authentication = optparse.OptionGroup(parser, 'Authentication Options')
authentication.add_option('-u', '--username',
Expand Down Expand Up @@ -2452,6 +2458,14 @@ if __name__ == '__main__':
# fallback if none of the others work
fd.add_info_extractor(generic_ie)

# Dump regular expressions used to match supported sites
if opts.dump_regexps:
for ie in fd.ies:
regex = ie.url_regex()
if regex is not None:
print ie.url_regex()
sys.exit(0)

# Update version
if opts.update_self:
update_self(fd, sys.argv[0])
Expand Down