from json import dumps as json_dumps, loads as json_loads
from pathlib import Path
from time import sleep
-from typing import Any, Generator, Optional, TypeAlias
+from typing import Any, Generator, Optional
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 (
- FilterStr, FlagName, QueryId, QueryText, Tag, UrlStr, YoutubeId,
+ FilterStr, FlagName, QueryId, QueryText, Tag, YoutubeId,
FILE_FLAGS, PATH_THUMBNAILS, YOUTUBE_URL_PREFIX,
ensure_expected_dirs,
Config, DownloadsManager, Player, QuotaLog, VideoFile, YoutubeQuery,
)
from ytplom.primitives import NotFoundException, PATH_APP_DATA
-# type definitions for mypy
-_PageNames: TypeAlias = dict[str, Path]
-_ReqDict: TypeAlias = dict[str, list[str]]
-_TemplateContext: TypeAlias = dict[str, Any]
-
# API expectations
-_THUMBNAIL_URL_PREFIX = UrlStr('https://i.ytimg.com/vi/')
-_THUMBNAIL_URL_SUFFIX = UrlStr('/default.jpg')
+_THUMBNAIL_URL_PREFIX = 'https://i.ytimg.com/vi/'
+_THUMBNAIL_URL_SUFFIX = '/default.jpg'
# template paths
_PATH_TEMPLATES = PATH_APP_DATA.joinpath('templates')
_NAME_TEMPLATE_PLAYLIST = Path('playlist.tmpl')
# page names
-PAGE_NAMES: _PageNames = {
+PAGE_NAMES: dict[str, Path] = {
'download': Path('dl'),
'events': Path('events'),
'file': Path('file'),
self.as_str = map_as_str
@property
- def as_dict(self) -> _ReqDict:
+ def as_dict(self) -> dict[str, list[str]]:
"""Return parsed to dictionary."""
if self.is_json:
return json_loads(self.as_str)
def _send_rendered_template(self,
tmpl_name: Path,
- tmpl_ctx: _TemplateContext
+ tmpl_ctx: dict[str, Any]
) -> None:
tmpl = self.server.jinja.get_template(str(tmpl_name))
tmpl_ctx['selected'] = tmpl_ctx.get('selected', '')
"""Main ytplom lib."""
# included libs
-from typing import NewType, Optional, Self, TypeAlias
+from typing import NewType, Optional, Self
from os import chdir, environ
from random import shuffle
from time import sleep
FlagName = NewType('FlagName', str)
FlagsInt = NewType('FlagsInt', int)
Tag = NewType('Tag', str)
-AmountDownloads = NewType('AmountDownloads', int)
-UrlStr = NewType('UrlStr', str)
-FilesWithIndex: TypeAlias = list[tuple[int, 'VideoFile']]
# major expected directories
PATH_DOWNLOADS = Path.home().joinpath('ytplom_downloads')
'format': YT_DOWNLOAD_FORMAT}
# Youtube API expectations
-YOUTUBE_URL_PREFIX = UrlStr('https://www.youtube.com/watch?v=')
+YOUTUBE_URL_PREFIX = 'https://www.youtube.com/watch?v='
QUOTA_COST_YOUTUBE_SEARCH = QuotaCost(100)
QUOTA_COST_YOUTUBE_DETAILS = QuotaCost(1)