mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-09 12:50:23 -05:00
some more refactoring
This commit is contained in:
parent
a6979c7ba7
commit
93aa21b3b2
13 changed files with 37 additions and 46 deletions
|
@ -12,7 +12,7 @@
|
||||||
from devscripts.utils import get_filename_args, read_file, write_file
|
from devscripts.utils import get_filename_args, read_file, write_file
|
||||||
from yt_dlp.extractor import import_extractors
|
from yt_dlp.extractor import import_extractors
|
||||||
from yt_dlp.extractor.common import InfoExtractor, SearchInfoExtractor
|
from yt_dlp.extractor.common import InfoExtractor, SearchInfoExtractor
|
||||||
from yt_dlp._globals import extractors
|
from yt_dlp.globals import extractors
|
||||||
|
|
||||||
NO_ATTR = object()
|
NO_ATTR = object()
|
||||||
STATIC_CLASS_PROPERTIES = [
|
STATIC_CLASS_PROPERTIES = [
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from yt_dlp._globals import all_plugins_loaded
|
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__))))
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
get_plugin_spec,
|
get_plugin_spec,
|
||||||
)
|
)
|
||||||
|
|
||||||
from yt_dlp._globals import (
|
from yt_dlp.globals import (
|
||||||
extractors,
|
extractors,
|
||||||
postprocessors,
|
postprocessors,
|
||||||
plugin_dirs,
|
plugin_dirs,
|
||||||
|
|
|
@ -33,11 +33,11 @@
|
||||||
from .extractor import gen_extractor_classes, get_info_extractor, import_extractors
|
from .extractor import gen_extractor_classes, get_info_extractor, import_extractors
|
||||||
from .extractor.common import UnsupportedURLIE
|
from .extractor.common import UnsupportedURLIE
|
||||||
from .extractor.openload import PhantomJSwrapper
|
from .extractor.openload import PhantomJSwrapper
|
||||||
from ._globals import (
|
from .globals import (
|
||||||
IN_CLI,
|
IN_CLI,
|
||||||
LAZY_EXTRACTORS,
|
LAZY_EXTRACTORS,
|
||||||
plugin_ies,
|
plugin_ies,
|
||||||
plugin_overrides,
|
plugin_ies_overrides,
|
||||||
plugin_pps,
|
plugin_pps,
|
||||||
all_plugins_loaded,
|
all_plugins_loaded,
|
||||||
plugin_dirs,
|
plugin_dirs,
|
||||||
|
@ -4090,7 +4090,7 @@ def get_encoding(stream):
|
||||||
for name, klass in plugins.value.items()]
|
for name, klass in plugins.value.items()]
|
||||||
if plugin_type == 'Extractor':
|
if plugin_type == 'Extractor':
|
||||||
display_list.extend(f'{plugins[-1].IE_NAME.partition("+")[2]} ({parent.__name__})'
|
display_list.extend(f'{plugins[-1].IE_NAME.partition("+")[2]} ({parent.__name__})'
|
||||||
for parent, plugins in plugin_overrides.value.items())
|
for parent, plugins in plugin_ies_overrides.value.items())
|
||||||
if not display_list:
|
if not display_list:
|
||||||
continue
|
continue
|
||||||
write_debug(f'{plugin_type} Plugins: {", ".join(sorted(display_list))}')
|
write_debug(f'{plugin_type} Plugins: {", ".join(sorted(display_list))}')
|
||||||
|
|
|
@ -19,11 +19,9 @@
|
||||||
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 .networking.impersonate import ImpersonateTarget
|
||||||
from ._globals import IN_CLI as _IN_CLI
|
from .globals import IN_CLI as _IN_CLI, plugin_dirs
|
||||||
from .options import parseOpts
|
from .options import parseOpts
|
||||||
from .plugins import load_all_plugins as _load_all_plugins
|
from .plugins import load_all_plugins as _load_all_plugins
|
||||||
from .plugins import disable_plugins as _disable_plugins
|
|
||||||
from .plugins import set_plugin_dirs as _set_plugin_dirs
|
|
||||||
from .postprocessor import (
|
from .postprocessor import (
|
||||||
FFmpegExtractAudioPP,
|
FFmpegExtractAudioPP,
|
||||||
FFmpegMergerPP,
|
FFmpegMergerPP,
|
||||||
|
@ -991,7 +989,10 @@ def _real_main(argv=None):
|
||||||
FFmpegPostProcessor._ffmpeg_location.set(opts.ffmpeg_location)
|
FFmpegPostProcessor._ffmpeg_location.set(opts.ffmpeg_location)
|
||||||
|
|
||||||
# load all plugins into the global lookup
|
# load all plugins into the global lookup
|
||||||
_set_plugin_dirs(*set(opts.plugin_dirs))
|
print(opts.plugin_dirs)
|
||||||
|
plugin_dirs.value = list(set(opts.plugin_dirs))
|
||||||
|
if plugin_dirs.value:
|
||||||
|
_load_all_plugins()
|
||||||
|
|
||||||
with YoutubeDL(ydl_opts) as ydl:
|
with YoutubeDL(ydl_opts) as ydl:
|
||||||
pre_process = opts.update_self or opts.rm_cachedir
|
pre_process = opts.update_self or opts.rm_cachedir
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from .._globals import extractors as _extractors_context
|
from ..globals import extractors as _extractors_context
|
||||||
from .._globals import plugin_ies as _plugin_ies_context
|
from ..globals import plugin_ies as _plugin_ies_context
|
||||||
from ..compat.compat_utils import passthrough_module
|
from ..compat.compat_utils import passthrough_module
|
||||||
from ..plugins import PluginSpec, register_plugin_spec
|
from ..plugins import PluginSpec, register_plugin_spec
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import xml.etree.ElementTree
|
import xml.etree.ElementTree
|
||||||
|
|
||||||
from .._globals import plugin_overrides as _plugin_overrides
|
from ..globals import plugin_ies_overrides as _plugin_overrides
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
compat_etree_fromstring,
|
compat_etree_fromstring,
|
||||||
compat_expanduser,
|
compat_expanduser,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from .._globals import LAZY_EXTRACTORS
|
from ..globals import LAZY_EXTRACTORS
|
||||||
from .._globals import extractors as _extractors_context
|
from ..globals import extractors as _extractors_context
|
||||||
|
|
||||||
_CLASS_LOOKUP = None
|
_CLASS_LOOKUP = None
|
||||||
if not os.environ.get('YTDLP_NO_LAZY_EXTRACTORS'):
|
if not os.environ.get('YTDLP_NO_LAZY_EXTRACTORS'):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
# Internal only - no backwards compatibility guaranteed
|
# Please Note: Due to necessary changes and the complex nature involved in the plugin/globals system,
|
||||||
|
# no backwards compatibility is guaranteed for the plugin system API.
|
||||||
|
# However, we will still try our best.
|
||||||
|
|
||||||
|
|
||||||
class Indirect:
|
class Indirect:
|
||||||
|
@ -14,14 +16,16 @@ def __repr__(self, /):
|
||||||
postprocessors = Indirect({})
|
postprocessors = Indirect({})
|
||||||
extractors = Indirect({})
|
extractors = Indirect({})
|
||||||
|
|
||||||
|
# Plugins
|
||||||
|
all_plugins_loaded = Indirect(False)
|
||||||
|
plugin_specs = Indirect({})
|
||||||
|
plugin_dirs = Indirect(['default'])
|
||||||
|
|
||||||
|
plugin_ies = Indirect({})
|
||||||
|
plugin_pps = Indirect({})
|
||||||
|
plugin_ies_overrides = Indirect(defaultdict(list))
|
||||||
|
|
||||||
|
# Misc
|
||||||
IN_CLI = Indirect(False)
|
IN_CLI = Indirect(False)
|
||||||
# `False`=force, `None`=disabled, `True`=enabled
|
# `False`=force, `None`=disabled, `True`=enabled
|
||||||
LAZY_EXTRACTORS = Indirect(False)
|
LAZY_EXTRACTORS = Indirect(False)
|
||||||
|
|
||||||
# Plugins
|
|
||||||
plugin_specs = Indirect({})
|
|
||||||
all_plugins_loaded = Indirect(False)
|
|
||||||
plugin_dirs = Indirect(['default'])
|
|
||||||
plugin_ies = Indirect({})
|
|
||||||
plugin_overrides = Indirect(defaultdict(list))
|
|
||||||
plugin_pps = Indirect({})
|
|
|
@ -413,6 +413,7 @@ def _alias_callback(option, opt_str, value, parser, opts, nargs):
|
||||||
metavar='PATH',
|
metavar='PATH',
|
||||||
dest='plugin_dirs',
|
dest='plugin_dirs',
|
||||||
action='append',
|
action='append',
|
||||||
|
default=['default'],
|
||||||
help=(
|
help=(
|
||||||
'Path to an additional directory to search for plugins. '
|
'Path to an additional directory to search for plugins. '
|
||||||
'This option can be used multiple times to add multiple directories. '))
|
'This option can be used multiple times to add multiple directories. '))
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from ._globals import (
|
from .globals import (
|
||||||
plugin_dirs,
|
plugin_dirs,
|
||||||
all_plugins_loaded,
|
all_plugins_loaded,
|
||||||
plugin_specs,
|
plugin_specs,
|
||||||
|
@ -37,19 +37,18 @@
|
||||||
_BASE_PACKAGE_PATH = Path(__file__).parent
|
_BASE_PACKAGE_PATH = Path(__file__).parent
|
||||||
|
|
||||||
|
|
||||||
# Public APIs
|
# Please Note: Due to necessary changes and the complex nature involved,
|
||||||
# Anything else is NOT public and no backwards compatibility is guaranteed
|
# no backwards compatibility is guaranteed for the plugin system API.
|
||||||
|
# However, we will still try our best.
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'COMPAT_PACKAGE_NAME',
|
'COMPAT_PACKAGE_NAME',
|
||||||
'PACKAGE_NAME',
|
'PACKAGE_NAME',
|
||||||
'add_plugin_dirs',
|
|
||||||
'directories',
|
'directories',
|
||||||
'disable_plugins',
|
'disable_plugins',
|
||||||
'get_plugin_spec',
|
|
||||||
'load_all_plugins',
|
'load_all_plugins',
|
||||||
'load_plugins',
|
'load_plugins',
|
||||||
'register_plugin_spec',
|
'register_plugin_spec',
|
||||||
'set_plugin_dirs',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -264,20 +263,6 @@ def register_plugin_spec(plugin_spec: PluginSpec):
|
||||||
sys.meta_path.insert(0, PluginFinder(f'{PACKAGE_NAME}.{plugin_spec.module_name}'))
|
sys.meta_path.insert(0, PluginFinder(f'{PACKAGE_NAME}.{plugin_spec.module_name}'))
|
||||||
|
|
||||||
|
|
||||||
def add_plugin_dirs(*paths):
|
|
||||||
"""Add external plugin dirs to the existing ones"""
|
|
||||||
plugin_dirs.value.extend(paths)
|
|
||||||
|
|
||||||
|
|
||||||
def set_plugin_dirs(*paths):
|
|
||||||
"""Set external plugin dirs, overriding the default ones"""
|
|
||||||
plugin_dirs.value = list(paths)
|
|
||||||
|
|
||||||
|
|
||||||
def get_plugin_spec(module_name):
|
|
||||||
return plugin_specs.value.get(module_name)
|
|
||||||
|
|
||||||
|
|
||||||
def disable_plugins():
|
def disable_plugins():
|
||||||
if (
|
if (
|
||||||
all_plugins_loaded.value
|
all_plugins_loaded.value
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
from .sponskrub import SponSkrubPP
|
from .sponskrub import SponSkrubPP
|
||||||
from .sponsorblock import SponsorBlockPP
|
from .sponsorblock import SponsorBlockPP
|
||||||
from .xattrpp import XAttrMetadataPP
|
from .xattrpp import XAttrMetadataPP
|
||||||
from .._globals import plugin_pps, postprocessors
|
from ..globals import plugin_pps, postprocessors
|
||||||
from ..plugins import PACKAGE_NAME, register_plugin_spec, PluginSpec
|
from ..plugins import PACKAGE_NAME, register_plugin_spec, PluginSpec
|
||||||
from ..utils import deprecation_warning
|
from ..utils import deprecation_warning
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
compat_HTMLParseError,
|
compat_HTMLParseError,
|
||||||
)
|
)
|
||||||
from ..dependencies import xattr
|
from ..dependencies import xattr
|
||||||
from .._globals import IN_CLI as _IN_CLI
|
from ..globals import IN_CLI as _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