separate style file

This commit is contained in:
Roy Olav Purser 2021-05-13 11:15:40 +02:00
parent 8d29d58f76
commit 612d8143f4
Signed by: roypur
GPG Key ID: E14D26A036F21656
6 changed files with 22 additions and 11 deletions

View File

@ -3,8 +3,9 @@ RUN ["apk", "add", "--no-cache", "--repository", "https://dl-cdn.alpinelinux.org
RUN ["mkdir", "/app"] RUN ["mkdir", "/app"]
COPY ["stream.py", "/app/stream.py"] COPY ["stream.py", "/app/stream.py"]
COPY ["sources.py", "/app/sources.py"] COPY ["sources.py", "/app/sources.py"]
COPY ["index.html", "/app/index.html"] COPY ["frontend/index.html", "/app/index.html"]
COPY ["script.js", "/app/script.js"] COPY ["frontend/script.js", "/app/script.js"]
COPY ["frontend/style.css", "/app/style.css"]
RUN ["chmod", "-R", "755", "/app"] RUN ["chmod", "-R", "755", "/app"]
COPY ["tv.json", "/app/tv.json"] COPY ["tv.json", "/app/tv.json"]
RUN ["python3", "/app/sources.py"] RUN ["python3", "/app/sources.py"]

View File

@ -1,13 +1,12 @@
<html> <html>
<head> <head>
<style>body { margin: 0px; }</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ videojs_version }}/video-js.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ videojs_version }}/video-js.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@silvermine/videojs-chromecast@latest/dist/silvermine-videojs-chromecast.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@silvermine/videojs-chromecast@latest/dist/silvermine-videojs-chromecast.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ videojs_version }}/video.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/{{ videojs_version }}/video.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@silvermine/videojs-chromecast@latest/dist/silvermine-videojs-chromecast.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@silvermine/videojs-chromecast@latest/dist/silvermine-videojs-chromecast.min.js"></script>
<script src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"></script> <script src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"></script>
<script src="{{ script }}"></script> <script src="{{ script }}"></script>
<style>@media(max-device-width:500px){.vjs-control-bar{font-size:3em;}}</style> <link rel="stylesheet" href="{{ custom_style }}">
</head> </head>
<body> <body>
</body> </body>

6
frontend/style.css Normal file
View File

@ -0,0 +1,6 @@
body {
margin: 0px;
}
.vjs-control-bar {
font-size: 1rem;
}

View File

@ -35,12 +35,12 @@ if playlist is not None:
try: try:
resp = requests.get("https://api.cdnjs.com/libraries/castjs?fields=version") resp = requests.get("https://api.cdnjs.com/libraries/castjs?fields=version")
data = json.loads(resp.text) data = json.loads(resp.text)
castjs_version = data["version"] chromecast_version = data["version"]
except Exception as e: except Exception as e:
print(e) print(e)
else: else:
with open("/app/castjs-version.txt", "w") as f: with open("/app/chromecast-version.txt", "w") as f:
f.write(castjs_version) f.write(chromecast_version)
try: try:
resp = requests.get("https://api.cdnjs.com/libraries/video.js?fields=version") resp = requests.get("https://api.cdnjs.com/libraries/video.js?fields=version")
data = json.loads(resp.text) data = json.loads(resp.text)

View File

@ -74,6 +74,7 @@ template_html = None
template_js = None template_js = None
videojs_version = None videojs_version = None
castjs_version = None castjs_version = None
custom_style = None
try: try:
with open("/app/index.html", "r") as f: with open("/app/index.html", "r") as f:
template_html = tornado.template.Template(f.read().strip()) template_html = tornado.template.Template(f.read().strip())
@ -81,8 +82,12 @@ try:
template_js = tornado.template.Template(f.read().strip()) template_js = tornado.template.Template(f.read().strip())
with open("/app/videojs-version.txt", "r") as f: with open("/app/videojs-version.txt", "r") as f:
videojs_version = f.read().strip() videojs_version = f.read().strip()
with open("/app/castjs-version.txt", "r") as f: with open("/app/chromecast-version.txt", "r") as f:
castjs_version = f.read().strip() chromecast_version = f.read().strip()
with open("/app/style.css", "r") as f:
custom_style_raw = bytes(f.read().strip(), "utf-8")
b64 = str(base64.b64encode(custom_style_raw), "ascii")
custom_style = f'data:text/css;charset=utf-8;base64,{b64}'
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
@ -170,8 +175,8 @@ class MainHandler(tornado.web.RequestHandler):
stream_path = f'{self.request.path}?provider={provider}' stream_path = f'{self.request.path}?provider={provider}'
rendered_js = template_js.generate(stream=stream_path); rendered_js = template_js.generate(stream=stream_path);
b64 = str(base64.b64encode(rendered_js), "ascii") b64 = str(base64.b64encode(rendered_js), "ascii")
script = f'data:text/javascript;charset=utf8;base64,{b64}' script = f'data:text/javascript;charset=utf-8;base64,{b64}'
rendered_html = template_html.generate(script=script, videojs_version=videojs_version, castjs_version=castjs_version) rendered_html = template_html.generate(script=script, videojs_version=videojs_version, chromecast_version=chromecast_version, custom_style=custom_style)
self.write(rendered_html) self.write(rendered_html)
else: else:
self.set_status(404) self.set_status(404)