Restyled by yapf

This commit is contained in:
Restyled.io
2021-05-22 01:27:30 +00:00
parent 9c47be20a5
commit 0fbe39722b
48 changed files with 1213 additions and 1198 deletions

View File

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

View File

@@ -51,15 +51,18 @@ 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

View File

@@ -20,7 +20,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)
@@ -39,9 +40,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,
@@ -51,7 +52,9 @@ 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,8 +22,7 @@ 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):
@@ -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"