{% block body %}
{{ macros.nav_head(page_names, "files") }}
<form method="GET">
-filter: <input name="filter" value="{{filter}}" />
+filter filename: <input name="filter_path" value="{{filter_path}}" />
+filter tags: <input name="filter_tags" value="{{filter_tags}}" />
show absent: <input type="checkbox" name="show_absent" {% if show_absent %}checked{% endif %}/>
<input type="submit" value="filter" />
</form>
<p>known files (shown: {{files|length}}):</p>
<form action="files" method="POST">
<table>
-<tr><th>size</th><th>actions</th><th>path</th></tr>
+<tr><th>size</th><th>actions</th><th>tags</th><th>path</th></tr>
{% for file in files %}
<tr>
<td>{{ file.size | round(3) }}</td>
<td><input type="submit" name="play_{{file.digest.b64}}" value="play" {% if not file.present %}disabled {% endif %}/></td>
+<td>{% for tag in file.tags %}{{tag}} {%endfor %}</td>
<td><a href="/{{page_names.file}}/{{file.digest.b64}}">{{file.rel_path}}</a></td>
</tr>
{% endfor %}
# type definitions for mypy
_PageNames: TypeAlias = dict[str, Path]
-_ParamsStr = NewType('_ParamsStr', str)
+_FilterStr = NewType('_FilterStr', str)
_TemplateContext: TypeAlias = dict[
str,
None | bool
- | FilesWithIndex | _PageNames | _ParamsStr | Path | PlayerUpdateId
+ | FilesWithIndex | _PageNames | _FilterStr | Path | PlayerUpdateId
| QueryText | QuotaCost | UrlStr | 'VideoFile' | YoutubeId
| 'YoutubeVideo' | list[FlagName] | list['Tag'] | list['VideoFile']
| list['YoutubeVideo'] | list['YoutubeQuery']
elif PAGE_NAMES['download'] == page_name:
self._send_or_download_video(YoutubeId(toks_url[2]))
elif PAGE_NAMES['files'] == page_name:
- params = parse_qs(url.query)
- filter_ = _ParamsStr(params.get('filter', [''])[0])
- show_absent = params.get('show_absent', [False])[0]
- self._send_files_index(filter_, bool(show_absent))
+ self._send_files_index(parse_qs(url.query))
elif PAGE_NAMES['file'] == page_name:
self._send_file_data(Hash.from_b64(toks_url[2]))
elif PAGE_NAMES['yt_result'] == page_name:
{'file': file, 'flag_names': list(FILE_FLAGS),
'unused_tags': [t for t in all_tags if t not in file.tags]})
- def _send_files_index(self,
- filter_: _ParamsStr,
- show_absent: bool
- ) -> None:
+ def _send_files_index(self, params: dict[str, list[str]]) -> None:
+ filter_path = _FilterStr(params.get('filter_path', [''])[0])
+ filter_tags = _FilterStr(params.get('filter_tags', [''])[0])
+ show_absent = bool(params.get('show_absent', [False])[0])
with DbConn() as conn:
files = [f for f in VideoFile.get_all(conn)
- if filter_.lower() in str(f.rel_path).lower()
+ if str(filter_path).lower() in str(f.rel_path).lower()
+ and ([t for t in f.tags if str(filter_tags).lower() in t]
+ or not filter_tags)
and (show_absent or f.present)]
files.sort(key=lambda t: t.rel_path)
- self._send_rendered_template(
- _NAME_TEMPLATE_FILES,
- {'files': files, 'filter': filter_,
- 'show_absent': show_absent})
+ self._send_rendered_template(_NAME_TEMPLATE_FILES,
+ {'files': files,
+ 'filter_path': filter_path,
+ 'filter_tags': filter_tags,
+ 'show_absent': show_absent})
def _send_missing_json(self) -> None:
with DbConn() as conn: