from json import dumps as json_dumps
from pathlib import Path
from time import sleep
-from typing import Generator, NewType, Optional, TypeAlias
+from typing import Any, Generator, Optional, TypeAlias
from urllib.parse import parse_qs, urlparse
from urllib.request import urlretrieve
from urllib.error import HTTPError
Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader)
from ytplom.db import Hash, DbConn
from ytplom.misc import (
- FilesWithIndex, FilterStr, FlagName, PlayerUpdateId, QueryId,
- QueryText, QuotaCost, Tag, UrlStr, YoutubeId,
+ FilterStr, FlagName, PlayerUpdateId, QueryId, QueryText, Tag, UrlStr,
+ YoutubeId,
FILE_FLAGS, PATH_THUMBNAILS, YOUTUBE_URL_PREFIX,
ensure_expected_dirs,
Config, DownloadsManager, Player, QuotaLog, VideoFile, YoutubeQuery,
# type definitions for mypy
-_ColorStr = NewType('_ColorStr', str)
_PageNames: TypeAlias = dict[str, Path]
_ReqDict: TypeAlias = dict[str, list[str]]
-_PlayerState: TypeAlias = dict[str, bool | Path | str]
-_TemplateContext: TypeAlias = dict[
- str,
- None | bool
- | _ColorStr | FilesWithIndex | _PlayerState | _PageNames | FilterStr
- | Path | PlayerUpdateId | QueryText | QuotaCost | UrlStr | 'VideoFile'
- | YoutubeId | 'YoutubeVideo' | list[FlagName] | set['Tag']
- | list['VideoFile'] | list['YoutubeVideo'] | list['YoutubeQuery']
-]
+_TemplateContext: TypeAlias = dict[str, Any]
# API expectations
_THUMBNAIL_URL_PREFIX = UrlStr('https://i.ytimg.com/vi/')
tmpl_ctx: _TemplateContext
) -> None:
tmpl = self.server.jinja.get_template(str(tmpl_name))
- tmpl_ctx['redir_target'] = Path(self.path)
- tmpl_ctx['background_color'] = _ColorStr(
- self.server.config.background_color)
+ tmpl_ctx['redir_target'] = self.path
+ tmpl_ctx['background_color'] = self.server.config.background_color
tmpl_ctx['page_names'] = PAGE_NAMES
tmpl_ctx['player_state'] = {
- 'running': self.server.player.is_running,
- 'paused': self.server.player.is_paused,
- 'title': (self.server.player.current_file_cached.rel_path
- if self.server.player.current_file_cached
- else 'none')}
+ 'running': self.server.player.is_running,
+ 'paused': self.server.player.is_paused,
+ 'title': (self.server.player.current_file_cached.rel_path
+ if self.server.player.current_file_cached
+ else 'none')}
html = tmpl.render(**tmpl_ctx)
self._send_http(bytes(html, 'utf8'))