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