[ytdl] improve module imports (#1680)
Apply 'extractor.ytdl.module' for every URL, not just the first.
This commit is contained in:
@@ -15,13 +15,9 @@ import os
|
|||||||
|
|
||||||
class YoutubeDLDownloader(DownloaderBase):
|
class YoutubeDLDownloader(DownloaderBase):
|
||||||
scheme = "ytdl"
|
scheme = "ytdl"
|
||||||
module = None
|
|
||||||
|
|
||||||
def __init__(self, job):
|
def __init__(self, job):
|
||||||
module = self.module
|
module = __import__(self.config("module") or "youtube_dl")
|
||||||
if not module:
|
|
||||||
module_name = self.config("module") or "youtube_dl"
|
|
||||||
module = YoutubeDLDownloader.module = __import__(module_name)
|
|
||||||
|
|
||||||
DownloaderBase.__init__(self, job)
|
DownloaderBase.__init__(self, job)
|
||||||
extractor = job.extractor
|
extractor = job.extractor
|
||||||
|
|||||||
@@ -20,43 +20,37 @@ class YoutubeDLExtractor(Extractor):
|
|||||||
archive_fmt = "{extractor_key} {id}"
|
archive_fmt = "{extractor_key} {id}"
|
||||||
pattern = r"ytdl:(.*)"
|
pattern = r"ytdl:(.*)"
|
||||||
test = ("ytdl:https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9",)
|
test = ("ytdl:https://www.youtube.com/watch?v=BaW_jenozKc&t=1s&end=9",)
|
||||||
ytdl_module = None
|
|
||||||
ytdl_module_name = None
|
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
# import main youtube_dl module
|
# import main youtube_dl module
|
||||||
module = self.ytdl_module
|
module_name = self.ytdl_module_name = config.get(
|
||||||
if not module:
|
("extractor", "ytdl"), "module") or "youtube_dl"
|
||||||
name = YoutubeDLExtractor.ytdl_module_name = config.get(
|
module = __import__(module_name)
|
||||||
("extractor", "ytdl"), "module") or "youtube_dl"
|
|
||||||
module = YoutubeDLExtractor.ytdl_module = __import__(name)
|
|
||||||
|
|
||||||
# find suitable youtube_dl extractor
|
# find suitable youtube_dl extractor
|
||||||
self.ytdl_url = url = match.group(1)
|
self.ytdl_url = url = match.group(1)
|
||||||
generic = config.interpolate(("extractor", "ytdl"), "generic", True)
|
generic = config.interpolate(("extractor", "ytdl"), "generic", True)
|
||||||
if generic == "force":
|
if generic == "force":
|
||||||
self.ytdl_ie = ie = module.extractor.GenericIE
|
self.ytdl_ie_key = "Generic"
|
||||||
self.force_generic_extractor = True
|
self.force_generic_extractor = True
|
||||||
else:
|
else:
|
||||||
for ie in module.extractor.gen_extractor_classes():
|
for ie in module.extractor.gen_extractor_classes():
|
||||||
if ie.suitable(url):
|
if ie.suitable(url):
|
||||||
self.ytdl_ie = ie
|
self.ytdl_ie_key = ie.ie_key()
|
||||||
break
|
break
|
||||||
if not generic and ie == module.extractor.GenericIE:
|
if not generic and self.ytdl_ie_key == "Generic":
|
||||||
raise exception.NoExtractorError()
|
raise exception.NoExtractorError()
|
||||||
self.force_generic_extractor = False
|
self.force_generic_extractor = False
|
||||||
|
|
||||||
# set subcategory to youtube_dl extractor's key
|
# set subcategory to youtube_dl extractor's key
|
||||||
self.subcategory = ie.ie_key()
|
self.subcategory = self.ytdl_ie_key
|
||||||
Extractor.__init__(self, match)
|
Extractor.__init__(self, match)
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
# check subcategory module; import and use if needed
|
# import subcategory module
|
||||||
name = config.get(("extractor", "ytdl", self.subcategory), "module")
|
ytdl_module = __import__(
|
||||||
if name and name != self.ytdl_module_name:
|
config.get(("extractor", "ytdl", self.subcategory), "module") or
|
||||||
ytdl_module = __import__(name)
|
self.ytdl_module_name)
|
||||||
else:
|
|
||||||
ytdl_module = self.ytdl_module
|
|
||||||
self.log.debug("Using %s", ytdl_module)
|
self.log.debug("Using %s", ytdl_module)
|
||||||
|
|
||||||
# construct YoutubeDL object
|
# construct YoutubeDL object
|
||||||
@@ -92,7 +86,7 @@ class YoutubeDLExtractor(Extractor):
|
|||||||
# extract youtube_dl info_dict
|
# extract youtube_dl info_dict
|
||||||
info_dict = ytdl._YoutubeDL__extract_info(
|
info_dict = ytdl._YoutubeDL__extract_info(
|
||||||
self.ytdl_url,
|
self.ytdl_url,
|
||||||
ytdl.get_info_extractor(self.ytdl_ie.ie_key()),
|
ytdl.get_info_extractor(self.ytdl_ie_key),
|
||||||
False, {}, True)
|
False, {}, True)
|
||||||
|
|
||||||
if "entries" in info_dict:
|
if "entries" in info_dict:
|
||||||
|
|||||||
Reference in New Issue
Block a user