Restyled by black

This commit is contained in:
Restyled.io
2021-05-22 01:26:33 +00:00
parent 58e8ba2347
commit 544c57ff1f
52 changed files with 3303 additions and 2729 deletions

View File

@@ -38,8 +38,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
@@ -55,8 +54,7 @@ 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)

View File

@@ -15,11 +15,17 @@ class PlayerConfiguration:
initial_volume: int
volume_steps: int
def __init__(self, preferred_quality: AudioQuality,
enable_normalisation: bool, normalisation_pregain: float,
autoplay_enabled: bool, crossfade_duration: int,
preload_enabled: bool, initial_volume: int,
volume_steps: int):
def __init__(
self,
preferred_quality: AudioQuality,
enable_normalisation: bool,
normalisation_pregain: float,
autoplay_enabled: bool,
crossfade_duration: int,
preload_enabled: bool,
initial_volume: int,
volume_steps: int,
):
self.preferred_quality = preferred_quality
self.enable_normalisation = enable_normalisation
self.normalisation_pregain = normalisation_pregain
@@ -44,18 +50,15 @@ class PlayerConfiguration:
def __init__(self):
pass
def set_preferred_quality(
self, preferred_quality: AudioQuality) -> __class__:
def set_preferred_quality(self, preferred_quality: AudioQuality) -> __class__:
self.preferred_quality = preferred_quality
return self
def set_enable_normalisation(self,
enable_normalisation: bool) -> __class__:
def set_enable_normalisation(self, enable_normalisation: bool) -> __class__:
self.enable_normalisation = enable_normalisation
return self
def set_normalisation_pregain(
self, normalisation_pregain: float) -> __class__:
def set_normalisation_pregain(self, normalisation_pregain: float) -> __class__:
self.normalisation_pregain = normalisation_pregain
return self
@@ -73,7 +76,12 @@ class PlayerConfiguration:
def build(self) -> PlayerConfiguration:
return PlayerConfiguration(
self.preferred_quality, self.enable_normalisation,
self.normalisation_pregain, self.autoplay_enabled,
self.crossfade_duration, self.preload_enabled,
self.initial_volume, self.volume_steps)
self.preferred_quality,
self.enable_normalisation,
self.normalisation_pregain,
self.autoplay_enabled,
self.crossfade_duration,
self.preload_enabled,
self.initial_volume,
self.volume_steps,
)

View File

@@ -20,8 +20,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)
@@ -40,9 +39,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,
@@ -52,9 +51,7 @@ 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: typing.Dict[str, str],
payload: bytes):
def on_message(self, uri: str, headers: typing.Dict[str, str], payload: bytes):
pass

View File

@@ -19,26 +19,26 @@ class VorbisOnlyAudioQuality(AudioQualityPicker):
@staticmethod
def get_vorbis_file(files: typing.List[Metadata.AudioFile]):
for file in files:
if hasattr(file, "format") and SuperAudioFormat.get(
file.format) == SuperAudioFormat.VORBIS:
if (
hasattr(file, "format")
and SuperAudioFormat.get(file.format) == SuperAudioFormat.VORBIS
):
return file
return None
def get_file(self, files: typing.List[Metadata.AudioFile]):
matches: typing.List[Metadata.AudioFile] = self.preferred.get_matches(
files)
vorbis: Metadata.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file(
matches)
matches: typing.List[Metadata.AudioFile] = self.preferred.get_matches(files)
vorbis: Metadata.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file(matches)
if vorbis is None:
vorbis: Metadata.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file(
files)
vorbis: Metadata.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file(files)
if vorbis is not None:
self._LOGGER.warning(
"Using {} because preferred {} couldn't be found.".format(
vorbis.format, self.preferred))
vorbis.format, self.preferred
)
)
else:
self._LOGGER.fatal(
"Couldn't find any Vorbis file, available: {}")
self._LOGGER.fatal("Couldn't find any Vorbis file, available: {}")
return vorbis

View File

@@ -22,7 +22,8 @@ class DeviceStateHandler:
_listeners: typing.List[DeviceStateHandler.Listener] = []
_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):
@@ -35,8 +36,9 @@ 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):
@@ -69,11 +71,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"