openvideo-server 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openvideo_server/__init__.py +5 -0
- openvideo_server/_version.py +24 -0
- openvideo_server/admin/__init__.py +1 -0
- openvideo_server/admin/bridge.py +85 -0
- openvideo_server/admin/client.py +142 -0
- openvideo_server/admin/server.py +73 -0
- openvideo_server/admin/service.py +363 -0
- openvideo_server/admin/ui.py +692 -0
- openvideo_server/api/__init__.py +1 -0
- openvideo_server/api/capabilities.py +25 -0
- openvideo_server/api/dependencies.py +172 -0
- openvideo_server/api/ranges.py +64 -0
- openvideo_server/api/routes_auth.py +298 -0
- openvideo_server/api/routes_downloads.py +340 -0
- openvideo_server/api/routes_history.py +188 -0
- openvideo_server/api/routes_media.py +238 -0
- openvideo_server/api/routes_playback.py +436 -0
- openvideo_server/api/routes_server.py +171 -0
- openvideo_server/api/routes_sources.py +225 -0
- openvideo_server/api/routes_subtitles.py +133 -0
- openvideo_server/cli.py +793 -0
- openvideo_server/config.py +201 -0
- openvideo_server/core/__init__.py +1 -0
- openvideo_server/core/browser.py +501 -0
- openvideo_server/core/download_manager.py +655 -0
- openvideo_server/core/security.py +176 -0
- openvideo_server/core/session_manager.py +1085 -0
- openvideo_server/discovery/__init__.py +1 -0
- openvideo_server/discovery/bonjour.py +256 -0
- openvideo_server/macos/__init__.py +1 -0
- openvideo_server/macos/launch_agent.py +168 -0
- openvideo_server/main.py +281 -0
- openvideo_server/media/__init__.py +1 -0
- openvideo_server/media/binaries.py +264 -0
- openvideo_server/media/cache.py +51 -0
- openvideo_server/media/downloads.py +308 -0
- openvideo_server/media/probe.py +280 -0
- openvideo_server/media/subtitles.py +303 -0
- openvideo_server/media/thumbnails.py +273 -0
- openvideo_server/redaction.py +13 -0
- openvideo_server/runtime.py +103 -0
- openvideo_server/storage/__init__.py +1 -0
- openvideo_server/storage/db.py +47 -0
- openvideo_server/storage/disk.py +20 -0
- openvideo_server/storage/migrations.py +58 -0
- openvideo_server/storage/repository.py +722 -0
- openvideo_server-0.1.0.dist-info/METADATA +146 -0
- openvideo_server-0.1.0.dist-info/RECORD +52 -0
- openvideo_server-0.1.0.dist-info/WHEEL +4 -0
- openvideo_server-0.1.0.dist-info/entry_points.txt +2 -0
- openvideo_server-0.1.0.dist-info/licenses/LICENSE +201 -0
- openvideo_server-0.1.0.dist-info/licenses/NOTICE +2 -0
|
@@ -0,0 +1,692 @@
|
|
|
1
|
+
"""Optional native window that presents the admin API to a local user."""
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from openvideo_server.admin.bridge import AdminBridge
|
|
7
|
+
from openvideo_server.admin.client import AdminClient
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AdminUiUnavailable(Exception):
|
|
11
|
+
"""Raised when the optional window dependencies are not installed."""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
ADMIN_HTML = """<!doctype html>
|
|
15
|
+
<html lang="en">
|
|
16
|
+
<head>
|
|
17
|
+
<meta charset="utf-8">
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
19
|
+
<title>OpenVideo Admin</title>
|
|
20
|
+
<style>
|
|
21
|
+
:root {
|
|
22
|
+
color-scheme: light dark;
|
|
23
|
+
--bg: #f5f6f8;
|
|
24
|
+
--card: #ffffff;
|
|
25
|
+
--text: #1c1f24;
|
|
26
|
+
--muted: #6a7280;
|
|
27
|
+
--line: #dfe3e9;
|
|
28
|
+
--accent: #2b6cb0;
|
|
29
|
+
--danger: #b3362f;
|
|
30
|
+
--warn-bg: #fff4d6;
|
|
31
|
+
--warn-text: #6b4c00;
|
|
32
|
+
}
|
|
33
|
+
@media (prefers-color-scheme: dark) {
|
|
34
|
+
:root {
|
|
35
|
+
--bg: #171a1f;
|
|
36
|
+
--card: #1f2329;
|
|
37
|
+
--text: #e8eaed;
|
|
38
|
+
--muted: #9aa3af;
|
|
39
|
+
--line: #323842;
|
|
40
|
+
--accent: #6aa6e0;
|
|
41
|
+
--danger: #e0736c;
|
|
42
|
+
--warn-bg: #40350f;
|
|
43
|
+
--warn-text: #f0d18a;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
* { box-sizing: border-box; }
|
|
47
|
+
body {
|
|
48
|
+
margin: 0;
|
|
49
|
+
background: var(--bg);
|
|
50
|
+
color: var(--text);
|
|
51
|
+
font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
52
|
+
}
|
|
53
|
+
header {
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
justify-content: space-between;
|
|
57
|
+
gap: 16px;
|
|
58
|
+
padding: 18px 24px;
|
|
59
|
+
border-bottom: 1px solid var(--line);
|
|
60
|
+
background: var(--card);
|
|
61
|
+
}
|
|
62
|
+
h1 { margin: 0; font-size: 20px; }
|
|
63
|
+
h2 { margin: 0 0 4px; font-size: 16px; }
|
|
64
|
+
h3 { margin: 18px 0 6px; font-size: 14px; }
|
|
65
|
+
p { margin: 6px 0; }
|
|
66
|
+
.muted { color: var(--muted); font-size: 13px; }
|
|
67
|
+
.hidden { display: none; }
|
|
68
|
+
main { padding: 20px 24px 48px; display: grid; gap: 18px; max-width: 920px; }
|
|
69
|
+
section {
|
|
70
|
+
background: var(--card);
|
|
71
|
+
border: 1px solid var(--line);
|
|
72
|
+
border-radius: 10px;
|
|
73
|
+
padding: 18px;
|
|
74
|
+
}
|
|
75
|
+
.banner { margin: 0; padding: 10px 24px; font-size: 13px; }
|
|
76
|
+
.banner.info { background: var(--card); color: var(--muted); }
|
|
77
|
+
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
|
|
78
|
+
.banner.error { background: #fbe3e1; color: #7a1f19; }
|
|
79
|
+
button {
|
|
80
|
+
font: inherit;
|
|
81
|
+
border: 1px solid var(--line);
|
|
82
|
+
background: var(--card);
|
|
83
|
+
color: var(--text);
|
|
84
|
+
border-radius: 7px;
|
|
85
|
+
padding: 7px 13px;
|
|
86
|
+
cursor: pointer;
|
|
87
|
+
}
|
|
88
|
+
button:hover:not(:disabled) { border-color: var(--accent); }
|
|
89
|
+
button:disabled { opacity: 0.55; cursor: default; }
|
|
90
|
+
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
|
|
91
|
+
button.danger { color: var(--danger); border-color: var(--danger); }
|
|
92
|
+
button.small { padding: 3px 9px; font-size: 12px; }
|
|
93
|
+
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
|
|
94
|
+
.row.end { justify-content: flex-end; }
|
|
95
|
+
.actions { display: flex; gap: 8px; }
|
|
96
|
+
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
|
|
97
|
+
.field { display: grid; gap: 4px; }
|
|
98
|
+
.field span { font-size: 12px; color: var(--muted); }
|
|
99
|
+
input[type="text"], input[type="number"], textarea {
|
|
100
|
+
font: inherit;
|
|
101
|
+
width: 100%;
|
|
102
|
+
padding: 7px 9px;
|
|
103
|
+
border-radius: 7px;
|
|
104
|
+
border: 1px solid var(--line);
|
|
105
|
+
background: var(--bg);
|
|
106
|
+
color: var(--text);
|
|
107
|
+
}
|
|
108
|
+
input[type="checkbox"] { justify-self: start; width: 17px; height: 17px; }
|
|
109
|
+
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
|
|
110
|
+
dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; margin: 12px 0 0; }
|
|
111
|
+
dt { color: var(--muted); }
|
|
112
|
+
dd { margin: 0; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
|
|
113
|
+
table { width: 100%; border-collapse: collapse; margin-top: 12px; }
|
|
114
|
+
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
|
|
115
|
+
th { font-size: 12px; color: var(--muted); font-weight: 600; }
|
|
116
|
+
table.sources td { vertical-align: top; }
|
|
117
|
+
table.sources td:nth-child(3) input { min-width: 200px; }
|
|
118
|
+
.hint {
|
|
119
|
+
display: inline-block;
|
|
120
|
+
margin-left: 5px;
|
|
121
|
+
width: 15px; height: 15px;
|
|
122
|
+
line-height: 15px;
|
|
123
|
+
text-align: center;
|
|
124
|
+
border-radius: 50%;
|
|
125
|
+
border: 1px solid var(--line);
|
|
126
|
+
color: var(--muted);
|
|
127
|
+
font-size: 10px;
|
|
128
|
+
cursor: help;
|
|
129
|
+
}
|
|
130
|
+
.pin {
|
|
131
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
132
|
+
font-size: 34px;
|
|
133
|
+
letter-spacing: 6px;
|
|
134
|
+
margin-top: 10px;
|
|
135
|
+
}
|
|
136
|
+
.overlay {
|
|
137
|
+
position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35);
|
|
138
|
+
display: flex; align-items: center; justify-content: center; padding: 24px;
|
|
139
|
+
}
|
|
140
|
+
.dialog { background: var(--card); border-radius: 10px; padding: 20px; max-width: 420px; }
|
|
141
|
+
</style>
|
|
142
|
+
</head>
|
|
143
|
+
<body>
|
|
144
|
+
<header>
|
|
145
|
+
<div>
|
|
146
|
+
<h1 id="server-name">OpenVideo</h1>
|
|
147
|
+
<p id="server-meta" class="muted">Connecting to the server...</p>
|
|
148
|
+
</div>
|
|
149
|
+
<div class="actions">
|
|
150
|
+
<button id="refresh">Refresh</button>
|
|
151
|
+
<button id="restart" class="danger">Restart server</button>
|
|
152
|
+
</div>
|
|
153
|
+
</header>
|
|
154
|
+
<div id="banner" class="banner hidden"></div>
|
|
155
|
+
<main>
|
|
156
|
+
<section>
|
|
157
|
+
<h2>Server</h2>
|
|
158
|
+
<p class="muted">This window talks to the server over a private local socket. Closing it does not stop the server.</p>
|
|
159
|
+
<dl>
|
|
160
|
+
<dt>Configuration</dt><dd id="status-config">-</dd>
|
|
161
|
+
<dt>Database</dt><dd id="status-database">-</dd>
|
|
162
|
+
<dt>ffmpeg</dt><dd id="status-ffmpeg">-</dd>
|
|
163
|
+
<dt>ffprobe</dt><dd id="status-ffprobe">-</dd>
|
|
164
|
+
</dl>
|
|
165
|
+
</section>
|
|
166
|
+
|
|
167
|
+
<section>
|
|
168
|
+
<h2>Settings</h2>
|
|
169
|
+
<p class="muted">Saving writes config.yaml. The running server keeps its current settings until it restarts.</p>
|
|
170
|
+
<div id="settings-form" class="grid"></div>
|
|
171
|
+
<h3>Sources</h3>
|
|
172
|
+
<p class="muted">Folders the server may stream from. Pick a folder, then edit the id, name, path, or enabled flag before saving.</p>
|
|
173
|
+
<table class="sources">
|
|
174
|
+
<thead>
|
|
175
|
+
<tr>
|
|
176
|
+
<th title="Unique prefix used in client paths and media IDs.">ID</th>
|
|
177
|
+
<th title="Display name shown to clients.">Name</th>
|
|
178
|
+
<th title="Absolute folder path. Streams stay inside it.">Path</th>
|
|
179
|
+
<th title="Disabled sources are not listed or browsable.">Enabled</th>
|
|
180
|
+
<th></th>
|
|
181
|
+
</tr>
|
|
182
|
+
</thead>
|
|
183
|
+
<tbody id="sources-body"></tbody>
|
|
184
|
+
</table>
|
|
185
|
+
<p id="sources-empty" class="muted">No sources are configured.</p>
|
|
186
|
+
<div class="row" style="margin-top: 10px">
|
|
187
|
+
<button id="add-source">Add folder…</button>
|
|
188
|
+
<span id="sources-message" class="muted"></span>
|
|
189
|
+
</div>
|
|
190
|
+
<div class="row" style="margin-top: 12px">
|
|
191
|
+
<button id="save-settings" class="primary">Save settings</button>
|
|
192
|
+
<span id="settings-message" class="muted"></span>
|
|
193
|
+
</div>
|
|
194
|
+
</section>
|
|
195
|
+
|
|
196
|
+
<section>
|
|
197
|
+
<h2>Paired devices</h2>
|
|
198
|
+
<p class="muted">Revoking a device forces it to pair again before it can stream.</p>
|
|
199
|
+
<table>
|
|
200
|
+
<thead>
|
|
201
|
+
<tr><th>Name</th><th>Device ID</th><th>Paired</th><th>Last seen</th><th></th></tr>
|
|
202
|
+
</thead>
|
|
203
|
+
<tbody id="devices-body"></tbody>
|
|
204
|
+
</table>
|
|
205
|
+
<p id="devices-empty" class="muted">No devices are paired.</p>
|
|
206
|
+
<div class="row" style="margin-top: 12px">
|
|
207
|
+
<button id="pair" class="primary">Generate pairing PIN</button>
|
|
208
|
+
</div>
|
|
209
|
+
<div id="pin"></div>
|
|
210
|
+
</section>
|
|
211
|
+
|
|
212
|
+
<section>
|
|
213
|
+
<h2>Maintenance</h2>
|
|
214
|
+
<p class="muted">Cache clearing removes derived thumbnails, subtitles, and transcodes. The database holds paired devices and playback history.</p>
|
|
215
|
+
<div class="row" style="margin-top: 12px">
|
|
216
|
+
<button id="clear-cache">Clear cache</button>
|
|
217
|
+
<button id="optimize-db">Optimize database</button>
|
|
218
|
+
</div>
|
|
219
|
+
<div class="row" style="margin-top: 14px">
|
|
220
|
+
<input id="reset-confirm" type="text" placeholder="Type RESET to confirm" style="max-width: 220px">
|
|
221
|
+
<button id="reset-db" class="danger">Reset database</button>
|
|
222
|
+
</div>
|
|
223
|
+
<p id="maintenance-message" class="muted"></p>
|
|
224
|
+
</section>
|
|
225
|
+
</main>
|
|
226
|
+
<script>
|
|
227
|
+
const FIELDS = [
|
|
228
|
+
{ path: "server.name", label: "Server name", type: "text", hint: "Shown to clients and used for the Bonjour service name." },
|
|
229
|
+
{ path: "server.port", label: "Port", type: "number", min: 1, max: 65535, hint: "TCP port for the API and streams. Restart after changing it." },
|
|
230
|
+
{ path: "server.bind_address", label: "Bind address", type: "text", hint: "0.0.0.0 listens everywhere; 127.0.0.1 only on this Mac." },
|
|
231
|
+
{ path: "network.local_discovery", label: "Advertise on the local network", type: "checkbox", hint: "Advertise the server over Bonjour so local clients can find it." },
|
|
232
|
+
{ path: "network.remote_access_enabled", label: "Allow remote access", type: "checkbox", hint: "Off answers every non-loopback request with 403." },
|
|
233
|
+
{ path: "network.require_pairing", label: "Require pairing (always on)", type: "checkbox", locked: true, hint: "Pairing is required; trusted-LAN anonymous mode was removed." },
|
|
234
|
+
{ path: "network.trusted_proxies", label: "Trusted proxies (comma separated)", type: "list", hint: "Proxy IPs or CIDRs whose forwarded client address is trusted." },
|
|
235
|
+
{ path: "network.advertised_urls", label: "Advertised URLs (comma separated)", type: "list", hint: "Client-facing http/https base URLs for a proxy, VPN, or DDNS; HTTPS recommended." },
|
|
236
|
+
{ path: "playback.max_simultaneous_transcodes", label: "Max simultaneous transcodes", type: "number", min: 1, hint: "Concurrent HLS sessions; extra requests get 429." },
|
|
237
|
+
{ path: "playback.hardware_acceleration", label: "Hardware acceleration", type: "checkbox", hint: "Use VideoToolbox encoders when available." },
|
|
238
|
+
{ path: "playback.preferred_video_codec", label: "Preferred video codec", type: "text", hint: "h264 or hevc; anything else falls back to h264." },
|
|
239
|
+
{ path: "playback.preferred_audio_codec", label: "Preferred audio codec", type: "text", hint: "aac or mp3; anything else falls back to aac." },
|
|
240
|
+
{ path: "playback.session_idle_timeout_seconds", label: "Session idle timeout (seconds)", type: "number", min: 30, hint: "Stop idle HLS sessions and delete their files after this." },
|
|
241
|
+
{ path: "playback.hls_segment_seconds", label: "HLS segment length (seconds)", type: "number", min: 1, max: 30, hint: "Segment length in seconds (1-30)." },
|
|
242
|
+
{ path: "playback.disk_buffer_percent", label: "Playback disk free buffer (% of volume)", type: "number", min: 0, max: 50, hint: "Refuse new HLS sessions while free space is at or below this percent of the transcode volume." },
|
|
243
|
+
{ path: "playback.transcode_cache_quota_gb", label: "HLS transcode cache quota (GB)", type: "number", min: 0, hint: "Stop least recently accessed HLS sessions when scratch usage exceeds this. 0 disables." },
|
|
244
|
+
{ path: "cache.thumbnail_max_dimension", label: "Thumbnail max dimension", type: "number", min: 1, hint: "Longest edge of generated thumbnails in pixels." },
|
|
245
|
+
{ path: "cache.cache_retention_days", label: "Cache retention (days)", type: "number", min: 0, hint: "Delete cache files older than this at startup. 0 disables." },
|
|
246
|
+
{ path: "download.ttl_hours", label: "Download artifact retention (hours)", type: "number", min: 1, hint: "Delete finished conversion artifacts this many hours after they become ready." },
|
|
247
|
+
{ path: "download.ack_grace_seconds", label: "Download delete-after-ack grace (seconds)", type: "number", min: 0, hint: "Keep an artifact this long after a client acknowledges it, so interrupted clients can retry." },
|
|
248
|
+
{ path: "download.conversion_sessions", label: "Conversion sessions", type: "number", min: 1, hint: "Concurrent ffmpeg conversions for downloads, separate from playback transcodes." },
|
|
249
|
+
{ path: "download.disk_buffer_percent", label: "Disk free buffer (% of volume)", type: "number", min: 0, max: 50, hint: "Refuse new conversions while free space is at or below this percent of the volume." },
|
|
250
|
+
{ path: "download.max_active_jobs_per_device", label: "Max active download jobs per device", type: "number", min: 1, hint: "Maximum queued or converting download jobs a single device may have." },
|
|
251
|
+
{ path: "download.queue_depth", label: "Download queue depth", type: "number", min: 0, hint: "Maximum jobs waiting for a conversion slot; extra requests get 429." },
|
|
252
|
+
{ path: "binaries.ffmpeg", label: "ffmpeg path override", type: "text", optional: true, hint: "Absolute ffmpeg path. Blank uses the managed copy, then PATH." },
|
|
253
|
+
{ path: "binaries.ffprobe", label: "ffprobe path override", type: "text", optional: true, hint: "Absolute ffprobe path. Blank uses the managed copy, then PATH." },
|
|
254
|
+
{ path: "logging.level", label: "Log level", type: "text", hint: "DEBUG, INFO, WARNING, ERROR, or CRITICAL. DEBUG adds probe results, ffmpeg commands, and cache detail." }
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
let settingsState = null;
|
|
258
|
+
let booted = false;
|
|
259
|
+
|
|
260
|
+
function el(id) {
|
|
261
|
+
return document.getElementById(id);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function getPath(object, path) {
|
|
265
|
+
return path.split(".").reduce(function (value, key) {
|
|
266
|
+
return value == null ? undefined : value[key];
|
|
267
|
+
}, object);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function setPath(object, path, value) {
|
|
271
|
+
const keys = path.split(".");
|
|
272
|
+
let target = object;
|
|
273
|
+
for (let index = 0; index < keys.length - 1; index += 1) {
|
|
274
|
+
if (target[keys[index]] == null || typeof target[keys[index]] !== "object") {
|
|
275
|
+
target[keys[index]] = {};
|
|
276
|
+
}
|
|
277
|
+
target = target[keys[index]];
|
|
278
|
+
}
|
|
279
|
+
target[keys[keys.length - 1]] = value;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async function call(method) {
|
|
283
|
+
const args = Array.prototype.slice.call(arguments, 1);
|
|
284
|
+
if (!window.pywebview || !window.pywebview.api) {
|
|
285
|
+
throw new Error("The admin bridge is not ready yet.");
|
|
286
|
+
}
|
|
287
|
+
const result = await window.pywebview.api[method].apply(window.pywebview.api, args);
|
|
288
|
+
if (!result || result.ok !== true) {
|
|
289
|
+
throw new Error((result && result.error) || "The request failed.");
|
|
290
|
+
}
|
|
291
|
+
return result.data;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function showBanner(message, kind) {
|
|
295
|
+
const banner = el("banner");
|
|
296
|
+
if (!message) {
|
|
297
|
+
banner.className = "banner hidden";
|
|
298
|
+
banner.textContent = "";
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
banner.textContent = message;
|
|
302
|
+
banner.className = "banner " + (kind || "info");
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function formatTime(seconds) {
|
|
306
|
+
if (!seconds) return "-";
|
|
307
|
+
return new Date(seconds * 1000).toLocaleString();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function busy(button, task) {
|
|
311
|
+
button.disabled = true;
|
|
312
|
+
return Promise.resolve().then(task).finally(function () {
|
|
313
|
+
button.disabled = false;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function ask(message) {
|
|
318
|
+
return new Promise(function (resolve) {
|
|
319
|
+
const overlay = document.createElement("div");
|
|
320
|
+
overlay.className = "overlay";
|
|
321
|
+
const dialog = document.createElement("div");
|
|
322
|
+
dialog.className = "dialog";
|
|
323
|
+
const text = document.createElement("p");
|
|
324
|
+
text.textContent = message;
|
|
325
|
+
const actions = document.createElement("div");
|
|
326
|
+
actions.className = "row end";
|
|
327
|
+
const cancel = document.createElement("button");
|
|
328
|
+
cancel.textContent = "Cancel";
|
|
329
|
+
const confirm = document.createElement("button");
|
|
330
|
+
confirm.textContent = "Confirm";
|
|
331
|
+
confirm.className = "danger";
|
|
332
|
+
function close(result) {
|
|
333
|
+
overlay.remove();
|
|
334
|
+
resolve(result);
|
|
335
|
+
}
|
|
336
|
+
cancel.addEventListener("click", function () { close(false); });
|
|
337
|
+
confirm.addEventListener("click", function () { close(true); });
|
|
338
|
+
actions.appendChild(cancel);
|
|
339
|
+
actions.appendChild(confirm);
|
|
340
|
+
dialog.appendChild(text);
|
|
341
|
+
dialog.appendChild(actions);
|
|
342
|
+
overlay.appendChild(dialog);
|
|
343
|
+
document.body.appendChild(overlay);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async function loadStatus() {
|
|
348
|
+
const status = await call("get_status");
|
|
349
|
+
el("server-name").textContent = status.name;
|
|
350
|
+
el("server-meta").textContent = "Version " + status.version + " - listening on " +
|
|
351
|
+
status.bind_address + ":" + status.port + " - " + status.paired_devices +
|
|
352
|
+
(status.paired_devices === 1 ? " paired device" : " paired devices");
|
|
353
|
+
el("status-config").textContent = status.config_path;
|
|
354
|
+
el("status-database").textContent = status.database_path;
|
|
355
|
+
el("status-ffmpeg").textContent = status.ffmpeg;
|
|
356
|
+
el("status-ffprobe").textContent = status.ffprobe;
|
|
357
|
+
if (status.restart_required) {
|
|
358
|
+
showBanner("Settings on disk differ from the running server. Restart to apply them.", "warn");
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function renderSettings() {
|
|
363
|
+
const form = el("settings-form");
|
|
364
|
+
form.textContent = "";
|
|
365
|
+
FIELDS.forEach(function (field) {
|
|
366
|
+
const label = document.createElement("label");
|
|
367
|
+
label.className = "field";
|
|
368
|
+
const caption = document.createElement("span");
|
|
369
|
+
caption.textContent = field.label;
|
|
370
|
+
if (field.hint) {
|
|
371
|
+
caption.title = field.hint;
|
|
372
|
+
const hint = document.createElement("span");
|
|
373
|
+
hint.className = "hint";
|
|
374
|
+
hint.textContent = "?";
|
|
375
|
+
hint.title = field.hint;
|
|
376
|
+
caption.appendChild(hint);
|
|
377
|
+
}
|
|
378
|
+
const input = document.createElement("input");
|
|
379
|
+
if (field.hint) input.title = field.hint;
|
|
380
|
+
const value = getPath(settingsState, field.path);
|
|
381
|
+
if (field.type === "checkbox") {
|
|
382
|
+
input.type = "checkbox";
|
|
383
|
+
input.checked = Boolean(value);
|
|
384
|
+
} else if (field.type === "number") {
|
|
385
|
+
input.type = "number";
|
|
386
|
+
if (field.min !== undefined) input.min = field.min;
|
|
387
|
+
if (field.max !== undefined) input.max = field.max;
|
|
388
|
+
input.value = value == null ? "" : String(value);
|
|
389
|
+
} else {
|
|
390
|
+
input.type = "text";
|
|
391
|
+
input.value = Array.isArray(value) ? value.join(", ") : (value == null ? "" : String(value));
|
|
392
|
+
}
|
|
393
|
+
input.dataset.path = field.path;
|
|
394
|
+
input.dataset.kind = field.type;
|
|
395
|
+
input.dataset.optional = field.optional ? "true" : "false";
|
|
396
|
+
if (field.locked) input.disabled = true;
|
|
397
|
+
label.appendChild(caption);
|
|
398
|
+
label.appendChild(input);
|
|
399
|
+
form.appendChild(label);
|
|
400
|
+
});
|
|
401
|
+
renderSources(settingsState.sources || []);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function sourceRow(source) {
|
|
405
|
+
const row = document.createElement("tr");
|
|
406
|
+
row._source = Object.assign({}, source);
|
|
407
|
+
["id", "name", "path"].forEach(function (key) {
|
|
408
|
+
const cell = document.createElement("td");
|
|
409
|
+
const input = document.createElement("input");
|
|
410
|
+
input.type = "text";
|
|
411
|
+
input.spellcheck = false;
|
|
412
|
+
input.dataset.key = key;
|
|
413
|
+
input.value = source[key] == null ? "" : String(source[key]);
|
|
414
|
+
cell.appendChild(input);
|
|
415
|
+
row.appendChild(cell);
|
|
416
|
+
});
|
|
417
|
+
const enabledCell = document.createElement("td");
|
|
418
|
+
const enabled = document.createElement("input");
|
|
419
|
+
enabled.type = "checkbox";
|
|
420
|
+
enabled.dataset.key = "enabled";
|
|
421
|
+
enabled.checked = source.enabled !== false;
|
|
422
|
+
enabledCell.appendChild(enabled);
|
|
423
|
+
row.appendChild(enabledCell);
|
|
424
|
+
const actions = document.createElement("td");
|
|
425
|
+
const remove = document.createElement("button");
|
|
426
|
+
remove.className = "danger small";
|
|
427
|
+
remove.textContent = "Remove";
|
|
428
|
+
remove.addEventListener("click", function () {
|
|
429
|
+
row.remove();
|
|
430
|
+
updateSourcesEmpty();
|
|
431
|
+
});
|
|
432
|
+
actions.appendChild(remove);
|
|
433
|
+
row.appendChild(actions);
|
|
434
|
+
return row;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function renderSources(sources) {
|
|
438
|
+
const body = el("sources-body");
|
|
439
|
+
body.textContent = "";
|
|
440
|
+
sources.forEach(function (source) {
|
|
441
|
+
body.appendChild(sourceRow(source));
|
|
442
|
+
});
|
|
443
|
+
updateSourcesEmpty();
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function updateSourcesEmpty() {
|
|
447
|
+
el("sources-empty").className = el("sources-body").children.length ? "hidden" : "muted";
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function collectSources() {
|
|
451
|
+
const sources = [];
|
|
452
|
+
const rows = el("sources-body").querySelectorAll("tr");
|
|
453
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
454
|
+
const source = Object.assign({}, rows[index]._source || {});
|
|
455
|
+
const inputs = rows[index].querySelectorAll("[data-key]");
|
|
456
|
+
for (let field = 0; field < inputs.length; field += 1) {
|
|
457
|
+
const input = inputs[field];
|
|
458
|
+
const key = input.dataset.key;
|
|
459
|
+
source[key] = key === "enabled" ? input.checked : input.value.trim();
|
|
460
|
+
}
|
|
461
|
+
if (!source.id || !source.name || !source.path) {
|
|
462
|
+
throw new Error("Every source needs an id, name, and path.");
|
|
463
|
+
}
|
|
464
|
+
sources.push(source);
|
|
465
|
+
}
|
|
466
|
+
return sources;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async function addSource() {
|
|
470
|
+
const message = el("sources-message");
|
|
471
|
+
message.textContent = "";
|
|
472
|
+
const picked = await call("choose_source_folder");
|
|
473
|
+
if (!picked) {
|
|
474
|
+
message.textContent = "No folder was selected.";
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
el("sources-body").appendChild(sourceRow({
|
|
478
|
+
id: picked.id,
|
|
479
|
+
name: picked.name,
|
|
480
|
+
path: picked.path,
|
|
481
|
+
enabled: true
|
|
482
|
+
}));
|
|
483
|
+
updateSourcesEmpty();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
async function loadSettings() {
|
|
487
|
+
const snapshot = await call("get_settings");
|
|
488
|
+
if (snapshot.values) {
|
|
489
|
+
settingsState = snapshot.values;
|
|
490
|
+
renderSettings();
|
|
491
|
+
}
|
|
492
|
+
el("settings-message").textContent = snapshot.error || "";
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function collectSettings() {
|
|
496
|
+
const values = JSON.parse(JSON.stringify(settingsState));
|
|
497
|
+
const inputs = el("settings-form").querySelectorAll("input");
|
|
498
|
+
for (let index = 0; index < inputs.length; index += 1) {
|
|
499
|
+
const input = inputs[index];
|
|
500
|
+
const kind = input.dataset.kind;
|
|
501
|
+
let value;
|
|
502
|
+
if (kind === "checkbox") {
|
|
503
|
+
value = input.checked;
|
|
504
|
+
} else if (kind === "number") {
|
|
505
|
+
value = input.value === "" ? null : Number(input.value);
|
|
506
|
+
} else if (kind === "list") {
|
|
507
|
+
value = input.value.split(",").map(function (item) {
|
|
508
|
+
return item.trim();
|
|
509
|
+
}).filter(Boolean);
|
|
510
|
+
} else if (input.dataset.optional === "true" && input.value.trim() === "") {
|
|
511
|
+
value = null;
|
|
512
|
+
} else {
|
|
513
|
+
value = input.value;
|
|
514
|
+
}
|
|
515
|
+
setPath(values, input.dataset.path, value);
|
|
516
|
+
}
|
|
517
|
+
values.sources = collectSources();
|
|
518
|
+
return values;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
async function saveSettings() {
|
|
522
|
+
const message = el("settings-message");
|
|
523
|
+
message.textContent = "";
|
|
524
|
+
let values;
|
|
525
|
+
try {
|
|
526
|
+
values = collectSettings();
|
|
527
|
+
} catch (error) {
|
|
528
|
+
message.textContent = error.message;
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
try {
|
|
532
|
+
const snapshot = await call("save_settings", values);
|
|
533
|
+
settingsState = snapshot.values;
|
|
534
|
+
renderSettings();
|
|
535
|
+
message.textContent = snapshot.restart_required
|
|
536
|
+
? "Saved. Restart the server to apply the new settings."
|
|
537
|
+
: "Saved.";
|
|
538
|
+
loadStatus().catch(function () {});
|
|
539
|
+
} catch (error) {
|
|
540
|
+
message.textContent = error.message;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
async function loadDevices() {
|
|
545
|
+
const devices = await call("list_devices");
|
|
546
|
+
const body = el("devices-body");
|
|
547
|
+
body.textContent = "";
|
|
548
|
+
el("devices-empty").className = devices.length ? "hidden" : "muted";
|
|
549
|
+
devices.forEach(function (device) {
|
|
550
|
+
const row = document.createElement("tr");
|
|
551
|
+
const cells = [device.name, device.id, formatTime(device.paired_at), formatTime(device.last_seen_at)];
|
|
552
|
+
cells.forEach(function (value) {
|
|
553
|
+
const cell = document.createElement("td");
|
|
554
|
+
cell.textContent = value == null ? "-" : value;
|
|
555
|
+
row.appendChild(cell);
|
|
556
|
+
});
|
|
557
|
+
const actions = document.createElement("td");
|
|
558
|
+
const button = document.createElement("button");
|
|
559
|
+
button.textContent = "Revoke";
|
|
560
|
+
button.className = "danger small";
|
|
561
|
+
button.addEventListener("click", function () {
|
|
562
|
+
ask("Remove " + device.name + "? The device must pair again and its playback history is deleted.").then(function (confirmed) {
|
|
563
|
+
if (!confirmed) return;
|
|
564
|
+
busy(button, function () {
|
|
565
|
+
return call("revoke_device", device.id).then(loadDevices).then(loadStatus).catch(function (error) {
|
|
566
|
+
showBanner(error.message, "error");
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
actions.appendChild(button);
|
|
572
|
+
row.appendChild(actions);
|
|
573
|
+
body.appendChild(row);
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
async function createPin() {
|
|
578
|
+
const target = el("pin");
|
|
579
|
+
try {
|
|
580
|
+
const data = await call("create_pin");
|
|
581
|
+
target.textContent = "";
|
|
582
|
+
const code = document.createElement("div");
|
|
583
|
+
code.className = "pin";
|
|
584
|
+
code.textContent = data.pin;
|
|
585
|
+
const note = document.createElement("p");
|
|
586
|
+
note.className = "muted";
|
|
587
|
+
note.textContent = "Enter this PIN on the client before " +
|
|
588
|
+
new Date(data.expires_at * 1000).toLocaleTimeString() + ".";
|
|
589
|
+
target.appendChild(code);
|
|
590
|
+
target.appendChild(note);
|
|
591
|
+
} catch (error) {
|
|
592
|
+
target.textContent = error.message;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
function maintenanceMessage(message) {
|
|
597
|
+
el("maintenance-message").textContent = message;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function boot() {
|
|
601
|
+
if (booted) return;
|
|
602
|
+
booted = true;
|
|
603
|
+
el("refresh").addEventListener("click", function () { refreshAll(); });
|
|
604
|
+
el("save-settings").addEventListener("click", function (event) {
|
|
605
|
+
busy(event.target, saveSettings);
|
|
606
|
+
});
|
|
607
|
+
el("add-source").addEventListener("click", function (event) {
|
|
608
|
+
busy(event.target, addSource).catch(function (error) {
|
|
609
|
+
el("sources-message").textContent = error.message;
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
el("pair").addEventListener("click", function (event) {
|
|
613
|
+
busy(event.target, createPin);
|
|
614
|
+
});
|
|
615
|
+
el("clear-cache").addEventListener("click", function (event) {
|
|
616
|
+
busy(event.target, async function () {
|
|
617
|
+
const result = await call("clear_cache");
|
|
618
|
+
maintenanceMessage(result.message + " (" + result.removed_files + " files removed)");
|
|
619
|
+
}).catch(function (error) { maintenanceMessage(error.message); });
|
|
620
|
+
});
|
|
621
|
+
el("optimize-db").addEventListener("click", function (event) {
|
|
622
|
+
busy(event.target, async function () {
|
|
623
|
+
const result = await call("optimize_database");
|
|
624
|
+
maintenanceMessage(result.message + " (" + result.removed_records + " playback records for unpaired devices removed).");
|
|
625
|
+
}).catch(function (error) { maintenanceMessage(error.message); });
|
|
626
|
+
});
|
|
627
|
+
el("reset-db").addEventListener("click", async function () {
|
|
628
|
+
const confirmation = el("reset-confirm").value.trim();
|
|
629
|
+
if (confirmation !== "RESET") {
|
|
630
|
+
maintenanceMessage("Type RESET to enable the database reset.");
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (!(await ask("Delete all paired devices and playback history? This cannot be undone."))) return;
|
|
634
|
+
try {
|
|
635
|
+
const result = await call("reset_database", confirmation);
|
|
636
|
+
maintenanceMessage(result.message + ".");
|
|
637
|
+
el("reset-confirm").value = "";
|
|
638
|
+
loadDevices().catch(function () {});
|
|
639
|
+
loadStatus().catch(function () {});
|
|
640
|
+
} catch (error) {
|
|
641
|
+
maintenanceMessage(error.message);
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
el("restart").addEventListener("click", async function () {
|
|
645
|
+
if (!(await ask("Restart the OpenVideo server now?"))) return;
|
|
646
|
+
try {
|
|
647
|
+
await call("restart");
|
|
648
|
+
showBanner("Restart requested. The connection may drop for a few seconds.", "info");
|
|
649
|
+
} catch (error) {
|
|
650
|
+
showBanner(error.message, "error");
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
refreshAll();
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function refreshAll() {
|
|
657
|
+
Promise.all([loadStatus(), loadSettings(), loadDevices()]).catch(function (error) {
|
|
658
|
+
showBanner(error.message, "error");
|
|
659
|
+
el("server-meta").textContent = "Could not reach the OpenVideo server.";
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
window.addEventListener("pywebviewready", boot);
|
|
664
|
+
if (window.pywebview) {
|
|
665
|
+
boot();
|
|
666
|
+
}
|
|
667
|
+
</script>
|
|
668
|
+
</body>
|
|
669
|
+
</html>
|
|
670
|
+
"""
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
def run_admin_ui(client: AdminClient | None = None) -> None:
|
|
674
|
+
"""Open the admin window and block until the user closes it."""
|
|
675
|
+
try:
|
|
676
|
+
webview: Any = importlib.import_module("webview")
|
|
677
|
+
except ImportError as exc:
|
|
678
|
+
raise AdminUiUnavailable(
|
|
679
|
+
"The admin window needs the optional ui dependencies. "
|
|
680
|
+
'Install them with: uv tool install --from ".[ui]" openvideo-server',
|
|
681
|
+
) from exc
|
|
682
|
+
bridge = AdminBridge(client, webview=webview)
|
|
683
|
+
window = webview.create_window(
|
|
684
|
+
"OpenVideo Admin",
|
|
685
|
+
html=ADMIN_HTML,
|
|
686
|
+
width=980,
|
|
687
|
+
height=780,
|
|
688
|
+
min_size=(760, 560),
|
|
689
|
+
js_api=bridge,
|
|
690
|
+
)
|
|
691
|
+
bridge.attach_window(window)
|
|
692
|
+
webview.start()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""HTTP API routers."""
|