Optimize get_youtube_id().

The watch URL is the most common and should be checked first. The swf
URL probably no longer works but can be kept for compatibility.
This commit is contained in:
auouymous 2021-10-14 19:19:12 -06:00
parent 8d0bfce460
commit 8a403d2783
1 changed files with 4 additions and 4 deletions

View File

@ -354,10 +354,6 @@ def get_real_download_url(url, allow_partial, preferred_fmt_ids=None):
def get_youtube_id(url):
r = re.compile(r'http[s]?://(?:[a-z]+\.)?youtube\.com/v/(.*)\.swf', re.IGNORECASE).match(url)
if r is not None:
return r.group(1)
r = re.compile(r'http[s]?://(?:[a-z]+\.)?youtube\.com/watch\?v=([^&]*)', re.IGNORECASE).match(url)
if r is not None:
return r.group(1)
@ -366,6 +362,10 @@ def get_youtube_id(url):
if r is not None:
return r.group(1)
r = re.compile(r'http[s]?://(?:[a-z]+\.)?youtube\.com/v/(.*)\.swf', re.IGNORECASE).match(url)
if r is not None:
return r.group(1)
return for_each_feed_pattern(lambda url, channel: channel, url, None)