From cc49433aa9b0f9d809b8cae46eb88a19b309e0e3 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 9 Apr 2021 23:16:18 +0000 Subject: [PATCH 1/4] Restyled by black --- docs/conf.py | 20 +++++----- librespot/metadata/AlbumId.py | 6 +-- librespot/metadata/ArtistId.py | 9 ++--- librespot/metadata/ShowId.py | 6 +-- librespot/metadata/TrackId.py | 6 +-- librespot/player/Player.py | 13 ++++--- librespot/player/StateWrapper.py | 41 ++++++++++++-------- librespot/player/mixing/AudioSink.py | 3 +- librespot/player/state/DeviceStateHandler.py | 37 +++++++++++------- 9 files changed, 78 insertions(+), 63 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 7f699a2..8935244 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -16,41 +16,41 @@ # -- Project information ----------------------------------------------------- -project = 'librespot-python' -copyright = '2021, kokarare1212' -author = 'kokarare1212' +project = "librespot-python" +copyright = "2021, kokarare1212" +author = "kokarare1212" # -- General configuration --------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['recommonmark'] +extensions = ["recommonmark"] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # -- Markdown ---------------------------------------------------------------- -source_suffix = ['.rst', '.md'] +source_suffix = [".rst", ".md"] source_parsers = { - '.md': 'recommonmark.parser.CommonMarkParser', + ".md": "recommonmark.parser.CommonMarkParser", } diff --git a/librespot/metadata/AlbumId.py b/librespot/metadata/AlbumId.py index 63688fe..1558531 100644 --- a/librespot/metadata/AlbumId.py +++ b/librespot/metadata/AlbumId.py @@ -18,8 +18,7 @@ class AlbumId(SpotifyId.SpotifyId): matcher = AlbumId._PATTERN.search(uri) if matcher is not None: album_id = matcher.group(1) - return AlbumId( - Utils.bytes_to_hex(AlbumId._BASE62.decode(album_id, 16))) + return AlbumId(Utils.bytes_to_hex(AlbumId._BASE62.decode(album_id, 16))) else: raise TypeError("Not a Spotify album ID: {}.f".format(uri)) @@ -33,7 +32,8 @@ class AlbumId(SpotifyId.SpotifyId): def to_mercury_uri(self) -> str: return "spotify:album:{}".format( - AlbumId._BASE62.encode(Utils.hex_to_bytes(self._hexId))) + AlbumId._BASE62.encode(Utils.hex_to_bytes(self._hexId)) + ) def hex_id(self) -> str: return self._hexId diff --git a/librespot/metadata/ArtistId.py b/librespot/metadata/ArtistId.py index 094cb4d..98c1c2e 100644 --- a/librespot/metadata/ArtistId.py +++ b/librespot/metadata/ArtistId.py @@ -17,15 +17,13 @@ class ArtistId(SpotifyId.SpotifyId): matcher = ArtistId._PATTERN.search(uri) if matcher is not None: artist_id = matcher.group(1) - return ArtistId( - Utils.bytes_to_hex(ArtistId._BASE62.decode(artist_id, 16))) + return ArtistId(Utils.bytes_to_hex(ArtistId._BASE62.decode(artist_id, 16))) else: raise TypeError("Not a Spotify artist ID: {}".format(uri)) @staticmethod def from_base62(base62: str) -> ArtistId: - return ArtistId(Utils.bytes_to_hex(ArtistId._BASE62.decode(base62, - 16))) + return ArtistId(Utils.bytes_to_hex(ArtistId._BASE62.decode(base62, 16))) @staticmethod def from_hex(hex_str: str) -> ArtistId: @@ -36,7 +34,8 @@ class ArtistId(SpotifyId.SpotifyId): def to_spotify_uri(self) -> str: return "spotify:artist:{}".format( - ArtistId._BASE62.encode(Utils.hex_to_bytes(self._hexId))) + ArtistId._BASE62.encode(Utils.hex_to_bytes(self._hexId)) + ) def hex_id(self) -> str: return self._hexId diff --git a/librespot/metadata/ShowId.py b/librespot/metadata/ShowId.py index c236641..df9bb7d 100644 --- a/librespot/metadata/ShowId.py +++ b/librespot/metadata/ShowId.py @@ -17,8 +17,7 @@ class ShowId(SpotifyId.SpotifyId): matcher = ShowId._PATTERN.search(uri) if matcher is not None: show_id = matcher.group(1) - return ShowId( - Utils.bytes_to_hex(ShowId._BASE62.decode(show_id, 16))) + return ShowId(Utils.bytes_to_hex(ShowId._BASE62.decode(show_id, 16))) else: raise TypeError("Not a Spotify show ID: {}".format(uri)) @@ -35,7 +34,8 @@ class ShowId(SpotifyId.SpotifyId): def to_spotify_uri(self) -> str: return "spotify:show:{}".format( - ShowId._BASE62.encode(Utils.hex_to_bytes(self._hexId))) + ShowId._BASE62.encode(Utils.hex_to_bytes(self._hexId)) + ) def hex_id(self) -> str: return self._hexId diff --git a/librespot/metadata/TrackId.py b/librespot/metadata/TrackId.py index 8206a0d..6344706 100644 --- a/librespot/metadata/TrackId.py +++ b/librespot/metadata/TrackId.py @@ -17,15 +17,13 @@ class TrackId(PlayableId, SpotifyId): search = TrackId._PATTERN.search(uri) if search is not None: track_id = search.group(1) - return TrackId( - Utils.bytes_to_hex(PlayableId.BASE62.decode(track_id, 16))) + return TrackId(Utils.bytes_to_hex(PlayableId.BASE62.decode(track_id, 16))) else: raise RuntimeError("Not a Spotify track ID: {}".format(uri)) @staticmethod def from_base62(base62: str) -> TrackId: - return TrackId(Utils.bytes_to_hex(PlayableId.BASE62.decode(base62, - 16))) + return TrackId(Utils.bytes_to_hex(PlayableId.BASE62.decode(base62, 16))) @staticmethod def from_hex(hex_str: str) -> TrackId: diff --git a/librespot/player/Player.py b/librespot/player/Player.py index 6f58c6c..5397ffd 100644 --- a/librespot/player/Player.py +++ b/librespot/player/Player.py @@ -34,8 +34,7 @@ class Player(Closeable, PlayerSession.Listener, AudioSink.Listener): self._init_state() def _init_state(self): - self._state = StateWrapper.StateWrapper(self._session, self, - self._conf) + self._state = StateWrapper.StateWrapper(self._session, self, self._conf) class Anonymous(DeviceStateHandler.Listener): _player: Player = None @@ -46,10 +45,12 @@ class Player(Closeable, PlayerSession.Listener, AudioSink.Listener): def ready(self) -> None: pass - def command(self, endpoint: DeviceStateHandler.Endpoint, - data: DeviceStateHandler.CommandBody) -> None: - self._player._LOGGER.debug( - "Received command: {}".format(endpoint)) + def command( + self, + endpoint: DeviceStateHandler.Endpoint, + data: DeviceStateHandler.CommandBody, + ) -> None: + self._player._LOGGER.debug("Received command: {}".format(endpoint)) self._deviceStateListener = Anonymous(self) self._state.add_listener(self._deviceStateListener) diff --git a/librespot/player/StateWrapper.py b/librespot/player/StateWrapper.py index d2ef8ef..cb2899d 100644 --- a/librespot/player/StateWrapper.py +++ b/librespot/player/StateWrapper.py @@ -4,7 +4,12 @@ from librespot.dealer import DealerClient from librespot.player import Player, PlayerConfiguration from librespot.player.state import DeviceStateHandler from librespot.proto import Connect -from librespot.proto.Player import ContextPlayerOptions, PlayerState, Restrictions, Suppressions +from librespot.proto.Player import ( + ContextPlayerOptions, + PlayerState, + Restrictions, + Suppressions, +) class StateWrapper(DeviceStateHandler.Listener, DealerClient.MessageListener): @@ -13,8 +18,7 @@ class StateWrapper(DeviceStateHandler.Listener, DealerClient.MessageListener): _player: Player = None _device: DeviceStateHandler = None - def __init__(self, session: Session, player: Player, - conf: PlayerConfiguration): + def __init__(self, session: Session, player: Player, conf: PlayerConfiguration): self._session = session self._player = player self._device = DeviceStateHandler(session, self, conf) @@ -22,27 +26,30 @@ class StateWrapper(DeviceStateHandler.Listener, DealerClient.MessageListener): self._device.add_listener(self) self._session.dealer().add_message_listener( - self, "spotify:user:attributes:update", "hm://playlist/", - "hm://collection/collection/" + self._session.username() + "/json") + self, + "spotify:user:attributes:update", + "hm://playlist/", + "hm://collection/collection/" + self._session.username() + "/json", + ) def _init_state(self) -> PlayerState: - return PlayerState(playback_speed=1.0, - suppressions=Suppressions(), - context_restrictions=Restrictions(), - options=ContextPlayerOptions( - repeating_context=False, - shuffling_context=False, - repeating_track=False), - position_as_of_timestamp=0, - position=0, - is_playing=False) + return PlayerState( + playback_speed=1.0, + suppressions=Suppressions(), + context_restrictions=Restrictions(), + options=ContextPlayerOptions( + repeating_context=False, shuffling_context=False, repeating_track=False + ), + position_as_of_timestamp=0, + position=0, + is_playing=False, + ) def add_listener(self, listener: DeviceStateHandler.Listener): self._device.add_listener(listener) def ready(self) -> None: - self._device.update_state(Connect.PutStateReason.NEW_DEVICE, 0, - self._state) + self._device.update_state(Connect.PutStateReason.NEW_DEVICE, 0, self._state) def on_message(self, uri: str, headers: dict[str, str], payload: bytes): pass diff --git a/librespot/player/mixing/AudioSink.py b/librespot/player/mixing/AudioSink.py index 85ecb3b..5e4234b 100644 --- a/librespot/player/mixing/AudioSink.py +++ b/librespot/player/mixing/AudioSink.py @@ -3,8 +3,7 @@ from librespot.player import PlayerConfiguration class AudioSink: - def __init__(self, conf: PlayerConfiguration, - listener: AudioSink.Listener): + def __init__(self, conf: PlayerConfiguration, listener: AudioSink.Listener): pass class Listener: diff --git a/librespot/player/state/DeviceStateHandler.py b/librespot/player/state/DeviceStateHandler.py index ce622b3..2cc50a2 100644 --- a/librespot/player/state/DeviceStateHandler.py +++ b/librespot/player/state/DeviceStateHandler.py @@ -18,7 +18,8 @@ class DeviceStateHandler: _deviceInfo: Connect.DeviceInfo = None _listeners: list[DeviceStateHandler.Listener] = list() _putState: Connect.PutStateRequest = None - _putStateWorker: concurrent.futures.ThreadPoolExecutor = concurrent.futures.ThreadPoolExecutor( + _putStateWorker: concurrent.futures.ThreadPoolExecutor = ( + concurrent.futures.ThreadPoolExecutor() ) _connectionId: str = None @@ -30,11 +31,11 @@ class DeviceStateHandler: def _update_connection_id(self, newer: str) -> None: newer = urllib.parse.unquote(newer, "UTF-8") - if self._connectionId is None or \ - self._connectionId != newer: + if self._connectionId is None or self._connectionId != newer: self._connectionId = newer - self._LOGGER.debug("Updated Spotify-Connection-Id: {}".format( - self._connectionId)) + self._LOGGER.debug( + "Updated Spotify-Connection-Id: {}".format(self._connectionId) + ) self._notify_ready() def add_listener(self, listener: DeviceStateHandler.Listener): @@ -44,8 +45,12 @@ class DeviceStateHandler: for listener in self._listeners: listener.ready() - def update_state(self, reason: Connect.PutStateReason, player_time: int, - state: Player.PlayerState): + def update_state( + self, + reason: Connect.PutStateReason, + player_time: int, + state: Player.PlayerState, + ): if self._connectionId is None: raise TypeError() @@ -63,10 +68,13 @@ class DeviceStateHandler: def _put_connect_state(self, req: Connect.PutStateRequest): self._session.api().put_connect_state(self._connectionId, req) - self._LOGGER.info("Put state. ts: {}, connId: {}, reason: {}".format( - req.client_side_timestamp, - Utils.truncate_middle(self._connectionId, 10), - req.put_state_reason)) + self._LOGGER.info( + "Put state. ts: {}, connId: {}, reason: {}".format( + req.client_side_timestamp, + Utils.truncate_middle(self._connectionId, 10), + req.put_state_reason, + ) + ) class Endpoint(enum.Enum): Play: str = "play" @@ -80,8 +88,11 @@ class DeviceStateHandler: def ready(self) -> None: pass - def command(self, endpoint: DeviceStateHandler.Endpoint, - data: DeviceStateHandler.CommandBody) -> None: + def command( + self, + endpoint: DeviceStateHandler.Endpoint, + data: DeviceStateHandler.CommandBody, + ) -> None: pass def volume_changed(self) -> None: From fa7d74d9df8afea9101665e2736d15bafbd09422 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 9 Apr 2021 23:16:20 +0000 Subject: [PATCH 2/4] Restyled by isort --- librespot/metadata/AlbumId.py | 3 ++- librespot/metadata/ArtistId.py | 4 +++- librespot/metadata/ShowId.py | 4 +++- librespot/metadata/TrackId.py | 4 +++- librespot/player/Player.py | 8 +++++--- librespot/player/StateWrapper.py | 9 +++------ librespot/player/mixing/AudioSink.py | 1 + librespot/player/state/DeviceStateHandler.py | 10 ++++++---- 8 files changed, 26 insertions(+), 17 deletions(-) diff --git a/librespot/metadata/AlbumId.py b/librespot/metadata/AlbumId.py index 1558531..14efec8 100644 --- a/librespot/metadata/AlbumId.py +++ b/librespot/metadata/AlbumId.py @@ -1,8 +1,9 @@ from __future__ import annotations +import re + from librespot.common import Base62, Utils from librespot.metadata import SpotifyId -import re class AlbumId(SpotifyId.SpotifyId): diff --git a/librespot/metadata/ArtistId.py b/librespot/metadata/ArtistId.py index 98c1c2e..e3a8c68 100644 --- a/librespot/metadata/ArtistId.py +++ b/librespot/metadata/ArtistId.py @@ -1,7 +1,9 @@ from __future__ import annotations + +import re + from librespot.common import Base62, Utils from librespot.metadata import SpotifyId -import re class ArtistId(SpotifyId.SpotifyId): diff --git a/librespot/metadata/ShowId.py b/librespot/metadata/ShowId.py index df9bb7d..1ec25c1 100644 --- a/librespot/metadata/ShowId.py +++ b/librespot/metadata/ShowId.py @@ -1,7 +1,9 @@ from __future__ import annotations + +import re + from librespot.common import Base62, Utils from librespot.metadata import SpotifyId -import re class ShowId(SpotifyId.SpotifyId): diff --git a/librespot/metadata/TrackId.py b/librespot/metadata/TrackId.py index 6344706..bf8d372 100644 --- a/librespot/metadata/TrackId.py +++ b/librespot/metadata/TrackId.py @@ -1,8 +1,10 @@ from __future__ import annotations + +import re + from librespot.common import Utils from librespot.metadata import SpotifyId from librespot.metadata.PlayableId import PlayableId -import re class TrackId(PlayableId, SpotifyId): diff --git a/librespot/player/Player.py b/librespot/player/Player.py index 5397ffd..5def457 100644 --- a/librespot/player/Player.py +++ b/librespot/player/Player.py @@ -1,4 +1,9 @@ from __future__ import annotations + +import logging +import sched +import time + from librespot.core.Session import Session from librespot.player import PlayerConfiguration, StateWrapper from librespot.player.metrics import PlaybackMetrics @@ -6,9 +11,6 @@ from librespot.player.mixing import AudioSink from librespot.player.playback.PlayerSession import PlayerSession from librespot.player.state.DeviceStateHandler import DeviceStateHandler from librespot.standard.Closeable import Closeable -import logging -import sched -import time class Player(Closeable, PlayerSession.Listener, AudioSink.Listener): diff --git a/librespot/player/StateWrapper.py b/librespot/player/StateWrapper.py index cb2899d..148ee49 100644 --- a/librespot/player/StateWrapper.py +++ b/librespot/player/StateWrapper.py @@ -1,15 +1,12 @@ from __future__ import annotations + from librespot.core import Session from librespot.dealer import DealerClient from librespot.player import Player, PlayerConfiguration from librespot.player.state import DeviceStateHandler from librespot.proto import Connect -from librespot.proto.Player import ( - ContextPlayerOptions, - PlayerState, - Restrictions, - Suppressions, -) +from librespot.proto.Player import (ContextPlayerOptions, PlayerState, + Restrictions, Suppressions) class StateWrapper(DeviceStateHandler.Listener, DealerClient.MessageListener): diff --git a/librespot/player/mixing/AudioSink.py b/librespot/player/mixing/AudioSink.py index 5e4234b..8e4420a 100644 --- a/librespot/player/mixing/AudioSink.py +++ b/librespot/player/mixing/AudioSink.py @@ -1,4 +1,5 @@ from __future__ import annotations + from librespot.player import PlayerConfiguration diff --git a/librespot/player/state/DeviceStateHandler.py b/librespot/player/state/DeviceStateHandler.py index 2cc50a2..17156ba 100644 --- a/librespot/player/state/DeviceStateHandler.py +++ b/librespot/player/state/DeviceStateHandler.py @@ -1,8 +1,5 @@ from __future__ import annotations -from librespot.common import Utils -from librespot.core import Session -from librespot.player import PlayerConfiguration -from librespot.proto import Connect, Player + import base64 import concurrent.futures import enum @@ -11,6 +8,11 @@ import time import typing import urllib.parse +from librespot.common import Utils +from librespot.core import Session +from librespot.player import PlayerConfiguration +from librespot.proto import Connect, Player + class DeviceStateHandler: _LOGGER: logging = logging.getLogger(__name__) From ee0dacc040a93f7c358530f4a27f527f48fd3f37 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 9 Apr 2021 23:16:25 +0000 Subject: [PATCH 3/4] Restyled by reorder-python-imports --- docs/conf.py | 3 --- librespot/metadata/AlbumId.py | 3 ++- librespot/metadata/ArtistId.py | 3 ++- librespot/metadata/ShowId.py | 3 ++- librespot/player/Player.py | 3 ++- librespot/player/StateWrapper.py | 9 ++++++--- librespot/player/state/DeviceStateHandler.py | 3 ++- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 8935244..83e0082 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -3,9 +3,7 @@ # This file only contains a selection of the most common options. For a full # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html - # -- Path setup -------------------------------------------------------------- - # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. @@ -13,7 +11,6 @@ # import os # import sys # sys.path.insert(0, os.path.abspath('.')) - # -- Project information ----------------------------------------------------- project = "librespot-python" diff --git a/librespot/metadata/AlbumId.py b/librespot/metadata/AlbumId.py index 14efec8..2316014 100644 --- a/librespot/metadata/AlbumId.py +++ b/librespot/metadata/AlbumId.py @@ -2,7 +2,8 @@ from __future__ import annotations import re -from librespot.common import Base62, Utils +from librespot.common import Base62 +from librespot.common import Utils from librespot.metadata import SpotifyId diff --git a/librespot/metadata/ArtistId.py b/librespot/metadata/ArtistId.py index e3a8c68..414e77e 100644 --- a/librespot/metadata/ArtistId.py +++ b/librespot/metadata/ArtistId.py @@ -2,7 +2,8 @@ from __future__ import annotations import re -from librespot.common import Base62, Utils +from librespot.common import Base62 +from librespot.common import Utils from librespot.metadata import SpotifyId diff --git a/librespot/metadata/ShowId.py b/librespot/metadata/ShowId.py index 1ec25c1..e98f6a8 100644 --- a/librespot/metadata/ShowId.py +++ b/librespot/metadata/ShowId.py @@ -2,7 +2,8 @@ from __future__ import annotations import re -from librespot.common import Base62, Utils +from librespot.common import Base62 +from librespot.common import Utils from librespot.metadata import SpotifyId diff --git a/librespot/player/Player.py b/librespot/player/Player.py index 5def457..9d553a4 100644 --- a/librespot/player/Player.py +++ b/librespot/player/Player.py @@ -5,7 +5,8 @@ import sched import time from librespot.core.Session import Session -from librespot.player import PlayerConfiguration, StateWrapper +from librespot.player import PlayerConfiguration +from librespot.player import StateWrapper from librespot.player.metrics import PlaybackMetrics from librespot.player.mixing import AudioSink from librespot.player.playback.PlayerSession import PlayerSession diff --git a/librespot/player/StateWrapper.py b/librespot/player/StateWrapper.py index 148ee49..f9d3473 100644 --- a/librespot/player/StateWrapper.py +++ b/librespot/player/StateWrapper.py @@ -2,11 +2,14 @@ from __future__ import annotations from librespot.core import Session from librespot.dealer import DealerClient -from librespot.player import Player, PlayerConfiguration +from librespot.player import Player +from librespot.player import PlayerConfiguration from librespot.player.state import DeviceStateHandler from librespot.proto import Connect -from librespot.proto.Player import (ContextPlayerOptions, PlayerState, - Restrictions, Suppressions) +from librespot.proto.Player import ContextPlayerOptions +from librespot.proto.Player import PlayerState +from librespot.proto.Player import Restrictions +from librespot.proto.Player import Suppressions class StateWrapper(DeviceStateHandler.Listener, DealerClient.MessageListener): diff --git a/librespot/player/state/DeviceStateHandler.py b/librespot/player/state/DeviceStateHandler.py index 17156ba..68a68ec 100644 --- a/librespot/player/state/DeviceStateHandler.py +++ b/librespot/player/state/DeviceStateHandler.py @@ -11,7 +11,8 @@ import urllib.parse from librespot.common import Utils from librespot.core import Session from librespot.player import PlayerConfiguration -from librespot.proto import Connect, Player +from librespot.proto import Connect +from librespot.proto import Player class DeviceStateHandler: From cdad65011b2ddc5cb65bcc0a792caf55f7f35300 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 9 Apr 2021 23:16:32 +0000 Subject: [PATCH 4/4] Restyled by yapf --- librespot/metadata/AlbumId.py | 6 +++--- librespot/metadata/ArtistId.py | 9 +++++---- librespot/metadata/ShowId.py | 6 +++--- librespot/metadata/TrackId.py | 6 ++++-- librespot/player/Player.py | 6 ++++-- librespot/player/StateWrapper.py | 12 +++++++----- librespot/player/mixing/AudioSink.py | 3 ++- librespot/player/state/DeviceStateHandler.py | 20 ++++++++------------ 8 files changed, 36 insertions(+), 32 deletions(-) diff --git a/librespot/metadata/AlbumId.py b/librespot/metadata/AlbumId.py index 2316014..894b9b6 100644 --- a/librespot/metadata/AlbumId.py +++ b/librespot/metadata/AlbumId.py @@ -20,7 +20,8 @@ class AlbumId(SpotifyId.SpotifyId): matcher = AlbumId._PATTERN.search(uri) if matcher is not None: album_id = matcher.group(1) - return AlbumId(Utils.bytes_to_hex(AlbumId._BASE62.decode(album_id, 16))) + return AlbumId( + Utils.bytes_to_hex(AlbumId._BASE62.decode(album_id, 16))) else: raise TypeError("Not a Spotify album ID: {}.f".format(uri)) @@ -34,8 +35,7 @@ class AlbumId(SpotifyId.SpotifyId): def to_mercury_uri(self) -> str: return "spotify:album:{}".format( - AlbumId._BASE62.encode(Utils.hex_to_bytes(self._hexId)) - ) + AlbumId._BASE62.encode(Utils.hex_to_bytes(self._hexId))) def hex_id(self) -> str: return self._hexId diff --git a/librespot/metadata/ArtistId.py b/librespot/metadata/ArtistId.py index 414e77e..0eb0513 100644 --- a/librespot/metadata/ArtistId.py +++ b/librespot/metadata/ArtistId.py @@ -20,13 +20,15 @@ class ArtistId(SpotifyId.SpotifyId): matcher = ArtistId._PATTERN.search(uri) if matcher is not None: artist_id = matcher.group(1) - return ArtistId(Utils.bytes_to_hex(ArtistId._BASE62.decode(artist_id, 16))) + return ArtistId( + Utils.bytes_to_hex(ArtistId._BASE62.decode(artist_id, 16))) else: raise TypeError("Not a Spotify artist ID: {}".format(uri)) @staticmethod def from_base62(base62: str) -> ArtistId: - return ArtistId(Utils.bytes_to_hex(ArtistId._BASE62.decode(base62, 16))) + return ArtistId(Utils.bytes_to_hex(ArtistId._BASE62.decode(base62, + 16))) @staticmethod def from_hex(hex_str: str) -> ArtistId: @@ -37,8 +39,7 @@ class ArtistId(SpotifyId.SpotifyId): def to_spotify_uri(self) -> str: return "spotify:artist:{}".format( - ArtistId._BASE62.encode(Utils.hex_to_bytes(self._hexId)) - ) + ArtistId._BASE62.encode(Utils.hex_to_bytes(self._hexId))) def hex_id(self) -> str: return self._hexId diff --git a/librespot/metadata/ShowId.py b/librespot/metadata/ShowId.py index e98f6a8..3678926 100644 --- a/librespot/metadata/ShowId.py +++ b/librespot/metadata/ShowId.py @@ -20,7 +20,8 @@ class ShowId(SpotifyId.SpotifyId): matcher = ShowId._PATTERN.search(uri) if matcher is not None: show_id = matcher.group(1) - return ShowId(Utils.bytes_to_hex(ShowId._BASE62.decode(show_id, 16))) + return ShowId( + Utils.bytes_to_hex(ShowId._BASE62.decode(show_id, 16))) else: raise TypeError("Not a Spotify show ID: {}".format(uri)) @@ -37,8 +38,7 @@ class ShowId(SpotifyId.SpotifyId): def to_spotify_uri(self) -> str: return "spotify:show:{}".format( - ShowId._BASE62.encode(Utils.hex_to_bytes(self._hexId)) - ) + ShowId._BASE62.encode(Utils.hex_to_bytes(self._hexId))) def hex_id(self) -> str: return self._hexId diff --git a/librespot/metadata/TrackId.py b/librespot/metadata/TrackId.py index bf8d372..fa29b2d 100644 --- a/librespot/metadata/TrackId.py +++ b/librespot/metadata/TrackId.py @@ -19,13 +19,15 @@ class TrackId(PlayableId, SpotifyId): search = TrackId._PATTERN.search(uri) if search is not None: track_id = search.group(1) - return TrackId(Utils.bytes_to_hex(PlayableId.BASE62.decode(track_id, 16))) + return TrackId( + Utils.bytes_to_hex(PlayableId.BASE62.decode(track_id, 16))) else: raise RuntimeError("Not a Spotify track ID: {}".format(uri)) @staticmethod def from_base62(base62: str) -> TrackId: - return TrackId(Utils.bytes_to_hex(PlayableId.BASE62.decode(base62, 16))) + return TrackId(Utils.bytes_to_hex(PlayableId.BASE62.decode(base62, + 16))) @staticmethod def from_hex(hex_str: str) -> TrackId: diff --git a/librespot/player/Player.py b/librespot/player/Player.py index 9d553a4..20e5d12 100644 --- a/librespot/player/Player.py +++ b/librespot/player/Player.py @@ -37,7 +37,8 @@ class Player(Closeable, PlayerSession.Listener, AudioSink.Listener): self._init_state() def _init_state(self): - self._state = StateWrapper.StateWrapper(self._session, self, self._conf) + self._state = StateWrapper.StateWrapper(self._session, self, + self._conf) class Anonymous(DeviceStateHandler.Listener): _player: Player = None @@ -53,7 +54,8 @@ class Player(Closeable, PlayerSession.Listener, AudioSink.Listener): endpoint: DeviceStateHandler.Endpoint, data: DeviceStateHandler.CommandBody, ) -> None: - self._player._LOGGER.debug("Received command: {}".format(endpoint)) + self._player._LOGGER.debug( + "Received command: {}".format(endpoint)) self._deviceStateListener = Anonymous(self) self._state.add_listener(self._deviceStateListener) diff --git a/librespot/player/StateWrapper.py b/librespot/player/StateWrapper.py index f9d3473..56785a6 100644 --- a/librespot/player/StateWrapper.py +++ b/librespot/player/StateWrapper.py @@ -18,7 +18,8 @@ class StateWrapper(DeviceStateHandler.Listener, DealerClient.MessageListener): _player: Player = None _device: DeviceStateHandler = None - def __init__(self, session: Session, player: Player, conf: PlayerConfiguration): + def __init__(self, session: Session, player: Player, + conf: PlayerConfiguration): self._session = session self._player = player self._device = DeviceStateHandler(session, self, conf) @@ -37,9 +38,9 @@ class StateWrapper(DeviceStateHandler.Listener, DealerClient.MessageListener): playback_speed=1.0, suppressions=Suppressions(), context_restrictions=Restrictions(), - options=ContextPlayerOptions( - repeating_context=False, shuffling_context=False, repeating_track=False - ), + options=ContextPlayerOptions(repeating_context=False, + shuffling_context=False, + repeating_track=False), position_as_of_timestamp=0, position=0, is_playing=False, @@ -49,7 +50,8 @@ class StateWrapper(DeviceStateHandler.Listener, DealerClient.MessageListener): self._device.add_listener(listener) def ready(self) -> None: - self._device.update_state(Connect.PutStateReason.NEW_DEVICE, 0, self._state) + self._device.update_state(Connect.PutStateReason.NEW_DEVICE, 0, + self._state) def on_message(self, uri: str, headers: dict[str, str], payload: bytes): pass diff --git a/librespot/player/mixing/AudioSink.py b/librespot/player/mixing/AudioSink.py index 8e4420a..716c68e 100644 --- a/librespot/player/mixing/AudioSink.py +++ b/librespot/player/mixing/AudioSink.py @@ -4,7 +4,8 @@ from librespot.player import PlayerConfiguration class AudioSink: - def __init__(self, conf: PlayerConfiguration, listener: AudioSink.Listener): + def __init__(self, conf: PlayerConfiguration, + listener: AudioSink.Listener): pass class Listener: diff --git a/librespot/player/state/DeviceStateHandler.py b/librespot/player/state/DeviceStateHandler.py index 68a68ec..71b8fe1 100644 --- a/librespot/player/state/DeviceStateHandler.py +++ b/librespot/player/state/DeviceStateHandler.py @@ -22,8 +22,7 @@ class DeviceStateHandler: _listeners: list[DeviceStateHandler.Listener] = list() _putState: Connect.PutStateRequest = None _putStateWorker: concurrent.futures.ThreadPoolExecutor = ( - concurrent.futures.ThreadPoolExecutor() - ) + concurrent.futures.ThreadPoolExecutor()) _connectionId: str = None def __init__(self, session: Session, player, conf: PlayerConfiguration): @@ -36,9 +35,8 @@ class DeviceStateHandler: if self._connectionId is None or self._connectionId != newer: self._connectionId = newer - self._LOGGER.debug( - "Updated Spotify-Connection-Id: {}".format(self._connectionId) - ) + self._LOGGER.debug("Updated Spotify-Connection-Id: {}".format( + self._connectionId)) self._notify_ready() def add_listener(self, listener: DeviceStateHandler.Listener): @@ -71,13 +69,11 @@ class DeviceStateHandler: def _put_connect_state(self, req: Connect.PutStateRequest): self._session.api().put_connect_state(self._connectionId, req) - self._LOGGER.info( - "Put state. ts: {}, connId: {}, reason: {}".format( - req.client_side_timestamp, - Utils.truncate_middle(self._connectionId, 10), - req.put_state_reason, - ) - ) + self._LOGGER.info("Put state. ts: {}, connId: {}, reason: {}".format( + req.client_side_timestamp, + Utils.truncate_middle(self._connectionId, 10), + req.put_state_reason, + )) class Endpoint(enum.Enum): Play: str = "play"