src/streamlink_cli/main.py
def output_stream_http(plugin, initial_streams, external=False, port=0):
    """Continuously output the stream over HTTP."""
    global output

    if not external:
        if not args.player:
            console.exit("The default player (VLC) does not seem to be "
                         "installed. You must specify the path to a player "
                         "executable with --player.")

        title = create_title(plugin)
        server = create_http_server()
        player = output = PlayerOutput(args.player, args=args.player_args,
                                       filename=server.url,
                                       quiet=not args.verbose_player,
                                       title=title)

        try:
            log.info("Starting player: {0}", args.player)
            if player:
                player.open()
        except OSError as err:
            console.exit("Failed to start player: {0} ({1})",
                         args.player, err)
    else:
        server = create_http_server(host=None, port=port)
        player = None

        log.info("Starting server, access with one of:")
        for url in server.urls:
            log.info(" " + url)

    for req in iter_http_requests(server, player):
        user_agent = req.headers.get("User-Agent") or "unknown player"
        log.info("Got HTTP request from {0}".format(user_agent))

        stream_fd = prebuffer = None
        while not stream_fd and (not player or player.running):
            try:
                streams = initial_streams or fetch_streams(plugin)
                initial_streams = None

                for stream_name in (resolve_stream_name(streams, s) for s in args.stream):
                    if stream_name in streams:
                        stream = streams[stream_name]
                        break
                else:
                    log.info("Stream not available, will re-fetch "
                             "streams in 10 sec")
                    sleep(10)
                    continue
            except PluginError as err:
                log.error(u"Unable to fetch new streams: {0}", err)
                continue

            try:
                log.info("Opening stream: {0} ({1})", stream_name,
                         type(stream).shortname())
                stream_fd, prebuffer = open_stream(stream)
            except StreamError as err:
                log.error("{0}", err)

        if stream_fd and prebuffer:
            log.debug("Writing stream to player")
            read_stream(stream_fd, server, prebuffer)

        server.close(True)

    player.close()
    server.close()
def output_stream_http(plugin, initial_streams, external=False, port=0):
    global output

    if not external:
        if not args.player:
            console.exit("The default player (VLC) does not seem to be "
                         "installed. You must specify the path to a player "
                         "executable with --player.")

        title = create_title(plugin)
        server = create_http_server()
        player = output = PlayerOutput(args.player, args=args.player_args,
                                       filename=server.url,
                                       quiet=not args.verbose_player,
                                       title=title)

        try:
            log.info("Starting player: {0}", args.player)
            if player:
                player.open()
        except OSError as err:
            console.exit("Failed to start player: {0} ({1})",
                         args.player, err)
    else:
        server = create_http_server(host=None, port=port)
        player = None

        log.info("Starting server, access with one of:")
        for url in server.urls:
            log.info(" " + url)

    for req in iter_http_requests(server, player):
        user_agent = req.headers.get("User-Agent") or "unknown player"
        log.info("Got HTTP request from {0}".format(user_agent))

        stream_fd = prebuffer = None
        while not stream_fd and (not player or player.running):
            try:
                streams = initial_streams or fetch_streams(plugin)
                initial_streams = None

                for stream_name in (resolve_stream_name(streams, s) for s in args.stream):
                    if stream_name in streams:
                        stream = streams[stream_name]
                        break
                else:
                    log.info("Stream not available, will re-fetch "
                             "streams in 10 sec")
                    sleep(10)
                    continue
            except PluginError as err:
                log.error(u"Unable to fetch new streams: {0}", err)
                continue

            try:
                log.info("Opening stream: {0} ({1})", stream_name,
                         type(stream).shortname())
                stream_fd, prebuffer = open_stream(stream)
            except StreamError as err:
                log.error("{0}", err)

        if stream_fd and prebuffer:
            log.debug("Writing stream to player")
            read_stream(stream_fd, server, prebuffer)

        server.close(True)

    player.close()
    server.close()
def output_stream_http ( plugin , initial_streams , external = False , port = 0 ) : global output if not external : if not args . player : console . exit ( "The default player (VLC) does not seem to be " "installed. You must specify the path to a player " "executable with --player." ) title = create_title ( plugin ) server = create_http_server ( ) player = output = PlayerOutput ( args . player , args = args . player_args , filename = server . url , quiet = not args . verbose_player , title = title ) try : log . info ( "Starting player: {0}" , args . player ) if player : player . open ( ) except OSError as err : console . exit ( "Failed to start player: {0} ({1})" , args . player , err ) else : server = create_http_server ( host = None , port = port ) player = None log . info ( "Starting server, access with one of:" ) for url in server . urls : log . info ( " " + url ) for req in iter_http_requests ( server , player ) : user_agent = req . headers . get ( "User-Agent" ) or "unknown player" log . info ( "Got HTTP request from {0}" . format ( user_agent ) ) stream_fd = prebuffer = None while not stream_fd and ( not player or player . running ) : try : streams = initial_streams or fetch_streams ( plugin ) initial_streams = None for stream_name in ( resolve_stream_name ( streams , s ) for s in args . stream ) : if stream_name in streams : stream = streams [ stream_name ] break else : log . info ( "Stream not available, will re-fetch " "streams in 10 sec" ) sleep ( 10 ) continue except PluginError as err : log . error ( u"Unable to fetch new streams: {0}" , err ) continue try : log . info ( "Opening stream: {0} ({1})" , stream_name , type ( stream ) . shortname ( ) ) stream_fd , prebuffer = open_stream ( stream ) except StreamError as err : log . error ( "{0}" , err ) if stream_fd and prebuffer : log . debug ( "Writing stream to player" ) read_stream ( stream_fd , server , prebuffer ) server . close ( True ) player . close ( ) server . close ( )
Continuously output the stream over HTTP.
Continuously output the stream over HTTP .