From ef6674b35bf50e50ec6db60bf1d522e76e60df78 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sun, 23 May 2021 21:48:10 +0200 Subject: [PATCH] add favicon --- Dockerfile | 11 +++++++++-- backend/stream.py | 19 ++++++------------- backend/stream_providers.py | 2 +- frontend/favicon-basic.svg | 3 +++ frontend/favicon.svg | 4 ++++ frontend/index.html | 1 + 6 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 frontend/favicon-basic.svg create mode 100644 frontend/favicon.svg diff --git a/Dockerfile b/Dockerfile index 477de78..c9a7f25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM roypur/stream-runtime:latest as base +FROM alpine:edge as base +RUN ["apk", "add", "--no-cache", "inkscape"] RUN ["mkdir", "-p", "/app/version"] COPY ["tv.json", "/app/setup/tv.json"] COPY ["backend/start.sh", "/app/start.sh"] @@ -6,14 +7,20 @@ COPY ["backend/sources.py", "/app/setup/sources.py"] COPY ["backend/stream.py", "/app/stream.py"] COPY ["backend/stream_providers.py", "/app/stream_providers.py"] COPY ["frontend/index.html", "/app/index.html"] +COPY ["frontend/favicon.svg", "/app/favicon.svg"] COPY ["frontend/script.js", "/app/script.js"] COPY ["frontend/style.css", "/app/style.css"] RUN ["chmod", "-R", "755", "/app"] +RUN ["inkscape", "--export-area-page", "--export-width=256", "--export-height=256", "/app/favicon.svg", "--export-filename=/app/favicon.png"] +RUN ["rm", "/app/favicon.svg"] + +FROM roypur/stream-runtime:latest as venv +COPY --from=base /app /app RUN ["/app/venv/bin/python3", "/app/setup/sources.py"] RUN ["rm", "-r", "/app/setup"] FROM scratch -COPY --from=base / / +COPY --from=venv / / USER 1444:1444 ENV ICECAST_SERVER=https://icecast.purser.it:7000 ENV STREAM_SERVER=https://stream.purser.it diff --git a/backend/stream.py b/backend/stream.py index 0670962..ae40b70 100755 --- a/backend/stream.py +++ b/backend/stream.py @@ -229,6 +229,7 @@ script_file = None videojs_version = None font_awesome_version = None custom_style = None +favicon = None try: with open("/app/index.html", "r") as f: template_html = tornado.template.Template(f.read().strip()) @@ -242,6 +243,8 @@ try: chromecast_version = f.read().strip() with open("/app/version/font-awesome.txt", "r") as f: font_awesome_version = f.read().strip() + with open("/app/favicon.png", "rb") as f: + favicon = f.read() 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") @@ -319,27 +322,18 @@ class MainHandler(tornado.web.RequestHandler): if script_file is not None and template_html is not None: meta = await handler.meta() title = handler.render_url - video_creator = None video_title = None for elem in meta: if isinstance(elem[1], str): if elem[0] == "og:title": video_title = elem[1] - elif elem[0] == "og:description": - video_creator = elem[1] - if isinstance(video_creator, str) and isinstance(video_title, str): - title = f'{video_creator}: {video_title}' - elif isinstance(video_creator, str): - title = video_creator - elif isinstance(video_title, str): - title = video_title data["script"] = script_file data["videojs_version"] = videojs_version data["chromecast_version"] = chromecast_version data["font_awesome_version"] = font_awesome_version data["custom_style"] = custom_style - rendered_html = template_html.generate(data=data, meta=meta) + rendered_html = template_html.generate(data=data, meta=meta, title=video_title) self.write(rendered_html) else: self.set_status(404) @@ -377,11 +371,10 @@ class FileHandler(tornado.web.RequestHandler): def get(self): self.set_header("Content-Type", "text/plain; charset=utf-8") self.write(playlist) - class IconHandler(tornado.web.RequestHandler): def get(self): - self.set_header("Content-Type", "text/plain; charset=utf-8") - self.set_status(204) + self.set_header("Content-Type", "image/png") + self.write(favicon) try: handlers = [] handlers.append((tornado.routing.PathMatches("/sources.m3u8"), FileHandler)) diff --git a/backend/stream_providers.py b/backend/stream_providers.py index 30b5595..6bd70d1 100755 --- a/backend/stream_providers.py +++ b/backend/stream_providers.py @@ -91,7 +91,7 @@ async def get_any(upstream, proxy, logger): tasks.append(asyncio.create_task(get_streamlink(upstream, proxy, logger))) tasks.append(asyncio.create_task(get_ytdl(upstream, proxy, logger))) result = None - for task in asyncio.as_completed(tasks, timeout=2.0): + for task in asyncio.as_completed(tasks, timeout=5.0): result = await task if isinstance(result, str): break diff --git a/frontend/favicon-basic.svg b/frontend/favicon-basic.svg new file mode 100644 index 0000000..8dd3f9a --- /dev/null +++ b/frontend/favicon-basic.svg @@ -0,0 +1,3 @@ + + + diff --git a/frontend/favicon.svg b/frontend/favicon.svg new file mode 100644 index 0000000..ceef09a --- /dev/null +++ b/frontend/favicon.svg @@ -0,0 +1,4 @@ + + + + diff --git a/frontend/index.html b/frontend/index.html index 4ac3e71..aff73fb 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,5 +1,6 @@ + {{ title }} {% for item in meta %} {% block item %}{% end %}{% end %}