Skip to content

Commit f41dc2b

Browse files
author
andrew (from workstation)
committed
webui
1 parent b2cedb8 commit f41dc2b

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include smart_tv_telegram/static/*

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A Telegram Bot to stream content on your smart TV (also Chromecast, FireTV and o
1111
- You can streaming on any device that supports UPnP (AVTransport)
1212
- Chromecast, Vlc (telnet api) and Kodi (xbmc http api) support
1313
- Streaming over HTTP
14+
- Web interface that plays videos in your browser
1415

1516
Note: Chromecast (1st, 2nd and 3rd Gen.) [only supports H.264 and VP8 video codecs](https://developers.google.com/cast/docs/media#video_codecs)
1617

@@ -52,6 +53,15 @@ docker run --network host -v "$(pwd)/config.ini:/app/config.ini:ro" -d smart-tv-
5253

5354
## Troubleshooting
5455

56+
**Q:** How do I use the web interface?
57+
58+
**A:** Set `enabled` to `1` in `web_ui` config block, and change the `password`
59+
60+
- open http://`listen_ip`:`listen_port`/static/index.html
61+
62+
- now if you send a video in the bot on telegram you can choose to play it in the browser
63+
64+
##
5565
**Q:** My Firewall block upnp and broadcasting, how can use kodi without it
5666

5767
**A:** Set `xbmc_enabled` to `1` and add your kodi device to `xbmc_devices` list

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
"smart_tv_telegram=smart_tv_telegram.__main__:arg_parser",
3232
"smart_tv_telegram_tests=smart_tv_telegram.__main__:unit_test"
3333
],
34-
}
34+
},
35+
include_package_data=True
3536
)

smart_tv_telegram/http.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import os.path
23
import typing
34
from urllib.parse import quote
45

@@ -39,6 +40,7 @@ def __init__(self, mtproto: Mtproto, config: Config, finders: typing.List[Device
3940

4041
async def start(self):
4142
app = web.Application()
43+
app.add_routes([web.static("/static/", os.path.dirname(__file__) + "/static/")])
4244
app.add_routes([web.get("/stream/{message_id}/{token}", self._stream_handler)])
4345
app.add_routes([web.options("/stream/{message_id}/{token}", self._upnp_discovery_handler)])
4446
app.add_routes([web.put("/stream/{message_id}/{token}", self._upnp_discovery_handler)])

smart_tv_telegram/static/index.html

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<html lang="en">
2+
<head>
3+
<title>smart-telegram-bot web</title>
4+
<script>
5+
const source = document.createElement("source");
6+
7+
function onPasswordSubmit() {
8+
const xhttp = new XMLHttpRequest();
9+
const inputPassword = document.getElementById("password");
10+
const buttonPassword = document.getElementById("password_submit")
11+
12+
xhttp.onloadend = function() {
13+
if (this.status === 200) {
14+
inputPassword.hidden = true;
15+
buttonPassword.hidden = true;
16+
pollVideo(xhttp.responseText);
17+
} else {
18+
window.alert("wrong password");
19+
}
20+
};
21+
22+
xhttp.open("GET", "/web/api/register/" + inputPassword.value, true);
23+
xhttp.send();
24+
}
25+
26+
function pollVideo(token) {
27+
const player = document.getElementById("player")
28+
const xhttp = new XMLHttpRequest();
29+
30+
xhttp.onloadend = function() {
31+
if (this.status === 200) {
32+
if (player.hidden) {
33+
player.appendChild(source);
34+
player.hidden = false;
35+
}
36+
37+
player.pause();
38+
source.setAttribute("src", xhttp.responseText);
39+
player.load();
40+
player.play();
41+
}
42+
43+
if (this.status === 404) {
44+
location.reload();
45+
}
46+
47+
setTimeout(function () { pollVideo(token); }, 1000);
48+
};
49+
50+
xhttp.open("GET", "/web/api/poll/" + token, true);
51+
xhttp.send();
52+
}
53+
</script>
54+
</head>
55+
<body>
56+
<label for="password">
57+
<input id="password" type="password" placeholder="password">
58+
<button onclick="onPasswordSubmit()" id="password_submit">submit password</button>
59+
</label>
60+
<label for="player">
61+
<video id="player" controls hidden></video>
62+
</label>
63+
</body>
64+
</html>

0 commit comments

Comments
 (0)