youtube-dl: In yt-dlp _VALID_URL_RE is now an iterable of regexes

This commit is contained in:
Teemu Ikonen 2023-06-29 23:12:05 +03:00
parent b1492e60e5
commit d64eb6e0b2
1 changed files with 10 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import os
import re
import sys
import time
from collections.abc import Iterable
try:
import yt_dlp as youtube_dl
@ -311,7 +312,7 @@ class gPodderYoutubeDL(download.CustomDownloader):
# Don't create downloaders for URLs supported by these youtube-dl extractors
self.ie_blacklist = ["Generic"]
# Cache URL regexes from youtube-dl matches here, seed with youtube regex
self.regex_cache = [re.compile(r'https://www.youtube.com/watch\?v=.+')]
self.regex_cache = [(re.compile(r'https://www.youtube.com/watch\?v=.+'),)]
# #686 on windows without a console, sys.stdout is None, causing exceptions
# when adding podcasts.
# See https://docs.python.org/3/library/sys.html#sys.__stderr__ Note
@ -453,12 +454,11 @@ class gPodderYoutubeDL(download.CustomDownloader):
def is_supported_url(self, url):
if url is None:
return False
if self.regex_cache[0].match(url) is not None:
return True
for r in self.regex_cache[1:]:
if r.match(url) is not None:
self.regex_cache.remove(r)
self.regex_cache.insert(0, r)
for i, res in enumerate(self.regex_cache):
if next(filter(None, (r.match(url) for r in res)), None) is not None:
if i > 0:
self.regex_cache.remove(res)
self.regex_cache.insert(0, res)
return True
with youtube_dl.YoutubeDL(self._ydl_opts) as ydl:
# youtube-dl returns a list, yt-dlp returns a dict
@ -467,7 +467,9 @@ class gPodderYoutubeDL(download.CustomDownloader):
ies = ydl._ies.values()
for ie in ies:
if ie.suitable(url) and ie.ie_key() not in self.ie_blacklist:
self.regex_cache.insert(0, ie._VALID_URL_RE)
self.regex_cache.insert(
0, (ie._VALID_URL_RE if isinstance(ie._VALID_URL_RE, Iterable)
else (ie._VALID_URL_RE,)))
return True
return False