fix some minor issues discovered by typing, enable composition
This commit is contained in:
parent
dc5bce5ff9
commit
0cb0a1604b
4 changed files with 36 additions and 15 deletions
|
|
@ -14,8 +14,6 @@ class MixinProtocol(Protocol):
|
|||
|
||||
parser: Parser
|
||||
|
||||
headers: Dict[str, str]
|
||||
|
||||
proxies: Optional[Dict[str, str]]
|
||||
|
||||
def _check_auth(self) -> None:
|
||||
|
|
@ -26,3 +24,7 @@ class MixinProtocol(Protocol):
|
|||
|
||||
def _send_get_request(self, url: str, params: Optional[Dict] = None) -> Response:
|
||||
pass
|
||||
|
||||
@property
|
||||
def headers(self) -> Dict[str, str]:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ class UploadsMixin(MixinProtocol):
|
|||
"""
|
||||
self._check_auth()
|
||||
if not self.auth_type == AuthType.BROWSER:
|
||||
raise Exception("Please provide authentication before using this function")
|
||||
raise Exception("Please provide browser authentication before using this function")
|
||||
if not os.path.isfile(filepath):
|
||||
raise Exception("The provided file does not exist.")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# commonly used navigation paths
|
||||
from typing import Any, Dict, List
|
||||
"""commonly used navigation paths"""
|
||||
from typing import Any, Dict, List, Literal, Optional, overload
|
||||
|
||||
CONTENT = ["contents", 0]
|
||||
RUN_TEXT = ["runs", 0, "text"]
|
||||
|
|
@ -69,7 +69,17 @@ CARD_SHELF_TITLE = ["header", "musicCardShelfHeaderBasicRenderer"] + TITLE_TEXT
|
|||
FRAMEWORK_MUTATIONS = ["frameworkUpdates", "entityBatchUpdate", "mutations"]
|
||||
|
||||
|
||||
def nav(root: Dict[str, Any], items: List[Any], none_if_absent: bool = False) -> Any:
|
||||
@overload
|
||||
def nav(root: Dict[str, Any], items: List[Any], none_if_absent: Literal[False] = False) -> Any:
|
||||
...
|
||||
|
||||
|
||||
@overload
|
||||
def nav(root: Dict, items: List[Any], none_if_absent: Literal[True] = True) -> Optional[Any]:
|
||||
...
|
||||
|
||||
|
||||
def nav(root: Dict, items: List[Any], none_if_absent: bool = False) -> Optional[Any]:
|
||||
"""Access a nested object in root by item sequence."""
|
||||
try:
|
||||
for k in items:
|
||||
|
|
|
|||
|
|
@ -38,15 +38,7 @@ from .auth.oauth.token import Token
|
|||
from .auth.types import AuthType
|
||||
|
||||
|
||||
class YTMusic(
|
||||
BrowsingMixin, SearchMixin, WatchMixin, ExploreMixin, LibraryMixin, PlaylistsMixin, UploadsMixin
|
||||
):
|
||||
"""
|
||||
Allows automated interactions with YouTube Music by emulating the YouTube web client's requests.
|
||||
Permits both authenticated and non-authenticated requests.
|
||||
Authentication header data must be provided on initialization.
|
||||
"""
|
||||
|
||||
class YTMusicBase:
|
||||
def __init__(
|
||||
self,
|
||||
auth: Optional[str | Dict] = None,
|
||||
|
|
@ -266,3 +258,20 @@ class YTMusic(
|
|||
|
||||
def __exit__(self, execType=None, execValue=None, trackback=None):
|
||||
pass
|
||||
|
||||
|
||||
class YTMusic(
|
||||
YTMusicBase,
|
||||
BrowsingMixin,
|
||||
SearchMixin,
|
||||
WatchMixin,
|
||||
ExploreMixin,
|
||||
LibraryMixin,
|
||||
PlaylistsMixin,
|
||||
UploadsMixin,
|
||||
):
|
||||
"""
|
||||
Allows automated interactions with YouTube Music by emulating the YouTube web client's requests.
|
||||
Permits both authenticated and non-authenticated requests.
|
||||
Authentication header data must be provided on initialization.
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue