@@ -226,10 +226,13 @@ def open_stream(stream):
226
226
def output_stream (stream ):
227
227
"""Open stream, create output and finally write the stream to output."""
228
228
229
- try :
230
- stream_fd , prebuffer = open_stream (stream )
231
- except StreamError as err :
232
- console .logger .error ("{0}" , err )
229
+ for i in range (args .retry_open ):
230
+ try :
231
+ stream_fd , prebuffer = open_stream (stream )
232
+ break
233
+ except StreamError as err :
234
+ console .logger .error ("{0}" , err )
235
+ else :
233
236
return
234
237
235
238
output = create_output ()
@@ -371,6 +374,29 @@ def fetch_streams(plugin):
371
374
sorting_excludes = args .stream_sorting_excludes )
372
375
373
376
377
+ def fetch_streams_infinite (plugin , interval ):
378
+ """Attempts to fetch streams until some are returned."""
379
+
380
+ try :
381
+ streams = fetch_streams (plugin )
382
+ except PluginError as err :
383
+ console .logger .error ("{0}" , err )
384
+ streams = None
385
+
386
+ if not streams :
387
+ console .logger .info ("Waiting for streams, retrying every {0} "
388
+ "second(s)" , args .retry_streams )
389
+ while not streams :
390
+ sleep (args .retry_streams )
391
+
392
+ try :
393
+ streams = fetch_streams (plugin )
394
+ except PluginError as err :
395
+ console .logger .error ("{0}" , err )
396
+
397
+ return streams
398
+
399
+
374
400
def resolve_stream_name (streams , stream_name ):
375
401
"""Returns the real stream name of a synonym."""
376
402
@@ -424,7 +450,11 @@ def handle_url():
424
450
plugin = livestreamer .resolve_url (args .url )
425
451
console .logger .info ("Found matching plugin {0} for URL {1}" ,
426
452
plugin .module , args .url )
427
- streams = fetch_streams (plugin )
453
+
454
+ if args .retry_streams :
455
+ streams = fetch_streams_infinite (plugin , args .retry_streams )
456
+ else :
457
+ streams = fetch_streams (plugin )
428
458
except NoPluginError :
429
459
console .exit ("No plugin can handle URL: {0}" , args .url )
430
460
except PluginError as err :
0 commit comments