@@ -169,33 +169,32 @@ def read(self, __size: int = 0) -> bytes:
169169 buffer .seek (0 )
170170 self .__pos += buffer .getbuffer ().nbytes
171171 return buffer .read ()
172- else :
173- buffer = io .BytesIO ()
174- chunk = int (self .__pos / (128 * 1024 ))
175- chunk_off = int (self .__pos % (128 * 1024 ))
176- chunk_end = int (__size / (128 * 1024 ))
177- chunk_end_off = int (__size % (128 * 1024 ))
178- if chunk_end > self .size ():
179- chunk_end = int (self .size () / (128 * 1024 ))
180- chunk_end_off = int (self .size () % (128 * 1024 ))
181- if chunk_off + __size > len (self .buffer ()[chunk ]):
172+ buffer = io .BytesIO ()
173+ chunk = int (self .__pos / (128 * 1024 ))
174+ chunk_off = int (self .__pos % (128 * 1024 ))
175+ chunk_end = int (__size / (128 * 1024 ))
176+ chunk_end_off = int (__size % (128 * 1024 ))
177+ if chunk_end > self .size ():
178+ chunk_end = int (self .size () / (128 * 1024 ))
179+ chunk_end_off = int (self .size () % (128 * 1024 ))
180+ if chunk_off + __size > len (self .buffer ()[chunk ]):
181+ self .check_availability (chunk , True , False )
182+ buffer .write (self .buffer ()[chunk ][chunk_off :])
183+ chunk += 1
184+ while chunk <= chunk_end :
182185 self .check_availability (chunk , True , False )
183- buffer .write (self .buffer ()[chunk ][chunk_off :])
186+ if chunk == chunk_end :
187+ buffer .write (self .buffer ()[chunk ][:chunk_end_off ])
188+ else :
189+ buffer .write (self .buffer ()[chunk ])
184190 chunk += 1
185- while chunk <= chunk_end :
186- self .check_availability (chunk , True , False )
187- if chunk == chunk_end :
188- buffer .write (self .buffer ()[chunk ][:chunk_end_off ])
189- else :
190- buffer .write (self .buffer ()[chunk ])
191- chunk += 1
192- else :
193- self .check_availability (chunk , True , False )
194- buffer .write (self .buffer ()[chunk ][chunk_off :chunk_off +
195- __size ])
196- buffer .seek (0 )
197- self .__pos += buffer .getbuffer ().nbytes
198- return buffer .read ()
191+ else :
192+ self .check_availability (chunk , True , False )
193+ buffer .write (self .buffer ()[chunk ][chunk_off :chunk_off +
194+ __size ])
195+ buffer .seek (0 )
196+ self .__pos += buffer .getbuffer ().nbytes
197+ return buffer .read ()
199198
200199 def notify_chunk_available (self , index : int ) -> None :
201200 self .available_chunks ()[index ] = True
@@ -718,11 +717,10 @@ def load(self, playable_id: PlayableId,
718717 if type (playable_id ) is TrackId :
719718 return self .load_track (playable_id , audio_quality_picker , preload ,
720719 halt_listener )
721- elif type (playable_id ) is EpisodeId :
720+ if type (playable_id ) is EpisodeId :
722721 return self .load_episode (playable_id , audio_quality_picker ,
723722 preload , halt_listener )
724- else :
725- raise TypeError ("Unknown content: {}" .format (playable_id ))
723+ raise TypeError ("Unknown content: {}" .format (playable_id ))
726724
727725 def load_stream (self , file : Metadata .AudioFile , track : Metadata .Track ,
728726 episode : Metadata .Episode , preload : bool ,
@@ -736,7 +734,7 @@ def load_stream(self, file: Metadata.AudioFile, track: Metadata.Track,
736734 response , preload , halt_lister )
737735 return CdnFeedHelper .load_episode (self .__session , episode , file ,
738736 response , preload , halt_lister )
739- elif response .result == StorageResolve .StorageResolveResponse .Result .STORAGE :
737+ if response .result == StorageResolve .StorageResolveResponse .Result .STORAGE :
740738 if track is None :
741739 pass
742740 elif response .result == StorageResolve .StorageResolveResponse .Result .RESTRICTED :
@@ -753,14 +751,13 @@ def load_episode(self, episode_id: EpisodeId,
753751 if episode .external_url :
754752 return CdnFeedHelper .load_episode_external (self .__session , episode ,
755753 halt_listener )
756- else :
757- file = audio_quality_picker .get_file (episode .audio )
758- if file is None :
759- self .logger .fatal (
760- "Couldn't find any suitable audio file, available: {}" .
761- format (episode .audio ))
762- return self .load_stream (file , None , episode , preload ,
763- halt_listener )
754+ file = audio_quality_picker .get_file (episode .audio )
755+ if file is None :
756+ self .logger .fatal (
757+ "Couldn't find any suitable audio file, available: {}" .
758+ format (episode .audio ))
759+ return self .load_stream (file , None , episode , preload ,
760+ halt_listener )
764761
765762 def load_track (self , track_id_or_track : typing .Union [TrackId ,
766763 Metadata .Track ],
0 commit comments