--- /dev/null
+{% import '_macros.tmpl' as macros %}
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<script>
+{% block script %}
+{% endblock %}
+</script>
+<style>
+body { background-color: #aaaa00; }
+{% block css %}
+{% endblock %}
+</style>
+</head>
+<body>
+{% block body %}
+{% endblock %}
+</body>
+</html>
--- /dev/null
+{% macro _link_if(cond, target) %}{% if cond %}<a href="/{{target}}">{% endif %}{{target}}{% if cond %}</a>{% endif %}{% endmacro %}
+
+
+{% macro nav_head(selected="") %}
+<p>
+{{ _link_if("playlist" != selected, "playlist") }}
+·
+{{ _link_if("videos" != selected, "videos") }}
+·
+{{ _link_if("queries" != selected, "queries") }}
+</p>
+<hr />
+{% endmacro %}
-<html>
-<head>
-<meta charset="UTF-8">
-<script>
+{% extends '_base.tmpl' %}
+
+
+{% block script %}
const RELOAD_INTERVAL_S = 10;
const PATH_LAST_UPDATE = '/_last_playlist_update.json';
const MSG_SERVER_DOWN = 'Server seems to be unavailable.';
setTimeout(keep_updated, RELOAD_INTERVAL_S * 1000);
}
window.onload = keep_updated;
-</script>
-<style>
-body { background-color: #aaaaaa; }
+{% endblock %}
+
+
+{% block css %}
table { width: 100%; }
#status { text-align: center; font-weight: bold; }
td.history { width: 50%; }
-</style>
-</head>
-<body>
-<p>playlist · <a href="/videos">videos</a> · <a href="/queries">queries</a></p>
+{% endblock %}
+
+
+{% block body %}
+{{ macros.nav_head("playlist") }}
<table>
<tr><td id="status" colspan=2>
{% if running %}{% if pause %}PAUSED{% else %}PLAYING{% endif %}{% else %}STOPPED{% endif %}:<br />
</td></tr>
{% endfor %}
</table>
-</body>
-</html>
+{% endblock %}
-<html>
-<meta charset="UTF-8">
-<body>
-<p><a href="/playlist">playlist</a> · <a href="/videos">videos</a> · queries</p>
+{% extends '_base.tmpl' %}
+
+
+{% block body %}
+{{ macros.nav_head("queries") }}
<p>quota: {{quota_count}}/100000</p>
<form action="/queries" method="POST" />
<input name="query" />
</tr>
{% endfor %}
</table>
-</body>
-</html>
+{% endblock %}
-<html>
-<meta charset="UTF-8">
-<body>
-<p><a href="/playlist">playlist</a> · <a href="/videos">videos</a> · <a href="/queries">queries</a></p>
+{% extends '_base.tmpl' %}
+
+
+{% block body %}
+{{ macros.nav_head() }}
<p>query: {{query}}</p>
<table>
{% for video in videos %}
</tr>
{% endfor %}
</table>
-</body>
-</html>
+{% endblock %}
-<html>
-<meta charset="UTF-8">
-<body>
-<p><a href="/playlist">playlist</a> · <a href="/videos">videos</a> · <a href="/queries">queries</a></p>
+{% extends '_base.tmpl' %}
+
+
+{% block body %}
+{{ macros.nav_head() }}
<table>
<tr><th>path:</th><td>{{file.rel_path}}</td></tr>
<tr><th>YouTube ID:</th><td><a href="/yt_video/{{file.yt_id}}">{{file.yt_id}}</a></tr>
{% endfor %}
<input type="submit" />
</form>
-</body>
-</html>
-
-
+{% endblock %}
-<html>
-<meta charset="UTF-8">
-<body>
-<p><a href="/playlist">playlist</a> · videos · <a href="/queries">queries</a></p>
+{% extends '_base.tmpl' %}
+
+
+{% block body %}
+{{ macros.nav_head("videos") }}
<p>downloaded videos:</p>
<ul>
{% for video_id, path in videos %}
<li><a href="/video/{{video_id}}">{{ path }}</a>
{% endfor %}
</ul>
-</body>
-</html>
+{% endblock %}
-<html>
-<meta charset="UTF-8">
-<body>
-<p><a href="/playlist">playlist</a> · <a href="/videos">videos</a> · <a href="/queries">queries</a></p>
+{% extends '_base.tmpl' %}
+
+
+{% block body %}
+{{ macros.nav_head() }}
<table>
<tr><th>title:</th><td>{{video_data.title}}</td></tr>
<tr><th>thumbnail:</th><td><img src="/thumbnails/{{video_data.id_}}.jpg" /></td></tr>
</td>
</tr>
</table>
-</body>
-</html>
-
+{% endblock %}
from urllib.request import urlretrieve
from urllib.error import HTTPError
# non-included libs
-from jinja2 import Template
+from jinja2 import Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader
from mpv import MPV # type: ignore
from yt_dlp import YoutubeDL # type: ignore
import googleapiclient.discovery # type: ignore
def __init__(self, downloads_db: DownloadsDb, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
+ self.jinja = JinjaEnv(loader=JinjaFSLoader(PATH_TEMPLATES))
self.player = Player()
self.downloads = downloads_db
tmpl_name: PathStr,
tmpl_ctx: TemplateContext
) -> None:
- with open(path_join(PATH_TEMPLATES, tmpl_name),
- 'r', encoding='utf8'
- ) as templ_file:
- tmpl = Template(str(templ_file.read()))
+ tmpl = self.server.jinja.get_template(tmpl_name)
html = tmpl.render(**tmpl_ctx)
self._send_http(bytes(html, 'utf8'))