summary refs log tree commit diff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2017-02-06 00:20:30 +0700
committerSergey M․ <dstftw@gmail.com>2017-02-06 00:20:30 +0700
commit2aec7256ae3ef877cc57f7d27f0fa171a7f25a98 (patch)
treefe9af6df1494ab64ee079a6eadef1189647ab9a8
parent815482d4eb03c2b3ea319288cc66b38406dbb9d5 (diff)
downloadyoutube-dl-2aec7256ae3ef877cc57f7d27f0fa171a7f25a98.tar.gz
youtube-dl-2aec7256ae3ef877cc57f7d27f0fa171a7f25a98.tar.xz
youtube-dl-2aec7256ae3ef877cc57f7d27f0fa171a7f25a98.zip
[extractor/common] Speed-up media tags regex (closes #11979)
-rw-r--r--youtube_dl/extractor/common.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py
index 2c8ec1417..519188622 100644
--- a/youtube_dl/extractor/common.py
+++ b/youtube_dl/extractor/common.py
@@ -1959,7 +1959,12 @@ class InfoExtractor(object):
         media_tags = [(media_tag, media_type, '')
                       for media_tag, media_type
                       in re.findall(r'(?s)(<(video|audio)[^>]*/>)', webpage)]
-        media_tags.extend(re.findall(r'(?s)(<(?P<tag>video|audio)[^>]*>)(.*?)</(?P=tag)>', webpage))
+        media_tags.extend(re.findall(
+            # We only allow video|audio followed by a whitespace or '>'.
+            # Allowing more characters may end up in significant slow down (see
+            # https://github.com/rg3/youtube-dl/issues/11979, example URL:
+            # http://www.porntrex.com/maps/videositemap.xml).
+            r'(?s)(<(?P<tag>video|audio)(?:\s+[^>]*)?>)(.*?)</(?P=tag)>', webpage))
         for media_tag, media_type, media_content in media_tags:
             media_info = {
                 'formats': [],