@@ -331,7 +331,7 @@ def load_track(
331331 session : Session , track : Metadata .Track , file : Metadata .AudioFile ,
332332 resp_or_url : typing .Union [StorageResolve .StorageResolveResponse ,
333333 str ], preload : bool ,
334- halt_listener : HaltListener ) -> PlayableContentFeeder . LoadedStream :
334+ halt_listener : HaltListener ) -> LoadedStream :
335335 if type (resp_or_url ) is str :
336336 url = resp_or_url
337337 else :
@@ -345,18 +345,17 @@ def load_track(
345345 normalization_data = NormalizationData .read (input_stream )
346346 if input_stream .skip (0xA7 ) != 0xA7 :
347347 raise IOError ("Couldn't skip 0xa7 bytes!" )
348- return PlayableContentFeeder . LoadedStream (
348+ return LoadedStream (
349349 track ,
350350 streamer ,
351351 normalization_data ,
352- PlayableContentFeeder .Metrics (file .file_id , preload ,
353- - 1 if preload else audio_key_time ),
352+ file .file_id , preload , audio_key_time
354353 )
355354
356355 @staticmethod
357356 def load_episode_external (
358357 session : Session , episode : Metadata .Episode ,
359- halt_listener : HaltListener ) -> PlayableContentFeeder . LoadedStream :
358+ halt_listener : HaltListener ) -> LoadedStream :
360359 resp = session .client ().head (episode .external_url )
361360
362361 if resp .status_code != 200 :
@@ -368,11 +367,11 @@ def load_episode_external(
368367
369368 streamer = session .cdn ().stream_external_episode (
370369 episode , url , halt_listener )
371- return PlayableContentFeeder . LoadedStream (
370+ return LoadedStream (
372371 episode ,
373372 streamer ,
374373 None ,
375- PlayableContentFeeder . Metrics ( None , False , - 1 ),
374+ None , False , - 1
376375 )
377376
378377 @staticmethod
@@ -383,7 +382,7 @@ def load_episode(
383382 resp_or_url : typing .Union [StorageResolve .StorageResolveResponse , str ],
384383 preload : bool ,
385384 halt_listener : HaltListener ,
386- ) -> PlayableContentFeeder . LoadedStream :
385+ ) -> LoadedStream :
387386 if type (resp_or_url ) is str :
388387 url = resp_or_url
389388 else :
@@ -397,12 +396,11 @@ def load_episode(
397396 normalization_data = NormalizationData .read (input_stream )
398397 if input_stream .skip (0xA7 ) != 0xA7 :
399398 raise IOError ("Couldn't skip 0xa7 bytes!" )
400- return PlayableContentFeeder . LoadedStream (
399+ return LoadedStream (
401400 episode ,
402401 streamer ,
403402 normalization_data ,
404- PlayableContentFeeder .Metrics (file .file_id , preload ,
405- - 1 if preload else audio_key_time ),
403+ file .file_id , preload , audio_key_time
406404 )
407405
408406
@@ -748,7 +746,9 @@ def load_stream(self, file: Metadata.AudioFile, track: Metadata.Track,
748746 episode : Metadata .Episode , preload : bool ,
749747 halt_lister : HaltListener ):
750748 if track is None and episode is None :
751- raise RuntimeError ()
749+ raise RuntimeError ("No content passed!" )
750+ elif file is None :
751+ raise RuntimeError ("Content has no audio file!" )
752752 response = self .resolve_storage_interactive (file .file_id , preload )
753753 if response .result == StorageResolve .StorageResolveResponse .Result .CDN :
754754 if track is not None :
@@ -778,6 +778,7 @@ def load_episode(self, episode_id: EpisodeId,
778778 self .logger .fatal (
779779 "Couldn't find any suitable audio file, available: {}" .format (
780780 episode .audio ))
781+ raise FeederException ("Cannot find suitable audio file" )
781782 return self .load_stream (file , None , episode , preload , halt_listener )
782783
783784 def load_track (self , track_id_or_track : typing .Union [TrackId ,
@@ -797,7 +798,7 @@ def load_track(self, track_id_or_track: typing.Union[TrackId,
797798 self .logger .fatal (
798799 "Couldn't find any suitable audio file, available: {}" .format (
799800 track .file ))
800- raise FeederException ()
801+ raise FeederException ("Cannot find suitable audio file" )
801802 return self .load_stream (file , track , None , preload , halt_listener )
802803
803804 def pick_alternative_if_necessary (
@@ -848,43 +849,41 @@ def resolve_storage_interactive(
848849 storage_resolve_response .ParseFromString (body )
849850 return storage_resolve_response
850851
851- class LoadedStream :
852- episode : Metadata .Episode
853- track : Metadata .Track
854- input_stream : GeneralAudioStream
855- normalization_data : NormalizationData
856- metrics : PlayableContentFeeder .Metrics
857-
858- def __init__ (self , track_or_episode : typing .Union [Metadata .Track ,
859- Metadata .Episode ],
860- input_stream : GeneralAudioStream ,
861- normalization_data : typing .Union [NormalizationData , None ],
862- metrics : PlayableContentFeeder .Metrics ):
863- if type (track_or_episode ) is Metadata .Track :
864- self .track = track_or_episode
865- self .episode = None
866- elif type (track_or_episode ) is Metadata .Episode :
867- self .track = None
868- self .episode = track_or_episode
869- else :
870- raise TypeError ()
871- self .input_stream = input_stream
872- self .normalization_data = normalization_data
873- self .metrics = metrics
852+
853+ class LoadedStream :
854+ episode : Metadata .Episode
855+ track : Metadata .Track
856+ input_stream : GeneralAudioStream
857+ normalization_data : NormalizationData
858+ metrics : Metrics
874859
875860 class Metrics :
876861 file_id : str
877862 preloaded_audio_key : bool
878863 audio_key_time : int
879864
880865 def __init__ (self , file_id : typing .Union [bytes , None ],
881- preloaded_audio_key : bool , audio_key_time : int ):
866+ preloaded_audio_key : bool , audio_key_time : int ):
882867 self .file_id = None if file_id is None else util .bytes_to_hex (
883868 file_id )
884869 self .preloaded_audio_key = preloaded_audio_key
885- self .audio_key_time = audio_key_time
886- if preloaded_audio_key and audio_key_time != - 1 :
887- raise RuntimeError ()
870+ self .audio_key_time = - 1 if preloaded_audio_key else audio_key_time
871+
872+ def __init__ (self , track_or_episode : typing .Union [Metadata .Track , Metadata .Episode ],
873+ input_stream : GeneralAudioStream ,
874+ normalization_data : typing .Union [NormalizationData , None ],
875+ file_id : str , preloaded_audio_key : bool , audio_key_time : int ):
876+ if type (track_or_episode ) is Metadata .Track :
877+ self .track = track_or_episode
878+ self .episode = None
879+ elif type (track_or_episode ) is Metadata .Episode :
880+ self .track = None
881+ self .episode = track_or_episode
882+ else :
883+ raise TypeError ()
884+ self .input_stream = input_stream
885+ self .normalization_data = normalization_data
886+ self .metrics = self .Metrics (file_id , preloaded_audio_key , audio_key_time )
888887
889888
890889class StreamId :
0 commit comments