mirror of
https://github.com/yt-dlp/yt-dlp
synced 2025-01-19 10:26:56 +01:00
fix
This commit is contained in:
parent
3d939b68fe
commit
9f1f2c5410
5 changed files with 46 additions and 40 deletions
|
@ -52,7 +52,6 @@ from .networking.exceptions import (
|
||||||
)
|
)
|
||||||
from .networking.impersonate import ImpersonateRequestHandler
|
from .networking.impersonate import ImpersonateRequestHandler
|
||||||
from .plugins import directories as plugin_directories
|
from .plugins import directories as plugin_directories
|
||||||
from .postprocessor import _PLUGIN_CLASSES as plugin_pps
|
|
||||||
from .postprocessor import (
|
from .postprocessor import (
|
||||||
EmbedThumbnailPP,
|
EmbedThumbnailPP,
|
||||||
FFmpegFixupDuplicateMoovPP,
|
FFmpegFixupDuplicateMoovPP,
|
||||||
|
|
|
@ -19,6 +19,7 @@ from .cookies import SUPPORTED_BROWSERS, SUPPORTED_KEYRINGS, CookieLoadError
|
||||||
from .downloader.external import get_external_downloader
|
from .downloader.external import get_external_downloader
|
||||||
from .extractor import list_extractor_classes
|
from .extractor import list_extractor_classes
|
||||||
from .extractor.adobepass import MSO_INFO
|
from .extractor.adobepass import MSO_INFO
|
||||||
|
from .networking.impersonate import ImpersonateTarget
|
||||||
from .globals import IN_CLI, plugin_dirs
|
from .globals import IN_CLI, plugin_dirs
|
||||||
from .options import parseOpts
|
from .options import parseOpts
|
||||||
from .plugins import load_all_plugin_types
|
from .plugins import load_all_plugin_types
|
||||||
|
|
|
@ -6,6 +6,7 @@ import hashlib
|
||||||
import http.client
|
import http.client
|
||||||
import http.cookiejar
|
import http.cookiejar
|
||||||
import http.cookies
|
import http.cookies
|
||||||
|
import inspect
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
|
@ -30,6 +31,7 @@ from ..compat import (
|
||||||
from ..cookies import LenientSimpleCookie
|
from ..cookies import LenientSimpleCookie
|
||||||
from ..downloader.f4m import get_base_url, remove_encrypted_media
|
from ..downloader.f4m import get_base_url, remove_encrypted_media
|
||||||
from ..downloader.hls import HlsFD
|
from ..downloader.hls import HlsFD
|
||||||
|
from ..globals import plugin_overrides
|
||||||
from ..networking import HEADRequest, Request
|
from ..networking import HEADRequest, Request
|
||||||
from ..networking.exceptions import (
|
from ..networking.exceptions import (
|
||||||
HTTPError,
|
HTTPError,
|
||||||
|
@ -3932,8 +3934,17 @@ class InfoExtractor:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __init_subclass__(cls, *, plugin_name=None, **kwargs):
|
def __init_subclass__(cls, *, plugin_name=None, **kwargs):
|
||||||
if plugin_name is not None:
|
if plugin_name:
|
||||||
cls._plugin_name = plugin_name
|
mro = inspect.getmro(cls)
|
||||||
|
super_class = cls.__wrapped__ = mro[mro.index(cls) + 1]
|
||||||
|
cls.PLUGIN_NAME, cls.ie_key = plugin_name, super_class.ie_key
|
||||||
|
cls.IE_NAME = f'{super_class.IE_NAME}+{plugin_name}'
|
||||||
|
while getattr(super_class, '__wrapped__', None):
|
||||||
|
super_class = super_class.__wrapped__
|
||||||
|
setattr(sys.modules[super_class.__module__], super_class.__name__, cls)
|
||||||
|
plugin_overrides.get()[super_class].append(cls)
|
||||||
|
# if plugin_name is not None:
|
||||||
|
# cls._plugin_name = plugin_name
|
||||||
return super().__init_subclass__(**kwargs)
|
return super().__init_subclass__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ from .globals import (
|
||||||
extractors,
|
extractors,
|
||||||
plugin_dirs,
|
plugin_dirs,
|
||||||
plugin_ies,
|
plugin_ies,
|
||||||
plugin_overrides,
|
|
||||||
plugin_pps,
|
plugin_pps,
|
||||||
postprocessors,
|
postprocessors,
|
||||||
)
|
)
|
||||||
|
@ -167,16 +166,13 @@ def iter_modules(subpackage):
|
||||||
|
|
||||||
|
|
||||||
def load_module(module, module_name, suffix):
|
def load_module(module, module_name, suffix):
|
||||||
return inspect.getmembers(
|
result = inspect.getmembers(module, lambda obj: (
|
||||||
module,
|
inspect.isclass(obj)
|
||||||
lambda obj: (
|
and obj.__name__.endswith(suffix)
|
||||||
inspect.isclass(obj)
|
and obj.__module__.startswith(module_name)
|
||||||
and obj.__name__.endswith(suffix)
|
and not obj.__name__.startswith('_')
|
||||||
and obj.__module__.startswith(module_name)
|
and obj.__name__ in getattr(module, '__all__', [obj.__name__])))
|
||||||
and not obj.__name__.startswith('_')
|
return result
|
||||||
and obj.__name__ in getattr(module, '__all__', [obj.__name__])
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def load_plugins(plugin_type: PluginType):
|
def load_plugins(plugin_type: PluginType):
|
||||||
|
@ -221,42 +217,41 @@ def load_plugins(plugin_type: PluginType):
|
||||||
spec.loader.exec_module(plugins)
|
spec.loader.exec_module(plugins)
|
||||||
classes.update(load_module(plugins, spec.name, suffix))
|
classes.update(load_module(plugins, spec.name, suffix))
|
||||||
|
|
||||||
regular_plugins = {}
|
# regular_plugins = {}
|
||||||
# __init_subclass__ was removed so we manually add overrides
|
# __init_subclass__ was removed so we manually add overrides
|
||||||
for name, klass in classes.items():
|
# for name, klass in classes.items():
|
||||||
plugin_name = getattr(klass, '_plugin_name', None)
|
# plugin_name = getattr(klass, '_plugin_name', None)
|
||||||
if not plugin_name:
|
# if not plugin_name:
|
||||||
regular_plugins[name] = klass
|
# regular_plugins[name] = klass
|
||||||
continue
|
# continue
|
||||||
|
|
||||||
# FIXME: Most likely something wrong here
|
# FIXME: Most likely something wrong here
|
||||||
mro = inspect.getmro(klass)
|
# This does not work as plugin overrides are not available here. They are not imported in plugin_ies.
|
||||||
super_class = klass.__wrapped__ = mro[mro.index(klass) + 1]
|
|
||||||
klass.PLUGIN_NAME, klass.ie_key = plugin_name, super_class.ie_key
|
# mro = inspect.getmro(klass)
|
||||||
klass.IE_NAME = f'{super_class.IE_NAME}+{plugin_name}'
|
# super_class = klass.__wrapped__ = mro[mro.index(klass) + 1]
|
||||||
while getattr(super_class, '__wrapped__', None):
|
# klass.PLUGIN_NAME, klass.ie_key = plugin_name, super_class.ie_key
|
||||||
super_class = super_class.__wrapped__
|
# klass.IE_NAME = f'{super_class.IE_NAME}+{plugin_name}'
|
||||||
setattr(sys.modules[super_class.__module__], super_class.__name__, klass)
|
# while getattr(super_class, '__wrapped__', None):
|
||||||
plugin_overrides.get()[super_class].append(klass)
|
# super_class = super_class.__wrapped__
|
||||||
|
# setattr(sys.modules[super_class.__module__], super_class.__name__, klass)
|
||||||
|
# plugin_overrides.get()[super_class].append(klass)
|
||||||
|
|
||||||
# Add the classes into the global plugin lookup
|
# Add the classes into the global plugin lookup
|
||||||
plugin_destination.set(regular_plugins)
|
plugin_destination.set(classes)
|
||||||
# We want to prepend to the main lookup
|
# # We want to prepend to the main lookup
|
||||||
current = destination.get()
|
destination.set(merge_dicts(destination.get(), classes))
|
||||||
result = merge_dicts(regular_plugins, current)
|
|
||||||
destination.set(result)
|
|
||||||
|
|
||||||
return result
|
return classes
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
load_plugins(PluginType.EXTRACTORS)
|
||||||
|
|
||||||
|
|
||||||
sys.meta_path.insert(
|
sys.meta_path.insert(0, PluginFinder(f'{PACKAGE_NAME}.extractor', f'{PACKAGE_NAME}.postprocessor'))
|
||||||
0, PluginFinder(f'{PACKAGE_NAME}.extractor', f'{PACKAGE_NAME}.postprocessor'),
|
|
||||||
)
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'directories',
|
'directories',
|
||||||
|
|
|
@ -52,7 +52,7 @@ from ..compat import (
|
||||||
compat_os_name,
|
compat_os_name,
|
||||||
)
|
)
|
||||||
from ..dependencies import xattr
|
from ..dependencies import xattr
|
||||||
from .globals import IN_CLI
|
from ..globals import IN_CLI
|
||||||
|
|
||||||
__name__ = __name__.rsplit('.', 1)[0] # noqa: A001: Pretend to be the parent module
|
__name__ = __name__.rsplit('.', 1)[0] # noqa: A001: Pretend to be the parent module
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue