aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dlc/utils.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan@gmail.com>2021-01-24 19:10:02 +0530
committerpukkandan <pukkandan@gmail.com>2021-01-24 20:24:07 +0530
commitf74980cbaebaf3c4ea89d1b257424a50545991d9 (patch)
tree896c00839bf145432303e745e21dd7ad6935b938 /youtube_dlc/utils.py
parentc571435f9c22129c3663b738ca7b577ee05eec97 (diff)
downloadhypervideo-pre-f74980cbaebaf3c4ea89d1b257424a50545991d9.tar.lz
hypervideo-pre-f74980cbaebaf3c4ea89d1b257424a50545991d9.tar.xz
hypervideo-pre-f74980cbaebaf3c4ea89d1b257424a50545991d9.zip
Plugin support
Extractor plugins are loaded from <root-dir>/ytdlp_plugins/extractor/__init__.py Inspired by https://github.com/un-def/dl-plus :ci skip dl
Diffstat (limited to 'youtube_dlc/utils.py')
-rw-r--r--youtube_dlc/utils.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py
index 6740f0cdb..34a14424a 100644
--- a/youtube_dlc/utils.py
+++ b/youtube_dlc/utils.py
@@ -16,6 +16,7 @@ import email.header
import errno
import functools
import gzip
+import imp
import io
import itertools
import json
@@ -5905,3 +5906,31 @@ def make_dir(path, to_screen=None):
if callable(to_screen) is not None:
to_screen('unable to create directory ' + error_to_compat_str(err))
return False
+
+
+def get_executable_path():
+ path = os.path.dirname(sys.argv[0])
+ if os.path.abspath(sys.argv[0]) != os.path.abspath(sys.executable): # Not packaged
+ path = os.path.join(path, '..')
+ return os.path.abspath(path)
+
+
+def load_plugins(name, type, namespace):
+ plugin_info = [None]
+ classes = []
+ try:
+ plugin_info = imp.find_module(
+ name, [os.path.join(get_executable_path(), 'ytdlp_plugins')])
+ plugins = imp.load_module(name, *plugin_info)
+ for name in dir(plugins):
+ if not name.endswith(type):
+ continue
+ klass = getattr(plugins, name)
+ classes.append(klass)
+ namespace[name] = klass
+ except ImportError:
+ pass
+ finally:
+ if plugin_info[0] is not None:
+ plugin_info[0].close()
+ return classes