Restyled by yapf
This commit is contained in:
parent
ee0dacc040
commit
cdad65011b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue