Merge pull request #8 from kokarare1212/deepsource-fix-8489b1ba
Refactor unnecessary `else` / `elif` when `if` block has a `return` statement
This commit is contained in:
@@ -9,10 +9,9 @@ class Version:
|
|||||||
def platform() -> Platform:
|
def platform() -> Platform:
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
return Platform.PLATFORM_WIN32_X86
|
return Platform.PLATFORM_WIN32_X86
|
||||||
elif platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
return Platform.PLATFORM_OSX_X86
|
return Platform.PLATFORM_OSX_X86
|
||||||
else:
|
return Platform.PLATFORM_LINUX_X86
|
||||||
return Platform.PLATFORM_LINUX_X86
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ class AbsChunkedInputStream(InputStream, HaltListener):
|
|||||||
length: int = None) -> int:
|
length: int = None) -> int:
|
||||||
if b is None and offset is None and length is None:
|
if b is None and offset is None and length is None:
|
||||||
return self.internal_read()
|
return self.internal_read()
|
||||||
elif not (b is not None and offset is not None and length is not None):
|
if not (b is not None and offset is not None and length is not None):
|
||||||
raise TypeError()
|
raise TypeError()
|
||||||
|
|
||||||
if self.closed:
|
if self.closed:
|
||||||
|
|||||||
@@ -45,11 +45,10 @@ class AudioKeyManager(PacketsReceiver):
|
|||||||
if key is None:
|
if key is None:
|
||||||
if retry:
|
if retry:
|
||||||
return self.get_audio_key(gid, file_id, False)
|
return self.get_audio_key(gid, file_id, False)
|
||||||
else:
|
raise RuntimeError(
|
||||||
raise RuntimeError(
|
"Failed fetching audio key! gid: {}, fileId: {}".format(
|
||||||
"Failed fetching audio key! gid: {}, fileId: {}".format(
|
Utils.Utils.bytes_to_hex(gid),
|
||||||
Utils.Utils.bytes_to_hex(gid),
|
Utils.Utils.bytes_to_hex(file_id)))
|
||||||
Utils.Utils.bytes_to_hex(file_id)))
|
|
||||||
|
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
|||||||
@@ -87,9 +87,8 @@ class PlayableContentFeeder:
|
|||||||
if track is not None:
|
if track is not None:
|
||||||
return CdnFeedHelper.load_track(self.session, track, file,
|
return CdnFeedHelper.load_track(self.session, track, file,
|
||||||
resp, preload, halt_lister)
|
resp, preload, halt_lister)
|
||||||
else:
|
return CdnFeedHelper.load_episode(self.session, episode, file,
|
||||||
return CdnFeedHelper.load_episode(self.session, episode, file,
|
resp, preload, halt_lister)
|
||||||
resp, preload, halt_lister)
|
|
||||||
elif resp.result == StorageResolve.StorageResolveResponse.Result.STORAGE:
|
elif resp.result == StorageResolve.StorageResolveResponse.Result.STORAGE:
|
||||||
if track is None:
|
if track is None:
|
||||||
# return StorageFeedHelper
|
# return StorageFeedHelper
|
||||||
|
|||||||
@@ -79,9 +79,8 @@ class CdnManager:
|
|||||||
self._LOGGER.debug("Fetched CDN url for {}: {}".format(
|
self._LOGGER.debug("Fetched CDN url for {}: {}".format(
|
||||||
Utils.bytes_to_hex(file_id), url))
|
Utils.bytes_to_hex(file_id), url))
|
||||||
return url
|
return url
|
||||||
else:
|
raise CdnManager.CdnException(
|
||||||
raise CdnManager.CdnException(
|
"Could not retrieve CDN url! result: {}".format(proto.result))
|
||||||
"Could not retrieve CDN url! result: {}".format(proto.result))
|
|
||||||
|
|
||||||
class CdnException(Exception):
|
class CdnException(Exception):
|
||||||
def __init__(self, ex):
|
def __init__(self, ex):
|
||||||
@@ -228,8 +227,7 @@ class CdnManager:
|
|||||||
if self._streamId.is_episode():
|
if self._streamId.is_episode():
|
||||||
return "episode_gid: {}".format(
|
return "episode_gid: {}".format(
|
||||||
self._streamId.get_episode_gid())
|
self._streamId.get_episode_gid())
|
||||||
else:
|
return "file_id: {}".format(self._streamId.get_file_id())
|
||||||
return "file_id: {}".format(self._streamId.get_file_id())
|
|
||||||
|
|
||||||
def decrypt_time_ms(self) -> int:
|
def decrypt_time_ms(self) -> int:
|
||||||
return self._audioDecrypt.decrypt_time_ms()
|
return self._audioDecrypt.decrypt_time_ms()
|
||||||
|
|||||||
@@ -10,18 +10,17 @@ class SuperAudioFormat(enum.Enum):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get(audio_format: Metadata.AudioFile.Format):
|
def get(audio_format: Metadata.AudioFile.Format):
|
||||||
if audio_format == Metadata.AudioFile.Format.OGG_VORBIS_96 or \
|
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_160 or \
|
||||||
audio_format == Metadata.AudioFile.Format.OGG_VORBIS_320:
|
audio_format == Metadata.AudioFile.Format.OGG_VORBIS_320:
|
||||||
return SuperAudioFormat.VORBIS
|
return SuperAudioFormat.VORBIS
|
||||||
elif audio_format == Metadata.AudioFile.Format.MP3_256 or \
|
if audio_format == Metadata.AudioFile.Format.MP3_256 or \
|
||||||
audio_format == Metadata.AudioFile.Format.MP3_320 or \
|
audio_format == Metadata.AudioFile.Format.MP3_320 or \
|
||||||
audio_format == Metadata.AudioFile.Format.MP3_160 or \
|
audio_format == Metadata.AudioFile.Format.MP3_160 or \
|
||||||
audio_format == Metadata.AudioFile.Format.MP3_96 or \
|
audio_format == Metadata.AudioFile.Format.MP3_96 or \
|
||||||
audio_format == Metadata.AudioFile.Format.MP3_160_ENC:
|
audio_format == Metadata.AudioFile.Format.MP3_160_ENC:
|
||||||
return SuperAudioFormat.MP3
|
return SuperAudioFormat.MP3
|
||||||
elif audio_format == Metadata.AudioFile.Format.AAC_24 or \
|
if audio_format == Metadata.AudioFile.Format.AAC_24 or \
|
||||||
audio_format == Metadata.AudioFile.Format.AAC_48 or \
|
audio_format == Metadata.AudioFile.Format.AAC_48 or \
|
||||||
audio_format == Metadata.AudioFile.Format.AAC_24_NORM:
|
audio_format == Metadata.AudioFile.Format.AAC_24_NORM:
|
||||||
return SuperAudioFormat.AAC
|
return SuperAudioFormat.AAC
|
||||||
else:
|
raise RuntimeError("Unknown audio format: {}".format(audio_format))
|
||||||
raise RuntimeError("Unknown audio format: {}".format(audio_format))
|
|
||||||
|
|||||||
@@ -59,10 +59,9 @@ class Base62:
|
|||||||
out += bytes([0])
|
out += bytes([0])
|
||||||
|
|
||||||
return self.reverse(out)
|
return self.reverse(out)
|
||||||
elif len(out) > estimated_length:
|
if len(out) > estimated_length:
|
||||||
return self.reverse(out[:estimated_length])
|
return self.reverse(out[:estimated_length])
|
||||||
else:
|
return self.reverse(out)
|
||||||
return self.reverse(out)
|
|
||||||
|
|
||||||
def estimate_output_length(self, input_length: int, source_base: int,
|
def estimate_output_length(self, input_length: int, source_base: int,
|
||||||
target_base: int):
|
target_base: int):
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ class Utils:
|
|||||||
fmt = '%%0%dx' % (width // 4)
|
fmt = '%%0%dx' % (width // 4)
|
||||||
if i == 0:
|
if i == 0:
|
||||||
return bytes([0])
|
return bytes([0])
|
||||||
else:
|
return binascii.unhexlify(fmt % i)
|
||||||
return binascii.unhexlify(fmt % i)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def bytes_to_hex(buffer: bytes) -> str:
|
def bytes_to_hex(buffer: bytes) -> str:
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class EventService:
|
|||||||
self.body.write(byte=0x09)
|
self.body.write(byte=0x09)
|
||||||
self.body.write(byte=c)
|
self.body.write(byte=c)
|
||||||
return self
|
return self
|
||||||
elif s is not None:
|
if s is not None:
|
||||||
self.body.write(byte=0x09)
|
self.body.write(byte=0x09)
|
||||||
self.append_no_delimiter(s)
|
self.append_no_delimiter(s)
|
||||||
return self
|
return self
|
||||||
|
|||||||
@@ -73,8 +73,7 @@ class MercuryClient(PacketsReceiver.PacketsReceiver, Closeable):
|
|||||||
resp = self.send_sync(request.request)
|
resp = self.send_sync(request.request)
|
||||||
if 200 <= resp.status_code < 300:
|
if 200 <= resp.status_code < 300:
|
||||||
return json.loads(resp.payload[0])
|
return json.loads(resp.payload[0])
|
||||||
else:
|
raise MercuryClient.MercuryException(resp)
|
||||||
raise MercuryClient.MercuryException(resp)
|
|
||||||
|
|
||||||
def send(self, request: RawMercuryRequest, callback) -> int:
|
def send(self, request: RawMercuryRequest, callback) -> int:
|
||||||
buffer = BytesOutputStream()
|
buffer = BytesOutputStream()
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ class AlbumId(SpotifyId.SpotifyId):
|
|||||||
album_id = matcher.group(1)
|
album_id = matcher.group(1)
|
||||||
return AlbumId(
|
return AlbumId(
|
||||||
Utils.bytes_to_hex(AlbumId._BASE62.decode(album_id, 16)))
|
Utils.bytes_to_hex(AlbumId._BASE62.decode(album_id, 16)))
|
||||||
else:
|
raise TypeError("Not a Spotify album ID: {}.f".format(uri))
|
||||||
raise TypeError("Not a Spotify album ID: {}.f".format(uri))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_base62(base62: str) -> AlbumId:
|
def from_base62(base62: str) -> AlbumId:
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ class ArtistId(SpotifyId.SpotifyId):
|
|||||||
artist_id = matcher.group(1)
|
artist_id = matcher.group(1)
|
||||||
return ArtistId(
|
return ArtistId(
|
||||||
Utils.bytes_to_hex(ArtistId._BASE62.decode(artist_id, 16)))
|
Utils.bytes_to_hex(ArtistId._BASE62.decode(artist_id, 16)))
|
||||||
else:
|
raise TypeError("Not a Spotify artist ID: {}".format(uri))
|
||||||
raise TypeError("Not a Spotify artist ID: {}".format(uri))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_base62(base62: str) -> ArtistId:
|
def from_base62(base62: str) -> ArtistId:
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ class EpisodeId(SpotifyId.SpotifyId, PlayableId):
|
|||||||
return EpisodeId(
|
return EpisodeId(
|
||||||
Utils.Utils.bytes_to_hex(
|
Utils.Utils.bytes_to_hex(
|
||||||
PlayableId.BASE62.decode(episode_id, 16)))
|
PlayableId.BASE62.decode(episode_id, 16)))
|
||||||
else:
|
TypeError("Not a Spotify episode ID: {}".format(uri))
|
||||||
TypeError("Not a Spotify episode ID: {}".format(uri))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_base62(base62: str) -> EpisodeId:
|
def from_base62(base62: str) -> EpisodeId:
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ class ShowId(SpotifyId.SpotifyId):
|
|||||||
show_id = matcher.group(1)
|
show_id = matcher.group(1)
|
||||||
return ShowId(
|
return ShowId(
|
||||||
Utils.bytes_to_hex(ShowId._BASE62.decode(show_id, 16)))
|
Utils.bytes_to_hex(ShowId._BASE62.decode(show_id, 16)))
|
||||||
else:
|
raise TypeError("Not a Spotify show ID: {}".format(uri))
|
||||||
raise TypeError("Not a Spotify show ID: {}".format(uri))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_base62(base62: str) -> ShowId:
|
def from_base62(base62: str) -> ShowId:
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ class TrackId(PlayableId, SpotifyId):
|
|||||||
track_id = search.group(1)
|
track_id = search.group(1)
|
||||||
return TrackId(
|
return TrackId(
|
||||||
Utils.bytes_to_hex(PlayableId.BASE62.decode(track_id, 16)))
|
Utils.bytes_to_hex(PlayableId.BASE62.decode(track_id, 16)))
|
||||||
else:
|
raise RuntimeError("Not a Spotify track ID: {}".format(uri))
|
||||||
raise RuntimeError("Not a Spotify track ID: {}".format(uri))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_base62(base62: str) -> TrackId:
|
def from_base62(base62: str) -> TrackId:
|
||||||
|
|||||||
@@ -11,21 +11,20 @@ class AudioQuality(enum.Enum):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_quality(audio_format: AudioFile.Format) -> AudioQuality:
|
def get_quality(audio_format: AudioFile.Format) -> AudioQuality:
|
||||||
if audio_format == AudioFile.MP3_96 or \
|
if audio_format == AudioFile.MP3_96 or \
|
||||||
audio_format == AudioFile.OGG_VORBIS_96 or \
|
audio_format == AudioFile.OGG_VORBIS_96 or \
|
||||||
audio_format == AudioFile.AAC_24_NORM:
|
audio_format == AudioFile.AAC_24_NORM:
|
||||||
return AudioQuality.NORMAL
|
return AudioQuality.NORMAL
|
||||||
elif audio_format == AudioFile.MP3_160 or \
|
if audio_format == AudioFile.MP3_160 or \
|
||||||
audio_format == AudioFile.MP3_160_ENC or \
|
audio_format == AudioFile.MP3_160_ENC or \
|
||||||
audio_format == AudioFile.OGG_VORBIS_160 or \
|
audio_format == AudioFile.OGG_VORBIS_160 or \
|
||||||
audio_format == AudioFile.AAC_24:
|
audio_format == AudioFile.AAC_24:
|
||||||
return AudioQuality.HIGH
|
return AudioQuality.HIGH
|
||||||
elif audio_format == AudioFile.MP3_320 or \
|
if audio_format == AudioFile.MP3_320 or \
|
||||||
audio_format == AudioFile.MP3_256 or \
|
audio_format == AudioFile.MP3_256 or \
|
||||||
audio_format == AudioFile.OGG_VORBIS_320 or \
|
audio_format == AudioFile.OGG_VORBIS_320 or \
|
||||||
audio_format == AudioFile.AAC_48:
|
audio_format == AudioFile.AAC_48:
|
||||||
return AudioQuality.VERY_HIGH
|
return AudioQuality.VERY_HIGH
|
||||||
else:
|
raise RuntimeError("Unknown format: {}".format(format))
|
||||||
raise RuntimeError("Unknown format: {}".format(format))
|
|
||||||
|
|
||||||
def get_matches(self, files: list[AudioFile]) -> list[AudioFile]:
|
def get_matches(self, files: list[AudioFile]) -> list[AudioFile]:
|
||||||
file_list = []
|
file_list = []
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class ByteArrayOutputStream(OutputStream):
|
|||||||
if byte is not None and buffer is None and offset is None and length is None:
|
if byte is not None and buffer is None and offset is None and length is None:
|
||||||
self.internal_write(byte)
|
self.internal_write(byte)
|
||||||
return
|
return
|
||||||
elif byte is None and buffer is not None and offset is None and length is None:
|
if byte is None and buffer is not None and offset is None and length is None:
|
||||||
offset = 0
|
offset = 0
|
||||||
length = len(buffer)
|
length = len(buffer)
|
||||||
elif not (byte is None and buffer is not None and offset is not None
|
elif not (byte is None and buffer is not None and offset is not None
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ class DataInputStream(FilterInputStream, DataInput):
|
|||||||
length: int = None) -> int:
|
length: int = None) -> int:
|
||||||
if b is not None and offset is None and length is None:
|
if b is not None and offset is None and length is None:
|
||||||
return self.input_stream.read(b, 0, len(b))
|
return self.input_stream.read(b, 0, len(b))
|
||||||
elif b is not None and offset is not None and length is not None:
|
if b is not None and offset is not None and length is not None:
|
||||||
return self.input_stream.read(b, offset, length)
|
return self.input_stream.read(b, offset, length)
|
||||||
else:
|
raise TypeError()
|
||||||
raise TypeError()
|
|
||||||
|
|
||||||
def read_fully(self,
|
def read_fully(self,
|
||||||
b: bytearray = None,
|
b: bytearray = None,
|
||||||
|
|||||||
@@ -35,11 +35,10 @@ class InputStream(Closeable):
|
|||||||
return 0
|
return 0
|
||||||
self.ensure_open()
|
self.ensure_open()
|
||||||
return -1
|
return -1
|
||||||
elif b is None and offset is None and length is None:
|
if b is None and offset is None and length is None:
|
||||||
self.ensure_open()
|
self.ensure_open()
|
||||||
return -1
|
return -1
|
||||||
else:
|
raise TypeError()
|
||||||
raise TypeError()
|
|
||||||
|
|
||||||
def read_all_bytes(self):
|
def read_all_bytes(self):
|
||||||
self.ensure_open()
|
self.ensure_open()
|
||||||
@@ -83,7 +82,7 @@ class InputStream(Closeable):
|
|||||||
length: int = None) -> int:
|
length: int = None) -> int:
|
||||||
if b is None and offset is None and length is None:
|
if b is None and offset is None and length is None:
|
||||||
return self.internal_read()
|
return self.internal_read()
|
||||||
elif b is not None and offset is None and length is None:
|
if b is not None and offset is None and length is None:
|
||||||
offset = 0
|
offset = 0
|
||||||
length = len(b)
|
length = len(b)
|
||||||
elif not (b is not None and offset is not None and length is not None):
|
elif not (b is not None and offset is not None and length is not None):
|
||||||
@@ -165,7 +164,7 @@ class InputStream(Closeable):
|
|||||||
remaining -= count
|
remaining -= count
|
||||||
|
|
||||||
return result
|
return result
|
||||||
elif b is not None and offset is not None and length is not None:
|
if b is not None and offset is not None and length is not None:
|
||||||
if len(b) < (offset + length):
|
if len(b) < (offset + length):
|
||||||
raise IndexError()
|
raise IndexError()
|
||||||
|
|
||||||
@@ -176,8 +175,7 @@ class InputStream(Closeable):
|
|||||||
break
|
break
|
||||||
n += count
|
n += count
|
||||||
return n
|
return n
|
||||||
else:
|
raise TypeError()
|
||||||
raise TypeError()
|
|
||||||
|
|
||||||
def skip(self, n: int) -> int:
|
def skip(self, n: int) -> int:
|
||||||
remaining = n
|
remaining = n
|
||||||
|
|||||||
Reference in New Issue
Block a user