[extractor/common] Eliminate media tag name regex duplication
authorSergey M․ <dstftw@gmail.com>
Sun, 6 Dec 2020 17:55:49 +0000 (00:55 +0700)
committerSergey M․ <dstftw@gmail.com>
Sun, 6 Dec 2020 17:56:29 +0000 (00:56 +0700)
youtube_dl/extractor/common.py

index 864596e66a6a4a3fc88f1ac8e8b9339ffd2aa439..877873ebd3bb4fae3b753a0c41049294e4d75ba0 100644 (file)
@@ -2513,15 +2513,16 @@ class InfoExtractor(object):
         # amp-video and amp-audio are very similar to their HTML5 counterparts
         # so we wll include them right here (see
         # https://www.ampproject.org/docs/reference/components/amp-video)
+        _MEDIA_TAG_NAME_RE = r'(?:amp-)?(video|audio)'
         media_tags = [(media_tag, media_type, '')
                       for media_tag, media_type
-                      in re.findall(r'(?s)(<(?:amp-)?(video|audio)[^>]*/>)', webpage)]
+                      in re.findall(r'(?s)(<%s[^>]*/>)' % _MEDIA_TAG_NAME_RE, 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/ytdl-org/youtube-dl/issues/11979, example URL:
             # http://www.porntrex.com/maps/videositemap.xml).
-            r'(?s)(<(?P<tag>(?:amp-)?(video|audio))(?:\s+[^>]*)?>)(.*?)</(?P=tag)>', webpage))
+            r'(?s)(<(?P<tag>%s)(?:\s+[^>]*)?>)(.*?)</(?P=tag)>' % _MEDIA_TAG_NAME_RE, webpage))
         for media_tag, _, media_type, media_content in media_tags:
             media_info = {
                 'formats': [],