diff --git a/librespot/Version.py b/librespot/Version.py index bad60ca..6150c2d 100644 --- a/librespot/Version.py +++ b/librespot/Version.py @@ -12,7 +12,6 @@ class Version: if platform.system() == "Darwin": return Platform.PLATFORM_OSX_X86 return Platform.PLATFORM_LINUX_X86 - pass @staticmethod def version_string(): diff --git a/librespot/ZeroconfServer.py b/librespot/ZeroconfServer.py index 0fe97c5..19f111f 100644 --- a/librespot/ZeroconfServer.py +++ b/librespot/ZeroconfServer.py @@ -61,10 +61,10 @@ class ZeroconfServer(Closeable): ) class Inner: - device_type: Connect.DeviceType = None - device_name: str = None - device_id: str = None - preferred_locale: str = None + device_type: Connect.DeviceType + device_name: str + device_id: str + preferred_locale: str conf = None def __init__( diff --git a/librespot/audio/StreamId.py b/librespot/audio/StreamId.py index 1116e20..fdbe139 100644 --- a/librespot/audio/StreamId.py +++ b/librespot/audio/StreamId.py @@ -3,8 +3,8 @@ from librespot.proto import Metadata_pb2 as Metadata class StreamId: - file_id: bytes = None - episode_gid: bytes = None + file_id: bytes + episode_gid: bytes def __init__(self, file: Metadata.AudioFile = None, diff --git a/librespot/audio/cdn/CdnManager.py b/librespot/audio/cdn/CdnManager.py index 3499b72..6bd2416 100644 --- a/librespot/audio/cdn/CdnManager.py +++ b/librespot/audio/cdn/CdnManager.py @@ -29,7 +29,7 @@ if typing.TYPE_CHECKING: class CdnManager: _LOGGER: logging = logging.getLogger(__name__) - _session: Session = None + _session: Session def __init__(self, session: Session): self._session = session @@ -118,14 +118,14 @@ class CdnManager: self._headers = headers class CdnUrl: - _cdnManager = None - _fileId: bytes + __cdnManager = None + __fileId: bytes _expiration: int _url: str def __init__(self, cdn_manager, file_id: bytes, url: str): - self._cdnManager: CdnManager = cdn_manager - self._fileId = file_id + self.__cdnManager: CdnManager = cdn_manager + self.__fileId = file_id self.set_url(url) def url(self): @@ -133,14 +133,14 @@ class CdnManager: return self._url if self._expiration <= int(time.time() * 1000) + 5 * 60 * 1000: - self._url = self._cdnManager.get_audio_url(self._fileId) + self._url = self.__cdnManager.get_audio_url(self.__fileId) return self.url def set_url(self, url: str): self._url = url - if self._fileId is not None: + if self.__fileId is not None: token_url = urllib.parse.urlparse(url) token_query = urllib.parse.parse_qs(token_url.query) token_list = token_query.get("__token__") @@ -163,7 +163,7 @@ class CdnManager: if expire_at is None: self._expiration = -1 - self._cdnManager._LOGGER.warning( + self.__cdnManager._LOGGER.warning( "Invalid __token__ in CDN url: {}".format(url)) return @@ -173,8 +173,8 @@ class CdnManager: i = token_url.query.index("_") except ValueError: self._expiration = -1 - self._cdnManager._LOGGER.warning( - "Couldn't extract expiration, invalid parameter in CDN url: " + self.__cdnManager._LOGGER.warning( + "Couldn't extract expiration, invalid parameter in CDN url: {}" .format(url)) return @@ -187,19 +187,19 @@ class CdnManager: GeneralAudioStream.GeneralAudioStream, GeneralWritableStream.GeneralWritableStream, ): - _session: Session = None - _streamId: StreamId.StreamId = None + _session: Session + _streamId: StreamId.StreamId _executorService = concurrent.futures.ThreadPoolExecutor() - _audioFormat: SuperAudioFormat = None - _audioDecrypt: AudioDecrypt = None + _audioFormat: SuperAudioFormat + _audioDecrypt: AudioDecrypt _cdnUrl = None _size: int _buffer: typing.List[bytearray] _available: typing.List[bool] _requested: typing.List[bool] _chunks: int - _internalStream: CdnManager.Streamer.InternalStream = None - _haltListener: HaltListener = None + _internalStream: CdnManager.Streamer.InternalStream + _haltListener: HaltListener def __init__( self, diff --git a/librespot/audio/decrypt/AesAudioDecrypt.py b/librespot/audio/decrypt/AesAudioDecrypt.py index 10130ff..bdc4fa2 100644 --- a/librespot/audio/decrypt/AesAudioDecrypt.py +++ b/librespot/audio/decrypt/AesAudioDecrypt.py @@ -31,7 +31,7 @@ class AesAudioDecrypt(AudioDecrypt): cipher = None decrypt_count = 0 decrypt_total_time = 0 - key: bytes = None + key: bytes def __init__(self, key: bytes): self.key = key @@ -57,7 +57,7 @@ class AesAudioDecrypt(AudioDecrypt): iv += self.iv_diff - self.decrypt_total_time += time.time_ns() + self.decrypt_total_time += time.time_ns() - start self.decrypt_count += 1 return new_buffer diff --git a/librespot/common/Base62.py b/librespot/common/Base62.py index 5ab0c71..7bcce0b 100644 --- a/librespot/common/Base62.py +++ b/librespot/common/Base62.py @@ -55,7 +55,7 @@ class Base62: if len(out) < estimated_length: size = len(out) - for i in range(estimated_length - size): + for _ in range(estimated_length - size): out += bytes([0]) return self.reverse(out) diff --git a/librespot/core/EventService.py b/librespot/core/EventService.py index 24f6e08..427b736 100644 --- a/librespot/core/EventService.py +++ b/librespot/core/EventService.py @@ -42,7 +42,7 @@ class EventService: elif type(event_or_builder) is EventService.EventBuilder: builder = event_or_builder else: - TypeError() + raise TypeError() self._worker.submit(lambda: self._worker_callback(builder)) def language(self, lang: str): diff --git a/librespot/core/Session.py b/librespot/core/Session.py index b838e85..0e8c329 100644 --- a/librespot/core/Session.py +++ b/librespot/core/Session.py @@ -331,7 +331,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): _search: SearchManager = None _contentFeeder: PlayableContentFeeder.PlayableContentFeeder = None _eventService: EventService = None - _countryCode: str = None + _countryCode: str _closed: bool = False _closing: bool = False _scheduledReconnect: sched.Event = None @@ -869,10 +869,10 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): class Inner: device_type: Connect.DeviceType = None - device_name: str = None - device_id: str = None + device_name: str + device_id: str conf = None - preferred_locale: str = None + preferred_locale: str def __init__( self, @@ -1035,17 +1035,17 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): class Builder: # Proxy proxyEnabled: bool = False - proxyType: Proxy.Type = None - proxyAddress: str = None - proxyPort: int = None - proxyAuth: bool = None - proxyUsername: str = None - proxyPassword: str = None + proxyType: Proxy.Type + proxyAddress: str + proxyPort: int + proxyAuth: bool + proxyUsername: str + proxyPassword: str # Cache cache_enabled: bool = True cache_dir: str = os.path.join(os.getcwd(), "cache") - do_cache_clean_up: bool = None + do_cache_clean_up: bool # Stored credentials store_credentials: bool = True @@ -1053,7 +1053,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): os.getcwd(), "credentials.json") # Fetching - retry_on_chunk_error: bool = None + retry_on_chunk_error: bool def set_proxy_enabled( self, @@ -1230,7 +1230,7 @@ class Session(Closeable, SubListener, DealerClient.MessageListener): return 2 class Receiver: - session: Session = None + session: Session thread: threading.Thread running: bool = True diff --git a/librespot/dealer/ApiClient.py b/librespot/dealer/ApiClient.py index f8df920..5e38beb 100644 --- a/librespot/dealer/ApiClient.py +++ b/librespot/dealer/ApiClient.py @@ -17,7 +17,7 @@ from librespot.standard import Closeable class ApiClient(Closeable): _LOGGER: logging = logging.getLogger(__name__) _session = None - _baseUrl: str = None + _baseUrl: str def __init__(self, session): self._session = session diff --git a/librespot/mercury/MercuryClient.py b/librespot/mercury/MercuryClient.py index c36753a..bbd85fb 100644 --- a/librespot/mercury/MercuryClient.py +++ b/librespot/mercury/MercuryClient.py @@ -249,7 +249,7 @@ class MercuryClient(PacketsReceiver.PacketsReceiver, Closeable): code: int def __init__(self, response): - super("status: {}".format(response.status_code)) + super().__init__("status: {}".format(response.status_code)) self.code = response.status_code class Response: diff --git a/librespot/metadata/__init__.py b/librespot/metadata/__init__.py index 59f7f6a..1b43855 100644 --- a/librespot/metadata/__init__.py +++ b/librespot/metadata/__init__.py @@ -36,7 +36,6 @@ class PlayableId: @staticmethod def from_uri(uri: str) -> PlayableId: - pass if not PlayableId.is_supported(uri): return UnsupportedId(uri) @@ -167,7 +166,7 @@ class EpisodeId(SpotifyId, PlayableId): episode_id = matcher.group(1) return EpisodeId( Utils.bytes_to_hex(PlayableId.BASE62.decode(episode_id, 16))) - TypeError("Not a Spotify episode ID: {}".format(uri)) + raise TypeError("Not a Spotify episode ID: {}".format(uri)) @staticmethod def from_base62(base62: str) -> EpisodeId: diff --git a/librespot/player/Player.py b/librespot/player/Player.py index 3bb6279..d4238b7 100644 --- a/librespot/player/Player.py +++ b/librespot/player/Player.py @@ -19,15 +19,15 @@ class Player(Closeable, PlayerSession.Listener, AudioSink.Listener): VOLUME_MAX: int = 65536 _LOGGER: logging = logging.getLogger(__name__) _scheduler: sched.scheduler = sched.scheduler(time.time) - _session: Session = None - _conf: PlayerConfiguration = None - _events: Player.EventsDispatcher = None - _sink: AudioSink = None + _session: Session + _conf: PlayerConfiguration + _events: Player.EventsDispatcher + _sink: AudioSink _metrics: typing.Dict[str, PlaybackMetrics] = {} - _state: StateWrapper = None - _playerSession: PlayerSession = None + _state: StateWrapper + _playerSession: PlayerSession _releaseLineFuture = None - _deviceStateListener: DeviceStateHandler.Listener = None + _deviceStateListener: DeviceStateHandler.Listener def __init__(self, conf: PlayerConfiguration, session: Session): self._conf = conf diff --git a/librespot/player/state/DeviceStateHandler.py b/librespot/player/state/DeviceStateHandler.py index 13885cc..c4988f6 100644 --- a/librespot/player/state/DeviceStateHandler.py +++ b/librespot/player/state/DeviceStateHandler.py @@ -17,13 +17,13 @@ from librespot.proto import Player_pb2 as Player class DeviceStateHandler: _LOGGER: logging = logging.getLogger(__name__) - _session: Session = None - _deviceInfo: Connect.DeviceInfo = None + _session: Session + _deviceInfo: Connect.DeviceInfo _listeners: typing.List[DeviceStateHandler.Listener] = [] - _putState: Connect.PutStateRequest = None + _putState: Connect.PutStateRequest _putStateWorker: concurrent.futures.ThreadPoolExecutor = ( concurrent.futures.ThreadPoolExecutor()) - _connectionId: str = None + _connectionId: str def __init__(self, session: Session, player, conf: PlayerConfiguration): self._session = session @@ -101,9 +101,9 @@ class DeviceStateHandler: pass class CommandBody: - _obj: typing.Any = None - _data: bytes = None - _value: str = None + _obj: typing.Any + _data: bytes + _value: str def __init__(self, obj: typing.Any): self._obj = obj diff --git a/librespot/zeroconf/Zeroconf.py b/librespot/zeroconf/Zeroconf.py index 2807ea8..a0274ce 100644 --- a/librespot/zeroconf/Zeroconf.py +++ b/librespot/zeroconf/Zeroconf.py @@ -24,7 +24,7 @@ class Zeroconf(Closeable): self.__BROADCAST6 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) self.__BROADCAST6.connect(("FF02::FB", 5353)) - except Exception as e: + except Exception: pass self.set_domain(".local") self.set_local_host_name(Zeroconf.get_or_create_local_host_name())