Skip to content

Commit 5b64cde

Browse files
committed
Implement JavaScript runtime options and refactor Deno integration
1 parent 5a666b0 commit 5b64cde

5 files changed

Lines changed: 333 additions & 24 deletions

File tree

core/addon_params.py

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import json
2+
import os
3+
import platform
24
import urllib.parse
35

46

57
DEFAULT_MEDIA_DOWNLOAD_PATH = 'special://profile/addon_data/plugin.video.sendtokodi/downloads'
68
DEFAULT_YTDLP_VERSION = 'latest'
79
DEFAULT_DENO_VERSION = 'latest'
10+
DEFAULT_JS_RUNTIME_MODE = 'auto'
811
DEFAULT_DASH_HTTPD_IDLE_TIMEOUT_SECONDS = 120
912
MIN_DASH_HTTPD_IDLE_TIMEOUT_SECONDS = 10
1013
MAX_DASH_HTTPD_IDLE_TIMEOUT_SECONDS = 600
@@ -71,10 +74,6 @@ def build_ydl_opts(parsed_params, deno_opts=None):
7174

7275

7376
def 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+
88159
def resolve_deno_settings(handle, get_setting):
89160
enabled = get_setting(handle, "deno_enabled") == 'true'
90161
auto_update = get_setting(handle, "deno_autodownload") == 'true'

resources/language/resource.language.en_gb/strings.po

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ msgid "URL Resolver"
2525
msgstr ""
2626

2727
msgctxt "#32060"
28-
msgid "Deno"
28+
msgid "JavaScript Runtime"
2929
msgstr ""
3030

3131
msgctxt "#32061"
@@ -56,6 +56,34 @@ msgctxt "#32028"
5656
msgid "Update Deno now"
5757
msgstr ""
5858

59+
msgctxt "#32062"
60+
msgid "Enable QuickJS JavaScript runtime"
61+
msgstr ""
62+
63+
msgctxt "#32063"
64+
msgid "QuickJS binary path"
65+
msgstr ""
66+
67+
msgctxt "#32064"
68+
msgid "JavaScript runtime mode (auto|deno|quickjs)"
69+
msgstr ""
70+
71+
msgctxt "#32065"
72+
msgid "Auto"
73+
msgstr ""
74+
75+
msgctxt "#32066"
76+
msgid "Deno"
77+
msgstr ""
78+
79+
msgctxt "#32067"
80+
msgid "QuickJS"
81+
msgstr ""
82+
83+
msgctxt "#32068"
84+
msgid "Disabled"
85+
msgstr ""
86+
5987
msgctxt "#32051"
6088
msgid "Auto-update yt-dlp"
6189
msgstr ""

resources/settings.xml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,23 @@
1717
</category>
1818
<category id="deno" label="32060">
1919
<group id="3">
20-
<setting type="boolean" id="deno_enabled" label="32024">
20+
<setting type="string" id="js_runtime_mode" label="32064">
2121
<level>0</level>
22-
<default>true</default>
23-
<control type="toggle"/>
22+
<default>auto</default>
23+
<constraints>
24+
<options>
25+
<option label="32065">auto</option>
26+
<option label="32066">deno</option>
27+
<option label="32067">quickjs</option>
28+
<option label="32068">disabled</option>
29+
</options>
30+
</constraints>
31+
<control type="spinner" format="string"/>
32+
</setting>
33+
<setting type="string" id="quickjs_path" label="32063">
34+
<level>0</level>
35+
<default></default>
36+
<control type="edit" format="string"/>
2437
</setting>
2538
<setting type="boolean" id="deno_autodownload" label="32023">
2639
<level>0</level>

service.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
parse_query_params,
1515
resolve_queue_request,
1616
build_ydl_opts,
17-
resolve_deno_opts,
17+
resolve_js_runtime_opts,
1818
resolve_media_download_settings,
1919
resolve_dash_httpd_idle_timeout,
2020
)
@@ -168,14 +168,14 @@ def handle_queue_action(paramstring):
168168
params = parse_cli_paramstring(sys.argv[2])
169169
url = str(params['url'])
170170

171-
deno_opts = {}
171+
js_runtime_opts = {}
172172
try:
173173
from core.deno_manager import get_ydl_opts
174-
deno_opts = resolve_deno_opts(__handle__, xbmcplugin.getSetting, get_ydl_opts)
174+
js_runtime_opts = resolve_js_runtime_opts(__handle__, xbmcplugin.getSetting, get_ydl_opts)
175175
except Exception as e:
176-
log("Failed to configure Deno: {}".format(str(e)), xbmc.LOGWARNING)
176+
log("Failed to configure JavaScript runtime: {}".format(str(e)), xbmc.LOGWARNING)
177177

178-
ydl_opts = build_ydl_opts(params, deno_opts)
178+
ydl_opts = build_ydl_opts(params, js_runtime_opts)
179179

180180
media_download_settings = resolve_media_download_settings(__handle__, xbmcplugin.getSetting)
181181
media_download_enabled = media_download_settings['enabled']

0 commit comments

Comments
 (0)