mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-09 12:50:23 -05:00
load plugins in youtubedl if they haven't already
This commit is contained in:
parent
cb9e38a797
commit
3561d2a08f
4 changed files with 19 additions and 3 deletions
|
@ -6,6 +6,8 @@
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch
|
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__))))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
|
|
||||||
|
@ -1396,6 +1398,12 @@ def check_for_cookie_header(result):
|
||||||
self.assertFalse(result.get('cookies'), msg='Cookies set in cookies field for wrong domain')
|
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')
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
LAZY_EXTRACTORS,
|
LAZY_EXTRACTORS,
|
||||||
plugin_ies,
|
plugin_ies,
|
||||||
plugin_overrides,
|
plugin_overrides,
|
||||||
plugin_pps,
|
plugin_pps, ALL_PLUGINS_LOADED,
|
||||||
)
|
)
|
||||||
from .minicurses import format_text
|
from .minicurses import format_text
|
||||||
from .networking import HEADRequest, Request, RequestDirector
|
from .networking import HEADRequest, Request, RequestDirector
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
network_exceptions,
|
network_exceptions,
|
||||||
)
|
)
|
||||||
from .networking.impersonate import ImpersonateRequestHandler
|
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 (
|
from .postprocessor import (
|
||||||
EmbedThumbnailPP,
|
EmbedThumbnailPP,
|
||||||
FFmpegFixupDuplicateMoovPP,
|
FFmpegFixupDuplicateMoovPP,
|
||||||
|
@ -645,6 +645,10 @@ def __init__(self, params=None, auto_init=True):
|
||||||
self.cache = Cache(self)
|
self.cache = Cache(self)
|
||||||
self.__header_cookies = []
|
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
|
stdout = sys.stderr if self.params.get('logtostderr') else sys.stdout
|
||||||
self._out_files = Namespace(
|
self._out_files = Namespace(
|
||||||
out=stdout,
|
out=stdout,
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
# `False`=force, `None`=disabled, `True`=enabled
|
# `False`=force, `None`=disabled, `True`=enabled
|
||||||
LAZY_EXTRACTORS = ContextVar('LAZY_EXTRACTORS', default=False)
|
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
|
# `...`=search default plugin dirs
|
||||||
plugin_dirs = ContextVar('plugin_dirs', default=(..., ))
|
plugin_dirs = ContextVar('plugin_dirs', default=(..., ))
|
||||||
plugin_ies = ContextVar('plugin_ies', default={})
|
plugin_ies = ContextVar('plugin_ies', default={})
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
plugin_dirs,
|
plugin_dirs,
|
||||||
plugin_ies,
|
plugin_ies,
|
||||||
plugin_pps,
|
plugin_pps,
|
||||||
postprocessors, plugin_overrides,
|
postprocessors, plugin_overrides, ALL_PLUGINS_LOADED,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .compat import functools # isort: split
|
from .compat import functools # isort: split
|
||||||
|
@ -297,6 +297,7 @@ def load_plugins(plugin_type: PluginType):
|
||||||
def load_all_plugin_types():
|
def load_all_plugin_types():
|
||||||
for plugin_type in PluginType:
|
for plugin_type in PluginType:
|
||||||
load_plugins(plugin_type)
|
load_plugins(plugin_type)
|
||||||
|
ALL_PLUGINS_LOADED.set(True)
|
||||||
|
|
||||||
|
|
||||||
sys.meta_path.insert(0, PluginFinder(f'{PACKAGE_NAME}.extractor', f'{PACKAGE_NAME}.postprocessor'))
|
sys.meta_path.insert(0, PluginFinder(f'{PACKAGE_NAME}.extractor', f'{PACKAGE_NAME}.postprocessor'))
|
||||||
|
|
Loading…
Reference in a new issue