)
# type definitions for mypy
-PageNames: TypeAlias = dict[str, Path]
-ParamsStr = NewType('ParamsStr', str)
-TemplateContext: TypeAlias = dict[
+_PageNames: TypeAlias = dict[str, Path]
+_ParamsStr = NewType('_ParamsStr', str)
+_TemplateContext: TypeAlias = dict[
str,
None | bool
- | FilesWithIndex | PageNames | ParamsStr | Path | PlayerUpdateId
+ | FilesWithIndex | _PageNames | _ParamsStr | Path | PlayerUpdateId
| QueryText | QuotaCost | UrlStr | 'VideoFile' | YoutubeId
| 'YoutubeVideo' | list[FlagName] | list['VideoFile']
| list['YoutubeVideo'] | list['YoutubeQuery']
]
# API expectations
-THUMBNAIL_URL_PREFIX = UrlStr('https://i.ytimg.com/vi/')
-THUMBNAIL_URL_SUFFIX = UrlStr('/default.jpg')
+_THUMBNAIL_URL_PREFIX = UrlStr('https://i.ytimg.com/vi/')
+_THUMBNAIL_URL_SUFFIX = UrlStr('/default.jpg')
# template paths
-PATH_TEMPLATES = PATH_APP_DATA.joinpath('templates')
-NAME_TEMPLATE_QUERIES = Path('yt_queries.tmpl')
-NAME_TEMPLATE_RESULTS = Path('yt_results.tmpl')
-NAME_TEMPLATE_FILES = Path('files.tmpl')
-NAME_TEMPLATE_FILE_DATA = Path('file_data.tmpl')
-NAME_TEMPLATE_YT_VIDEO = Path('yt_result.tmpl')
-NAME_TEMPLATE_PLAYLIST = Path('playlist.tmpl')
+_PATH_TEMPLATES = PATH_APP_DATA.joinpath('templates')
+_NAME_TEMPLATE_QUERIES = Path('yt_queries.tmpl')
+_NAME_TEMPLATE_RESULTS = Path('yt_results.tmpl')
+_NAME_TEMPLATE_FILES = Path('files.tmpl')
+_NAME_TEMPLATE_FILE_DATA = Path('file_data.tmpl')
+_NAME_TEMPLATE_YT_VIDEO = Path('yt_result.tmpl')
+_NAME_TEMPLATE_PLAYLIST = Path('playlist.tmpl')
# page names
-PAGE_NAMES: PageNames = {
+PAGE_NAMES: _PageNames = {
'download': Path('dl'),
'file': Path('file'),
'files': Path('files'),
super().__init__((config.host, config.port), _TaskHandler,
*args, **kwargs)
self.config = config
- self.jinja = JinjaEnv(loader=JinjaFSLoader(PATH_TEMPLATES))
+ self.jinja = JinjaEnv(loader=JinjaFSLoader(_PATH_TEMPLATES))
self.player = Player()
self.downloads = DownloadsManager()
self.downloads.clean_unfinished()
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])
+ filter_ = _ParamsStr(params.get('filter', [''])[0])
show_absent = params.get('show_absent', [False])[0]
self._send_files_index(filter_, bool(show_absent))
elif PAGE_NAMES['file'] == page_name:
def _send_rendered_template(self,
tmpl_name: Path,
- tmpl_ctx: TemplateContext
+ tmpl_ctx: _TemplateContext
) -> None:
tmpl = self.server.jinja.get_template(str(tmpl_name))
tmpl_ctx['page_names'] = PAGE_NAMES
path_thumbnail = PATH_THUMBNAILS.joinpath(filename)
if not path_thumbnail.exists():
video_id = filename.stem
- url = f'{THUMBNAIL_URL_PREFIX}{video_id}{THUMBNAIL_URL_SUFFIX}'
+ url = f'{_THUMBNAIL_URL_PREFIX}{video_id}{_THUMBNAIL_URL_SUFFIX}'
try:
urlretrieve(url, PATH_THUMBNAILS.joinpath(f'{video_id}.jpg'))
except HTTPError as e:
results = YoutubeVideo.get_all_for_query(conn, query_id)
conn.commit_close()
self._send_rendered_template(
- NAME_TEMPLATE_RESULTS,
+ _NAME_TEMPLATE_RESULTS,
{'query': query.text, 'videos': results})
def _send_yt_queries_index_and_search(self) -> None:
conn.commit_close()
queries_data.sort(key=lambda q: q.retrieved_at, reverse=True)
self._send_rendered_template(
- NAME_TEMPLATE_QUERIES, {'queries': queries_data,
- 'quota_count': quota_count})
+ _NAME_TEMPLATE_QUERIES,
+ {'queries': queries_data, 'quota_count': quota_count})
def _send_yt_result(self, video_id: YoutubeId) -> None:
conn = DbConnection()
file_path = None
conn.commit_close()
self._send_rendered_template(
- NAME_TEMPLATE_YT_VIDEO,
+ _NAME_TEMPLATE_YT_VIDEO,
{'video_data': video_data,
'is_temp': video_id in self.server.downloads.ids_unfinished,
'file_path': file_path,
file = VideoFile.get_by_b64(conn, rel_path_b64)
conn.commit_close()
self._send_rendered_template(
- NAME_TEMPLATE_FILE_DATA,
+ _NAME_TEMPLATE_FILE_DATA,
{'file': file, 'flag_names': list(FILE_FLAGS)})
- def _send_files_index(self, filter_: ParamsStr, show_absent: bool) -> None:
+ def _send_files_index(self,
+ filter_: _ParamsStr,
+ show_absent: bool
+ ) -> None:
conn = DbConnection()
files = [f for f in VideoFile.get_all(conn)
if filter_.lower() in str(f.rel_path).lower()
conn.commit_close()
files.sort(key=lambda t: t.rel_path)
self._send_rendered_template(
- NAME_TEMPLATE_FILES,
+ _NAME_TEMPLATE_FILES,
{'files': files, 'filter': filter_,
'show_absent': show_absent})
if self.server.player.empty:
self.server.player.load_files()
self._send_rendered_template(
- NAME_TEMPLATE_PLAYLIST,
+ _NAME_TEMPLATE_PLAYLIST,
{'last_update': self.server.player.last_update,
'running': self.server.player.is_running,
'paused': self.server.player.is_paused,