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