awstream 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.
- awstream/__init__.py +20 -0
- awstream/cli.py +170 -0
- awstream/hud.py +489 -0
- awstream/obs.py +394 -0
- awstream/producer.py +232 -0
- awstream/state.py +276 -0
- awstream/youtube.py +84 -0
- awstream-0.1.0.dist-info/METADATA +30 -0
- awstream-0.1.0.dist-info/RECORD +12 -0
- awstream-0.1.0.dist-info/WHEEL +5 -0
- awstream-0.1.0.dist-info/entry_points.txt +2 -0
- awstream-0.1.0.dist-info/top_level.txt +1 -0
awstream/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""awstream: dual-stream producer for YouTube Live (OBS) + Discord."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from awstream.obs import OBSClient, OBSError, discover_obs_config
|
|
5
|
+
from awstream.state import ClipMark, StreamSession, StreamStore
|
|
6
|
+
from awstream.youtube import extract_video_id, normalize_youtube_url
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"ClipMark",
|
|
12
|
+
"OBSClient",
|
|
13
|
+
"OBSError",
|
|
14
|
+
"StreamSession",
|
|
15
|
+
"StreamStore",
|
|
16
|
+
"__version__",
|
|
17
|
+
"discover_obs_config",
|
|
18
|
+
"extract_video_id",
|
|
19
|
+
"normalize_youtube_url",
|
|
20
|
+
]
|
awstream/cli.py
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""CLI entrypoint for ``awstream`` (setup, doctor, hud, dual-stream controls)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
import sys
|
|
7
|
+
import tempfile
|
|
8
|
+
import threading
|
|
9
|
+
import urllib.request
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from awstream.hud import DEFAULT_HUD_PORT, create_hud_server
|
|
13
|
+
from awstream.obs import OBSError
|
|
14
|
+
from awstream.producer import StreamProducer
|
|
15
|
+
from awstream.state import StreamStore
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _self_test() -> int:
|
|
19
|
+
with tempfile.TemporaryDirectory(prefix="awstream-selftest-") as td:
|
|
20
|
+
prod = StreamProducer(store=StreamStore(Path(td) / "state.json"))
|
|
21
|
+
prod.set_focus("Self-test stream")
|
|
22
|
+
prod.clip("test highlight", by="selftest")
|
|
23
|
+
srv = create_hud_server(host="127.0.0.1", port=0, producer=prod, poll_dj=False)
|
|
24
|
+
port = srv.server_address[1]
|
|
25
|
+
threading.Thread(target=srv.serve_forever, daemon=True).start()
|
|
26
|
+
try:
|
|
27
|
+
with urllib.request.urlopen(f"http://127.0.0.1:{port}/health", timeout=3) as r:
|
|
28
|
+
assert json.loads(r.read().decode())["ok"] is True
|
|
29
|
+
with urllib.request.urlopen(f"http://127.0.0.1:{port}/overlay", timeout=3) as r:
|
|
30
|
+
html = r.read().decode()
|
|
31
|
+
assert "<!doctype html>" in html.lower() or "<html" in html.lower()
|
|
32
|
+
finally:
|
|
33
|
+
srv.shutdown()
|
|
34
|
+
srv.server_close()
|
|
35
|
+
print(json.dumps({"self_test": "PASS", "hud": "ok", "state": "ok"}, indent=2))
|
|
36
|
+
return 0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main(argv=None) -> int:
|
|
40
|
+
ap = argparse.ArgumentParser(
|
|
41
|
+
prog="awstream",
|
|
42
|
+
description="Dual-stream producer for YouTube Live (OBS) + Discord",
|
|
43
|
+
)
|
|
44
|
+
ap.add_argument("--self-test", action="store_true", help="Run offline HUD + state self-test")
|
|
45
|
+
sub = ap.add_subparsers(dest="cmd", required=False)
|
|
46
|
+
|
|
47
|
+
sub.add_parser("doctor", help="Check OBS WebSocket, YouTube RTMPS, and Stream HUD readiness")
|
|
48
|
+
|
|
49
|
+
p_setup = sub.add_parser("setup", help="Configure OBS work scenes, HUD browser source, and YouTube RTMPS")
|
|
50
|
+
p_setup.add_argument("--hud-port", type=int, default=DEFAULT_HUD_PORT)
|
|
51
|
+
p_setup.add_argument("--youtube-key", default="", help="YouTube Live stream key (never printed)")
|
|
52
|
+
|
|
53
|
+
p_hud = sub.add_parser("hud", help="Run the 1920x1080 transparent Stream HUD + Producer Control server")
|
|
54
|
+
p_hud.add_argument("--host", default="0.0.0.0")
|
|
55
|
+
p_hud.add_argument("--port", type=int, default=DEFAULT_HUD_PORT)
|
|
56
|
+
p_hud.add_argument("--no-dj-poll", action="store_true")
|
|
57
|
+
|
|
58
|
+
p_start = sub.add_parser("start", help="Start a dual-stream session")
|
|
59
|
+
p_start.add_argument("title", nargs="?", default="Working Live with Aither")
|
|
60
|
+
p_start.add_argument("--topic", default="")
|
|
61
|
+
p_start.add_argument("--youtube", default="")
|
|
62
|
+
p_start.add_argument("--obs", action="store_true", help="Also trigger OBS StartStream")
|
|
63
|
+
p_start.add_argument("--record", action="store_true", help="Also start local OBS recording")
|
|
64
|
+
|
|
65
|
+
p_stop = sub.add_parser("stop", help="Stop the stream and print the recap")
|
|
66
|
+
p_stop.add_argument("--keep-obs", action="store_true")
|
|
67
|
+
|
|
68
|
+
p_focus = sub.add_parser("focus", help="Update the 'Working On' task on the stream HUD")
|
|
69
|
+
p_focus.add_argument("topic")
|
|
70
|
+
|
|
71
|
+
p_sprint = sub.add_parser("sprint", help="Start a Pomodoro/focus sprint countdown on the HUD")
|
|
72
|
+
p_sprint.add_argument("minutes", type=float, nargs="?", default=25.0)
|
|
73
|
+
p_sprint.add_argument("--label", default="Focus Sprint")
|
|
74
|
+
|
|
75
|
+
p_clip = sub.add_parser("clip", help="Mark a highlight timestamp")
|
|
76
|
+
p_clip.add_argument("label", nargs="?", default="Highlight")
|
|
77
|
+
p_clip.add_argument("--by", default="Host")
|
|
78
|
+
|
|
79
|
+
p_priv = sub.add_parser("privacy", help="Toggle Privacy Shield / BRB screen")
|
|
80
|
+
p_priv.add_argument("state", choices=["on", "off"])
|
|
81
|
+
p_priv.add_argument("--message", default="")
|
|
82
|
+
|
|
83
|
+
p_scene = sub.add_parser("scene", help="Switch OBS program scene")
|
|
84
|
+
p_scene.add_argument("name")
|
|
85
|
+
|
|
86
|
+
sub.add_parser("status", help="Show current stream session JSON")
|
|
87
|
+
|
|
88
|
+
args = ap.parse_args(argv)
|
|
89
|
+
if args.self_test:
|
|
90
|
+
return _self_test()
|
|
91
|
+
if not args.cmd:
|
|
92
|
+
ap.print_help()
|
|
93
|
+
return 0
|
|
94
|
+
prod = StreamProducer()
|
|
95
|
+
|
|
96
|
+
if args.cmd == "doctor":
|
|
97
|
+
doc = prod.doctor()
|
|
98
|
+
for c in doc["checks"]:
|
|
99
|
+
mark = "OK " if c["ok"] else "WARN"
|
|
100
|
+
print(f"[{mark}] {c['name']}: {c['detail']}")
|
|
101
|
+
return 0 if doc["ready"] else 1
|
|
102
|
+
|
|
103
|
+
if args.cmd == "setup":
|
|
104
|
+
try:
|
|
105
|
+
res = prod.setup(hud_port=args.hud_port, youtube_key=args.youtube_key)
|
|
106
|
+
except OBSError as exc:
|
|
107
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
108
|
+
return 1
|
|
109
|
+
print(json.dumps(res, indent=2))
|
|
110
|
+
return 0
|
|
111
|
+
|
|
112
|
+
if args.cmd == "hud":
|
|
113
|
+
srv = create_hud_server(
|
|
114
|
+
host=args.host, port=args.port, producer=prod, poll_dj=not args.no_dj_poll,
|
|
115
|
+
)
|
|
116
|
+
print(
|
|
117
|
+
f"Aither Stream HUD live:\n"
|
|
118
|
+
f" OBS Overlay: http://127.0.0.1:{args.port}/overlay\n"
|
|
119
|
+
f" Control UI : http://127.0.0.1:{args.port}/control",
|
|
120
|
+
flush=True,
|
|
121
|
+
)
|
|
122
|
+
try:
|
|
123
|
+
srv.serve_forever()
|
|
124
|
+
except KeyboardInterrupt:
|
|
125
|
+
pass
|
|
126
|
+
return 0
|
|
127
|
+
|
|
128
|
+
if args.cmd == "start":
|
|
129
|
+
res = prod.start(
|
|
130
|
+
args.title, topic=args.topic, youtube_url=args.youtube,
|
|
131
|
+
start_obs=args.obs, record_local=args.record,
|
|
132
|
+
)
|
|
133
|
+
print(json.dumps(res, indent=2))
|
|
134
|
+
return 0
|
|
135
|
+
|
|
136
|
+
if args.cmd == "stop":
|
|
137
|
+
res = prod.stop(stop_obs=not args.keep_obs)
|
|
138
|
+
print(res["recap"])
|
|
139
|
+
return 0
|
|
140
|
+
|
|
141
|
+
if args.cmd == "focus":
|
|
142
|
+
print(json.dumps(prod.set_focus(args.topic).to_dict(), indent=2))
|
|
143
|
+
return 0
|
|
144
|
+
|
|
145
|
+
if args.cmd == "sprint":
|
|
146
|
+
print(json.dumps(prod.start_sprint(args.minutes, label=args.label).to_dict(), indent=2))
|
|
147
|
+
return 0
|
|
148
|
+
|
|
149
|
+
if args.cmd == "clip":
|
|
150
|
+
print(json.dumps(prod.clip(args.label, by=args.by), indent=2))
|
|
151
|
+
return 0
|
|
152
|
+
|
|
153
|
+
if args.cmd == "privacy":
|
|
154
|
+
print(json.dumps(prod.set_privacy(args.state == "on", message=args.message), indent=2))
|
|
155
|
+
return 0
|
|
156
|
+
|
|
157
|
+
if args.cmd == "scene":
|
|
158
|
+
res = prod.set_scene(args.name)
|
|
159
|
+
print(json.dumps(res, indent=2))
|
|
160
|
+
return 0 if res["ok"] else 1
|
|
161
|
+
|
|
162
|
+
if args.cmd == "status":
|
|
163
|
+
print(json.dumps(prod.status(), indent=2))
|
|
164
|
+
return 0
|
|
165
|
+
|
|
166
|
+
return 0
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
if __name__ == "__main__":
|
|
170
|
+
raise SystemExit(main())
|
awstream/hud.py
ADDED
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
"""Transparent 1920x1080 OBS Browser Source Stream HUD + Producer Control Panel.
|
|
2
|
+
|
|
3
|
+
Default port ``47960`` matches ``Aither_Live.json``'s existing ``Aither Overlay``
|
|
4
|
+
Browser Source (``http://127.0.0.1:47960/overlay``) so it drops right into OBS
|
|
5
|
+
with zero manual reconfiguration.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import subprocess
|
|
12
|
+
import threading
|
|
13
|
+
import time
|
|
14
|
+
import urllib.error
|
|
15
|
+
import urllib.request
|
|
16
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
17
|
+
from typing import Any, Dict, Optional
|
|
18
|
+
|
|
19
|
+
from awstream.producer import StreamProducer
|
|
20
|
+
from awstream.state import StreamStore
|
|
21
|
+
|
|
22
|
+
DEFAULT_HUD_PORT = 47960
|
|
23
|
+
|
|
24
|
+
_OVERLAY_HTML = r"""<!doctype html>
|
|
25
|
+
<html lang="en">
|
|
26
|
+
<head>
|
|
27
|
+
<meta charset="utf-8" />
|
|
28
|
+
<title>Aither Stream HUD</title>
|
|
29
|
+
<style>
|
|
30
|
+
:root {
|
|
31
|
+
--bg: rgba(12, 14, 24, 0.78);
|
|
32
|
+
--border: rgba(139, 92, 246, 0.42);
|
|
33
|
+
--accent: #a78bfa;
|
|
34
|
+
--live: #ef4444;
|
|
35
|
+
--mint: #34d399;
|
|
36
|
+
--text: #f8fafc;
|
|
37
|
+
--muted: #94a3b8;
|
|
38
|
+
}
|
|
39
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
40
|
+
html, body {
|
|
41
|
+
width: 1920px; height: 1080px; overflow: hidden;
|
|
42
|
+
background: transparent; color: var(--text);
|
|
43
|
+
font-family: "Inter", "Segoe UI", system-ui, sans-serif;
|
|
44
|
+
}
|
|
45
|
+
.glass {
|
|
46
|
+
background: var(--bg);
|
|
47
|
+
backdrop-filter: blur(14px);
|
|
48
|
+
border: 1px solid var(--border);
|
|
49
|
+
border-radius: 16px;
|
|
50
|
+
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
|
|
51
|
+
}
|
|
52
|
+
/* Top-Right Live + Sprint Pill */
|
|
53
|
+
.top-bar {
|
|
54
|
+
position: absolute; top: 28px; right: 32px;
|
|
55
|
+
display: flex; align-items: center; gap: 12px;
|
|
56
|
+
}
|
|
57
|
+
.pill {
|
|
58
|
+
display: inline-flex; align-items: center; gap: 10px;
|
|
59
|
+
padding: 10px 18px; font-weight: 600; font-size: 16px;
|
|
60
|
+
}
|
|
61
|
+
.dot {
|
|
62
|
+
width: 10px; height: 10px; border-radius: 50%;
|
|
63
|
+
background: var(--live); box-shadow: 0 0 12px var(--live);
|
|
64
|
+
animation: pulse 1.6s infinite;
|
|
65
|
+
}
|
|
66
|
+
.dot.idle { background: var(--muted); box-shadow: none; animation: none; }
|
|
67
|
+
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
|
|
68
|
+
.badge {
|
|
69
|
+
font-size: 12px; font-weight: 700; letter-spacing: 0.06em;
|
|
70
|
+
padding: 3px 8px; border-radius: 999px;
|
|
71
|
+
background: rgba(167, 139, 250, 0.2); color: #ddd6fe;
|
|
72
|
+
}
|
|
73
|
+
.badge.yt { background: rgba(239, 68, 68, 0.25); color: #fecaca; }
|
|
74
|
+
.badge.dc { background: rgba(99, 102, 241, 0.28); color: #c7d2fe; }
|
|
75
|
+
.sprint { color: var(--mint); font-variant-numeric: tabular-nums; }
|
|
76
|
+
|
|
77
|
+
/* Bottom-Left Focus + DJ Now Playing */
|
|
78
|
+
.bottom-left {
|
|
79
|
+
position: absolute; left: 32px; bottom: 28px;
|
|
80
|
+
display: flex; flex-direction: column; gap: 12px; max-width: 560px;
|
|
81
|
+
}
|
|
82
|
+
.focus-card { padding: 14px 20px; }
|
|
83
|
+
.eyebrow {
|
|
84
|
+
font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em;
|
|
85
|
+
color: var(--accent); font-weight: 700; margin-bottom: 4px;
|
|
86
|
+
}
|
|
87
|
+
.focus-text { font-size: 20px; font-weight: 700; line-height: 1.25; }
|
|
88
|
+
.stream-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
|
|
89
|
+
|
|
90
|
+
.dj-card {
|
|
91
|
+
display: flex; align-items: center; gap: 14px; padding: 12px 18px;
|
|
92
|
+
}
|
|
93
|
+
.eq { display: flex; align-items: flex-end; gap: 3px; height: 22px; }
|
|
94
|
+
.eq span {
|
|
95
|
+
width: 4px; background: var(--accent); border-radius: 2px;
|
|
96
|
+
animation: eq 0.9s infinite ease-in-out;
|
|
97
|
+
}
|
|
98
|
+
.eq span:nth-child(2) { animation-delay: 0.2s; }
|
|
99
|
+
.eq span:nth-child(3) { animation-delay: 0.45s; }
|
|
100
|
+
.eq.paused span { animation: none; height: 5px !important; opacity: 0.4; }
|
|
101
|
+
@keyframes eq { 0%,100% { height: 6px; } 50% { height: 22px; } }
|
|
102
|
+
.dj-meta { flex: 1; min-width: 0; }
|
|
103
|
+
.dj-title {
|
|
104
|
+
font-size: 16px; font-weight: 700; white-space: nowrap;
|
|
105
|
+
overflow: hidden; text-overflow: ellipsis;
|
|
106
|
+
}
|
|
107
|
+
.dj-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
|
|
108
|
+
.bar-wrap {
|
|
109
|
+
height: 4px; width: 100%; background: rgba(255,255,255,0.12);
|
|
110
|
+
border-radius: 99px; margin-top: 7px; overflow: hidden;
|
|
111
|
+
}
|
|
112
|
+
.bar-fill { height: 100%; background: linear-gradient(90deg, #8b5cf6, #34d399); width: 0%; transition: width 0.8s linear; }
|
|
113
|
+
|
|
114
|
+
/* Bottom-Right Chat & Clip Toast */
|
|
115
|
+
.bottom-right {
|
|
116
|
+
position: absolute; right: 32px; bottom: 28px;
|
|
117
|
+
width: 420px; display: flex; flex-direction: column; gap: 10px;
|
|
118
|
+
}
|
|
119
|
+
.clip-toast {
|
|
120
|
+
padding: 12px 16px; border-color: rgba(52, 211, 153, 0.55);
|
|
121
|
+
display: none;
|
|
122
|
+
}
|
|
123
|
+
.chat-box { padding: 12px 16px; display: none; }
|
|
124
|
+
.chat-msg { font-size: 14px; line-height: 1.35; margin-top: 6px; }
|
|
125
|
+
.chat-author { font-weight: 700; color: #c4b5fd; }
|
|
126
|
+
|
|
127
|
+
/* Full-Screen Privacy Shield */
|
|
128
|
+
.shield {
|
|
129
|
+
position: absolute; inset: 0; display: none;
|
|
130
|
+
align-items: center; justify-content: center; flex-direction: column; gap: 18px;
|
|
131
|
+
background: radial-gradient(circle at 30% 20%, #1e1b4b, #090b14 70%);
|
|
132
|
+
z-index: 999; text-align: center;
|
|
133
|
+
}
|
|
134
|
+
.shield.active { display: flex; }
|
|
135
|
+
.shield h1 { font-size: 54px; font-weight: 800; letter-spacing: -0.02em; }
|
|
136
|
+
.shield p { font-size: 24px; color: #cbd5e1; max-width: 780px; }
|
|
137
|
+
.shield .pill { font-size: 20px; padding: 14px 26px; }
|
|
138
|
+
</style>
|
|
139
|
+
</head>
|
|
140
|
+
<body>
|
|
141
|
+
<div class="top-bar">
|
|
142
|
+
<div id="sprintPill" class="glass pill" style="display:none;">
|
|
143
|
+
<span>🍅</span><span id="sprintLabel">Focus</span>
|
|
144
|
+
<span id="sprintTime" class="sprint">25:00</span>
|
|
145
|
+
</div>
|
|
146
|
+
<div class="glass pill">
|
|
147
|
+
<span id="liveDot" class="dot idle"></span>
|
|
148
|
+
<span id="liveText">STANDBY</span>
|
|
149
|
+
<span id="uptime" style="color:var(--muted);font-variant-numeric:tabular-nums;"></span>
|
|
150
|
+
<span class="badge yt">YouTube</span>
|
|
151
|
+
<span class="badge dc">Discord</span>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
|
|
155
|
+
<div class="bottom-left">
|
|
156
|
+
<div id="focusCard" class="glass focus-card">
|
|
157
|
+
<div class="eyebrow">Working On</div>
|
|
158
|
+
<div id="focusText" class="focus-text">Building with Aither</div>
|
|
159
|
+
<div id="streamTitle" class="stream-sub"></div>
|
|
160
|
+
</div>
|
|
161
|
+
<div id="djCard" class="glass dj-card" style="display:none;">
|
|
162
|
+
<div id="eq" class="eq"><span></span><span></span><span></span></div>
|
|
163
|
+
<div class="dj-meta">
|
|
164
|
+
<div id="djTitle" class="dj-title"></div>
|
|
165
|
+
<div id="djSub" class="dj-sub"></div>
|
|
166
|
+
<div class="bar-wrap"><div id="djBar" class="bar-fill"></div></div>
|
|
167
|
+
</div>
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<div class="bottom-right">
|
|
172
|
+
<div id="clipToast" class="glass clip-toast">
|
|
173
|
+
<div class="eyebrow" style="color:var(--mint);">✂️ Clip Marked</div>
|
|
174
|
+
<div id="clipText" style="font-size:15px;font-weight:600;"></div>
|
|
175
|
+
</div>
|
|
176
|
+
<div id="chatBox" class="glass chat-box">
|
|
177
|
+
<div class="eyebrow">Live Chat</div>
|
|
178
|
+
<div id="chatLines"></div>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<div id="shield" class="shield">
|
|
183
|
+
<div class="glass pill"><span>🛡️</span><span>Aither Privacy Shield</span></div>
|
|
184
|
+
<h1 id="shieldMsg">Be Right Back</h1>
|
|
185
|
+
<p id="shieldSub">Screen hidden while checking private tabs or credentials.</p>
|
|
186
|
+
<div id="shieldMusic" class="glass pill" style="display:none;"></div>
|
|
187
|
+
</div>
|
|
188
|
+
|
|
189
|
+
<script>
|
|
190
|
+
async function tick() {
|
|
191
|
+
try {
|
|
192
|
+
const r = await fetch('/api/state', { cache: 'no-store' });
|
|
193
|
+
const s = await r.json();
|
|
194
|
+
|
|
195
|
+
const dot = document.getElementById('liveDot');
|
|
196
|
+
const liveText = document.getElementById('liveText');
|
|
197
|
+
const uptime = document.getElementById('uptime');
|
|
198
|
+
if (s.live) {
|
|
199
|
+
dot.className = 'dot';
|
|
200
|
+
liveText.textContent = 'LIVE';
|
|
201
|
+
uptime.textContent = s.uptime_text || '';
|
|
202
|
+
} else {
|
|
203
|
+
dot.className = 'dot idle';
|
|
204
|
+
liveText.textContent = 'STANDBY';
|
|
205
|
+
uptime.textContent = '';
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
document.getElementById('focusText').textContent = s.topic || s.title || 'Working Live with Aither';
|
|
209
|
+
document.getElementById('streamTitle').textContent = s.topic && s.title ? s.title : '';
|
|
210
|
+
|
|
211
|
+
const sp = document.getElementById('sprintPill');
|
|
212
|
+
if (s.timer_remaining_s > 0) {
|
|
213
|
+
sp.style.display = 'inline-flex';
|
|
214
|
+
document.getElementById('sprintLabel').textContent = s.timer_label || 'Sprint';
|
|
215
|
+
document.getElementById('sprintTime').textContent = s.timer_remaining_text;
|
|
216
|
+
} else {
|
|
217
|
+
sp.style.display = 'none';
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const np = s.now_playing || {};
|
|
221
|
+
const djCard = document.getElementById('djCard');
|
|
222
|
+
const shieldMusic = document.getElementById('shieldMusic');
|
|
223
|
+
if (np.display || np.title) {
|
|
224
|
+
const label = np.display || (np.artist ? `${np.artist} — ${np.title}` : np.title);
|
|
225
|
+
djCard.style.display = 'flex';
|
|
226
|
+
document.getElementById('djTitle').textContent = label;
|
|
227
|
+
document.getElementById('djSub').textContent = np.requested_by ? `Aither DJ • ${np.requested_by}` : 'Aither DJ';
|
|
228
|
+
document.getElementById('eq').className = np.paused ? 'eq paused' : 'eq';
|
|
229
|
+
const pct = (np.duration_s > 0) ? Math.min(100, (np.elapsed_s / np.duration_s) * 100) : 100;
|
|
230
|
+
document.getElementById('djBar').style.width = pct.toFixed(1) + '%';
|
|
231
|
+
shieldMusic.style.display = 'inline-flex';
|
|
232
|
+
shieldMusic.textContent = '🎧 ' + label;
|
|
233
|
+
} else {
|
|
234
|
+
djCard.style.display = 'none';
|
|
235
|
+
shieldMusic.style.display = 'none';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const clips = s.clips || [];
|
|
239
|
+
const lastClip = clips[clips.length - 1];
|
|
240
|
+
const toast = document.getElementById('clipToast');
|
|
241
|
+
if (lastClip && (Date.now()/1000 - (lastClip.wall || 0)) < 15) {
|
|
242
|
+
toast.style.display = 'block';
|
|
243
|
+
document.getElementById('clipText').textContent = `[${lastClip.timestamp}] ${lastClip.label}`;
|
|
244
|
+
} else {
|
|
245
|
+
toast.style.display = 'none';
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const chat = (s.chat_feed || []).slice(-4);
|
|
249
|
+
const chatBox = document.getElementById('chatBox');
|
|
250
|
+
if (chat.length > 0) {
|
|
251
|
+
chatBox.style.display = 'block';
|
|
252
|
+
const box = document.getElementById('chatLines');
|
|
253
|
+
box.innerHTML = '';
|
|
254
|
+
for (const m of chat) {
|
|
255
|
+
const div = document.createElement('div');
|
|
256
|
+
div.className = 'chat-msg';
|
|
257
|
+
const tag = m.platform === 'youtube' ? '🔴 ' : '🟣 ';
|
|
258
|
+
const au = document.createElement('span');
|
|
259
|
+
au.className = 'chat-author';
|
|
260
|
+
au.textContent = tag + m.author + ': ';
|
|
261
|
+
div.appendChild(au);
|
|
262
|
+
div.appendChild(document.createTextNode(m.text));
|
|
263
|
+
box.appendChild(div);
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
chatBox.style.display = 'none';
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const shield = document.getElementById('shield');
|
|
270
|
+
if (s.privacy_shield) {
|
|
271
|
+
shield.className = 'shield active';
|
|
272
|
+
document.getElementById('shieldMsg').textContent = s.privacy_message || 'Be Right Back';
|
|
273
|
+
} else {
|
|
274
|
+
shield.className = 'shield';
|
|
275
|
+
}
|
|
276
|
+
} catch (e) {}
|
|
277
|
+
}
|
|
278
|
+
tick();
|
|
279
|
+
setInterval(tick, 1200);
|
|
280
|
+
</script>
|
|
281
|
+
</body>
|
|
282
|
+
</html>
|
|
283
|
+
"""
|
|
284
|
+
|
|
285
|
+
_CONTROL_HTML = r"""<!doctype html>
|
|
286
|
+
<html lang="en">
|
|
287
|
+
<head>
|
|
288
|
+
<meta charset="utf-8" />
|
|
289
|
+
<title>Aither Stream Producer</title>
|
|
290
|
+
<style>
|
|
291
|
+
body { background:#0b0e18; color:#f8fafc; font-family:system-ui,sans-serif; max-width:760px; margin:32px auto; padding:0 20px; }
|
|
292
|
+
h1 { font-size:24px; margin-bottom:16px; }
|
|
293
|
+
.card { background:#14192a; border:1px solid #2a3252; border-radius:12px; padding:18px; margin-bottom:16px; }
|
|
294
|
+
.row { display:flex; gap:10px; flex-wrap:wrap; margin-top:10px; }
|
|
295
|
+
input { flex:1; min-width:200px; padding:10px 12px; border-radius:8px; border:1px solid #334155; background:#0f172a; color:#fff; }
|
|
296
|
+
button { padding:10px 16px; border-radius:8px; border:0; cursor:pointer; font-weight:600; background:#7c3aed; color:#fff; }
|
|
297
|
+
button.sec { background:#334155; }
|
|
298
|
+
button.red { background:#dc2626; }
|
|
299
|
+
button.green { background:#059669; }
|
|
300
|
+
pre { background:#090b12; padding:12px; border-radius:8px; overflow:auto; font-size:12px; color:#cbd5e1; }
|
|
301
|
+
</style>
|
|
302
|
+
</head>
|
|
303
|
+
<body>
|
|
304
|
+
<h1>🎬 Aither Dual-Stream Producer (YouTube + Discord)</h1>
|
|
305
|
+
<div class="card">
|
|
306
|
+
<div class="row">
|
|
307
|
+
<input id="title" placeholder="Stream title (e.g. Building AitherOS live)" />
|
|
308
|
+
<input id="yt" placeholder="YouTube Live URL (optional)" />
|
|
309
|
+
</div>
|
|
310
|
+
<div class="row">
|
|
311
|
+
<button class="green" onclick="act('start', {title: v('title'), topic: v('focus'), youtube_url: v('yt'), start_obs: true})">🔴 Go Live (+OBS)</button>
|
|
312
|
+
<button class="sec" onclick="act('start', {title: v('title'), topic: v('focus'), youtube_url: v('yt'), start_obs: false})">▶️ Start HUD Only</button>
|
|
313
|
+
<button class="red" onclick="act('stop', {stop_obs: true})">⏹ End Stream</button>
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
<div class="card">
|
|
317
|
+
<div class="row">
|
|
318
|
+
<input id="focus" placeholder="Current focus / working on..." />
|
|
319
|
+
<button onclick="act('focus', {topic: v('focus')})">Update Focus</button>
|
|
320
|
+
</div>
|
|
321
|
+
<div class="row">
|
|
322
|
+
<button class="sec" onclick="act('privacy', {enabled: true})">🛡️ Privacy Shield ON</button>
|
|
323
|
+
<button class="sec" onclick="act('privacy', {enabled: false})">✅ Privacy Shield OFF</button>
|
|
324
|
+
<button class="sec" onclick="act('sprint', {minutes: 25, label: 'Focus Sprint'})">🍅 25m Sprint</button>
|
|
325
|
+
<button class="sec" onclick="act('sprint', {minutes: 45, label: 'Deep Work'})">⏱️ 45m Deep Work</button>
|
|
326
|
+
<button onclick="act('clip', {label: v('focus') || 'Highlight', by: 'Host'})">✂️ Clip That!</button>
|
|
327
|
+
</div>
|
|
328
|
+
</div>
|
|
329
|
+
<div class="card">
|
|
330
|
+
<div>OBS Browser Source URL: <code>http://127.0.0.1:47960/overlay</code></div>
|
|
331
|
+
<pre id="out">Loading...</pre>
|
|
332
|
+
</div>
|
|
333
|
+
<script>
|
|
334
|
+
const v = id => document.getElementById(id).value;
|
|
335
|
+
async function act(action, extra={}) {
|
|
336
|
+
await fetch('/api/action', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({action, ...extra}) });
|
|
337
|
+
refresh();
|
|
338
|
+
}
|
|
339
|
+
async function refresh() {
|
|
340
|
+
const r = await fetch('/api/state');
|
|
341
|
+
document.getElementById('out').textContent = JSON.stringify(await r.json(), null, 2);
|
|
342
|
+
}
|
|
343
|
+
refresh(); setInterval(refresh, 2000);
|
|
344
|
+
</script>
|
|
345
|
+
</body>
|
|
346
|
+
</html>
|
|
347
|
+
"""
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def _poll_awdiscord_dj(container: str = "") -> Optional[Dict[str, Any]]:
|
|
351
|
+
"""Best-effort read of Aither's live Voice DJ Now Playing state."""
|
|
352
|
+
container = (container or os.getenv("AWSTREAM_DISCORD_CONTAINER") or "awdiscord").strip()
|
|
353
|
+
url = (os.getenv("AWDISCORD_INBOX_URL") or "").strip().rstrip("/")
|
|
354
|
+
token = (os.getenv("AWDISCORD_INBOX_TOKEN") or "").strip()
|
|
355
|
+
try:
|
|
356
|
+
if not url:
|
|
357
|
+
ip = subprocess.check_output(
|
|
358
|
+
["podman", "inspect", container, "--format",
|
|
359
|
+
"{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}"],
|
|
360
|
+
timeout=3, stderr=subprocess.DEVNULL,
|
|
361
|
+
).decode().strip()
|
|
362
|
+
if ip:
|
|
363
|
+
url = f"http://{ip}:8371"
|
|
364
|
+
if url and not token:
|
|
365
|
+
token = subprocess.check_output(
|
|
366
|
+
["podman", "exec", container, "printenv", "AWDISCORD_INBOX_TOKEN"],
|
|
367
|
+
timeout=3, stderr=subprocess.DEVNULL,
|
|
368
|
+
).decode().strip()
|
|
369
|
+
if not (url and token):
|
|
370
|
+
return None
|
|
371
|
+
req = urllib.request.Request(
|
|
372
|
+
url + "/voice/dj/status",
|
|
373
|
+
headers={"Authorization": "Bearer " + token},
|
|
374
|
+
)
|
|
375
|
+
with urllib.request.urlopen(req, timeout=3) as resp:
|
|
376
|
+
doc = json.loads(resp.read().decode("utf-8") or "{}")
|
|
377
|
+
for g in (doc.get("guilds") or {}).values():
|
|
378
|
+
cur = g.get("current")
|
|
379
|
+
if cur:
|
|
380
|
+
return {**cur, "paused": bool(g.get("paused"))}
|
|
381
|
+
return {}
|
|
382
|
+
except Exception: # noqa: BLE001
|
|
383
|
+
return None
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def create_hud_server(
|
|
387
|
+
host: str = "0.0.0.0",
|
|
388
|
+
port: int = DEFAULT_HUD_PORT,
|
|
389
|
+
store: Optional[StreamStore] = None,
|
|
390
|
+
producer: Optional[StreamProducer] = None,
|
|
391
|
+
poll_dj: bool = True,
|
|
392
|
+
) -> ThreadingHTTPServer:
|
|
393
|
+
"""Create the Stream HUD HTTP server (serves ``/overlay``, ``/control``, ``/api/*``)."""
|
|
394
|
+
st = store or StreamStore()
|
|
395
|
+
prod = producer or StreamProducer(store=st)
|
|
396
|
+
|
|
397
|
+
if poll_dj:
|
|
398
|
+
def _dj_loop() -> None:
|
|
399
|
+
while True:
|
|
400
|
+
info = _poll_awdiscord_dj()
|
|
401
|
+
if info is not None:
|
|
402
|
+
st.set_now_playing(info)
|
|
403
|
+
time.sleep(3.0)
|
|
404
|
+
|
|
405
|
+
threading.Thread(target=_dj_loop, name="awstream-dj-poll", daemon=True).start()
|
|
406
|
+
|
|
407
|
+
class Handler(BaseHTTPRequestHandler):
|
|
408
|
+
def log_message(self, *a):
|
|
409
|
+
pass
|
|
410
|
+
|
|
411
|
+
def _send(self, code: int, body: bytes, ctype: str) -> None:
|
|
412
|
+
self.send_response(code)
|
|
413
|
+
self.send_header("Content-Type", ctype)
|
|
414
|
+
self.send_header("Content-Length", str(len(body)))
|
|
415
|
+
self.send_header("Cache-Control", "no-store")
|
|
416
|
+
self.end_headers()
|
|
417
|
+
self.wfile.write(body)
|
|
418
|
+
|
|
419
|
+
def do_GET(self):
|
|
420
|
+
path = self.path.split("?", 1)[0]
|
|
421
|
+
if path in ("/", "/overlay"):
|
|
422
|
+
self._send(200, _OVERLAY_HTML.encode("utf-8"), "text/html; charset=utf-8")
|
|
423
|
+
elif path == "/control":
|
|
424
|
+
self._send(200, _CONTROL_HTML.encode("utf-8"), "text/html; charset=utf-8")
|
|
425
|
+
elif path == "/api/state":
|
|
426
|
+
data = json.dumps(st.get().to_dict()).encode("utf-8")
|
|
427
|
+
self._send(200, data, "application/json")
|
|
428
|
+
elif path == "/health":
|
|
429
|
+
self._send(200, b'{"ok":true}', "application/json")
|
|
430
|
+
else:
|
|
431
|
+
self._send(404, b'{"error":"not found"}', "application/json")
|
|
432
|
+
|
|
433
|
+
def do_POST(self):
|
|
434
|
+
path = self.path.split("?", 1)[0]
|
|
435
|
+
if path != "/api/action":
|
|
436
|
+
self._send(404, b'{"error":"not found"}', "application/json")
|
|
437
|
+
return
|
|
438
|
+
try:
|
|
439
|
+
n = int(self.headers.get("Content-Length", "0"))
|
|
440
|
+
except ValueError:
|
|
441
|
+
n = 0
|
|
442
|
+
raw = self.rfile.read(min(n, 65536))
|
|
443
|
+
try:
|
|
444
|
+
body = json.loads(raw or b"{}")
|
|
445
|
+
action = str(body.get("action") or "").strip().lower()
|
|
446
|
+
if action == "start":
|
|
447
|
+
out = prod.start(
|
|
448
|
+
str(body.get("title") or "Working Live with Aither"),
|
|
449
|
+
topic=str(body.get("topic") or ""),
|
|
450
|
+
youtube_url=str(body.get("youtube_url") or ""),
|
|
451
|
+
host_name=str(body.get("host_name") or "David"),
|
|
452
|
+
start_obs=bool(body.get("start_obs", False)),
|
|
453
|
+
record_local=bool(body.get("record_local", False)),
|
|
454
|
+
)
|
|
455
|
+
elif action == "stop":
|
|
456
|
+
out = prod.stop(stop_obs=bool(body.get("stop_obs", False)))
|
|
457
|
+
elif action == "focus":
|
|
458
|
+
out = prod.set_focus(str(body.get("topic") or "")).to_dict()
|
|
459
|
+
elif action == "sprint":
|
|
460
|
+
out = prod.start_sprint(
|
|
461
|
+
float(body.get("minutes") or 25),
|
|
462
|
+
label=str(body.get("label") or "Focus Sprint"),
|
|
463
|
+
).to_dict()
|
|
464
|
+
elif action == "clip":
|
|
465
|
+
out = prod.clip(
|
|
466
|
+
label=str(body.get("label") or "Highlight"),
|
|
467
|
+
by=str(body.get("by") or ""),
|
|
468
|
+
)
|
|
469
|
+
elif action == "privacy":
|
|
470
|
+
out = prod.set_privacy(
|
|
471
|
+
bool(body.get("enabled", True)),
|
|
472
|
+
message=str(body.get("message") or ""),
|
|
473
|
+
)
|
|
474
|
+
elif action == "scene":
|
|
475
|
+
out = prod.set_scene(str(body.get("scene") or ""))
|
|
476
|
+
elif action == "chat":
|
|
477
|
+
out = st.push_chat(
|
|
478
|
+
str(body.get("author") or "viewer"),
|
|
479
|
+
str(body.get("text") or ""),
|
|
480
|
+
platform=str(body.get("platform") or "discord"),
|
|
481
|
+
)
|
|
482
|
+
else:
|
|
483
|
+
raise ValueError("unknown action: " + action)
|
|
484
|
+
self._send(200, json.dumps(out).encode("utf-8"), "application/json")
|
|
485
|
+
except Exception as exc: # noqa: BLE001
|
|
486
|
+
err = json.dumps({"error": str(exc)[:200]}).encode("utf-8")
|
|
487
|
+
self._send(400, err, "application/json")
|
|
488
|
+
|
|
489
|
+
return ThreadingHTTPServer((host, int(port)), Handler)
|