AmountDownloads = NewType('AmountDownloads', int)
PlayerUpdateId = NewType('PlayerUpdateId', str)
B64Str = NewType('B64Str', str)
+ParamsStr = NewType('ParamsStr', str)
PageNames: TypeAlias = dict[str, PathStr]
DownloadsIndex: TypeAlias = dict[YoutubeId, PathStr]
FilesWithIndex: TypeAlias = list[tuple[int, 'VideoFile']]
TemplateContext: TypeAlias = dict[
str,
None | bool
- | FilesWithIndex | PageNames | PathStr | PlayerUpdateId | QueryText
- | QuotaCost | 'VideoFile' | YoutubeId | 'YoutubeVideo'
+ | FilesWithIndex | PageNames | ParamsStr | PathStr | PlayerUpdateId
+ | QueryText | QuotaCost | 'VideoFile' | YoutubeId | 'YoutubeVideo'
| list[FlagName] | 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:
- self._send_files_index()
+ filter_ = ParamsStr(parse_qs(url.query).get('filter', [''])[0])
+ self._send_files_index(filter_)
elif PAGE_NAMES['file'] == page_name:
self._send_file_data(B64Str(toks_url[2]))
elif PAGE_NAMES['yt_result'] == page_name:
NAME_TEMPLATE_FILE_DATA,
{'file': file, 'flag_names': list(FILE_FLAGS)})
- def _send_files_index(self) -> None:
+ def _send_files_index(self, filter_: ParamsStr) -> None:
conn = DbConnection()
- files = VideoFile.get_all(conn)
+ files = [f for f in VideoFile.get_all(conn) if filter_ in f.rel_path]
conn.commit_close()
files.sort(key=lambda t: t.rel_path)
- self._send_rendered_template(NAME_TEMPLATE_FILES, {'files': files})
+ self._send_rendered_template(NAME_TEMPLATE_FILES,
+ {'files': files, 'filter': filter_})
def _send_missing_json(self) -> None:
conn = DbConnection()