src/streamlink_cli/main.py
def handle_stream(plugin, streams, stream_name):
    """Decides what to do with the selected stream.

    Depending on arguments it can be one of these:
     - Output internal command-line
     - Output JSON represenation
     - Continuously output the stream over HTTP
     - Output stream data to selected output

    """

    stream_name = resolve_stream_name(streams, stream_name)
    stream = streams[stream_name]

    # Print internal command-line if this stream
    # uses a subprocess.
    if args.subprocess_cmdline:
        if isinstance(stream, StreamProcess):
            try:
                cmdline = stream.cmdline()
            except StreamError as err:
                console.exit("{0}", err)

            console.msg("{0}", cmdline)
        else:
            console.exit("The stream specified cannot be translated to a command")

    # Print JSON representation of the stream
    elif console.json:
        console.msg_json(stream)

    elif args.stream_url:
        try:
            console.msg("{0}", stream.to_url())
        except TypeError:
            console.exit("The stream specified cannot be translated to a URL")

    # Output the stream
    else:
        # Find any streams with a '_alt' suffix and attempt
        # to use these in case the main stream is not usable.
        alt_streams = list(filter(lambda k: stream_name + "_alt" in k,
                                  sorted(streams.keys())))
        file_output = args.output or args.stdout

        for stream_name in [stream_name] + alt_streams:
            stream = streams[stream_name]
            stream_type = type(stream).shortname()

            if stream_type in args.player_passthrough and not file_output:
                log.info("Opening stream: {0} ({1})", stream_name,
                         stream_type)
                success = output_stream_passthrough(plugin, stream)
            elif args.player_external_http:
                return output_stream_http(plugin, streams, external=True,
                                          port=args.player_external_http_port)
            elif args.player_continuous_http and not file_output:
                return output_stream_http(plugin, streams)
            else:
                log.info("Opening stream: {0} ({1})", stream_name,
                         stream_type)

                success = output_stream(plugin, stream)

            if success:
                break
def handle_stream(plugin, streams, stream_name):
    stream_name = resolve_stream_name(streams, stream_name)
    stream = streams[stream_name]

    # Print internal command-line if this stream
    # uses a subprocess.
    if args.subprocess_cmdline:
        if isinstance(stream, StreamProcess):
            try:
                cmdline = stream.cmdline()
            except StreamError as err:
                console.exit("{0}", err)

            console.msg("{0}", cmdline)
        else:
            console.exit("The stream specified cannot be translated to a command")

    # Print JSON representation of the stream
    elif console.json:
        console.msg_json(stream)

    elif args.stream_url:
        try:
            console.msg("{0}", stream.to_url())
        except TypeError:
            console.exit("The stream specified cannot be translated to a URL")

    # Output the stream
    else:
        # Find any streams with a '_alt' suffix and attempt
        # to use these in case the main stream is not usable.
        alt_streams = list(filter(lambda k: stream_name + "_alt" in k,
                                  sorted(streams.keys())))
        file_output = args.output or args.stdout

        for stream_name in [stream_name] + alt_streams:
            stream = streams[stream_name]
            stream_type = type(stream).shortname()

            if stream_type in args.player_passthrough and not file_output:
                log.info("Opening stream: {0} ({1})", stream_name,
                         stream_type)
                success = output_stream_passthrough(plugin, stream)
            elif args.player_external_http:
                return output_stream_http(plugin, streams, external=True,
                                          port=args.player_external_http_port)
            elif args.player_continuous_http and not file_output:
                return output_stream_http(plugin, streams)
            else:
                log.info("Opening stream: {0} ({1})", stream_name,
                         stream_type)

                success = output_stream(plugin, stream)

            if success:
                break
def handle_stream ( plugin , streams , stream_name ) : stream_name = resolve_stream_name ( streams , stream_name ) stream = streams [ stream_name ] # Print internal command-line if this stream # uses a subprocess. if args . subprocess_cmdline : if isinstance ( stream , StreamProcess ) : try : cmdline = stream . cmdline ( ) except StreamError as err : console . exit ( "{0}" , err ) console . msg ( "{0}" , cmdline ) else : console . exit ( "The stream specified cannot be translated to a command" ) # Print JSON representation of the stream elif console . json : console . msg_json ( stream ) elif args . stream_url : try : console . msg ( "{0}" , stream . to_url ( ) ) except TypeError : console . exit ( "The stream specified cannot be translated to a URL" ) # Output the stream else : # Find any streams with a '_alt' suffix and attempt # to use these in case the main stream is not usable. alt_streams = list ( filter ( lambda k : stream_name + "_alt" in k , sorted ( streams . keys ( ) ) ) ) file_output = args . output or args . stdout for stream_name in [ stream_name ] + alt_streams : stream = streams [ stream_name ] stream_type = type ( stream ) . shortname ( ) if stream_type in args . player_passthrough and not file_output : log . info ( "Opening stream: {0} ({1})" , stream_name , stream_type ) success = output_stream_passthrough ( plugin , stream ) elif args . player_external_http : return output_stream_http ( plugin , streams , external = True , port = args . player_external_http_port ) elif args . player_continuous_http and not file_output : return output_stream_http ( plugin , streams ) else : log . info ( "Opening stream: {0} ({1})" , stream_name , stream_type ) success = output_stream ( plugin , stream ) if success : break
Decides what to do with the selected stream.

    Depending on arguments it can be one of these:
     - Output internal command-line
     - Output JSON represenation
     - Continuously output the stream over HTTP
     - Output stream data to selected output
Decides what to do with the selected stream .