From 4d576bd3807c91d1116b1c0c90c7bb5b7caa3af5 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Fri, 29 Dec 2023 15:36:18 -0500 Subject: [PATCH] fix: import youtube_dl from YoutubeDLWrapper (#20) --- addon.yaml | 1 + scripts/bootstrap_kodi.py | 30 ++++++++++++++++++++++-------- src/themerr/youtube.py | 5 ++++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/addon.yaml b/addon.yaml index afe8551..7084188 100644 --- a/addon.yaml +++ b/addon.yaml @@ -32,5 +32,6 @@ addon: import: - addon: "xbmc.python" version: "3.0.1" + - addon: "script.module.kodi-six" # this is a dependency of youtube-dl, but we need to put it here for CI tests - addon: "script.module.requests" - addon: "script.module.youtube.dl" diff --git a/scripts/bootstrap_kodi.py b/scripts/bootstrap_kodi.py index be8a1db..f8a8f2b 100644 --- a/scripts/bootstrap_kodi.py +++ b/scripts/bootstrap_kodi.py @@ -22,20 +22,34 @@ def get_modules(): def bootstrap_modules(): + lib_dirs = ( + 'lib', + 'libs', + ) + required_modules = get_modules() # check if the required modules are installed, only for unit testing for m in required_modules: module_found = False for p in sys.path: - if p.endswith(os.path.join(m, 'lib')): - module_found = True - break - if not module_found: - dev_path = os.path.join(root_dir, 'third-party', 'repo-scripts', m, 'lib') - if os.path.isdir(dev_path): - print(f"Adding dev path: {dev_path}") - sys.path.insert(0, dev_path) + if not module_found: + for lib_dir in lib_dirs: + if p.endswith(os.path.join(m, lib_dir)): + module_found = True + break # break out of lib_dirs loop else: + break # module already found, break out of sys.path loop + if not module_found: + + for lib_dir in lib_dirs: + dev_path = os.path.join(root_dir, 'third-party', 'repo-scripts', m, lib_dir) + if os.path.isdir(dev_path): + print(f"Adding dev path: {dev_path}") + sys.path.insert(0, dev_path) + module_found = True + break + + if not module_found: print(f"Module not found: {m}") raise ModuleNotFoundError(f"Module not found: {m}") diff --git a/src/themerr/youtube.py b/src/themerr/youtube.py index 102e2cb..1ac6805 100644 --- a/src/themerr/youtube.py +++ b/src/themerr/youtube.py @@ -2,7 +2,10 @@ from typing import Optional # lib imports -import youtube_dl +try: + from YoutubeDLWrapper import youtube_dl # importing from wrapper applies kodi patches +except TypeError: + import youtube_dl # patches fail when building docs # local imports from . import logger