11import json
2+ import os
3+ import platform
24import urllib .parse
35
46
57DEFAULT_MEDIA_DOWNLOAD_PATH = 'special://profile/addon_data/plugin.video.sendtokodi/downloads'
68DEFAULT_YTDLP_VERSION = 'latest'
79DEFAULT_DENO_VERSION = 'latest'
10+ DEFAULT_JS_RUNTIME_MODE = 'auto'
811DEFAULT_DASH_HTTPD_IDLE_TIMEOUT_SECONDS = 120
912MIN_DASH_HTTPD_IDLE_TIMEOUT_SECONDS = 10
1013MAX_DASH_HTTPD_IDLE_TIMEOUT_SECONDS = 600
@@ -71,10 +74,6 @@ def build_ydl_opts(parsed_params, deno_opts=None):
7174
7275
7376def resolve_deno_opts (handle , get_setting , get_deno_ydl_opts ):
74- deno_enabled = get_setting (handle , "deno_enabled" ) == 'true'
75- if not deno_enabled :
76- return {}
77-
7877 auto_update = get_setting (handle , "deno_autodownload" ) == 'true'
7978 version = (get_setting (handle , "deno_version" ) or '' ).strip ()
8079 # Auto-update mode should track latest, not a previously pinned version.
@@ -85,6 +84,78 @@ def resolve_deno_opts(handle, get_setting, get_deno_ydl_opts):
8584 return get_deno_ydl_opts (auto_download = auto_update , requested_version = requested_version )
8685
8786
87+ def _normalize_js_runtime_mode (mode ):
88+ value = (mode or '' ).strip ().lower ()
89+ if value in ('auto' , 'deno' , 'quickjs' , 'disabled' ):
90+ return value
91+ return DEFAULT_JS_RUNTIME_MODE
92+
93+
94+ def _is_armv7_machine (get_machine ):
95+ try :
96+ machine = (get_machine () or '' ).strip ().lower ()
97+ except Exception :
98+ machine = ''
99+
100+ # Common names include armv7l and armv7hl.
101+ return machine .startswith ('armv7' )
102+
103+
104+ def resolve_quickjs_opts (
105+ handle ,
106+ get_setting ,
107+ path_exists = os .path .exists ,
108+ is_executable = os .access ,
109+ access_flag = os .X_OK ,
110+ ):
111+ quickjs_path = (get_setting (handle , 'quickjs_path' ) or '' ).strip ()
112+ if not quickjs_path :
113+ return {}
114+ if not path_exists (quickjs_path ):
115+ return {}
116+ if not is_executable (quickjs_path , access_flag ):
117+ return {}
118+
119+ return {
120+ 'js_runtimes' : {'quickjs' : {'path' : quickjs_path }},
121+ 'remote_components' : {'ejs:github' },
122+ }
123+
124+
125+ def resolve_js_runtime_opts (
126+ handle ,
127+ get_setting ,
128+ get_deno_ydl_opts ,
129+ get_machine = platform .machine ,
130+ path_exists = os .path .exists ,
131+ is_executable = os .access ,
132+ access_flag = os .X_OK ,
133+ ):
134+ runtime_mode = _normalize_js_runtime_mode (get_setting (handle , 'js_runtime_mode' ))
135+
136+ deno_opts = resolve_deno_opts (handle , get_setting , get_deno_ydl_opts )
137+ quickjs_opts = resolve_quickjs_opts (
138+ handle ,
139+ get_setting ,
140+ path_exists = path_exists ,
141+ is_executable = is_executable ,
142+ access_flag = access_flag ,
143+ )
144+
145+ if runtime_mode == 'deno' :
146+ return deno_opts
147+ if runtime_mode == 'quickjs' :
148+ return quickjs_opts
149+ if runtime_mode == 'disabled' :
150+ return {}
151+
152+ if _is_armv7_machine (get_machine ) and quickjs_opts :
153+ return quickjs_opts
154+ if deno_opts :
155+ return deno_opts
156+ return quickjs_opts
157+
158+
88159def resolve_deno_settings (handle , get_setting ):
89160 enabled = get_setting (handle , "deno_enabled" ) == 'true'
90161 auto_update = get_setting (handle , "deno_autodownload" ) == 'true'
0 commit comments