load plugins in youtubedl if they haven't already

pull/11305/head
coletdjnz 2 months ago
parent cb9e38a797
commit 3561d2a08f
No known key found for this signature in database
GPG Key ID: 91984263BB39894A

@ -6,6 +6,8 @@ import sys
import unittest
from unittest.mock import patch
from yt_dlp._globals import ALL_PLUGINS_LOADED
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@ -1396,6 +1398,12 @@ class TestYoutubeDL(unittest.TestCase):
self.assertFalse(result.get('cookies'), msg='Cookies set in cookies field for wrong domain')
self.assertFalse(ydl.cookiejar.get_cookie_header(fmt['url']), msg='Cookies set in cookiejar for wrong domain')
def test_load_plugins_compat(self):
# Should try to reload plugins if they haven't already been loaded
ALL_PLUGINS_LOADED.set(False)
FakeYDL().close()
assert ALL_PLUGINS_LOADED.get()
if __name__ == '__main__':
unittest.main()

@ -38,7 +38,7 @@ from ._globals import (
LAZY_EXTRACTORS,
plugin_ies,
plugin_overrides,
plugin_pps,
plugin_pps, ALL_PLUGINS_LOADED,
)
from .minicurses import format_text
from .networking import HEADRequest, Request, RequestDirector
@ -51,7 +51,7 @@ from .networking.exceptions import (
network_exceptions,
)
from .networking.impersonate import ImpersonateRequestHandler
from .plugins import directories as plugin_directories
from .plugins import directories as plugin_directories, load_all_plugin_types
from .postprocessor import (
EmbedThumbnailPP,
FFmpegFixupDuplicateMoovPP,
@ -645,6 +645,10 @@ class YoutubeDL:
self.cache = Cache(self)
self.__header_cookies = []
# compat for API: load plugins if they have not already
if not ALL_PLUGINS_LOADED.get():
load_all_plugin_types()
stdout = sys.stderr if self.params.get('logtostderr') else sys.stdout
self._out_files = Namespace(
out=stdout,

@ -9,6 +9,9 @@ IN_CLI = ContextVar('IN_CLI', default=False)
# `False`=force, `None`=disabled, `True`=enabled
LAZY_EXTRACTORS = ContextVar('LAZY_EXTRACTORS', default=False)
# Whether plugins have been loaded once
ALL_PLUGINS_LOADED = ContextVar('PLUGINS_LOADED', default=False)
# `...`=search default plugin dirs
plugin_dirs = ContextVar('plugin_dirs', default=(..., ))
plugin_ies = ContextVar('plugin_ies', default={})

@ -22,7 +22,7 @@ from ._globals import (
plugin_dirs,
plugin_ies,
plugin_pps,
postprocessors, plugin_overrides,
postprocessors, plugin_overrides, ALL_PLUGINS_LOADED,
)
from .compat import functools # isort: split
@ -297,6 +297,7 @@ def load_plugins(plugin_type: PluginType):
def load_all_plugin_types():
for plugin_type in PluginType:
load_plugins(plugin_type)
ALL_PLUGINS_LOADED.set(True)
sys.meta_path.insert(0, PluginFinder(f'{PACKAGE_NAME}.extractor', f'{PACKAGE_NAME}.postprocessor'))

Loading…
Cancel
Save