From c4944ede7f041d21753a1662c42feb3f2cae823e Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Sun, 10 Nov 2024 21:10:13 +0300 Subject: [PATCH] [~] Refactor --- dotfiles/.local/bin/commands | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/dotfiles/.local/bin/commands b/dotfiles/.local/bin/commands index 61762bb..db6ac72 100755 --- a/dotfiles/.local/bin/commands +++ b/dotfiles/.local/bin/commands @@ -22,7 +22,8 @@ import sys import tempfile import time import traceback -from typing import (Literal, Optional, Iterable,) + +from typing import (Literal, Optional, Iterable, TypedDict, Callable, Any,) logger = logging.getLogger(__name__) @@ -1695,7 +1696,7 @@ def pm_service(argv): print('') -def scrap_yt_music(argv: Iterable[str]) -> None: +def scrap_yt_music(argv: list[str]) -> None: parser = optparse.OptionParser() parser.add_option( '--verbose', @@ -1817,7 +1818,15 @@ def scrap_yt_music(argv: Iterable[str]) -> None: if not p is None: p.terminate() - context = dict( + class Context(TypedDict): + http_on_event: Callable[..., None] + shutdown: bool + workers: list[threading.Thread] + track_cv: threading.Condition + main_cv: threading.Condition + track_name: Optional[str] + + context: Context = dict( http_on_event=lambda *args, **kwargs: None, shutdown=False, workers=[], @@ -3452,10 +3461,12 @@ def media_keys(argv): def mocp_info() -> str: t1 = subprocess.check_output(['mocp', '-i']) t3 = t1.decode('utf-8') - t2 = dict([ - tuple(o.split(':')[:2]) + t2 : dict[str, str] = dict([ + (lambda o2: (o2[0], o2[1]))(o.split(':')) + #tuple(o.split(':')[:2]) for o in t3.splitlines() ]) + return t2['Title'].strip()[:128] if is_mocp():