diff --git a/librespot/ZeroconfServer.py b/librespot/ZeroconfServer.py index 5fab774..0fe97c5 100644 --- a/librespot/ZeroconfServer.py +++ b/librespot/ZeroconfServer.py @@ -11,7 +11,7 @@ from zeroconf import Zeroconf from librespot.common import Utils from librespot.core import Session from librespot.crypto import DiffieHellman -from librespot.proto import Connect_pb2 +from librespot.proto import Connect_pb2 as Connect from librespot.standard import Closeable from librespot.standard import Runnable @@ -61,7 +61,7 @@ class ZeroconfServer(Closeable): ) class Inner: - device_type: Connect_pb2.DeviceType = None + device_type: Connect.DeviceType = None device_name: str = None device_id: str = None preferred_locale: str = None @@ -69,7 +69,7 @@ class ZeroconfServer(Closeable): def __init__( self, - device_type: Connect_pb2.DeviceType, + device_type: Connect.DeviceType, device_name: str, preferred_locale: str, conf: Session.Configuration, diff --git a/librespot/audio/PlayableContentFeeder.py b/librespot/audio/PlayableContentFeeder.py index 42e2988..3c7a007 100644 --- a/librespot/audio/PlayableContentFeeder.py +++ b/librespot/audio/PlayableContentFeeder.py @@ -12,8 +12,8 @@ from librespot.common.Utils import Utils from librespot.core import Session from librespot.metadata import PlayableId from librespot.metadata import TrackId -from librespot.proto import Metadata_pb2 -from librespot.proto import StorageResolve_pb2 +from librespot.proto import Metadata_pb2 as Metadata +from librespot.proto import StorageResolve_pb2 as StorageResolve class PlayableContentFeeder: @@ -26,7 +26,7 @@ class PlayableContentFeeder: def __init__(self, session: Session): self.session = session - def pick_alternative_if_necessary(self, track: Metadata_pb2.Track): + def pick_alternative_if_necessary(self, track: Metadata.Track): if len(track.file) > 0: return track @@ -49,7 +49,7 @@ class PlayableContentFeeder: def resolve_storage_interactive( self, file_id: bytes, - preload: bool) -> StorageResolve_pb2.StorageResolveResponse: + preload: bool) -> StorageResolve.StorageResolveResponse: resp = self.session.api().send( "GET", (self.STORAGE_RESOLVE_INTERACTIVE_PREFETCH @@ -65,13 +65,13 @@ class PlayableContentFeeder: if body is None: RuntimeError("Response body is empty!") - storage_resolve_response = StorageResolve_pb2.StorageResolveResponse() + storage_resolve_response = StorageResolve.StorageResolveResponse() storage_resolve_response.ParseFromString(body) return storage_resolve_response def load_track( self, - track_id_or_track: typing.Union[TrackId, Metadata_pb2.Track], + track_id_or_track: typing.Union[TrackId, Metadata.Track], audio_quality_picker: AudioQualityPicker, preload: bool, halt_listener: HaltListener, @@ -94,9 +94,9 @@ class PlayableContentFeeder: def load_stream( self, - file: Metadata_pb2.AudioFile, - track: Metadata_pb2.Track, - episode: Metadata_pb2.Episode, + file: Metadata.AudioFile, + track: Metadata.Track, + episode: Metadata.Episode, preload: bool, halt_lister: HaltListener, ): @@ -104,41 +104,41 @@ class PlayableContentFeeder: raise RuntimeError() resp = self.resolve_storage_interactive(file.file_id, preload) - if resp.result == StorageResolve_pb2.StorageResolveResponse.Result.CDN: + if resp.result == StorageResolve.StorageResolveResponse.Result.CDN: if track is not None: return CdnFeedHelper.load_track(self.session, track, file, resp, preload, halt_lister) return CdnFeedHelper.load_episode(self.session, episode, file, resp, preload, halt_lister) - elif resp.result == StorageResolve_pb2.StorageResolveResponse.Result.STORAGE: + elif resp.result == StorageResolve.StorageResolveResponse.Result.STORAGE: if track is None: # return StorageFeedHelper pass - elif resp.result == StorageResolve_pb2.StorageResolveResponse.Result.RESTRICTED: + elif resp.result == StorageResolve.StorageResolveResponse.Result.RESTRICTED: raise RuntimeError("Content is restricted!") - elif resp.result == StorageResolve_pb2.StorageResolveResponse.Response.UNRECOGNIZED: + elif resp.result == StorageResolve.StorageResolveResponse.Response.UNRECOGNIZED: raise RuntimeError("Content is unrecognized!") else: raise RuntimeError("Unknown result: {}".format(resp.result)) class LoadedStream: - episode: Metadata_pb2.Episode - track: Metadata_pb2.Track + episode: Metadata.Episode + track: Metadata.Track input_stream: GeneralAudioStream normalization_data: NormalizationData metrics: PlayableContentFeeder.Metrics def __init__( self, - track_or_episode: typing.Union[Metadata_pb2.Track, Metadata_pb2.Episode], + track_or_episode: typing.Union[Metadata.Track, Metadata.Episode], input_stream: GeneralAudioStream, normalization_data: NormalizationData, metrics: PlayableContentFeeder.Metrics, ): - if type(track_or_episode) is Metadata_pb2.Track: + if type(track_or_episode) is Metadata.Track: self.track = track_or_episode self.episode = None - elif type(track_or_episode) is Metadata_pb2.Episode: + elif type(track_or_episode) is Metadata.Episode: self.track = None self.episode = track_or_episode else: diff --git a/librespot/audio/StreamId.py b/librespot/audio/StreamId.py index 474f784..1116e20 100644 --- a/librespot/audio/StreamId.py +++ b/librespot/audio/StreamId.py @@ -1,5 +1,5 @@ from librespot.common.Utils import Utils -from librespot.proto import Metadata_pb2 +from librespot.proto import Metadata_pb2 as Metadata class StreamId: @@ -7,8 +7,8 @@ class StreamId: episode_gid: bytes = None def __init__(self, - file: Metadata_pb2.AudioFile = None, - episode: Metadata_pb2.Episode = None): + file: Metadata.AudioFile = None, + episode: Metadata.Episode = None): if file is None and episode is None: return if file is not None: diff --git a/librespot/audio/cdn/CdnFeedHelper.py b/librespot/audio/cdn/CdnFeedHelper.py index 7537ac6..a6b0d58 100644 --- a/librespot/audio/cdn/CdnFeedHelper.py +++ b/librespot/audio/cdn/CdnFeedHelper.py @@ -10,23 +10,23 @@ from librespot.audio import NormalizationData from librespot.audio import PlayableContentFeeder from librespot.common import Utils from librespot.core import Session -from librespot.proto import Metadata_pb2 -from librespot.proto import StorageResolve_pb2 +from librespot.proto import Metadata_pb2 as Metadata +from librespot.proto import StorageResolve_pb2 as StorageResolve class CdnFeedHelper: _LOGGER: logging = logging.getLogger(__name__) @staticmethod - def get_url(resp: StorageResolve_pb2.StorageResolveResponse) -> str: + def get_url(resp: StorageResolve.StorageResolveResponse) -> str: return random.choice(resp.cdnurl) @staticmethod def load_track( session: Session, - track: Metadata_pb2.Track, - file: Metadata_pb2.AudioFile, - resp_or_url: typing.Union[StorageResolve_pb2.StorageResolveResponse, str], + track: Metadata.Track, + file: Metadata.AudioFile, + resp_or_url: typing.Union[StorageResolve.StorageResolveResponse, str], preload: bool, halt_listener: HaltListener, ) -> PlayableContentFeeder.PlayableContentFeeder.LoadedStream: @@ -54,7 +54,7 @@ class CdnFeedHelper: @staticmethod def load_episode_external( - session: Session, episode: Metadata_pb2.Episode, + session: Session, episode: Metadata.Episode, halt_listener: HaltListener ) -> PlayableContentFeeder.PlayableContentFeeder.LoadedStream: resp = session.client().head(episode.external_url) @@ -79,9 +79,9 @@ class CdnFeedHelper: @staticmethod def load_episode( session: Session, - episode: Metadata_pb2.Episode, - file: Metadata_pb2.AudioFile, - resp_or_url: typing.Union[StorageResolve_pb2.StorageResolveResponse, str], + episode: Metadata.Episode, + file: Metadata.AudioFile, + resp_or_url: typing.Union[StorageResolve.StorageResolveResponse, str], halt_listener: HaltListener, ) -> PlayableContentFeeder.PlayableContentFeeder.LoadedStream: if type(resp_or_url) is str: diff --git a/librespot/audio/cdn/CdnManager.py b/librespot/audio/cdn/CdnManager.py index df42c03..a0e27bc 100644 --- a/librespot/audio/cdn/CdnManager.py +++ b/librespot/audio/cdn/CdnManager.py @@ -17,14 +17,14 @@ from librespot.audio.decrypt import NoopAudioDecrypt from librespot.audio.format import SuperAudioFormat from librespot.audio.storage import ChannelManager from librespot.common import Utils -from librespot.proto import StorageResolve_pb2 +from librespot.proto import StorageResolve_pb2 as StorageResolve if typing.TYPE_CHECKING: from librespot.audio.decrypt.AudioDecrypt import AudioDecrypt from librespot.audio.HaltListener import HaltListener from librespot.cache.CacheManager import CacheManager from librespot.core.Session import Session - from librespot.proto import Metadata_pb2 + from librespot.proto import Metadata_pb2 as Metadata class CdnManager: @@ -50,7 +50,7 @@ class CdnManager: return body - def stream_external_episode(self, episode: Metadata_pb2.Episode, + def stream_external_episode(self, episode: Metadata.Episode, external_url: str, halt_listener: HaltListener): return CdnManager.Streamer( @@ -65,7 +65,7 @@ class CdnManager: def stream_file( self, - file: Metadata_pb2.AudioFile, + file: Metadata.AudioFile, key: bytes, url: str, halt_listener: HaltListener, @@ -96,9 +96,9 @@ class CdnManager: if body is None: raise IOError("Response body is empty!") - proto = StorageResolve_pb2.StorageResolveResponse() + proto = StorageResolve.StorageResolveResponse() proto.ParseFromString(body) - if proto.result == StorageResolve_pb2.StorageResolveResponse.Result.CDN: + if proto.result == StorageResolve.StorageResolveResponse.Result.CDN: url = random.choice(proto.cdnurl) self._LOGGER.debug("Fetched CDN url for {}: {}".format( Utils.bytes_to_hex(file_id), url)) diff --git a/librespot/audio/format/AudioQualityPicker.py b/librespot/audio/format/AudioQualityPicker.py index 1d218d4..c395565 100644 --- a/librespot/audio/format/AudioQualityPicker.py +++ b/librespot/audio/format/AudioQualityPicker.py @@ -3,10 +3,10 @@ from __future__ import annotations import typing if typing.TYPE_CHECKING: - from librespot.proto import Metadata_pb2 + from librespot.proto import Metadata_pb2 as Metadata class AudioQualityPicker: def get_file(self, - files: typing.List[Metadata_pb2.AudioFile]) -> Metadata_pb2.AudioFile: + files: typing.List[Metadata.AudioFile]) -> Metadata.AudioFile: pass diff --git a/librespot/audio/format/SuperAudioFormat.py b/librespot/audio/format/SuperAudioFormat.py index 0fa2ae2..0b7e589 100644 --- a/librespot/audio/format/SuperAudioFormat.py +++ b/librespot/audio/format/SuperAudioFormat.py @@ -1,4 +1,4 @@ -from librespot.proto import Metadata_pb2 +from librespot.proto import Metadata_pb2 as Metadata import enum @@ -8,19 +8,19 @@ class SuperAudioFormat(enum.Enum): AAC = 0x02 @staticmethod - def get(audio_format: Metadata_pb2.AudioFile.Format): - if audio_format == Metadata_pb2.AudioFile.Format.OGG_VORBIS_96 or \ - audio_format == Metadata_pb2.AudioFile.Format.OGG_VORBIS_160 or \ - audio_format == Metadata_pb2.AudioFile.Format.OGG_VORBIS_320: + def get(audio_format: Metadata.AudioFile.Format): + if audio_format == Metadata.AudioFile.Format.OGG_VORBIS_96 or \ + audio_format == Metadata.AudioFile.Format.OGG_VORBIS_160 or \ + audio_format == Metadata.AudioFile.Format.OGG_VORBIS_320: return SuperAudioFormat.VORBIS - if audio_format == Metadata_pb2.AudioFile.Format.MP3_256 or \ - audio_format == Metadata_pb2.AudioFile.Format.MP3_320 or \ - audio_format == Metadata_pb2.AudioFile.Format.MP3_160 or \ - audio_format == Metadata_pb2.AudioFile.Format.MP3_96 or \ - audio_format == Metadata_pb2.AudioFile.Format.MP3_160_ENC: + if audio_format == Metadata.AudioFile.Format.MP3_256 or \ + audio_format == Metadata.AudioFile.Format.MP3_320 or \ + audio_format == Metadata.AudioFile.Format.MP3_160 or \ + audio_format == Metadata.AudioFile.Format.MP3_96 or \ + audio_format == Metadata.AudioFile.Format.MP3_160_ENC: return SuperAudioFormat.MP3 - if audio_format == Metadata_pb2.AudioFile.Format.AAC_24 or \ - audio_format == Metadata_pb2.AudioFile.Format.AAC_48 or \ - audio_format == Metadata_pb2.AudioFile.Format.AAC_24_NORM: + if audio_format == Metadata.AudioFile.Format.AAC_24 or \ + audio_format == Metadata.AudioFile.Format.AAC_48 or \ + audio_format == Metadata.AudioFile.Format.AAC_24_NORM: return SuperAudioFormat.AAC raise RuntimeError("Unknown audio format: {}".format(audio_format)) diff --git a/librespot/core/Session.py b/librespot/core/Session.py index 6272ae7..9bec223 100644 --- a/librespot/core/Session.py +++ b/librespot/core/Session.py @@ -35,9 +35,9 @@ from librespot.dealer import ApiClient from librespot.dealer import DealerClient from librespot.mercury import MercuryClient from librespot.mercury import SubListener -from librespot.proto import Authentication_pb2 -from librespot.proto import Connect_pb2 -from librespot.proto import Keyexchange_pb2 +from librespot.proto import Authentication_pb2 as Authentication +from librespot.proto import Connect_pb2 as Connect +from librespot.proto import Keyexchange_pb2 as Keyexchange from librespot.proto.ExplicitContentPubsub_pb2 import UserAttributesUpdate from librespot.standard import BytesInputStream from librespot.standard import Closeable @@ -319,7 +319,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): _conn: Session.ConnectionHolder = None _cipherPair: CipherPair = None _receiver: Session.Receiver = None - _apWelcome: Authentication_pb2.APWelcome = None + _apWelcome: Authentication.APWelcome = None _mercuryClient: MercuryClient = None _audioKeyManager: AudioKeyManager = None _channelManager: ChannelManager = None @@ -380,13 +380,13 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): nonce = os.urandom(0x10) - client_hello = Keyexchange_pb2.ClientHello( + client_hello = Keyexchange.ClientHello( build_info=Version.standard_build_info(), cryptosuites_supported=[ - Keyexchange_pb2.Cryptosuite.CRYPTO_SUITE_SHANNON + Keyexchange.Cryptosuite.CRYPTO_SUITE_SHANNON ], - login_crypto_hello=Keyexchange_pb2.LoginCryptoHelloUnion( - diffie_hellman=Keyexchange_pb2.LoginCryptoDiffieHellmanHello( + login_crypto_hello=Keyexchange.LoginCryptoHelloUnion( + diffie_hellman=Keyexchange.LoginCryptoDiffieHellmanHello( gc=self._keys.public_key_array(), server_keys_known=1), ), client_nonce=nonce, padding=bytes([0x1E]), @@ -412,7 +412,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): buffer = self._conn.read(length - 4) acc.write(buffer) - ap_response_message = Keyexchange_pb2.APResponseMessage() + ap_response_message = Keyexchange.APResponseMessage() ap_response_message.ParseFromString(buffer) shared_key = Utils.to_byte_array( self._keys.compute_shared_key( @@ -450,12 +450,12 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): mac.update(acc.array()) challenge = mac.digest() - client_response_plaintext = Keyexchange_pb2.ClientResponsePlaintext( - login_crypto_response=Keyexchange_pb2.LoginCryptoResponseUnion( - diffie_hellman=Keyexchange_pb2.LoginCryptoDiffieHellmanResponse( + client_response_plaintext = Keyexchange.ClientResponsePlaintext( + login_crypto_response=Keyexchange.LoginCryptoResponseUnion( + diffie_hellman=Keyexchange.LoginCryptoDiffieHellmanResponse( hmac=challenge)), - pow_response=Keyexchange_pb2.PoWResponseUnion(), - crypto_response=Keyexchange_pb2.CryptoResponseUnion(), + pow_response=Keyexchange.PoWResponseUnion(), + crypto_response=Keyexchange.CryptoResponseUnion(), ) client_response_plaintext_bytes = client_response_plaintext.SerializeToString( @@ -474,7 +474,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): | (scrap[2] << 8) | (scrap[3] & 0xFF)) payload = self._conn.read(length - 4) - failed = Keyexchange_pb2.APResponseMessage() + failed = Keyexchange.APResponseMessage() failed.ParseFromString(payload) raise RuntimeError(failed) except socket.timeout: @@ -490,7 +490,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): self._LOGGER.info("Connection successfully!") def _authenticate(self, - credentials: Authentication_pb2.LoginCredentials) -> None: + credentials: Authentication.LoginCredentials) -> None: self._authenticate_partial(credentials, False) with self._authLock: @@ -521,16 +521,16 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): self, "hm://connect-state/v1/connect/logout") def _authenticate_partial(self, - credentials: Authentication_pb2.LoginCredentials, + credentials: Authentication.LoginCredentials, remove_lock: bool) -> None: if self._cipherPair is None: raise RuntimeError("Connection not established!") - client_response_encrypted = Authentication_pb2.ClientResponseEncrypted( + client_response_encrypted = Authentication.ClientResponseEncrypted( login_credentials=credentials, - system_info=Authentication_pb2.SystemInfo( - os=Authentication_pb2.Os.OS_UNKNOWN, - cpu_family=Authentication_pb2.CpuFamily.CPU_UNKNOWN, + system_info=Authentication.SystemInfo( + os=Authentication.Os.OS_UNKNOWN, + cpu_family=Authentication.CpuFamily.CPU_UNKNOWN, system_information_string=Version.system_info_string(), device_id=self._inner.device_id, ), @@ -542,7 +542,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): packet = self._cipherPair.receive_encoded(self._conn) if packet.is_cmd(Packet.Type.ap_welcome): - self._apWelcome = Authentication_pb2.APWelcome() + self._apWelcome = Authentication.APWelcome() self._apWelcome.ParseFromString(packet.payload) self._receiver = Session.Receiver(self) @@ -564,7 +564,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): if self._inner.conf.store_credentials: reusable = self._apWelcome.reusable_auth_credentials - reusable_type = Authentication_pb2.AuthenticationType.Name( + reusable_type = Authentication.AuthenticationType.Name( self._apWelcome.reusable_auth_credentials_type) if self._inner.conf.stored_credentials_file is None: @@ -581,7 +581,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): ) elif packet.is_cmd(Packet.Type.auth_failure): - ap_login_failed = Keyexchange_pb2.APLoginFailed() + ap_login_failed = Keyexchange.APLoginFailed() ap_login_failed.ParseFromString(packet.payload) raise Session.SpotifyAuthenticationException(ap_login_failed) else: @@ -745,7 +745,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): def username(self) -> str: return self.ap_welcome().canonical_username - def ap_welcome(self) -> Authentication_pb2.APWelcome: + def ap_welcome(self) -> Authentication.APWelcome: self._wait_auth_lock() if self._apWelcome is None: raise RuntimeError("Session isn't authenticated!") @@ -770,7 +770,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): def preferred_locale(self) -> str: return self._inner.preferred_locale - def device_type(self) -> Connect_pb2.DeviceType: + def device_type(self) -> Connect.DeviceType: return self._inner.device_type def device_name(self) -> str: @@ -792,7 +792,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): ApResolver.get_random_accesspoint(), self._inner.conf) self._connect() self._authenticate_partial( - Authentication_pb2.LoginCredentials( + Authentication.LoginCredentials( typ=self._apWelcome.reusable_auth_credentials_type, username=self._apWelcome.canonical_username, auth_data=self._apWelcome.reusable_auth_credentials, @@ -868,7 +868,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): pass class Inner: - device_type: Connect_pb2.DeviceType = None + device_type: Connect.DeviceType = None device_name: str = None device_id: str = None conf = None @@ -876,7 +876,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): def __init__( self, - device_type: Connect_pb2.DeviceType, + device_type: Connect.DeviceType, device_name: str, preferred_locale: str, conf: Session.Configuration, @@ -893,7 +893,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): conf = None device_id = None device_name = "librespot-python" - device_type = Connect_pb2.DeviceType.COMPUTER + device_type = Connect.DeviceType.COMPUTER preferred_locale = "en" def __init__(self, conf: Session.Configuration = None): @@ -921,12 +921,12 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): return self def set_device_type( - self, device_type: Connect_pb2.DeviceType) -> Session.AbsBuilder: + self, device_type: Connect.DeviceType) -> Session.AbsBuilder: self.device_type = device_type return self class Builder(AbsBuilder): - login_credentials: Authentication_pb2.LoginCredentials = None + login_credentials: Authentication.LoginCredentials = None def stored(self): pass @@ -943,8 +943,8 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): pass else: try: - self.login_credentials = Authentication_pb2.LoginCredentials( - typ=Authentication_pb2.AuthenticationType.Value( + self.login_credentials = Authentication.LoginCredentials( + typ=Authentication.AuthenticationType.Value( obj["type"]), username=obj["username"], auth_data=base64.b64decode(obj["credentials"]), @@ -955,9 +955,9 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): return self def user_pass(self, username: str, password: str) -> Session.Builder: - self.login_credentials = Authentication_pb2.LoginCredentials( + self.login_credentials = Authentication.LoginCredentials( username=username, - typ=Authentication_pb2.AuthenticationType.AUTHENTICATION_USER_PASS, + typ=Authentication.AuthenticationType.AUTHENTICATION_USER_PASS, auth_data=password.encode(), ) return self @@ -1142,9 +1142,9 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): ) class SpotifyAuthenticationException(Exception): - def __init__(self, login_failed: Keyexchange_pb2.APLoginFailed): + def __init__(self, login_failed: Keyexchange.APLoginFailed): super().__init__( - Keyexchange_pb2.ErrorCode.Name(login_failed.error_code)) + Keyexchange.ErrorCode.Name(login_failed.error_code)) class Accumulator: buffer: bytes = bytes() diff --git a/librespot/dealer/ApiClient.py b/librespot/dealer/ApiClient.py index 6c97adb..f8df920 100644 --- a/librespot/dealer/ApiClient.py +++ b/librespot/dealer/ApiClient.py @@ -9,8 +9,8 @@ from librespot.metadata import ArtistId from librespot.metadata import EpisodeId from librespot.metadata import ShowId from librespot.metadata import TrackId -from librespot.proto import Connect_pb2 -from librespot.proto import Metadata_pb2 +from librespot.proto import Connect_pb2 as Connect +from librespot.proto import Metadata_pb2 as Metadata from librespot.standard import Closeable @@ -53,7 +53,7 @@ class ApiClient(Closeable): return resp def put_connect_state(self, connection_id: str, - proto: Connect_pb2.PutStateRequest) -> None: + proto: Connect.PutStateRequest) -> None: resp = self.send( "PUT", "/connect-state/v1/devices/{}".format(self._session.device_id()), @@ -72,7 +72,7 @@ class ApiClient(Closeable): self._LOGGER.warning("PUT state returned {}. headers: {}".format( resp.status_code, resp.headers)) - def get_metadata_4_track(self, track: TrackId) -> Metadata_pb2.Track: + def get_metadata_4_track(self, track: TrackId) -> Metadata.Track: resp = self.send("GET", "/metadata/4/track/{}".format(track.hex_id()), None, None) ApiClient.StatusCodeException.check_status(resp) @@ -80,11 +80,11 @@ class ApiClient(Closeable): body = resp.content if body is None: raise RuntimeError() - proto = Metadata_pb2.Track() + proto = Metadata.Track() proto.ParseFromString(body) return proto - def get_metadata_4_episode(self, episode: EpisodeId) -> Metadata_pb2.Episode: + def get_metadata_4_episode(self, episode: EpisodeId) -> Metadata.Episode: resp = self.send("GET", "/metadata/4/episode/{}".format(episode.hex_id()), None, None) @@ -93,11 +93,11 @@ class ApiClient(Closeable): body = resp.content if body is None: raise IOError() - proto = Metadata_pb2.Episode() + proto = Metadata.Episode() proto.ParseFromString(body) return proto - def get_metadata_4_album(self, album: AlbumId) -> Metadata_pb2.Album: + def get_metadata_4_album(self, album: AlbumId) -> Metadata.Album: resp = self.send("GET", "/metadata/4/album/{}".format(album.hex_id()), None, None) ApiClient.StatusCodeException.check_status(resp) @@ -105,11 +105,11 @@ class ApiClient(Closeable): body = resp.content if body is None: raise IOError() - proto = Metadata_pb2.Album() + proto = Metadata.Album() proto.ParseFromString(body) return proto - def get_metadata_4_artist(self, artist: ArtistId) -> Metadata_pb2.Artist: + def get_metadata_4_artist(self, artist: ArtistId) -> Metadata.Artist: resp = self.send("GET", "/metadata/4/artist/{}".format(artist.hex_id()), None, None) @@ -118,11 +118,11 @@ class ApiClient(Closeable): body = resp.content if body is None: raise IOError() - proto = Metadata_pb2.Artist() + proto = Metadata.Artist() proto.ParseFromString(body) return proto - def get_metadata_4_show(self, show: ShowId) -> Metadata_pb2.Show: + def get_metadata_4_show(self, show: ShowId) -> Metadata.Show: resp = self.send("GET", "/metadata/4/show/{}".format(show.hex_id()), None, None) ApiClient.StatusCodeException.check_status(resp) @@ -130,7 +130,7 @@ class ApiClient(Closeable): body = resp.content if body is None: raise IOError() - proto = Metadata_pb2.Show() + proto = Metadata.Show() proto.ParseFromString(body) return proto diff --git a/librespot/mercury/MercuryClient.py b/librespot/mercury/MercuryClient.py index 437d3c5..c36753a 100644 --- a/librespot/mercury/MercuryClient.py +++ b/librespot/mercury/MercuryClient.py @@ -13,8 +13,8 @@ from librespot.crypto import Packet from librespot.mercury import JsonMercuryRequest from librespot.mercury import RawMercuryRequest from librespot.mercury import SubListener -from librespot.proto import Mercury_pb2 -from librespot.proto import Pubsub_pb2 +from librespot.proto import Mercury_pb2 as Mercury +from librespot.proto import Pubsub_pb2 as Pubsub from librespot.standard import BytesInputStream from librespot.standard import BytesOutputStream from librespot.standard import Closeable @@ -42,7 +42,7 @@ class MercuryClient(PacketsReceiver.PacketsReceiver, Closeable): if len(response.payload) > 0: for payload in response.payload: - sub = Pubsub_pb2.Subscription() + sub = Pubsub.Subscription() sub.ParseFromString(payload) self._subscriptions.append( MercuryClient.InternalSubListener(sub.uri, listener, True)) @@ -150,7 +150,7 @@ class MercuryClient(PacketsReceiver.PacketsReceiver, Closeable): self._partials.pop(seq) - header = Mercury_pb2.Header() + header = Mercury.Header() header.ParseFromString(partial[0]) resp = MercuryClient.Response(header, partial) @@ -257,7 +257,7 @@ class MercuryClient(PacketsReceiver.PacketsReceiver, Closeable): payload: typing.List[bytes] status_code: int - def __init__(self, header: Mercury_pb2.Header, + def __init__(self, header: Mercury.Header, payload: typing.List[bytes]): self.uri = header.uri self.status_code = header.status_code diff --git a/librespot/mercury/RawMercuryRequest.py b/librespot/mercury/RawMercuryRequest.py index 6a0c89a..0ba37ed 100644 --- a/librespot/mercury/RawMercuryRequest.py +++ b/librespot/mercury/RawMercuryRequest.py @@ -1,13 +1,13 @@ import typing -from librespot.proto import Mercury_pb2 +from librespot.proto import Mercury_pb2 as Mercury class RawMercuryRequest: - header: Mercury_pb2.Header + header: Mercury.Header payload: typing.List[bytes] - def __init__(self, header: Mercury_pb2.Header, payload: typing.List[bytes]): + def __init__(self, header: Mercury.Header, payload: typing.List[bytes]): self.header = header self.payload = payload @@ -61,7 +61,7 @@ class RawMercuryRequest: return self def add_user_field(self, - field: Mercury_pb2.UserField = None, + field: Mercury.UserField = None, key: str = None, value: str = None): if field is None and (key is None or value is None): @@ -74,7 +74,7 @@ class RawMercuryRequest: self.header_dict["user_fields"].append(field) if key is not None and value is not None: self.header_dict["user_fields"].append( - Mercury_pb2.UserField(key=key, value=value.encode())) + Mercury.UserField(key=key, value=value.encode())) return self def add_payload_part(self, part: bytes): @@ -85,5 +85,5 @@ class RawMercuryRequest: return self.add_payload_part(msg) def build(self): - return RawMercuryRequest(Mercury_pb2.Header(**self.header_dict), + return RawMercuryRequest(Mercury.Header(**self.header_dict), self.payload) diff --git a/librespot/player/StateWrapper.py b/librespot/player/StateWrapper.py index 32c57c0..6652ab5 100644 --- a/librespot/player/StateWrapper.py +++ b/librespot/player/StateWrapper.py @@ -7,7 +7,7 @@ from librespot.dealer import DealerClient from librespot.player import Player from librespot.player import PlayerConfiguration from librespot.player.state import DeviceStateHandler -from librespot.proto import Connect_pb2 +from librespot.proto import Connect_pb2 as Connect from librespot.proto.Player_pb2 import ContextPlayerOptions from librespot.proto.Player_pb2 import PlayerState from librespot.proto.Player_pb2 import Restrictions @@ -52,7 +52,7 @@ class StateWrapper(DeviceStateHandler.Listener, DealerClient.MessageListener): self._device.add_listener(listener) def ready(self) -> None: - self._device.update_state(Connect_pb2.PutStateReason.NEW_DEVICE, 0, + self._device.update_state(Connect.PutStateReason.NEW_DEVICE, 0, self._state) def on_message(self, uri: str, headers: typing.Dict[str, str], diff --git a/librespot/player/codecs/VorbisOnlyAudioQuality.py b/librespot/player/codecs/VorbisOnlyAudioQuality.py index 99683fd..48755f6 100644 --- a/librespot/player/codecs/VorbisOnlyAudioQuality.py +++ b/librespot/player/codecs/VorbisOnlyAudioQuality.py @@ -6,7 +6,7 @@ import typing from librespot.audio.decoders.AudioQuality import AudioQuality from librespot.audio.format.AudioQualityPicker import AudioQualityPicker from librespot.audio.format.SuperAudioFormat import SuperAudioFormat -from librespot.proto import Metadata_pb2 +from librespot.proto import Metadata_pb2 as Metadata class VorbisOnlyAudioQuality(AudioQualityPicker): @@ -17,7 +17,7 @@ class VorbisOnlyAudioQuality(AudioQualityPicker): self.preferred = preferred @staticmethod - def get_vorbis_file(files: typing.List[Metadata_pb2.AudioFile]): + def get_vorbis_file(files: typing.List[Metadata.AudioFile]): for file in files: if (hasattr(file, "format") and SuperAudioFormat.get(file.format) == SuperAudioFormat.VORBIS): @@ -25,13 +25,13 @@ class VorbisOnlyAudioQuality(AudioQualityPicker): return None - def get_file(self, files: typing.List[Metadata_pb2.AudioFile]): - matches: typing.List[Metadata_pb2.AudioFile] = self.preferred.get_matches( + def get_file(self, files: typing.List[Metadata.AudioFile]): + matches: typing.List[Metadata.AudioFile] = self.preferred.get_matches( files) - vorbis: Metadata_pb2.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file( + vorbis: Metadata.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file( matches) if vorbis is None: - vorbis: Metadata_pb2.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file( + vorbis: Metadata.AudioFile = VorbisOnlyAudioQuality.get_vorbis_file( files) if vorbis is not None: self._LOGGER.warning( diff --git a/librespot/player/state/DeviceStateHandler.py b/librespot/player/state/DeviceStateHandler.py index afb98f7..13885cc 100644 --- a/librespot/player/state/DeviceStateHandler.py +++ b/librespot/player/state/DeviceStateHandler.py @@ -11,16 +11,16 @@ import urllib.parse from librespot.common import Utils from librespot.core import Session from librespot.player import PlayerConfiguration -from librespot.proto import Connect_pb2 -from librespot.proto import Player_pb2 +from librespot.proto import Connect_pb2 as Connect +from librespot.proto import Player_pb2 as Player class DeviceStateHandler: _LOGGER: logging = logging.getLogger(__name__) _session: Session = None - _deviceInfo: Connect_pb2.DeviceInfo = None + _deviceInfo: Connect.DeviceInfo = None _listeners: typing.List[DeviceStateHandler.Listener] = [] - _putState: Connect_pb2.PutStateRequest = None + _putState: Connect.PutStateRequest = None _putStateWorker: concurrent.futures.ThreadPoolExecutor = ( concurrent.futures.ThreadPoolExecutor()) _connectionId: str = None @@ -28,7 +28,7 @@ class DeviceStateHandler: def __init__(self, session: Session, player, conf: PlayerConfiguration): self._session = session self._deviceInfo = None - self._putState = Connect_pb2.PutStateRequest() + self._putState = Connect.PutStateRequest() def _update_connection_id(self, newer: str) -> None: newer = urllib.parse.unquote(newer, "UTF-8") @@ -48,9 +48,9 @@ class DeviceStateHandler: def update_state( self, - reason: Connect_pb2.PutStateReason, + reason: Connect.PutStateReason, player_time: int, - state: Player_pb2.PlayerState, + state: Player.PlayerState, ): if self._connectionId is None: raise TypeError() @@ -67,7 +67,7 @@ class DeviceStateHandler: self._putStateWorker.submit(self._put_connect_state, self._putState) - def _put_connect_state(self, req: Connect_pb2.PutStateRequest): + 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,