@@ -169,33 +169,31 @@ 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 + __size ])
194+ buffer .seek (0 )
195+ self .__pos += buffer .getbuffer ().nbytes
196+ return buffer .read ()
199197
200198 def notify_chunk_available (self , index : int ) -> None :
201199 self .available_chunks ()[index ] = True
@@ -718,11 +716,10 @@ def load(self, playable_id: PlayableId,
718716 if type (playable_id ) is TrackId :
719717 return self .load_track (playable_id , audio_quality_picker , preload ,
720718 halt_listener )
721- elif type (playable_id ) is EpisodeId :
719+ if type (playable_id ) is EpisodeId :
722720 return self .load_episode (playable_id , audio_quality_picker ,
723721 preload , halt_listener )
724- else :
725- raise TypeError ("Unknown content: {}" .format (playable_id ))
722+ raise TypeError ("Unknown content: {}" .format (playable_id ))
726723
727724 def load_stream (self , file : Metadata .AudioFile , track : Metadata .Track ,
728725 episode : Metadata .Episode , preload : bool ,
@@ -736,7 +733,7 @@ def load_stream(self, file: Metadata.AudioFile, track: Metadata.Track,
736733 response , preload , halt_lister )
737734 return CdnFeedHelper .load_episode (self .__session , episode , file ,
738735 response , preload , halt_lister )
739- elif response .result == StorageResolve .StorageResolveResponse .Result .STORAGE :
736+ if response .result == StorageResolve .StorageResolveResponse .Result .STORAGE :
740737 if track is None :
741738 pass
742739 elif response .result == StorageResolve .StorageResolveResponse .Result .RESTRICTED :
@@ -753,14 +750,12 @@ def load_episode(self, episode_id: EpisodeId,
753750 if episode .external_url :
754751 return CdnFeedHelper .load_episode_external (self .__session , episode ,
755752 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 )
753+ file = audio_quality_picker .get_file (episode .audio )
754+ if file is None :
755+ self .logger .fatal (
756+ "Couldn't find any suitable audio file, available: {}" .format (
757+ episode .audio ))
758+ return self .load_stream (file , None , episode , preload , halt_listener )
764759
765760 def load_track (self , track_id_or_track : typing .Union [TrackId ,
766761 Metadata .Track ],
0 commit comments